KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > bytecode > GETFIELD


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.jvm.bytecode;
20
21 import gov.nasa.jpf.JPFException;
22 import gov.nasa.jpf.jvm.ElementInfo;
23 import gov.nasa.jpf.jvm.KernelState;
24 import gov.nasa.jpf.jvm.SystemState;
25 import gov.nasa.jpf.jvm.ThreadInfo;
26
27 import gov.nasa.jpf.jvm.FieldInfo;
28 import gov.nasa.jpf.jvm.DynamicArea;
29
30
31 /**
32  * Fetch field from object
33  * ..., objectref => ..., value
34  */

35 public class GETFIELD extends InstanceFieldInstruction {
36   public Instruction execute (SystemState ss, KernelState ks, ThreadInfo ti) {
37     int objRef = lastThis = ti.pop();
38     if (objRef == -1) {
39       return ti.createAndThrowException("java.lang.NullPointerException",
40                                         "referencing field '" + fname + "' on null object");
41     }
42     
43     FieldInfo fi = getFieldInfo();
44     ElementInfo ei = DynamicArea.getHeap().get(objRef);
45     
46     // We could encapsulate the push in ElementInfo, but not the GET, so
47
// we keep it at a similiar level
48
switch (fi.getStorageSize()) {
49       case 1:
50         ti.push( ei.getIntField(fi), fi.isReference());
51         break;
52       case 2:
53         ti.longPush( ei.getLongField(fi));
54         break;
55       default:
56         throw new JPFException("invalid field type");
57     }
58            
59     return getNext(ti);
60   }
61   
62   public int getByteCode () {
63     return 0xB4;
64   }
65   
66   public boolean isSchedulingRelevant (SystemState ss, KernelState ks, ThreadInfo ti) {
67     // note that reachable doesn't really mean it's accessible, but
68
// we get the reachability for free during GC
69

70     if (ti.usePorFieldBoundaries()) {
71       int objRef = ti.peek();
72       return isSchedulingRelevant(ks, ti, objRef);
73     }
74     
75     return false;
76   }
77   
78 }
79
Popular Tags