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.Stack;
12 import jrre.StackFrame;
13 import jrre.MethodArea;
14 import jrre.types.*;
15 import jrre.api.java.lang.reflect.DescriptorDecoder;
16 import jrre.classloader.classfile.pool_entries.*;
17
18 /***
19 * Represents and contains execution tasks for the <code>invokespecial</code>
20 * instruction. This is used when calling the constructor of a method.
21 *
22 * @author Christopher Ellsworth (Chris@chrisellsworth.com)
23 * @author Clarence Alston
24 */
25 public class InvokeSpecial extends jrre.instructionset.Instruction {
26
27 private int operandOne;
28 private int operandTwo;
29
30 public InvokeSpecial(int operandOne, int operandTwo){
31 this.operandOne = operandOne;
32 this.operandTwo = operandTwo;
33 length=2;
34 }
35
36 /***
37 * Executed the <code>invokespecial</code> instruction on the
38 * specified stack frame.
39 */
40 public void execute(){
41
42 int cpMethodIndex = (operandOne << 8) | operandTwo;
43
44 // pop object and get methodref from objects symbol table.
45 //ReferenceType objectReference = (ReferenceType)Stack.popOperand();
46
47 // Get this class.
48 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod();
49
50 CPMethodRef methodRef = (CPMethodRef)thisClass.getSymbol(cpMethodIndex);
51
52 CPClass cpClass = (CPClass)thisClass.getSymbol(methodRef.getClassIndex());
53 CPUTF8 cpClassUTF8 = (CPUTF8)thisClass.getSymbol(cpClass.getNameIndex());
54
55 CPNameType methodNameType = (CPNameType)thisClass.getSymbol(methodRef.getNameTypeIndex());
56
57 String methodName = ((CPUTF8)thisClass.getSymbol(methodNameType.getNameIndex())).getValue();
58 String methodType = ((CPUTF8)thisClass.getSymbol(methodNameType.getDescriptorIndex())).getValue();
59
60 methodName += methodType;
61 jrre.api.java.lang.Class methodClass = MethodArea.getClass(cpClassUTF8.getValue());
62
63 //System.out.println(methodClass.getFullyQualifiedName());
64 //System.out.println("MethodName: "+methodName);
65 //System.out.println("Des: "+methodClass.getMethod(methodName).getDescriptor());
66
67 jrre.api.java.lang.reflect.MethodEntry method = methodClass.getMethod(methodName);
68 if(method.getMethodAccessFlags().isNative()){
69 if(jrre.JRRE.getVerbose())
70 System.out.println("Native: "+methodName);
71 return;
72 }
73
74 StackFrame newStackFrame = method.getStackFrame();
75
76 // get parameters.
77 String descriptor = method.getDescriptor();
78 java.util.Iterator methodTypeIterator = DescriptorDecoder.getMethodTypes(descriptor);
79
80 //int localVariableIndex = 1;
81 int localVariableIndex = DescriptorDecoder.getParameterCount();
82
83 // get return type.
84 methodTypeIterator.next();
85
86 while(methodTypeIterator.hasNext()){
87 newStackFrame.setLocalVariable(localVariableIndex--, Stack.popOperand());
88 if(jrre.JRRE.getVerbose())
89 System.out.println("\tparam: "+newStackFrame.getLocalVariable(localVariableIndex+1));
90 methodTypeIterator.next();
91 }
92
93 newStackFrame.setLocalVariable(0, Stack.popOperand());
94 if(jrre.JRRE.getVerbose())
95 System.out.println("obj: "+newStackFrame.getLocalVariable(localVariableIndex));
96
97 Stack.push(newStackFrame,
98 method.getFullyQualifiedName()+"::"+
99 cpClassUTF8.getValue());
100
101 }
102
103 public String toString(){
104 StringBuffer toReturn = new StringBuffer();
105 toReturn.append("invokespecial ");
106 toReturn.append(Integer.toHexString(operandOne));
107 toReturn.append(" ");
108 toReturn.append(Integer.toHexString(operandTwo));
109
110 return toReturn.toString();
111 }
112 }
113
This page was automatically generated by Maven