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 New extends jrre.instructionset.Instruction { 8 9 private int operandOne; 10 private int operandTwo; 11 12 public New(int operandOne, int operandTwo){ 13 14 name = "new"; 15 description = "foo foo moo poo"; 16 length = 2; 17 18 this.operandOne = operandOne; 19 this.operandTwo = operandTwo; 20 } 21 22 /*** 23 * Executes the <strong><code>new</code></strong> instruction. 24 * 25 */ 26 public void execute(){ 27 28 // Get this class. 29 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod(); 30 31 int cpClassIndex = (operandOne << 8) | operandTwo; 32 33 CPClass classRef = (CPClass)thisClass.getSymbol(cpClassIndex); 34 String className = ((CPUTF8)thisClass.getSymbol(classRef.getNameIndex())).getValue(); 35 36 //System.out.println("new: "+className); 37 38 jrre.api.java.lang.Class classToNew = MethodArea.getClass(className); 39 if(classToNew == null){ 40 return; 41 } 42 43 ObjectInstance newObject = classToNew.instanceOf(); 44 45 String key = className; 46 ObjectArea.addObject(key, newObject); 47 48 Stack.pushOperand(new ReferenceType(newObject)); 49 50 } 51 52 public String toString(){ 53 StringBuffer toReturn = new StringBuffer(); 54 toReturn.append("new "); 55 toReturn.append(Integer.toHexString(operandOne)); 56 toReturn.append(" "); 57 toReturn.append(Integer.toHexString(operandTwo)); 58 return toReturn.toString(); 59 } 60 }

This page was automatically generated by Maven