/** * Stores an element to an array. * * Operand stack: * ..., array, index, value -> ... * * @param elementType the type of the value to be stored. */ public CompactCodeAttributeComposer storeToArray(String elementType) { switch (elementType.charAt(0)) { case TYPE_BOOLEAN: case TYPE_BYTE: return bastore(); case TYPE_CHAR: return castore(); case TYPE_SHORT: return sastore(); case TYPE_INT: return iastore(); case TYPE_LONG: return lastore(); case TYPE_FLOAT: return fastore(); case TYPE_DOUBLE: return dastore(); default: return aastore(); } }
/** * Loads the given variable of primitive type onto the stack. * * Operand stack: * ... -> ..., value * * @param variableIndex the index of the variable to be loaded. * @param internalType the primitive type of the variable to be loaded. */ public CompactCodeAttributeComposer load(int variableIndex, char internalType) { switch (internalType) { case TYPE_BOOLEAN: case TYPE_BYTE: case TYPE_CHAR: case TYPE_SHORT: case TYPE_INT: return iload(variableIndex); case TYPE_LONG: return lload(variableIndex); case TYPE_FLOAT: return fload(variableIndex); case TYPE_DOUBLE: return dload(variableIndex); default: return aload(variableIndex); } }
/** * Appends instructions to print out the given message and the top int on * the stack. */ public CompactCodeAttributeComposer appendPrintIntegerInstructions(String message) { appendPrintInstructions(message); appendPrintIntegerInstructions(); return this; }
/** * Appends instructions to print out the given message and the top int on * the stack as a hexadecimal value. */ public CompactCodeAttributeComposer appendPrintIntegerHexInstructions(String message) { appendPrintInstructions(message); appendPrintIntegerHexInstructions(); return this; }
/** * Appends instructions to print out the given message and the top String on * the stack. */ public CompactCodeAttributeComposer appendPrintStringInstructions(String message) { appendPrintInstructions(message); appendPrintStringInstructions(); return this; }
10); composer.aload_0() .invokespecial(ClassConstants.NAME_JAVA_LANG_OBJECT, ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT) .return_(); composer.new_(lambdaClass.getName()) .dup() .invokespecial(lambdaClass.getName(), ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT) .putstatic(lambdaClass.getName(), LAMBDA_SINGLETON_FIELD_NAME, lambdaClassType) .return_(); composer.getstatic(lambdaClass.getName(), LAMBDA_SINGLETON_FIELD_NAME, lambdaClassType) .areturn(); composer.new_(lambdaExpression.invokedClassName) .dup(); composer.load(paramIndex, type); paramIndex += ClassUtil.internalTypeSize(type);
50); composer.aload_0() .invokespecial(ClassConstants.NAME_JAVA_LANG_OBJECT, ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT); type); composer.aload_0(); composer.load(variableIndex, type); composer.putfield(lambdaClass.getName(), fieldName, type); composer.return_(); composer.aload_0() .getfield(lambdaClass.getName(), fieldName, type);
public CompactCodeAttributeComposer tableswitch(int defaultOffset, int lowCase, int highCase, int[] jumpOffsets) { return add(new TableSwitchInstruction(InstructionConstants.OP_TABLESWITCH, defaultOffset, lowCase, highCase, jumpOffsets)); }
public static void main(String[] args) { ProgramClass targetClass = new ProgramClass(0, 0, new Constant[32], 0, 0, 0); CompactCodeAttributeComposer composer = new CompactCodeAttributeComposer(targetClass); composer.beginCodeFragment(4); composer.appendInstruction(0, new SimpleInstruction(InstructionConstants.OP_ICONST_0)); composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ISTORE, 0)); composer.appendInstruction(2, new BranchInstruction(InstructionConstants.OP_GOTO, 1)); composer.beginCodeFragment(4); composer.appendInstruction(0, new VariableInstruction(InstructionConstants.OP_IINC, 0, 1)); composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ILOAD, 0)); composer.appendInstruction(2, new SimpleInstruction(InstructionConstants.OP_ICONST_5)); composer.appendInstruction(3, new BranchInstruction(InstructionConstants.OP_IFICMPLT, -3)); composer.endCodeFragment(); composer.appendInstruction(3, new SimpleInstruction(InstructionConstants.OP_RETURN)); composer.endCodeFragment(); } }
50); composer.aload_0(); String interfaceType = interfaceTypeEnumeration.nextType(); composer.load(variableIndex, type); variableIndex += ClassUtil.internalTypeSize(type); composer.invokevirtual(lambdaClass.getName(), lambdaExpression.interfaceMethod, lambdaExpression.interfaceMethodDescriptor); composer); composer.return_(methodReturnType);
/** * Pushes a new array on the stack. * * Operand stack: * ... -> ..., array * * @param elementTypeOrClassName the array element type (or class name in case of objects). * @param size the size of the array to be created. */ public CompactCodeAttributeComposer pushNewArray(String elementTypeOrClassName, int size) { // Create new array. pushInt(size); return ClassUtil.isInternalPrimitiveType(elementTypeOrClassName) ? newarray(InstructionUtil.arrayTypeFromInternalType(elementTypeOrClassName.charAt(0))) : anewarray(elementTypeOrClassName, null); }
ClassConstants.METHOD_TYPE_INIT, 10) .aload_0() .invokespecial(ClassConstants.NAME_JAVA_LANG_OBJECT, ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT) .return_();
/** * Appends instructions to print out the given message and the top Object on * the stack. */ public CompactCodeAttributeComposer appendPrintObjectInstructions(String message) { appendPrintInstructions(message); appendPrintObjectInstructions(); return this; }
/** * Appends instructions to print out the given message and the top long on * the stack. */ public CompactCodeAttributeComposer appendPrintLongInstructions(String message) { appendPrintInstructions(message); appendPrintLongInstructions(); return this; }
/** * Appends instructions to print out the given message and the stack trace * of the top Throwable on the stack. */ public CompactCodeAttributeComposer appendPrintStackTraceInstructions(String message) { appendPrintInstructions(message); appendPrintStackTraceInstructions(); return this; }
public CompactCodeAttributeComposer anewarray(String className, Clazz referencedClass) { return anewarray(constantPoolEditor.addClassConstant(className, referencedClass)); }
10); composer.aload_0() .invokespecial(ClassConstants.NAME_JAVA_LANG_OBJECT, ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT) .return_(); composer.new_(lambdaClass.getName()) .dup() .invokespecial(lambdaClass.getName(), ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT) .putstatic(lambdaClass.getName(), LAMBDA_SINGLETON_FIELD_NAME, lambdaClassType) .return_(); composer.getstatic(lambdaClass.getName(), LAMBDA_SINGLETON_FIELD_NAME, lambdaClassType) .areturn(); composer.new_(lambdaExpression.invokedClassName) .dup(); composer.load(paramIndex, type); paramIndex += ClassUtil.internalTypeSize(type);
50); composer.aload_0() .invokespecial(ClassConstants.NAME_JAVA_LANG_OBJECT, ClassConstants.METHOD_NAME_INIT, ClassConstants.METHOD_TYPE_INIT); type); composer.aload_0(); composer.load(variableIndex, type); composer.putfield(lambdaClass.getName(), fieldName, type); composer.return_(); composer.aload_0() .getfield(lambdaClass.getName(), fieldName, type);
public CompactCodeAttributeComposer lookupswitch(int defaultOffset, int[] cases, int[] jumpOffsets) { return add(new LookUpSwitchInstruction(InstructionConstants.OP_LOOKUPSWITCH, defaultOffset, cases, jumpOffsets)); }
public static void main(String[] args) { ProgramClass targetClass = new ProgramClass(0, 0, new Constant[32], 0, 0, 0); CompactCodeAttributeComposer composer = new CompactCodeAttributeComposer(targetClass); composer.beginCodeFragment(4); composer.appendInstruction(0, new SimpleInstruction(InstructionConstants.OP_ICONST_0)); composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ISTORE, 0)); composer.appendInstruction(2, new BranchInstruction(InstructionConstants.OP_GOTO, 1)); composer.beginCodeFragment(4); composer.appendInstruction(0, new VariableInstruction(InstructionConstants.OP_IINC, 0, 1)); composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ILOAD, 0)); composer.appendInstruction(2, new SimpleInstruction(InstructionConstants.OP_ICONST_5)); composer.appendInstruction(3, new BranchInstruction(InstructionConstants.OP_IFICMPLT, -3)); composer.endCodeFragment(); composer.appendInstruction(3, new SimpleInstruction(InstructionConstants.OP_RETURN)); composer.endCodeFragment(); } }