List of usage examples for org.objectweb.asm Opcodes T_BYTE
int T_BYTE
To view the source code for org.objectweb.asm Opcodes T_BYTE.
Click Source Link
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
/** * Generates the instruction to create a new array. * * @param type the type of the array elements. *//* w w w.j ava 2s. c om*/ public void newArray(final Type type) { int typ; switch (type.getSort()) { case Type.BOOLEAN: typ = Opcodes.T_BOOLEAN; break; case Type.CHAR: typ = Opcodes.T_CHAR; break; case Type.BYTE: typ = Opcodes.T_BYTE; break; case Type.SHORT: typ = Opcodes.T_SHORT; break; case Type.INT: typ = Opcodes.T_INT; break; case Type.FLOAT: typ = Opcodes.T_FLOAT; break; case Type.LONG: typ = Opcodes.T_LONG; break; case Type.DOUBLE: typ = Opcodes.T_DOUBLE; break; default: typeInsn(Opcodes.ANEWARRAY, type); return; } visitIntInsn(Opcodes.NEWARRAY, typ); }
From source file:org.jboss.byteman.rule.expression.ArrayInitExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); Type baseType = getType().getBaseType(); int currentStack = compileContext.getStackCount(); int expected = 1; int length = elements.size(); // stack array size and then create the array mv.visitLdcInsn(length);//w ww . j ava 2s. co m compileContext.addStackCount(1); // new array pops count and pushes array so no change to stack size if (baseType.isArray()) { mv.visitMultiANewArrayInsn(getType().getInternalName(), 1); } else if (baseType.isObject()) { mv.visitTypeInsn(Opcodes.ANEWARRAY, baseType.getInternalName()); } else { int operand = 0; if (baseType.equals(Type.Z)) { operand = Opcodes.T_BOOLEAN; } else if (baseType.equals(Type.B)) { operand = Opcodes.T_BYTE; } else if (baseType.equals(Type.S)) { operand = Opcodes.T_SHORT; } else if (baseType.equals(Type.C)) { operand = Opcodes.T_CHAR; } else if (baseType.equals(Type.I)) { operand = Opcodes.T_INT; } else if (baseType.equals(Type.J)) { operand = Opcodes.T_LONG; } else if (baseType.equals(Type.F)) { operand = Opcodes.T_FLOAT; } else if (baseType.equals(Type.D)) { operand = Opcodes.T_DOUBLE; } mv.visitIntInsn(Opcodes.NEWARRAY, operand); } int idx = 0; boolean isTwoWords = (baseType.getNBytes() > 4); for (Expression element : elements) { int toPop = 0; // copy array so we can assign it -- adds one to height mv.visitInsn(Opcodes.DUP); // compile expression index -- adds 1 to height mv.visitLdcInsn(idx++); compileContext.addStackCount(2); // compile value -- adds one or two words to height element.compile(mv, compileContext); // ensure we have the correct value type compileContext.compileTypeConversion(element.type, baseType); // now we can do the array store if (baseType.isObject() || baseType.isArray()) { // compile load object - pops 3 mv.visitInsn(Opcodes.AASTORE); toPop = -3; } else if (baseType == Type.Z || baseType == Type.B) { // compile load byte - pops 3 mv.visitInsn(Opcodes.BASTORE); toPop = -3; } else if (baseType == Type.S) { // compile load short - pops 3 mv.visitInsn(Opcodes.SASTORE); toPop = -3; } else if (baseType == Type.C) { // compile load char - pops 3 mv.visitInsn(Opcodes.CASTORE); toPop = -3; } else if (baseType == Type.I) { // compile load int - pops 3 mv.visitInsn(Opcodes.IASTORE); toPop = -3; } else if (baseType == Type.J) { // compile load long - pops 4 mv.visitInsn(Opcodes.LASTORE); toPop = -4; } else if (baseType == Type.F) { // compile load float - pops 3 mv.visitInsn(Opcodes.FASTORE); toPop = -3; } else if (baseType == Type.D) { // compile load double - pops 4 mv.visitInsn(Opcodes.DASTORE); toPop = -4; } // pop the appropriate number of elements off the stack compileContext.addStackCount(toPop); } // check stack height if (compileContext.getStackCount() != currentStack + expected) { throw new CompileException("ArrayInitExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected)); } // no need to update stack max }
From source file:org.jboss.byteman.rule.expression.NewExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int expected = 1; int extraParams = 0; if (arrayDimCount == 0) { // ok, we need to create the new instance and then initialise it. // create the new instance -- adds 1 to stack String instantiatedClassName = type.getInternalName(); mv.visitTypeInsn(Opcodes.NEW, instantiatedClassName); compileContext.addStackCount(1); // copy the exception so we can init it mv.visitInsn(Opcodes.DUP);// ww w . j a v a2 s .c om compileContext.addStackCount(1); int argCount = arguments.size(); // stack each of the arguments to the constructor for (int i = 0; i < argCount; i++) { Type argType = argumentTypes.get(i); Type paramType = paramTypes.get(i); int paramCount = (paramType.getNBytes() > 4 ? 2 : 1); // track extra storage used after type conversion extraParams += (paramCount); arguments.get(i).compile(mv, compileContext); compileTypeConversion(argType, paramType, mv, compileContext); } // construct the exception mv.visitMethodInsn(Opcodes.INVOKESPECIAL, instantiatedClassName, "<init>", getDescriptor()); // modify the stack height to account for the removed exception and params compileContext.addStackCount(-(extraParams + 1)); } else { // TODO !!! implement compilation for array types !!! if (arrayDimCount == 1) { // we can use a NEWARRAY or ANEWARRAY Type baseType = type.getBaseType(); // compile first array dimension adds 1 to stack arrayDims.get(0).compile(mv, compileContext); // compile new array op -- pops 1 and adds 1 to stack if (baseType.isObject()) { mv.visitTypeInsn(Opcodes.ANEWARRAY, baseType.getInternalName()); // } else if (baseType.isArray()) { // cannot happen!!! } else { int operand = 0; if (baseType.equals(Type.Z)) { operand = Opcodes.T_BOOLEAN; } else if (baseType.equals(Type.B)) { operand = Opcodes.T_BYTE; } else if (baseType.equals(Type.S)) { operand = Opcodes.T_SHORT; } else if (baseType.equals(Type.C)) { operand = Opcodes.T_CHAR; } else if (baseType.equals(Type.I)) { operand = Opcodes.T_INT; } else if (baseType.equals(Type.J)) { operand = Opcodes.T_LONG; } else if (baseType.equals(Type.F)) { operand = Opcodes.T_FLOAT; } else if (baseType.equals(Type.D)) { operand = Opcodes.T_DOUBLE; } mv.visitIntInsn(Opcodes.NEWARRAY, operand); } } else { // we need to use MULTIANEWARRAY for (int i = 0; i < arrayDimDefinedCount; i++) { // compile next array dimension adds 1 to stack arrayDims.get(i).compile(mv, compileContext); } // execute the MULTIANEWARRAY operation -- pops arrayDims operands and pushes 1 mv.visitMultiANewArrayInsn(type.getInternalName(), arrayDimDefinedCount); compileContext.addStackCount(1 - arrayDimDefinedCount); } } if (compileContext.getStackCount() != currentStack + expected) { throw new CompileException("NewExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected)); } }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * @param elemType element type of the array. Must be a primitive type. * @return java op-code to use as the argument for the NEWARRAY op. *///from ww w.ja va 2 s. com private static int getNewArrayArgCode(JavaTypeName elemType) { switch (elemType.getTag()) { case JavaTypeName.VOID_TAG: throw new IllegalArgumentException(); case JavaTypeName.BOOLEAN_TAG: return Opcodes.T_BOOLEAN; case JavaTypeName.BYTE_TAG: return Opcodes.T_BYTE; case JavaTypeName.SHORT_TAG: return Opcodes.T_SHORT; case JavaTypeName.CHAR_TAG: return Opcodes.T_CHAR; case JavaTypeName.INT_TAG: return Opcodes.T_INT; case JavaTypeName.LONG_TAG: return Opcodes.T_LONG; case JavaTypeName.DOUBLE_TAG: return Opcodes.T_DOUBLE; case JavaTypeName.FLOAT_TAG: return Opcodes.T_FLOAT; case JavaTypeName.ARRAY_TAG: case JavaTypeName.OBJECT_TAG: default: { throw new IllegalArgumentException(); } } }
From source file:pxb.android.dex2jar.asm.PDescMethodVisitor.java
License:Apache License
public void visitIntInsn(int opcode, int operand) { super.visitIntInsn(opcode, operand); switch (opcode) { case BIPUSH:/*from w w w . j a v a 2 s . c o m*/ stack.push(Type.BYTE_TYPE); break; case SIPUSH: stack.push(Type.SHORT_TYPE); break; case NEWARRAY: stack.pop(); switch (operand) { case Opcodes.T_BOOLEAN: stack.push(Type.getType("[Z")); break; case Opcodes.T_BYTE: stack.push(Type.getType("[B")); break; case Opcodes.T_CHAR: stack.push(Type.getType("[C")); break; case Opcodes.T_DOUBLE: stack.push(Type.getType("[D")); break; case Opcodes.T_FLOAT: stack.push(Type.getType("[F")); break; case Opcodes.T_INT: stack.push(Type.getType("[I")); break; case Opcodes.T_LONG: stack.push(Type.getType("[J")); break; case Opcodes.T_SHORT: stack.push(Type.getType("[Z")); break; } break; } }
From source file:serianalyzer.JVMImpl.java
License:Open Source License
/** * @param operand// w ww.j a v a 2 s.c o m * @return */ private static Type makeBasicArrayType(int operand) { switch (operand) { case Opcodes.T_BOOLEAN: return Type.getType("[Z"); //$NON-NLS-1$ case Opcodes.T_BYTE: return Type.getType("[B"); //$NON-NLS-1$ case Opcodes.T_CHAR: return Type.getType("[C"); //$NON-NLS-1$ case Opcodes.T_DOUBLE: return Type.getType("[D"); //$NON-NLS-1$ case Opcodes.T_FLOAT: return Type.getType("[F"); //$NON-NLS-1$ case Opcodes.T_INT: return Type.getType("[I"); //$NON-NLS-1$ case Opcodes.T_LONG: return Type.getType("[J"); //$NON-NLS-1$ case Opcodes.T_SHORT: return Type.getType("[S"); //$NON-NLS-1$ default: log.error("Unknown array type " + operand); //$NON-NLS-1$ } return null; }