List of usage examples for org.objectweb.asm Opcodes RETURN
int RETURN
To view the source code for org.objectweb.asm Opcodes RETURN.
Click Source Link
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);/*from w ww . jav a2 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.HologramClassGenerator.java
License:Open Source License
public static void generateArray(ClassVisitor visitor, HologramClassLoader loader, HologramClassMirror hologramClassMirror) { boolean isInterface = !hologramClassMirror.isImplementationClass(); ClassMirror classMirror = hologramClassMirror.getOriginal(); Type originalType = Reflection.typeForClassMirror(classMirror); Type originalElementType = originalType.getElementType(); int dims = originalType.getDimensions(); String internalName = getHologramType(originalType, !isInterface).getInternalName(); ClassMirror superClassMirror = null; String superName = isInterface ? Type.getInternalName(Object.class) : Type.getInternalName(ObjectArrayHologram.class); Set<String> interfaces = new HashSet<String>(); int access = Opcodes.ACC_PUBLIC | (isInterface ? Opcodes.ACC_INTERFACE : 0); if (originalElementType.getSort() == Type.OBJECT || originalElementType.getSort() == Type.ARRAY) { ClassMirror elementClass = loader.loadOriginalClassMirror(originalElementType.getClassName()); superClassMirror = elementClass.getSuperClassMirror(); if (isInterface) { if (superClassMirror != null) { Type superType = Reflection.makeArrayType(dims, Type.getObjectType(superClassMirror.getClassName().replace('.', '/'))); String superInterfaceName = getHologramType(superType).getInternalName(); interfaces.add(superInterfaceName); }// w w w . j a va 2 s. c om for (ClassMirror interfaceMirror : elementClass.getInterfaceMirrors()) { Type superType = Reflection.makeArrayType(dims, Type.getObjectType(interfaceMirror.getClassName().replace('.', '/'))); String interfaceName = getHologramType(superType).getInternalName(); interfaces.add(interfaceName); } interfaces.add(hologramType.getInternalName()); Type nMinus1Type = Reflection.makeArrayType(dims - 1, Type.getType(Object.class)); interfaces.add(getHologramType(nMinus1Type).getInternalName()); } } if (!isInterface) { interfaces.add(getHologramType(originalType, false).getInternalName()); } visitor.visit(Opcodes.V1_5, access, internalName, null, superName, interfaces.toArray(new String[0])); if (isInterface) { // Generate clone() String cloneDesc = Type.getMethodDescriptor(objectType); MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "clone", cloneDesc, null, null); mv.visitEnd(); } else { // Generate thunk constructors String initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(ObjectArrayMirror.class)); MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); } // Generate the static field used to store the corresponding ClassMirror and the static initializer to set it int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC; visitor.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null); InstructionAdapter mv = new InstructionAdapter( visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null)); mv.visitCode(); HologramMethodGenerator.initializeStaticFields(Type.getObjectType(internalName), mv); mv.areturn(Type.VOID_TYPE); mv.visitMaxs(2, 2); mv.visitEnd(); visitor.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 ww w.ja v a 2 s. c om*/ 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:edu.ubc.mirrors.holograms.MainEntryAdaptor.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor superVisitor = super.visitMethod(access, name, desc, signature, exceptions); if (superVisitor != null && name.equals("main") && (Opcodes.ACC_STATIC & access) != 0 && desc.equals(mainDesc)) { superVisitor.visitCode();//from ww w .ja v a2 s.c o m superVisitor.visitLdcInsn(Type.getObjectType(className)); superVisitor.visitVarInsn(Opcodes.ALOAD, 0); superVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ObjectHologram.class), "invokeHologramMainMethod", invokeHologramMainMethodDesc); superVisitor.visitInsn(Opcodes.RETURN); superVisitor.visitMaxs(2, 1); superVisitor.visitEnd(); return null; } else { return superVisitor; } }
From source file:edu.ubc.mirrors.raw.NativeClassGenerator.java
License:Open Source License
@Override public void visitEnd() { if (!isInterface) { // Generate the no-argument constructor String constructorDesc = Type.getMethodDescriptor(Type.VOID_TYPE); MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null);/*w w w. ja va2s .c o m*/ methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructorDesc); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } super.visitEnd(); }
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();/*from w w w. jav a 2 s. c om*/ 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
static byte[] get_exported_fun_class_data(int arity) { /* Code template:/* w ww . j ava2s.c o m*/ * public abstract class EFun{arity}Exported extends EFun{arity} { * protected final EAtom module_name, function_name; * protected EFun{arity}Exported(String m, String f) { * module_name = EAtom.intern(m); * function_name = EAtom.intern(f); * } * } */ ensure(arity); // Ensure presence of superclass. String super_type = EFUN_TYPE.getInternalName() + arity; String self_type = super_type + "Exported"; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, super_type, null); cw.visitField(ACC_PROTECTED | ACC_FINAL, "module_name", EATOM_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(ACC_PROTECTED | ACC_FINAL, "function_name", EATOM_TYPE.getDescriptor(), null, null) .visitEnd(); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_type, "<init>", "()V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "module_name", EATOM_DESC); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "function_name", EATOM_DESC); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(3, 3); mv.visitEnd(); make_encode_method_for_exported(cw, self_type, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:erjang.ETuple.java
License:Apache License
private static void create_tuple_set(int n_cells, ClassAdapter cw, String this_class_name) { MethodVisitor mv;/*from w w w . jav a 2 s .c o m*/ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "set", "(I" + ETERM_TYPE.getDescriptor() + ")V", 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 mv.visitVarInsn(Opcodes.ALOAD, 2); // load term String field = "elem" + (zbase + 1); mv.visitFieldInsn(Opcodes.PUTFIELD, this_class_name, field, ETERM_TYPE.getDescriptor()); mv.visitInsn(Opcodes.RETURN); } 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.POP); mv.visitInsn(Opcodes.RETURN); // make compiler happy mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:erjang.ETuple.java
License:Apache License
private static void create_constructor(ClassAdapter cw, String super_class_name) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode();/* w w w. ja v a 2s. com*/ mv.visitVarInsn(Opcodes.ALOAD, 0); // load this mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_class_name, "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:gemlite.core.internal.measurement.MeasureHelper.java
License:Apache License
public final static void instrumentCheckPoint(String className, MethodNode mn) { if (LogUtil.getCoreLog().isTraceEnabled()) LogUtil.getCoreLog().trace("Found check point, class:" + className + " method:" + mn.name); InsnList insn = mn.instructions;//from w w w.j av a 2 s . c o m List<AbstractInsnNode> returnIndex = new ArrayList<>(); // return int localVarCount = mn.localVariables.size(); for (int i = 0; i < insn.size(); i++) { AbstractInsnNode insnNode = (AbstractInsnNode) insn.get(i); switch (insnNode.getOpcode()) { case Opcodes.ARETURN: case Opcodes.IRETURN: case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: returnIndex.add(insnNode.getPrevious()); break; case Opcodes.RETURN: returnIndex.add(insnNode); break; } } // insn.insert(new VarInsnNode(Opcodes.LSTORE, localVarCount + 2)); insn.insert( new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); // ? for (AbstractInsnNode insnNode : returnIndex) { insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LSTORE, localVarCount + 4)); insn.insertBefore(insnNode, new LdcInsnNode(className)); insn.insertBefore(insnNode, new LdcInsnNode(mn.name)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 2)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 4)); insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "gemlite/core/internal/measurement/MeasureHelper", "recordCheckPoint", "(Ljava/lang/String;Ljava/lang/String;JJ)V", false)); } }