1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter.operations;
11
12 import java.io.DataInput;
13 import java.io.IOException;
14 import java.lang.reflect.Field;
15
16 import nl.tudelft.simulation.dsol.interpreter.InterpreterException;
17 import nl.tudelft.simulation.dsol.interpreter.LocalVariable;
18 import nl.tudelft.simulation.dsol.interpreter.OperandStack;
19 import nl.tudelft.simulation.dsol.interpreter.classfile.Constant;
20 import nl.tudelft.simulation.dsol.interpreter.classfile.ConstantFieldref;
21 import nl.tudelft.simulation.language.reflection.ClassUtil;
22
23 /***
24 * The GETSTATIC operation as defined in <a
25 * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc5.html">
26 * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc5.html
27 * </a>.
28 * <p>
29 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
30 * University of Technology </a>, the Netherlands. <br>
31 * See for project information <a
32 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
33 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
34 * License (GPL) </a>, no warranty <br>
35 *
36 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
37 * Jacobs </a><a
38 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
39 * Verbraeck </a>
40 * @version 1.3 Apr 6, 2004
41 * @since 1.4
42 */
43 public class GETSTATIC extends VoidOperation
44 {
45 /*** OP refers to the operand code */
46 public static final int OP = 178;
47
48 /*** the index to load */
49 private int index = -1;
50
51 /***
52 * constructs a new GETSTATIC
53 *
54 * @param dataInput the dataInput
55 * @throws IOException on IOfailure
56 */
57 public GETSTATIC(final DataInput dataInput) throws IOException
58 {
59 super();
60 this.index = dataInput.readUnsignedShort();
61 }
62
63 /***
64 * @see nl.tudelft.simulation.dsol.interpreter.operations.VoidOperation
65 * #execute(nl.tudelft.simulation.dsol.interpreter.OperandStack,
66 * nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
67 * nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
68 */
69 public void execute(final OperandStack stack,
70 final Constant[] constantPool, final LocalVariable[] localVariables)
71 {
72 try
73 {
74 ConstantFieldref constantFieldref = (ConstantFieldref) constantPool[this.index];
75 Class referenceClass = constantFieldref.getConstantClass()
76 .getValue().getClassValue();
77 Field field = ClassUtil.resolveField(referenceClass,
78 constantFieldref.getConstantNameAndType().getName());
79 field.setAccessible(true);
80 stack.push(field.get(null));
81 } catch (Exception exception)
82 {
83 throw new InterpreterException(exception);
84 }
85 }
86
87 /***
88 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
89 */
90 public int getByteLength()
91 {
92 return OPCODE_BYTE_LENGTH + 2;
93 }
94
95 /***
96 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
97 */
98 public int getOpcode()
99 {
100 return GETSTATIC.OP;
101 }
102 }