List of usage examples for org.objectweb.asm Opcodes DLOAD
int DLOAD
To view the source code for org.objectweb.asm Opcodes DLOAD.
Click Source Link
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);//from ww w . jav a 2 s . co m 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.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 w ww . j a v a 2 s. co 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//from w w w.j av 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:gnu.classpath.tools.rmic.ClassRmicCompiler.java
License:Open Source License
private static int loadOpcode(Class cls) { if (cls.equals(Void.TYPE)) throw new IllegalArgumentException("can not load void"); int loadcode; if (cls.equals(Boolean.TYPE)) loadcode = Opcodes.ILOAD;//from w w w . j a va2 s . com else if (cls.equals(Byte.TYPE)) loadcode = Opcodes.ILOAD; else if (cls.equals(Character.TYPE)) loadcode = Opcodes.ILOAD; else if (cls.equals(Short.TYPE)) loadcode = Opcodes.ILOAD; else if (cls.equals(Integer.TYPE)) loadcode = Opcodes.ILOAD; else if (cls.equals(Long.TYPE)) loadcode = Opcodes.LLOAD; else if (cls.equals(Float.TYPE)) loadcode = Opcodes.FLOAD; else if (cls.equals(Double.TYPE)) loadcode = Opcodes.DLOAD; else loadcode = Opcodes.ALOAD; return loadcode; }
From source file:io.awacs.plugin.springmvc.ServiceWrapper.java
License:Apache License
/** * origin method: (XXX)X//from ww w.j a va 2 s . com * <p> * proxy method: (XXXLjavax/servlet/http/HttpServletRequest;)X * req -> localIndex - 1 * * @param cn * @param origin * @return */ private MethodNode doProxy(ClassNode cn, MethodNode origin) { MethodNode newNode = copyMethod(origin); //move annotations hideAnnotations(origin); LabelNode l0 = new LabelNode(); LabelNode l1 = new LabelNode(); LabelNode l2 = new LabelNode(); String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1); int localIndex = copyParameters(origin, newNode, l0, l2); newNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception")); //localIndex -> elapsedTime newNode.localVariables.add(new LocalVariableNode("elapsedTime", "J", null, l0, l1, localIndex)); // newNode.instructions.add(l0); // long elapsedTime = System.currentTimeMillis(); newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J")); newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex)); int paramCount = getParamCount(origin.desc, origin.access); //load? for (int i = 0; i < paramCount; i++) { LocalVariableNode node = (LocalVariableNode) newNode.localVariables.get(i); switch (node.desc) { case "J": newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, node.index)); break; case "D": newNode.instructions.add(new VarInsnNode(Opcodes.DLOAD, node.index)); break; case "F": newNode.instructions.add(new VarInsnNode(Opcodes.FLOAD, node.index)); break; case "I": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "S": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "Z": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "B": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "C": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; default: newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, node.index)); break; } } // newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, cn.name, origin.name, origin.desc)); // newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J")); newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex)); newNode.instructions.add(new InsnNode(Opcodes.LSUB)); newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex)); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1)); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;")); //? newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex)); //SpringmvcPlugin.incrAccess(uri, elapsedTime); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrAccess", "(Ljava/lang/String;J)V")); // newNode.instructions.add(l1); switch (returnType) { case "J": newNode.instructions.add(new InsnNode(Opcodes.LRETURN)); break; case "D": newNode.instructions.add(new InsnNode(Opcodes.DRETURN)); break; case "F": newNode.instructions.add(new InsnNode(Opcodes.FRETURN)); break; case "I": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "S": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "C": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "B": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "Z": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; default: newNode.instructions.add(new InsnNode(Opcodes.ARETURN)); break; } newNode.instructions.add(l2); newNode.instructions .add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" })); newNode.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex)); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1)); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;")); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex)); newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrFailure", "(Ljava/lang/String;Ljava/lang/Throwable;)V")); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex)); newNode.instructions.add(new InsnNode(Opcodes.ATHROW)); newNode.maxLocals = origin.maxLocals + 3; newNode.maxStack = Math.max(localIndex + 2, 6); return newNode; }
From source file:io.awacs.plugin.stacktrace.ClassTransformer.java
License:Apache License
/** * ?/* w w w. ja v a 2s . c o m*/ * 1?try catch? try{ * 2???? io.awacs.plugin.stacktrace.StackFrames.init(); * 3???? io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,0); * 4? Object val = methodName_origin_className(args); * 5????? io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,1); * 5??? List list = io.awacs.plugin.stacktrace.StackFrames.dump(); * 7????? io.awacs.plugin.stacktrace.StackTracePlugin.incrAccess(list); * 8? return val; * }catch(java.lang.Exception e){ * 9?? io.awacs.plugin.stacktrace.StackTracePlugin.incrFailure(e); * 10? throw e; * } */ private void transformTerminatedMethod(MethodNode origin, MethodNode proxy, ClassNode owner) { LabelNode l0 = new LabelNode(); LabelNode l1 = new LabelNode(); LabelNode l2 = new LabelNode(); //try catch? proxy.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception")); proxy.instructions.add(l0); //? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "init", "()V", false)); proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", "."))); proxy.instructions.add(new LdcInsnNode(proxy.name)); proxy.instructions.add(new LdcInsnNode(0)); // proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); int varIndex = 0;//??? //???,????this? if ((proxy.access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) { proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); varIndex = 1; } List<String> parameters = resolveParameters(proxy.desc); //??? for (String param : parameters) { VarInsnNode insnNode; switch (param) { case "J": insnNode = new VarInsnNode(Opcodes.LLOAD, varIndex); varIndex += 2; break; case "D": insnNode = new VarInsnNode(Opcodes.DLOAD, varIndex); varIndex += 2; break; case "F": insnNode = new VarInsnNode(Opcodes.FLOAD, varIndex++); break; case "I": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "S": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "Z": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "B": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "C": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; default: insnNode = new VarInsnNode(Opcodes.ALOAD, varIndex++); break; } proxy.instructions.add(insnNode); } // if ((origin.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) proxy.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner.name, origin.name, origin.desc, false)); else proxy.instructions .add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, owner.name, origin.name, origin.desc, false)); proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", "."))); proxy.instructions.add(new LdcInsnNode(proxy.name)); proxy.instructions.add(new LdcInsnNode(1)); //? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); //?? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "dump", "()Ljava/util/List;", false)); //??? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackTracePlugin", "incrAccess", "(Ljava/util/List;)V", false)); proxy.instructions.add(l1); // String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1); switch (returnType) { case "J": proxy.instructions.add(new InsnNode(Opcodes.LRETURN)); break; case "D": proxy.instructions.add(new InsnNode(Opcodes.DRETURN)); break; case "F": proxy.instructions.add(new InsnNode(Opcodes.FRETURN)); break; case "I": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "S": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "C": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "B": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "Z": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "V": proxy.instructions.add(new InsnNode(Opcodes.RETURN)); break; default: proxy.instructions.add(new InsnNode(Opcodes.ARETURN)); break; } proxy.instructions.add(l2); //? proxy.instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" })); proxy.instructions.add(new VarInsnNode(Opcodes.ASTORE, varIndex)); proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex)); proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackTracePlugin", "incrFailure", "(Ljava/lang/Throwable;)V", false)); proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex)); proxy.instructions.add(new InsnNode(Opcodes.ATHROW)); proxy.maxLocals = varIndex + 1; proxy.maxStack = Math.max(varIndex, 5); }
From source file:jasy.lang.ASMCompiler.java
private static int getLoad(Class<?> type) { String typeDescriptor = Type.getDescriptor(type); switch (typeDescriptor) { case "V": return -1; case "J": return Opcodes.LLOAD; case "D": return Opcodes.DLOAD; case "F": return Opcodes.FLOAD; case "I": case "Z": case "B": case "C": case "S": return Opcodes.ILOAD; default://from w w w. j a va2 s. co m return Opcodes.ALOAD; } }
From source file:jp.co.dgic.testing.common.virtualmock.asm.AbstractAsmMethodVisitor.java
License:Open Source License
protected int getLoadOpcodeByType(Type type) { if (type.equals(Type.BOOLEAN_TYPE)) return Opcodes.ILOAD; if (type.equals(Type.BYTE_TYPE)) return Opcodes.ILOAD; if (type.equals(Type.CHAR_TYPE)) return Opcodes.ILOAD; if (type.equals(Type.SHORT_TYPE)) return Opcodes.ILOAD; if (type.equals(Type.INT_TYPE)) return Opcodes.ILOAD; if (type.equals(Type.LONG_TYPE)) return Opcodes.LLOAD; if (type.equals(Type.DOUBLE_TYPE)) return Opcodes.DLOAD; if (type.equals(Type.FLOAT_TYPE)) return Opcodes.FLOAD; return Opcodes.ALOAD; }
From source file:lombok.patcher.MethodLogistics.java
License:Open Source License
private static int loadOpcodeFor(String spec) { switch (spec.charAt(0)) { case 'D': return Opcodes.DLOAD; case 'J': return Opcodes.LLOAD; case 'F': return Opcodes.FLOAD; case 'I': case 'S': case 'B': case 'Z': return Opcodes.ILOAD; case 'V': throw new IllegalArgumentException("There's no load opcode for 'void'"); case 'L': case '[': return Opcodes.ALOAD; }/* w w w . j a v a 2s.c om*/ throw new IllegalStateException("Uhoh - bug - unrecognized JVM type: " + spec); }
From source file:lucee.transformer.bytecode.statement.tag.TagLoop.java
License:Open Source License
/** * write out index loop//from w ww . j ava 2s. c o m * @param adapter * @throws TemplateException */ private void writeOutTypeFromTo(BytecodeContext bc) throws BytecodeException { ForDoubleVisitor forDoubleVisitor = new ForDoubleVisitor(); loopVisitor = forDoubleVisitor; GeneratorAdapter adapter = bc.getAdapter(); // int from=(int)@from; int from = adapter.newLocal(Types.DOUBLE_VALUE); ExpressionUtil.writeOutSilent(getAttribute("from").getValue(), bc, Expression.MODE_VALUE); adapter.storeLocal(from); // int to=(int)@to; int to = adapter.newLocal(Types.DOUBLE_VALUE); ExpressionUtil.writeOutSilent(getAttribute("to").getValue(), bc, Expression.MODE_VALUE); adapter.storeLocal(to); // int step=(int)@step; int step = adapter.newLocal(Types.DOUBLE_VALUE); Attribute attrStep = getAttribute("step"); if (attrStep != null) { ExpressionUtil.writeOutSilent(attrStep.getValue(), bc, Expression.MODE_VALUE); } else { adapter.push(1D); } adapter.storeLocal(step); // boolean dirPlus=(step > 0); int dirPlus = adapter.newLocal(Types.BOOLEAN_VALUE); DecisionDoubleVisitor div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.loadLocal(step); div.visitGT(); adapter.push(0D); div.visitEnd(bc); adapter.storeLocal(dirPlus); //if(step!=0) { div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.loadLocal(step); div.visitNEQ(); adapter.push(0D); div.visitEnd(bc); Label ifEnd = new Label(); adapter.ifZCmp(Opcodes.IFEQ, ifEnd); // VariableReference index>=VariableInterpreter.getVariableReference(pc,@index)); int index = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); Attribute attr = getAttribute("index"); if (attr == null) attr = getAttribute("item"); ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(index); // index.set(from); adapter.loadLocal(index); adapter.loadLocal(from); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); // for //int i=forConditionVisitor.visitBeforeExpression(adapter,from,step,true); // init adapter.visitLabel(forDoubleVisitor.beforeInit); forDoubleVisitor.forInit(adapter, from, true); adapter.goTo(forDoubleVisitor.beforeExpr); // update adapter.visitLabel(forDoubleVisitor.beforeUpdate); adapter.loadLocal(index); //forConditionVisitor.forUpdate(adapter, step, true); adapter.visitVarInsn(Opcodes.DLOAD, forDoubleVisitor.i); adapter.loadLocal(step); adapter.visitInsn(Opcodes.DADD); adapter.visitInsn(Opcodes.DUP2); adapter.visitVarInsn(Opcodes.DSTORE, forDoubleVisitor.i); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); // expression adapter.visitLabel(forDoubleVisitor.beforeExpr); int i = forDoubleVisitor.i; adapter.loadLocal(dirPlus); Label l1 = new Label(); adapter.visitJumpInsn(Opcodes.IFEQ, l1); div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.visitVarInsn(Opcodes.DLOAD, i); div.visitLTE(); adapter.loadLocal(to); div.visitEnd(bc); Label l2 = new Label(); adapter.visitJumpInsn(Opcodes.GOTO, l2); adapter.visitLabel(l1); div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.visitVarInsn(Opcodes.DLOAD, i); div.visitGTE(); adapter.loadLocal(to); div.visitEnd(bc); adapter.visitLabel(l2); forDoubleVisitor.visitAfterExpressionBeginBody(adapter); //adapter.loadLocal(index); //adapter.visitVarInsn(Opcodes.DLOAD, i); //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); getBody().writeOut(bc); forDoubleVisitor.visitEndBody(bc, getEnd()); ////// set i after usage //adapter.loadLocal(index); //adapter.visitVarInsn(Opcodes.DLOAD, i); //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); adapter.visitLabel(ifEnd); }