List of usage examples for org.objectweb.asm Opcodes ALOAD
int ALOAD
To view the source code for org.objectweb.asm Opcodes ALOAD.
Click Source Link
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: case Opcodes.LLOAD: case Opcodes.FLOAD: case Opcodes.DLOAD: case Opcodes.ALOAD: stack.add(registers.get(Integer.valueOf(var))); break;/*from ww w.ja v a 2s . c om*/ case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: registers.put(Integer.valueOf(var), stack.remove(stack.size() - 1)); break; case Opcodes.RET: //nop - a fudge break; } }
From source file:com.microsoft.applicationinsights.agent.internal.agent.AdvancedAdviceAdapter.java
License:Open Source License
/** * This method calls a Java enum method with its expected argumentes * @param clazz The enum class to activate * @param methodName The method of the class to activate * @param methodSignature The method signature * @param args The arguments to pass to the method *//* w ww .j a va 2 s . c o m*/ protected void activateEnumMethod(Class<?> clazz, String methodName, String methodSignature, Object... args) { String internalName = Type.getInternalName(clazz); super.visitFieldInsn(Opcodes.GETSTATIC, internalName, "INSTANCE", "L" + internalName + ";"); for (Object arg : args) { if (arg instanceof TempVar) { loadLocal(((TempVar) arg).tempVarIndex); } else if (arg instanceof TempArrayVar) { super.visitVarInsn(Opcodes.ALOAD, ((TempArrayVar) arg).tempVarIndex); } else { super.visitLdcInsn(arg); } } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, internalName, methodName, methodSignature, false); }
From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java
License:Open Source License
private void notifyEndOfMethod(TempArrayVar arrayOfArgumentsAfterBoxing, TempVar throwable) { super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE", ImplementationsCoordinator.internalNameAsJavaName); mv.visitLdcInsn(getMethodName());//from ww w . ja v a 2s . c o m mv.visitVarInsn(LLOAD, localDelta); if (arrayOfArgumentsAfterBoxing != null) { mv.visitVarInsn(Opcodes.ALOAD, arrayOfArgumentsAfterBoxing.tempVarIndex); } else { mv.visitInsn(ACONST_NULL); } if (throwable != null) { loadLocal(throwable.tempVarIndex); } else { mv.visitInsn(ACONST_NULL); } mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, FINISH_DETECT_METHOD_NAME, FINISH_METHOD_DEFAULT_SIGNATURE, false); }
From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java
License:Open Source License
private void reportFinishWithArgs1(int opcode) { int resultIndex = this.newLocal(Type.getType(Integer.class)); super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE", ImplementationsCoordinator.internalNameAsJavaName); mv.visitLdcInsn(getMethodName());/*from ww w . j a v a 2s.c o m*/ mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, FINISH_DETECT_METHOD_NAME, FINISH_METHOD_DEFAULT_SIGNATURE, false); mv.visitVarInsn(ISTORE, resultIndex); mv.visitVarInsn(ILOAD, resultIndex); Label ok = new Label(); mv.visitJumpInsn(IFEQ, ok); int boxedArgumentsIndex = 0; int argumentIndex = isMethodStatic() ? 0 : 1; TempArrayVar arrayOfArgumentsAfterBoxing; arrayOfArgumentsAfterBoxing = createArray(numberOfArguments()); // Fill the array with method parameters after boxing the primitive ones. for (Type argumentType : getArgumentTypes()) { setBoxedValueIntoArray(arrayOfArgumentsAfterBoxing, boxedArgumentsIndex, argumentType, argumentIndex); boxedArgumentsIndex++; if (ByteCodeUtils.isLargeType(argumentType)) { argumentIndex += 2; } else { ++argumentIndex; } } super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE", ImplementationsCoordinator.internalNameAsJavaName); mv.visitLdcInsn(getMethodName()); mv.visitVarInsn(Opcodes.ALOAD, arrayOfArgumentsAfterBoxing.tempVarIndex); mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, FINISH_DETECT_METHOD_NAME, FINISH_METHOD_DEFAULT_SIGNATURE, false); mv.visitLabel(ok); super.byteCodeForMethodExit(opcode); }
From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java
License:Open Source License
protected void boxVariable(Type argumentType, int argumentIndex) { if (argumentType.equals(Type.BOOLEAN_TYPE)) { mv.visitVarInsn(Opcodes.ILOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);/*from ww w . ja v a2 s. c o m*/ } else if (argumentType.equals(Type.BYTE_TYPE)) { mv.visitVarInsn(Opcodes.ILOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false); } else if (argumentType.equals(Type.CHAR_TYPE)) { mv.visitVarInsn(Opcodes.ILOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false); } else if (argumentType.equals(Type.SHORT_TYPE)) { mv.visitVarInsn(Opcodes.ILOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false); } else if (argumentType.equals(Type.INT_TYPE)) { mv.visitVarInsn(Opcodes.ILOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); } else if (argumentType.equals(Type.LONG_TYPE)) { mv.visitVarInsn(Opcodes.LLOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); } else if (argumentType.equals(Type.FLOAT_TYPE)) { mv.visitVarInsn(Opcodes.FLOAD, argumentIndex); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "valueOf", "(F)Ljava/lang/Long;", false); } else if (argumentType.equals(Type.DOUBLE_TYPE)) { mv.visitVarInsn(Opcodes.DLOAD, argumentIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false); } else { mv.visitVarInsn(Opcodes.ALOAD, argumentIndex); } }
From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java
License:Open Source License
protected void prepareArrayEntry(int arrayIndex, int entryIndex) { mv.visitVarInsn(Opcodes.ALOAD, arrayIndex); mv.visitIntInsn(Opcodes.BIPUSH, entryIndex); }
From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.PreparedStatementCtorMethodVisitor.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, metaData.sqlStringInCtor); super.visitFieldInsn(Opcodes.PUTFIELD, owner, metaData.fieldName, "Ljava/lang/String;"); }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
/** * Turns this class into an override class that can be loaded by our custom class loader: * <ul>// ww w . java 2s. c o m * <li>Make the class name be OriginalName$override</li> * <li>Ensure the class derives from java.lang.Object, no other inheritance</li> * <li>Ensure the class has a public parameterless constructor that is a noop.</li> * </ul> */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, name + OVERRIDE_SUFFIX, signature, "java/lang/Object", new String[] { CHANGE_TYPE.getInternalName() }); visitedClassName = name; visitedSuperName = superName; instanceToStaticDescPrefix = "(L" + visitedClassName + ";"; // Create empty constructor MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); // super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC, // "$obsolete", "Z", null, null); }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
/** * To each class, add the dispatch method called by the original code that acts as a trampoline to * invoke the changed methods./*from ww w .jav a 2s . co m*/ * <p/> * Pseudo code: * <code> * Object access$dispatch(String name, object[] args) { * if (name.equals( * "firstMethod.(L$type;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;")) { * return firstMethod(($type)arg[0], (String)arg[1], arg[2]); * } * if (name.equals("secondMethod.(L$type;Ljava/lang/String;I;)V")) { * secondMethod(($type)arg[0], (String)arg[1], (int)arg[2]); * return; * } * ... * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " + visitedClassName + * "$dispatch implementation, restart the application"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void addDispatchMethod() { int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_VARARGS; Method m = new Method("access$dispatch", "(I[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); if (TRACING_ENABLED) { mv.push("Redirecting "); mv.loadArg(0); trace(mv, 2); } List<MethodNode> allMethods = new ArrayList(); // if we are disabled, do not generate any dispatch, the method will throw an exception // if invoked which should never happen. if (!instantRunDisabled) { //noinspection unchecked allMethods.addAll(classNode.methods); allMethods.addAll(addedMethods); } final Map<String, MethodNode> methods = new HashMap(); for (MethodNode methodNode : allMethods) { if (methodNode.name.equals("<clinit>") || methodNode.name.equals("<init>")) { continue; } if (!isAccessCompatibleWithInstantRun(methodNode.access)) { continue; } methods.put(methodNode.name + "." + methodNode.desc, methodNode); } new IntSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitInt() { mv.visitVarInsn(Opcodes.ILOAD, 1); } @Override void visitCase(String methodName) { MethodNode methodNode = methods.get(methodName); String name = methodNode.name; boolean isStatic = (methodNode.access & Opcodes.ACC_STATIC) != 0; String newDesc = computeOverrideMethodDesc(methodNode.desc, isStatic); if (TRACING_ENABLED) { trace(mv, "M: " + name + " P:" + newDesc); } Type[] args = Type.getArgumentTypes(newDesc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } mv.visitMethodInsn(Opcodes.INVOKESTATIC, visitedClassName + "$override", isStatic ? computeOverrideMethodName(name, methodNode.desc) : name, newDesc, false); Type ret = Type.getReturnType(methodNode.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, methods.keySet(), visitedClassName); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
public void addSupportMethod() { int access = Opcodes.ACC_PUBLIC; Method m = new Method("isSupport", "(I)Z"); MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); mv.visitCode();/*from www . j a v a2 s.co m*/ mv.visitVarInsn(Opcodes.ALOAD, 1); // mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); int[] hashArray = new int[fixMtds.size()]; Label[] labelArray = new Label[fixMtds.size()]; Label l0 = new Label(); Label l1 = new Label(); for (int i = 0; i < fixMtds.size(); i++) { hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i)); labelArray[i] = l0; } mv.visitLookupSwitchInsn(l1, hashArray, labelArray); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 2); mv.visitEnd(); mv.visitMaxs(0, 0); mv.visitEnd(); }