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.eclipse.gemini.blueprint.test.internal.util.DependencyVisitor.java
License:Open Source License
public void visitMethodInsn(int opcode, String owner, String name, String desc) { String returnType = Type.getReturnType(desc).getClassName(); if (opcode == Opcodes.INVOKESTATIC && CLASS_NAME.equals(returnType)) { if (tempLdc != null) addName(tempLdc.replace('.', '/')); }//from www. j av a2 s. c o m tempLdc = null; addName(owner); addMethodDesc(desc); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractCreateDispatchCodeAdapter.java
License:Open Source License
protected InsnList getDispatchCode(MethodNode method, int joinPointId, int boundMethodId) { InsnList instructions = new InsnList(); // teams = TeamManager.getTeams(joinpointId) instructions.add(createLoadIntConstant(joinPointId)); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH, ConstantMembers.getTeams.getName(), ConstantMembers.getTeams.getSignature(), false)); instructions.add(createInstructionsToCheackTeams(method)); // get the first team instructions.add(new InsnNode(Opcodes.DUP)); instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.AALOAD)); instructions.add(new InsnNode(Opcodes.SWAP)); if (isStatic) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); } else {//from w w w .j av a 2 s. com // put "this" on the stack and cast it to IBoundBase2 instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, ClassNames.I_BOUND_BASE_SLASH)); } instructions.add(new InsnNode(Opcodes.SWAP)); // start index instructions.add(new InsnNode(Opcodes.ICONST_0)); // TeamManager.getCallinIds(joinpointId) instructions.add(createLoadIntConstant(joinPointId)); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH, ConstantMembers.getCallinIds.getName(), ConstantMembers.getCallinIds.getSignature(), false)); instructions.add(createLoadIntConstant(boundMethodId)); args = Type.getArgumentTypes(method.desc); // box the arguments instructions.add(getBoxedArguments(args)); instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, ClassNames.ITEAM_SLASH, ConstantMembers.callAllBindingsTeam.getName(), ConstantMembers.callAllBindingsTeam.getSignature(), true)); Type returnType = Type.getReturnType(method.desc); instructions.add(getUnboxingInstructionsForReturnValue(returnType)); return instructions; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddThreadNotificationAdapter.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions) {// w w w .j a va 2 s . co m if (INIT.equals(methodName)) { // into each constructor ... final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null); return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) { @Override public void invokeConstructor(Type type, Method method) { super.invokeConstructor(type, method); // ... that contains a super(..) call (rather than this(..)): if (type.getInternalName().equals(clazz.getInternalSuperClassName())) { // insert: // this._OT$creationThread = Thread.currentThread(); methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.THREAD_SLASH, CURRENT_THREAD, CURRENT_THREAD_DESC, false); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); } } }; } else if (RUN.equals(methodName) && RUN_DESC.equals(desc)) { final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null); return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) { Label start = new Label(); // start of method (scope of new local) Label end = new Label(); // end of method int isThreadStartIdx; // new local: boolean _OT$isThreadStart @Override protected void onMethodEnter() { methodVisitor.visitLabel(start); isThreadStartIdx = newLocal(Type.BOOLEAN_TYPE); methodVisitor.visitLocalVariable("_OT$isThreadStart", "Z", null, start, end, isThreadStartIdx); // TeamThreadManager.newThreadStarted(false, this._OT$creationThread) methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH, NEW_THREAD_STARTED, NEW_THREAD_STARTED_DESC, false); methodVisitor.visitIntInsn(Opcodes.ISTORE, isThreadStartIdx); // this._OT$creationThread = null; // avoid leak methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitInsn(Opcodes.ACONST_NULL); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); } @Override protected void onMethodExit(int opcode) { insertThreadEndedNotification(); } @Override public void endMethod() { methodVisitor.visitLabel(end); // insert another threadEnded notification as a handler for Throwable Label handler = new Label(); methodVisitor.visitLabel(handler); insertThreadEndedNotification(); methodVisitor.visitInsn(Opcodes.ATHROW); // rethrow caught exception methodVisitor.visitTryCatchBlock(start, end, handler, ClassNames.THROWABLE_SLASH); methodVisitor.visitMaxs(0, 0); } void insertThreadEndedNotification() { Label skip = new Label(); // insert: // if (_OT$isThreadStart) TeamThreadManager.threadEnded(); methodVisitor.visitIntInsn(Opcodes.ILOAD, isThreadStartIdx); methodVisitor.visitJumpInsn(Opcodes.IFEQ, skip); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH, THREAD_ENDED, THREAD_ENDED_DESC, false); methodVisitor.visitLabel(skip); } }; } return null; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AsmTypeHelper.java
License:Open Source License
public static AbstractInsnNode getBoxingInstructionForType(Type type) { String className = getObjectType(type); if (className == null) return new InsnNode(Opcodes.NOP); String desc = Type.getMethodDescriptor(Type.getObjectType(className), new Type[] { type }); return new MethodInsnNode(Opcodes.INVOKESTATIC, className, "valueOf", desc, false); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateDispatchCodeInOrgMethodAdapter.java
License:Open Source License
@Override protected InsnList createInstructionsToCheackTeams(MethodNode method) { InsnList instructions = new InsnList(); instructions.add(new InsnNode(Opcodes.DUP)); LabelNode label = new LabelNode(); //if (teams == null) { instructions.add(new JumpInsnNode(Opcodes.IFNONNULL, label)); instructions.add(new InsnNode(Opcodes.POP)); //put the boundMethodId on the stack instructions.add(createLoadIntConstant(boundMethodId)); Type[] args = Type.getArgumentTypes(method.desc); // box the arguments instructions.add(getBoxingInstructions(args, (method.access & Opcodes.ACC_STATIC) != 0)); //callOrigStatic(boundMethodId, args); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, name, ConstantMembers.callOrigStatic.getName(), ConstantMembers.callOrigStatic.getSignature())); Type returnType = Type.getReturnType(method.desc); instructions.add(getUnboxingInstructionsForReturnValue(returnType)); instructions.add(label);// ww w . j a va 2 s.c o m return instructions; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateMethodAccessAdapter.java
License:Open Source License
@Override public boolean transform() { MethodNode methodNode = getMethod(method); InsnList instructions = new InsnList(); if (isConstructor) { // create empty object for constructor invocation: instructions.add(new TypeInsnNode(Opcodes.NEW, name)); instructions.add(new InsnNode(Opcodes.DUP)); } else if (!method.isStatic()) { //put "this" on the stack for a non-static method instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); }//w w w .ja va 2 s . c o m //Unbox arguments Type[] args = Type.getArgumentTypes(methodNode.desc); if (args.length > 0) { for (int i = 0; i < args.length; i++) { instructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + 2)); instructions.add(createLoadIntConstant(i)); instructions.add(new InsnNode(Opcodes.AALOAD)); Type arg = args[i]; if (arg.getSort() != Type.ARRAY && arg.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(arg); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); instructions.add(AsmTypeHelper.getUnboxingInstructionForType(arg, objectType)); } else { instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, arg.getInternalName())); } } } //call original method int opcode = Opcodes.INVOKEVIRTUAL; if (method.isStatic()) { opcode = Opcodes.INVOKESTATIC; } else if (isConstructor) { opcode = Opcodes.INVOKESPECIAL; } instructions.add(new MethodInsnNode(opcode, name, method.getName(), method.getSignature())); //box return value Type returnType = Type.getReturnType(methodNode.desc); if (returnType.getSort() != Type.OBJECT && returnType.getSort() != Type.ARRAY && returnType.getSort() != Type.VOID) { instructions.add(AsmTypeHelper.getBoxingInstructionForType(returnType)); instructions.add(new InsnNode(Opcodes.ARETURN)); } else if (returnType.getSort() == Type.VOID && !isConstructor) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); instructions.add(new InsnNode(Opcodes.ARETURN)); } else { instructions.add(new InsnNode(Opcodes.ARETURN)); } //add the instructions to a new label in the existing switch MethodNode access = getMethod(this.access); addNewLabelToSwitch(access.instructions, instructions, accessId); return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForAccessAdapter.java
License:Open Source License
@Override protected void addPreSwitchInstructions(MethodNode method) { // put "accessId" on the stack method.instructions.add(new IntInsnNode(Opcodes.ILOAD, getFirstArgIndex())); // put "caller".getClass() on the stack method.instructions.add(new IntInsnNode(Opcodes.ALOAD, getFirstArgIndex() + 3)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false)); // call "getMemberId(accessId, callerClass) method.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH, ConstantMembers.getMemberId.getName(), ConstantMembers.getMemberId.getSignature(), false)); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForAccessAdapter.java
License:Open Source License
@Override protected void addInstructionForDefaultLabel(MethodNode method) { if (superClassName.equals("java/lang/Object")) { method.instructions.add(new TypeInsnNode(Opcodes.NEW, "org/objectteams/NoSuchMethodError")); method.instructions.add(new InsnNode(Opcodes.DUP)); method.instructions.add(new IntInsnNode(Opcodes.ILOAD, getFirstArgIndex())); // accessId method.instructions.add(new LdcInsnNode(clazz.getName())); // current class method.instructions.add(new LdcInsnNode("decapsulating access")); // access reason method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "org/objectteams/NoSuchMethodError", "<init>", "(ILjava/lang/String;Ljava/lang/String;)V", false)); method.instructions.add(new InsnNode(Opcodes.ATHROW)); } else {/* www . jav a 2 s .c om*/ Type[] args = Type.getArgumentTypes(method.desc); addInstructionsForLoadArguments(method.instructions, args, getMethod().isStatic()); int opcode = Opcodes.INVOKESPECIAL; if (getMethod().isStatic()) { opcode = Opcodes.INVOKESTATIC; } method.instructions.add( new MethodInsnNode(opcode, superClassName, getMethod().getName(), getMethod().getSignature())); method.instructions.add(new InsnNode(Opcodes.ARETURN)); } }
From source file:org.elasticsearch.painless.lookup.PainlessMethod.java
License:Apache License
public void write(MethodWriter writer) { final org.objectweb.asm.Type type; final Class<?> clazz; if (augmentation != null) { assert Modifier.isStatic(modifiers); clazz = augmentation;//from w w w.j a v a 2 s. co m type = org.objectweb.asm.Type.getType(augmentation); } else { clazz = target; type = Type.getType(target); } if (Modifier.isStatic(modifiers)) { // invokeStatic assumes that the owner class is not an interface, so this is a // special case for interfaces where the interface method boolean needs to be set to // true to reference the appropriate class constant when calling a static interface // method since java 8 did not check, but java 9 and 10 do if (Modifier.isInterface(clazz.getModifiers())) { writer.visitMethodInsn(Opcodes.INVOKESTATIC, type.getInternalName(), name, getMethodType().toMethodDescriptorString(), true); } else { writer.invokeStatic(type, method); } } else if (Modifier.isInterface(clazz.getModifiers())) { writer.invokeInterface(type, method); } else { writer.invokeVirtual(type, method); } }
From source file:org.elasticsearch.plan.a.Caster.java
License:Apache License
void writeTransform(final MethodVisitor visitor, final Transform transform) { final Class clazz = transform.method.owner.clazz; final java.lang.reflect.Method method = transform.method.method; final String name = method.getName(); final String internal = transform.method.owner.internal; final String descriptor = transform.method.descriptor; final Type upcast = transform.upcast; final Type downcast = transform.downcast; if (upcast != null) { visitor.visitTypeInsn(Opcodes.CHECKCAST, upcast.internal); }/*from ww w. j a va 2 s .com*/ if (java.lang.reflect.Modifier.isStatic(method.getModifiers())) { visitor.visitMethodInsn(Opcodes.INVOKESTATIC, internal, name, descriptor, false); } else if (java.lang.reflect.Modifier.isInterface(clazz.getModifiers())) { visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, internal, name, descriptor, true); } else { visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, internal, name, descriptor, false); } if (downcast != null) { visitor.visitTypeInsn(Opcodes.CHECKCAST, downcast.internal); } }