List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:org.apache.sling.metrics.impl.ReturnAdapter.java
License:Apache License
public void addReturnMetric(int opcode) { // make a copt of the top of the stack so the return value can ba passed // to the resource // Class.record(returnValue, timerName); if (Opcodes.DRETURN == opcode || Opcodes.LRETURN == opcode) { mv.visitInsn(Opcodes.DUP2);/*from w w w . java 2s . co m*/ } else { mv.visitInsn(Opcodes.DUP); } if (helperClassName != null) { mv.visitLdcInsn(timerName); mv.visitLdcInsn(helperClassName); if (mark) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE_USING_HELPER, RETURN_METHOD_CAPTURE_DESC, false); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE_USING_HELPER, RETURN_METHOD_CAPTURE_DESC, false); } } else if (keyMethodName != null) { mv.visitLdcInsn(timerName); mv.visitLdcInsn(keyMethodName); if (mark) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE, RETURN_METHOD_CAPTURE_DESC, false); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE, RETURN_METHOD_CAPTURE_DESC, false); } } else { mv.visitLdcInsn(timerName); if (mark) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE, RETURN_CAPTURE_DESC, false); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE, RETURN_CAPTURE_DESC, false); } } }
From source file:org.apache.sling.metrics.impl.TimerAdapter.java
License:Apache License
@Override protected void onMethodEnter() { mv.visitLdcInsn(timerName);/*from w w w .ja v a2s . co m*/ mv.visitMethodInsn(Opcodes.INVOKESTATIC, METRICS_UTIL_CL, "getTimer", METRICS_UTIL_GETMETER_DESC, false); // store the meter. contextid = newLocal(Type.getType(Context.class)); mv.visitVarInsn(Opcodes.ASTORE, contextid); }
From source file:org.apache.sling.metrics.impl.VoidAdapter.java
License:Apache License
@Override protected void onMethodEnter() { mv.visitLdcInsn(timerName); mv.visitMethodInsn(Opcodes.INVOKESTATIC, METRICS_UTIL_CL, method, METRICS_UTIL_DESC, false); }
From source file:org.boretti.drools.integration.drools5.DroolsAbstractMethodVisitor.java
License:Open Source License
private void addCondition(boolean preCondition, String type, String resourceName, Type error) { droolsGoalExecutionLog.getLogs()//from w w w . ja va 2 s.c o m .add(new DroolsGoalExecutionLog(droolsGoalExecutionLog.getFileName(), droolsGoalExecutionLog.getAction(), "Method instrumentalization for " + ((preCondition) ? "pre" : "post") + "-condition " + name + "/" + desc)); visitor.setMethodChange(true); Type types[] = Type.getArgumentTypes(super.methodDesc); //runPreCondition this.visitVarInsn(Opcodes.ALOAD, 0); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getObjectType(parent).getInternalName(), "getClass", "()Ljava/lang/Class;"); if (type == null) type = "COMPILED"; this.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(DroolsServiceType.class), type, Type.getDescriptor(DroolsServiceType.class)); this.visitLdcInsn(resourceName); this.visitLdcInsn(error); this.visitVarInsn(Opcodes.ALOAD, 0); this.visitIntInsn(Opcodes.BIPUSH, types.length); this.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); int position = 1; for (int i = 0; i < types.length; i++) { this.visitInsn(Opcodes.DUP); this.visitIntInsn(Opcodes.BIPUSH, i); if (types[i].equals(Type.BOOLEAN_TYPE)) { this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Boolean.class), "valueOf", "(Z)Ljava/lang/Boolean;"); position += 1; } else if (types[i].equals(Type.BYTE_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Byte"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Byte.class), "<init>", "(B)V"); position += 1; } else if (types[i].equals(Type.CHAR_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Character"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Character.class), "<init>", "(C)V"); position += 1; } else if (types[i].equals(Type.DOUBLE_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Double"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.DLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Double.class), "<init>", "(D)V"); position += 2; } else if (types[i].equals(Type.FLOAT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Float"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.FLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Float.class), "<init>", "(F)V"); position += 1; } else if (types[i].equals(Type.INT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Integer"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); position += 1; } else if (types[i].equals(Type.LONG_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Long"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.LLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); position += 2; } else if (types[i].equals(Type.SHORT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Short"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Short.class), "<init>", "(S)V"); position += 1; } else { this.visitVarInsn(Opcodes.ALOAD, position); position += 1; } this.visitInsn(Opcodes.AASTORE); } if (preCondition) this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class), "runPreCondition", "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V"); else this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class), "runPostCondition", "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V"); }
From source file:org.boretti.drools.integration.drools5.DroolsClassVisitor.java
License:Open Source License
@Override public void visitEnd() { FieldVisitor fv = null;/*from w ww. j a v a2 s . c om*/ if (isNeedChangeForBoth()) { fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor(), null, null); if (fv != null) { AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); fv.visitEnd(); } } if (isNeedChangeForField()) { fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_RULE, Type.getType(RuleBase.class).getDescriptor(), null, null); if (fv != null) { AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); fv.visitEnd(); } MethodVisitor mv = super.visitMethod(Opcodes.ACC_PRIVATE, DROOLS_METHOD_RUN, "()V", null, null); AnnotationVisitor av = mv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); mv.visitCode(); Label start = new Label(); mv.visitLabel(start); Label doIt = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor()); mv.visitJumpInsn(Opcodes.IFEQ, doIt); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(doIt); mv.visitFrame(Opcodes.F_SAME, 1, new Object[] { Type.getObjectType(me).getInternalName() }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_RULE, Type.getType(RuleBase.class).getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(RuleBase.class).getInternalName(), "newStatelessSession", "()Lorg/drools/StatelessSession;"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(FIELD_NAME_LOGGER); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(Object.class).getInternalName(), "getClass", "()Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(org.apache.log4j.Logger.class).getInternalName(), "getLogger", "(Ljava/lang/Class;)Lorg/apache/log4j/Logger;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(), "setGlobal", "(Ljava/lang/String;Ljava/lang/Object;)V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(), "execute", "(Ljava/lang/Object;)V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_1); mv.visitFieldInsn(Opcodes.PUTFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor()); mv.visitInsn(Opcodes.RETURN); Label end = new Label(); mv.visitLabel(end); mv.visitLocalVariable("this", Type.getObjectType(me).getDescriptor(), null, start, end, 0); mv.visitMaxs(4, 1); mv.visitEnd(); } super.visitEnd(); }
From source file:org.brutusin.instrumentation.Instrumentator.java
License:Apache License
private void addGetMethodInvocation(InsnList il) { il.add(TreeInstructions.getPushInstruction(this.methodArguments.length)); il.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class")); int parameterClassesIndex = getFistAvailablePosition(); il.add(new VarInsnNode(Opcodes.ASTORE, parameterClassesIndex)); this.mn.maxLocals++; for (int i = 0; i < this.methodArguments.length; i++) { il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(TreeInstructions.getPushInstruction(i)); il.add(TreeInstructions.getClassReferenceInstruction(methodArguments[i], cn.version & 0xFFFF)); il.add(new InsnNode(Opcodes.AASTORE)); }/*w ww.j a v a 2 s . c o m*/ il.add(TreeInstructions.getClassConstantReference(this.classType, cn.version & 0xFFFF)); il.add(new LdcInsnNode(this.mn.name)); il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/brutusin/instrumentation/utils/Helper", "getSource", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/Object;", false)); }
From source file:org.brutusin.instrumentation.Instrumentator.java
License:Apache License
private void addGetCallback(InsnList il) { il.add(new LdcInsnNode(this.callbackId)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/brutusin/instrumentation/Callback", "getInstance", "(Ljava/lang/String;)Lorg/brutusin/instrumentation/Callback;", false)); }
From source file:org.brutusin.instrumentation.utils.TreeInstructions.java
License:Apache License
public static MethodInsnNode getWrapperContructionInst(Type type) { char charType = type.getDescriptor().charAt(0); String wrapper;//from www. j a va 2s.c o m switch (charType) { case 'B': wrapper = "java/lang/Byte"; break; case 'C': wrapper = "java/lang/Character"; break; case 'D': wrapper = "java/lang/Double"; break; case 'F': wrapper = "java/lang/Float"; break; case 'I': wrapper = "java/lang/Integer"; break; case 'J': wrapper = "java/lang/Long"; break; case 'L': return null; case '[': return null; case 'Z': wrapper = "java/lang/Boolean"; break; case 'S': wrapper = "java/lang/Short"; break; default: throw new ClassFormatError("Invalid method signature: " + type.getDescriptor()); } return new MethodInsnNode(Opcodes.INVOKESTATIC, wrapper, "valueOf", "(" + charType + ")L" + wrapper + ";", false); }
From source file:org.brutusin.instrumentation.utils.TreeInstructions.java
License:Apache License
public static InsnList getClassConstantReference(Type type, int majorVersion) { InsnList il = new InsnList(); if (majorVersion >= Opcodes.V1_5) { il.add(new LdcInsnNode(type)); } else {/*w ww . j a v a 2 s. c o m*/ String fullyQualifiedName = type.getInternalName().replaceAll("/", "."); il.add(new LdcInsnNode(fullyQualifiedName)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false)); } return il; }
From source file:org.codehaus.groovy.reflection.MethodHandleFactory.java
License:Apache License
@Deprecated public static void genInvokeXxxWithArray(ClassWriter cw, Method method) { MethodVisitor mv;//from w ww. j a v a 2 s . co m mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", null, EXCEPTIONS); mv.visitCode(); Class callClass = method.getDeclaringClass(); boolean useInterface = callClass.isInterface(); String type = BytecodeHelper.getClassInternalName(callClass.getName()); String descriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameterTypes()); // make call if (Modifier.isStatic(method.getModifiers())) { genLoadParameters(2, mv, method); mv.visitMethodInsn(Opcodes.INVOKESTATIC, type, method.getName(), descriptor); } else { mv.visitVarInsn(Opcodes.ALOAD, 1); BytecodeHelper.doCast(mv, callClass); genLoadParameters(2, mv, method); mv.visitMethodInsn((useInterface) ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, type, method.getName(), descriptor); } BytecodeHelper.box(mv, method.getReturnType()); if (method.getReturnType() == void.class) { mv.visitInsn(Opcodes.ACONST_NULL); } mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }