List of usage examples for org.objectweb.asm Opcodes ILOAD
int ILOAD
To view the source code for org.objectweb.asm Opcodes ILOAD.
Click Source Link
From source file:dyco4j.instrumentation.LoggingHelper.java
License:BSD License
public static int emitLogArgument(final MethodVisitor mv, final int position, final OptionalInt localVarIndex, final Type argType) { mv.visitLdcInsn(position);/* w ww .ja v a2 s .c om*/ int _typeLength = 1; if (localVarIndex.isPresent()) { final int _tmp = localVarIndex.getAsInt(); switch (argType.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.INT: case Type.SHORT: mv.visitVarInsn(Opcodes.ILOAD, _tmp); break; case Type.LONG: mv.visitVarInsn(Opcodes.LLOAD, _tmp); _typeLength++; break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FLOAD, _tmp); break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DLOAD, _tmp); _typeLength++; break; case Type.ARRAY: case Type.OBJECT: mv.visitVarInsn(Opcodes.ALOAD, _tmp); break; } } else { mv.visitLdcInsn(Logger.UNINITIALIZED_THIS); } emitConvertToString(mv, argType); emitInvokeLog(mv, LOG_ARGUMENT); return _typeLength; }
From source file:dyco4j.LoggingHelper.java
License:BSD License
public static int emitLogArgument(final MethodVisitor mv, final int index, final Type argType) { mv.visitLdcInsn(index);// w ww .j a v a 2 s . c om int _typeLength = 1; switch (argType.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.INT: case Type.SHORT: mv.visitVarInsn(Opcodes.ILOAD, index); break; case Type.LONG: mv.visitVarInsn(Opcodes.LLOAD, index); _typeLength++; break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FLOAD, index); break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DLOAD, index); _typeLength++; break; case Type.ARRAY: case Type.OBJECT: mv.visitVarInsn(Opcodes.ALOAD, index); break; } emitConvertToString(mv, argType); emitInvokeLog(mv, LOG_ARGUMENT); return _typeLength; }
From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java
License:Open Source License
public void addNextIndex() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PROTECTED, "nextIndex", "()I", null, null); mv.visitCode();//from w w w. jav a2 s . c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "modCount", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "expectedModCount", "I"); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0); mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/IdentityHashMap$IdentityHashMapIterator", "hasNext", "()Z", false); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNE, l1); mv.visitTypeInsn(Opcodes.NEW, "java/util/NoSuchElementException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "keys", "Ljava/util/List;"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I"); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true); mv.visitVarInsn(Opcodes.ASTORE, 1); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 2); Label l2 = new Label(); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/lang/Object", Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARRAYLENGTH); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l3); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ALOAD, 1); Label l4 = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, l4); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "lastReturnedIndex", "I"); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitIincInsn(2, 2); mv.visitJumpInsn(Opcodes.GOTO, l2); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "lastReturnedIndex", "I"); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(5, 3); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.MethodShufflingAdder.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if ("getExceptionTypes".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override// ww w .j a va 2 s . co m public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { super.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;"); } super.visitInsn(opcode); } }; } if ("getGenericExceptionTypes".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { super.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/reflect/Type;"); } super.visitInsn(opcode); } }; } if ("getDeclaredAnnotations".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { super.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;"); } super.visitInsn(opcode); } }; } if ("getParameterAnnotations".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { super.visitVarInsn(Opcodes.ASTORE, 1); super.visitInsn(Opcodes.ICONST_0); super.visitVarInsn(Opcodes.ISTORE, 2); Label l0 = new Label(); super.visitLabel(l0); super.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "[[Ljava/lang/annotation/Annotation;", Opcodes.INTEGER }, 0, null); super.visitVarInsn(Opcodes.ILOAD, 2); super.visitVarInsn(Opcodes.ALOAD, 1); super.visitInsn(Opcodes.ARRAYLENGTH); Label l1 = new Label(); super.visitJumpInsn(Opcodes.IF_ICMPGE, l1); super.visitVarInsn(Opcodes.ALOAD, 1); super.visitVarInsn(Opcodes.ILOAD, 2); super.visitVarInsn(Opcodes.ALOAD, 1); super.visitVarInsn(Opcodes.ILOAD, 2); super.visitInsn(Opcodes.AALOAD); super.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;"); super.visitInsn(Opcodes.AASTORE); super.visitIincInsn(2, 1); super.visitJumpInsn(Opcodes.GOTO, l0); super.visitLabel(l1); super.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); super.visitVarInsn(Opcodes.ALOAD, 1); } super.visitInsn(opcode); } }; } return super.visitMethod(access, name, desc, signature, exceptions); }
From source file:edu.illinois.nondex.instr.PriorityBlockingQueueShufflingAdder.java
License:Open Source License
public void addToString() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode();//from w w w . j a v a2s . c o m Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, null); Label l3 = new Label(); Label l4 = new Label(); mv.visitTryCatchBlock(l3, l4, l2, null); Label l5 = new Label(); mv.visitTryCatchBlock(l2, l5, l2, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "lock", "Ljava/util/concurrent/locks/ReentrantLock;"); mv.visitVarInsn(Opcodes.ASTORE, 1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lock", "()V", false); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "size", "I"); mv.visitVarInsn(Opcodes.ISTORE, 2); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitJumpInsn(Opcodes.IFNE, l3); mv.visitLdcInsn("[]"); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER }, 0, null); mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 91); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "queue", "[Ljava/lang/Object;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "[Ljava/lang/Object;", "clone", "()Ljava/lang/Object;", false); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 5); Label l6 = new Label(); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] { "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitVarInsn(Opcodes.ILOAD, 2); Label l7 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l7); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitVarInsn(Opcodes.ALOAD, 0); Label l8 = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, l8); mv.visitLdcInsn("(this Collection)"); Label l9 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l9); mv.visitLabel(l8); mv.visitFrame(Opcodes.F_FULL, 7, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" }, 1, new Object[] { "java/lang/StringBuilder" }); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitLabel(l9); mv.visitFrame(Opcodes.F_FULL, 7, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" }, 2, new Object[] { "java/lang/StringBuilder", "java/lang/Object" }); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); Label l10 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l10); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 44); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitIntInsn(Opcodes.BIPUSH, 32); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitLabel(l10); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitIincInsn(5, 1); mv.visitJumpInsn(Opcodes.GOTO, l6); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 93); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitVarInsn(Opcodes.ASTORE, 5); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 5); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock" }, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitLabel(l5); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitInsn(Opcodes.ATHROW); mv.visitMaxs(3, 8); mv.visitEnd(); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(VarInsnNode insn, FrameState frame, BBInfo block) { int var = insn.var; switch (insn.getOpcode()) { case Opcodes.ILOAD: assert frame.locals[var].getType().isSubtypeOf(typeFactory.getType(int.class)); frame.stack.push(frame.locals[var]); break;//from ww w . j a va 2s. c o m case Opcodes.LLOAD: assert frame.locals[var].getType().isSubtypeOf(typeFactory.getType(long.class)); frame.stack.push(frame.locals[var]); break; case Opcodes.FLOAD: assert frame.locals[var].getType().isSubtypeOf(typeFactory.getType(float.class)); frame.stack.push(frame.locals[var]); break; case Opcodes.DLOAD: assert frame.locals[var].getType().isSubtypeOf(typeFactory.getType(double.class)); frame.stack.push(frame.locals[var]); break; case Opcodes.ALOAD: assert frame.locals[var].getType().isSubtypeOf(typeFactory.getType(Object.class)); frame.stack.push(frame.locals[var]); break; case Opcodes.ISTORE: assert frame.stack.peek().getType().isSubtypeOf(typeFactory.getType(int.class)); frame.locals[var] = frame.stack.pop(); break; case Opcodes.LSTORE: assert frame.stack.peek().getType().isSubtypeOf(typeFactory.getType(long.class)); frame.locals[var] = frame.stack.pop(); break; case Opcodes.FSTORE: assert frame.stack.peek().getType().isSubtypeOf(typeFactory.getType(float.class)); frame.locals[var] = frame.stack.pop(); break; case Opcodes.DSTORE: assert frame.stack.peek().getType().isSubtypeOf(typeFactory.getType(double.class)); frame.locals[var] = frame.stack.pop(); break; case Opcodes.ASTORE: assert frame.stack.peek().getType().isSubtypeOf(typeFactory.getType(Object.class)); frame.locals[var] = frame.stack.pop(); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void load(Value v, InsnList insns) { if (v instanceof Constant) { Object c = ((Constant<?>) v).getConstant(); if (c == null) insns.add(new InsnNode(Opcodes.ACONST_NULL)); else if (c instanceof Class) insns.add(new LdcInsnNode(org.objectweb.asm.Type.getType((Class) c))); else if (c instanceof Boolean) insns.add(loadIntegerConstant(((Boolean) c) ? 1 : 0)); else if (c instanceof Character) insns.add(loadIntegerConstant((int) ((Character) c).charValue())); else if (c instanceof Byte || c instanceof Short || c instanceof Integer) insns.add(loadIntegerConstant(((Number) c).intValue())); else if (c instanceof Long) insns.add(loadLongConstant((Long) c)); else if (c instanceof Float) insns.add(loadFloatConstant((Float) c)); else if (c instanceof Double) insns.add(loadDoubleConstant((Double) c)); else// w w w .j a v a 2 s . co m insns.add(new LdcInsnNode(c)); return; } assert registers.containsKey(v) : v; int reg = registers.get(v); Type t = v instanceof LocalVariable ? ((LocalVariable) v).getType().getFieldType() : v.getType(); if (t instanceof ReferenceType || t instanceof NullType) insns.add(new VarInsnNode(Opcodes.ALOAD, reg)); else if (t.equals(longType)) insns.add(new VarInsnNode(Opcodes.LLOAD, reg)); else if (t.equals(floatType)) insns.add(new VarInsnNode(Opcodes.FLOAD, reg)); else if (t.equals(doubleType)) insns.add(new VarInsnNode(Opcodes.DLOAD, reg)); else if (t.isSubtypeOf(intType)) insns.add(new VarInsnNode(Opcodes.ILOAD, reg)); else throw new AssertionError("unloadable value: " + v); }
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); }/*from w ww . j av a2 s. c o m*/ 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:erjang.ETuple.java
License:Apache License
private static void create_tuple_nth(int n_cells, ClassAdapter cw, String this_class_name) { MethodVisitor mv;// w w w . jav a 2 s . co 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_tuple_set(int n_cells, ClassAdapter cw, String this_class_name) { MethodVisitor mv;//from w w w. j a va 2 s. c om 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(); }