View Javadoc
1 package jrre.instructionset.objects; 2 3 import jrre.*; 4 import jrre.types.*; 5 import jrre.classloader.classfile.pool_entries.*; 6 7 public class PutStatic extends jrre.instructionset.Instruction { 8 9 private int operandOne; 10 private int operandTwo; 11 12 public PutStatic(int operandOne, int operandTwo){ 13 14 this.operandOne = operandOne; 15 this.operandTwo = operandTwo; 16 17 name = "putstatic "+operandOne+" "+operandTwo; 18 description = "pushes a field."; 19 length = 2; 20 } 21 22 /*** 23 * Executes the <strong><code>putstatic</code></strong> instruction. 24 * 25 */ 26 public void execute(){ 27 28 int fieldIndex = (operandOne << 8 | operandTwo); 29 30 // Get this class. 31 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod(); 32 33 CPFieldRef fieldRef = (CPFieldRef)thisClass.getSymbol(fieldIndex); 34 CPNameType nameType = (CPNameType)thisClass.getSymbol(fieldRef.getNameType()); 35 36 CPUTF8 fieldDescriptor = (CPUTF8)thisClass.getSymbol(nameType.getDescriptorIndex()); 37 CPUTF8 fieldName = (CPUTF8)thisClass.getSymbol(nameType.getNameIndex()); 38 39 String descriptor = fieldName.getValue()+"::"+fieldDescriptor.getValue(); 40 41 // Get class containing the field. 42 CPClass cpClass = (CPClass)thisClass.getSymbol(fieldRef.getClassIndex()); 43 CPUTF8 cpClassName = (CPUTF8)thisClass.getSymbol(cpClass.getNameIndex()); 44 45 String className = cpClassName.getValue(); 46 47 jrre.api.java.lang.Class classContainingField = MethodArea.getClass(className); 48 49 Type valueToPut = Stack.popOperand(); 50 51 //System.out.println("key: "+descriptor+" value: "+valueToPut+" in: "+classContainingField); 52 classContainingField.setStaticMemberValue(descriptor, valueToPut); 53 54 } 55 56 public String toString(){ 57 StringBuffer toReturn = new StringBuffer(); 58 toReturn.append("putstatic "); 59 toReturn.append(Integer.toHexString(operandOne)); 60 toReturn.append(" "); 61 toReturn.append(Integer.toHexString(operandTwo)); 62 return toReturn.toString(); 63 } 64 }

This page was automatically generated by Maven