View Javadoc
1 /* file name : InvokeSpecial.java 2 * authors : Christopher Ellsworth (Chris@chrisellsworth.com) 3 * Clarence Alston 4 * created : 11/15/2002 12:10:39 5 * 6 * modifications: 7 * 8 */ 9 package jrre.instructionset.methodinvocation; 10 11 import jrre.*; 12 import jrre.types.*; 13 import jrre.classloader.classfile.pool_entries.*; 14 import jrre.api.java.lang.reflect.*; 15 16 /*** 17 * Represents and contains execution tasks for the <code>invokespecial</code> 18 * instruction. This is used when calling the constructor of a method. 19 * 20 * @author Christopher Ellsworth (Chris@chrisellsworth.com) 21 * @author Clarence Alston 22 */ 23 public class InvokeStatic extends jrre.instructionset.Instruction { 24 25 private int operandOne; 26 private int operandTwo; 27 28 public InvokeStatic(int operandOne, int operandTwo){ 29 this.operandOne = operandOne; 30 this.operandTwo = operandTwo; 31 name="invokestatic"; 32 length=2; 33 } 34 35 /*** 36 * Executed the <code>invokestatic</code> instruction on the 37 * specified stack frame. 38 * 39 * @param stackFrame The stack frame to modify during execution. 40 */ 41 public void execute(){ 42 43 int cpMethodIndex = (operandOne << 8) | operandTwo; 44 45 // This should not be here for static. 46 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod(); 47 48 CPMethodRef methodRef = (CPMethodRef)thisClass.getSymbol(cpMethodIndex); 49 50 CPClass cpClass = (CPClass)thisClass.getSymbol(methodRef.getClassIndex()); 51 CPUTF8 cpClassUTF8 = (CPUTF8)thisClass.getSymbol(cpClass.getNameIndex()); 52 53 CPNameType methodNameType = (CPNameType)thisClass.getSymbol(methodRef.getNameTypeIndex()); 54 55 String methodName = ((CPUTF8)thisClass.getSymbol(methodNameType.getNameIndex())).getValue(); 56 String methodType = ((CPUTF8)thisClass.getSymbol(methodNameType.getDescriptorIndex())).getValue(); 57 58 methodName += methodType; 59 60 jrre.api.java.lang.Class methodClass = MethodArea.getClass(cpClassUTF8.getValue()); 61 if(methodClass == null){ 62 //System.out.println("Shit in invokestatic: ln. 62"); 63 return; 64 } 65 66 //System.out.println(methodClass.getFullyQualifiedName()); 67 //System.out.println("MethodName: "+methodName); 68 //System.out.println("Des: "+methodClass.getMethod(methodName).getDescriptor()); 69 70 jrre.api.java.lang.reflect.MethodEntry method = methodClass.getMethod(methodName); 71 72 73 if(method.getMethodAccessFlags().isNative()){ 74 75 jrre.NativeMethodArea.addMethod(methodClass.getFullyQualifiedName()+"."+methodName); 76 77 if(JRRE.getVerbose()){ 78 System.out.println("\nNative: "+methodName); 79 System.out.println("In Class: "+methodClass.getFullyQualifiedName()); 80 } 81 if(methodName.equals("currentTimeMillis()J")){ 82 Stack.pushOperand(new PrimitiveType(1)); 83 Stack.pushOperand(new PrimitiveType(1)); 84 } 85 if(methodName.equals("registerNatives()V")){ 86 87 jrre.nativesystem.NativeMethodTable nativeMethodTable; 88 nativeMethodTable = new jrre.nativesystem.NativeMethodTable(); 89 90 nativeMethodTable.registerClassNatives(methodClass.getFullyQualifiedName()); 91 } 92 else if(methodName.equals("arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V")){ 93 94 int length = ((PrimitiveType)Stack.popOperand()).getValue(); 95 int endPosition = ((PrimitiveType)Stack.popOperand()).getValue(); 96 97 Type destArrayRef = Stack.popOperand(); 98 99 int startPosition = ((PrimitiveType)Stack.popOperand()).getValue(); 100 101 ReferenceType sourceArrayRef = (ReferenceType)Stack.popOperand(); 102 103 ArrayInstance sourceArray = (ArrayInstance)sourceArrayRef.getValue(); 104 ArrayInstance destArray = (ArrayInstance)((ReferenceType)destArrayRef).getValue(); 105 106 if(destArray.getSize() < length){ 107 System.out.println("Resizing Array: "); 108 destArray.setSize(sourceArray.getSize()); 109 } 110 111 //System.out.println("Source: "+sourceArray.getElement(0)); 112 //System.out.println("Before: "+destArray.getElement(0)); 113 114 Object [] parameters = { sourceArray, 115 new Integer(startPosition), 116 destArray, 117 new Integer(endPosition), 118 new Integer(length) }; 119 120 jrre.nativesystem.NativeMethodTable nativeMethodTable; 121 nativeMethodTable = new jrre.nativesystem.NativeMethodTable(); 122 123 nativeMethodTable.invokeMethod("Java_java_lang_System_arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V", 124 parameters); 125 126 //System.out.println("After: "+destArray.getElement(0)); 127 128 } 129 return; 130 } 131 132 /* 133 if(methodName.startsWith("println")){ 134 System.out.println("System.out.println execution"); 135 System.out.println(((PrimitiveType)Stack.popOperand()).getValue()); 136 return; 137 } 138 */ 139 140 StackFrame newStackFrame = method.getStackFrame(); 141 142 143 // get parameters. 144 String descriptor = method.getDescriptor(); 145 //System.out.println("invokestatic descriptor: "+descriptor); 146 147 java.util.Iterator methodTypeIterator = DescriptorDecoder.getMethodTypes(descriptor); 148 149 int localVariableIndex = DescriptorDecoder.getParameterCount()-1; 150 151 methodTypeIterator.next(); 152 153 while(methodTypeIterator.hasNext()){ 154 newStackFrame.setLocalVariable(localVariableIndex--, Stack.popOperand()); 155 if(JRRE.getVerbose()) 156 System.out.println("\tparam: "+newStackFrame.getLocalVariable(localVariableIndex+1)); 157 methodTypeIterator.next(); 158 } 159 160 Stack.push(newStackFrame, 161 cpClassUTF8.getValue()+"::"+ 162 method.getFullyQualifiedName()); 163 } 164 165 public String toString(){ 166 StringBuffer toReturn = new StringBuffer(); 167 toReturn.append("invokestatic "); 168 toReturn.append(Integer.toHexString(operandOne)); 169 toReturn.append(" "); 170 toReturn.append(Integer.toHexString(operandTwo)); 171 172 return toReturn.toString(); 173 } 174 } 175

This page was automatically generated by Maven