List of usage examples for org.objectweb.asm Opcodes ARETURN
int ARETURN
To view the source code for org.objectweb.asm Opcodes ARETURN.
Click Source Link
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {/*from w ww . j a v a2 s .c om*/ this.name = name; this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0; this.superName = getHologramSuperclassName(isInterface, name, superName); interfaces = getHologramInterfaces(name, isInterface, interfaces); // Force everything to be public, since HologramClassLoader has to reflectively // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead. // Also remove enum flags. int hologramAccess = forcePublic(access); // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least) // creates objects that claim to be an instance of VirtualMachineError, which is abstract. if (name.equals("hologram/java/lang/VirtualMachineError")) { hologramAccess = ~Opcodes.ACC_ABSTRACT & access; } // We need at least 1.5 to use class literal constants // TODO-RS: Work out a better way to interpret 45.X numbers correctly if (version == Opcodes.V1_1 || version < Opcodes.V1_5) { version = 49; } super.visit(version, hologramAccess, name, signature, this.superName, interfaces); if (this.name.equals(hologramThrowableType.getInternalName())) { // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods, // so we can call them in stubs without hitting hologram code. MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace", Type.getMethodDescriptor(Type.VOID_TYPE), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace", Type.getMethodDescriptor(Type.getType(Throwable.class))); v.visitInsn(Opcodes.RETURN); v.visitMaxs(1, 1); v.visitEnd(); v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class))); v.visitInsn(Opcodes.ARETURN); v.visitMaxs(1, 1); v.visitEnd(); } }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public void visitEnd() { // Generate the static field used to store the corresponding ClassMirror int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC; super.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null); // Generate the constructor that takes a mirror instance as an Object parameter String constructorDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class)); if (name.equals(getHologramType(Type.getType(Throwable.class), true).getInternalName())) { // This doesn't extend ObjectHologram so we have to set the field directly super.visitField(Opcodes.ACC_PUBLIC, "mirror", objectMirrorType.getDescriptor(), null, null); MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null);// w w w . j ava2 s .c o m methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE)); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, objectMirrorType.getInternalName()); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, name, "mirror", Type.getDescriptor(ObjectMirror.class)); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "getMirror", Type.getMethodDescriptor(objectMirrorType), null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, name, "mirror", Type.getDescriptor(ObjectMirror.class)); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } else if (!isInterface) { MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructorDesc); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); } // Add a class initialization method to initialize the static fields, // if one doesn't exist already. if (!hasClinit) { InstructionAdapter mv = new InstructionAdapter( super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null)); mv.visitCode(); HologramMethodGenerator.initializeStaticFields(Type.getObjectType(this.name), mv); mv.areturn(Type.VOID_TYPE); mv.visitMaxs(2, 2); mv.visitEnd(); } super.visitEnd(); }
From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java
License:Open Source License
@Override public void visitInsn(int opcode) { Type arrayElementType = null; boolean isArrayLoad = (Opcodes.IALOAD <= opcode && opcode < Opcodes.IALOAD + 8); boolean isArrayStore = (Opcodes.IASTORE <= opcode && opcode < Opcodes.IASTORE + 8); if (isArrayLoad || isArrayStore) { switch (opcode) { case Opcodes.IALOAD: arrayElementType = Type.INT_TYPE; break; case Opcodes.LALOAD: arrayElementType = Type.LONG_TYPE; break; case Opcodes.FALOAD: arrayElementType = Type.FLOAT_TYPE; break; case Opcodes.DALOAD: arrayElementType = Type.DOUBLE_TYPE; break; case Opcodes.AALOAD: arrayElementType = hologramType; break; case Opcodes.BALOAD: arrayElementType = Type.BYTE_TYPE; break; case Opcodes.CALOAD: arrayElementType = Type.CHAR_TYPE; break; case Opcodes.SALOAD: arrayElementType = Type.SHORT_TYPE; break; case Opcodes.IASTORE: arrayElementType = Type.INT_TYPE; break; case Opcodes.LASTORE: arrayElementType = Type.LONG_TYPE; break; case Opcodes.FASTORE: arrayElementType = Type.FLOAT_TYPE; break; case Opcodes.DASTORE: arrayElementType = Type.DOUBLE_TYPE; break; case Opcodes.AASTORE: arrayElementType = hologramType; break; case Opcodes.BASTORE: arrayElementType = Type.BYTE_TYPE; break; case Opcodes.CASTORE: arrayElementType = Type.CHAR_TYPE; break; case Opcodes.SASTORE: arrayElementType = Type.SHORT_TYPE; break; }/*from www. java 2s . com*/ Type mirrorType = HologramClassGenerator.objectArrayMirrorType; if (arrayElementType.getSort() != Type.OBJECT && arrayElementType.getSort() != Type.ARRAY) { mirrorType = getPrimitiveArrayMirrorType(arrayElementType); } // Use the analyzer to figure out the expected array element type Type arrayElementTypeForMirrorCall = arrayElementType; Type hologramArrayType = Type .getObjectType((String) stackType(isArrayStore ? 1 + arrayElementType.getSize() : 1)); if (hologramArrayType == null) { hologramArrayType = Type.getType(ObjectArrayHologram.class); } if (arrayElementType.equals(hologramType)) { Type originalType = Type .getObjectType(getOriginalInternalClassName(hologramArrayType.getInternalName())); arrayElementType = getHologramType( Reflection.makeArrayType(originalType.getDimensions() - 1, originalType.getElementType())); hologramArrayType = Type.getType(ObjectArrayHologram.class); } // Call the appropriate getter/setter method on the hologram String methodDesc; if (isArrayStore) { methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, mirrorType, Type.INT_TYPE, arrayElementTypeForMirrorCall); } else { methodDesc = Type.getMethodDescriptor(arrayElementTypeForMirrorCall, mirrorType, Type.INT_TYPE); } invokestatic(hologramArrayType.getInternalName(), (isArrayStore ? "setHologram" : "getHologram"), methodDesc); if (!isArrayStore && arrayElementTypeForMirrorCall.equals(hologramType)) { checkcast(arrayElementType); } return; } if (opcode == Opcodes.ARRAYLENGTH) { invokeinterface(arrayMirrorType.getInternalName(), "length", Type.getMethodDescriptor(Type.INT_TYPE)); return; } if (opcode == Opcodes.ARETURN) { if (isToString) { invokestatic(objectHologramType.getInternalName(), "getRealStringForHologram", Type.getMethodDescriptor(Type.getType(String.class), Type.getType(ObjectHologram.class))); } else if (isGetStackTrace) { invokestatic(objectHologramType.getInternalName(), "getRealStackTraceForHologram", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class), Type.getType(Hologram.class))); } } if (opcode == Opcodes.RETURN && owner.equals(hologramThrowableType) && name.equals("<init>")) { load(0, owner); new MethodHandle() { protected void methodCall() throws Throwable { ObjectHologram.register(null); ; } }.invoke(this); } super.visitInsn(opcode); }
From source file:erjang.EFun.java
License:Apache License
static byte[] gen_fun_class_data(int arity) { String self_type = EFUN_TYPE.getInternalName() + arity; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, EFUN_TYPE.getInternalName(), null); make_invoke_method(cw, self_type, arity); CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "arity", "()I", null, null); mv.visitCode();// ww w. j a va 2 s .c o m mv.visitLdcInsn(new Integer(arity)); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "(" + EPROC_TYPE.getDescriptor() + EOBJECT_ARR_TYPE.getDescriptor() + ")" + EOBJECT_TYPE.getDescriptor(), null, PAUSABLE_EX); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); // load this mv.visitVarInsn(Opcodes.ALOAD, 1); // load proc for (int i = 0; i < arity; i++) { mv.visitVarInsn(Opcodes.ALOAD, 2); push_int(mv, i); mv.visitInsn(Opcodes.AALOAD); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, self_type, "invoke", EUtil.getSignature(arity, true)); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(arity + 2, arity + 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "()V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, EFUN_TYPE.getInternalName(), "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); make_cast_method(cw, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:erjang.EFun.java
License:Apache License
private static void make_cast_method(ClassWriter cw, int n) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "cast", "(" + EOBJECT_DESC + ")L" + EFUN_NAME + n + ";", null, null); mv.visitCode();//from w w w . j av a 2 s .c om mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(INSTANCEOF, EFUN_NAME + n); Label fail = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, fail); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, EFUN_NAME + n); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(fail); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void create_tuple_copy(int i, ClassAdapter cw, String this_class_name, String super_class_name) { MethodVisitor mv;/*from w w w .j a va 2 s.c om*/ make_blank_bridge(cw, this_class_name, super_class_name); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "blank", "()L" + this_class_name + ";", null, null); mv.visitCode(); mv.visitTypeInsn(Opcodes.NEW, this_class_name); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this_class_name, "<init>", "()V"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void make_blank_bridge(ClassAdapter cw, String this_class_name, String super_class_name) { MethodVisitor mv;/*from w w w . j a va 2 s. com*/ mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE, "blank", "()L" + super_class_name + ";", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this_class_name, "blank", "()L" + this_class_name + ";"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void create_tuple_nth(int n_cells, ClassAdapter cw, String this_class_name) { MethodVisitor mv;//from w w w. j av a2s. c o m mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "elm", "(I)" + ETERM_TYPE.getDescriptor(), null, null); mv.visitCode(); Label dflt = new Label(); Label[] labels = new Label[n_cells]; for (int i = 0; i < n_cells; i++) { labels[i] = new Label(); } mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitTableSwitchInsn(1, n_cells, dflt, labels); for (int zbase = 0; zbase < n_cells; zbase++) { mv.visitLabel(labels[zbase]); mv.visitVarInsn(Opcodes.ALOAD, 0); // load this String field = "elem" + (zbase + 1); mv.visitFieldInsn(Opcodes.GETFIELD, this_class_name, field, ETERM_TYPE.getDescriptor()); mv.visitInsn(Opcodes.ARETURN); } mv.visitLabel(dflt); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ETUPLE_NAME, "bad_nth", "(I)" + ETERM_TYPE.getDescriptor()); mv.visitInsn(Opcodes.ARETURN); // make compiler happy mv.visitMaxs(3, 2); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void create_cast(ClassAdapter cw, int n) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "cast", "(L" + ETUPLE_NAME + ";)L" + ETUPLE_NAME + n + ";", null, null); mv.visitCode();/*from w w w. j av a2s .com*/ mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ETUPLE_NAME, "arity", "()I"); if (n <= 5) { mv.visitInsn(Opcodes.ICONST_0 + n); } else { mv.visitLdcInsn(new Integer(n)); } Label fail = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPNE, fail); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, ETUPLE_NAME + n); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(fail); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void create_cast2(ClassAdapter cw, int n) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "cast", "(L" + Type.getInternalName(EObject.class) + ";)L" + ETUPLE_NAME + n + ";", null, null); mv.visitCode();//from w ww . j a v a 2 s . com mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.INSTANCEOF, ETUPLE_NAME + n); Label fail = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, fail); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, ETUPLE_NAME + n); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(fail); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }