List of usage examples for org.objectweb.asm Opcodes INVOKEINTERFACE
int INVOKEINTERFACE
To view the source code for org.objectweb.asm Opcodes INVOKEINTERFACE.
Click Source Link
From source file:bytecode.InstructionExporter.java
License:Apache License
/** * Output call instructions, outputing the correct opcode for the type of * call.//from ww w . j av a2s.c o m * * @param instruction Call instruction. * @return <code>null</code> */ @Override public Void visit(Call instruction) { Method m = instruction.getMethod(); ClassNode c = m.getOwner(); int opcode; switch (instruction.getSort()) { case INTERFACE: opcode = Opcodes.INVOKEINTERFACE; break; case VIRTUAL: opcode = Opcodes.INVOKEVIRTUAL; break; case SPECIAL: opcode = Opcodes.INVOKESPECIAL; break; case STATIC: opcode = Opcodes.INVOKESTATIC; break; default: throw new RuntimeException("Unknown call type"); } mv.visitMethodInsn(opcode, c.getName(), m.getName(), m.getDescriptor()); return null; }
From source file:bytecode.MethodImporter.java
License:Apache License
/** * Imports method calls, storing the type of invokation (virtual, static, * special and interface).//w ww. j a v a2 s. c om * * @param opcode Opcode. * @param owner Class containing the method. * @param name Name of the method. * @param descriptor Descriptor of the method. */ @Override public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor) { // Find relevant class and method. ClassNode clazz = ClassNode.getClass(owner); Method m = clazz.getMethod(name, descriptor); int thisOffset = (opcode == Opcodes.INVOKESTATIC) ? 0 : 1; // Pop arguments off stack (remembering to pass 'this' for non-statics). Producer[] arguments = new Producer[m.getParameterCount() + thisOffset]; List<Type> argTypes = m.getParameters(); for (int i = m.getParameterCount() - 1; i >= 0; i--) { Producer arg = stack.pop(); arg.getType().unify(argTypes.get(i), false); arguments[i + thisOffset] = arg; } // 'this' Argument if (thisOffset == 1) { Producer arg = stack.pop(); arg.getType().unify(Type.getObjectType(owner)); arguments[0] = arg; } // Call type Call.Sort sort = null; switch (opcode) { case Opcodes.INVOKEINTERFACE: sort = Call.Sort.INTERFACE; break; case Opcodes.INVOKESPECIAL: sort = Call.Sort.SPECIAL; break; case Opcodes.INVOKESTATIC: sort = Call.Sort.STATIC; break; case Opcodes.INVOKEVIRTUAL: sort = Call.Sort.VIRTUAL; break; } // Create instruction and update stack etc. Call c = new Call(arguments, m, sort); if (Type.getReturnType(descriptor).getSort() != null) stack.push(c); current.getStateful().add(c); ordered.add(c); }
From source file:co.paralleluniverse.fibers.instrument.MethodDatabase.java
License:Open Source License
private int isMethodSuspendable0(String className, String methodName, String methodDesc, int opcode) { if (methodName.charAt(0) == '<') return NONSUSPENDABLE; // special methods are never suspendable if (isYieldMethod(className, methodName)) return SUSPENDABLE; ClassEntry entry = getClassEntry(className); if (entry == null) { entry = CLASS_NOT_FOUND;//from w w w.j ava 2 s .c o m if (cl != null) { log(LogLevel.INFO, "Trying to read class: %s", className); CheckInstrumentationVisitor civ = checkClass(className); if (civ == null) log(LogLevel.WARNING, "Class not found: %s", className); else entry = civ.getClassEntry(); } else log(LogLevel.WARNING, "Can't check class: %s", className); recordSuspendableMethods(className, entry); } if (entry == CLASS_NOT_FOUND) { if (isJavaCore(className)) return MAYBE_CORE; // if (JavaAgent.isActive()) // throw new AssertionError(); return UNKNOWN; } SuspendableType susp1 = entry.check(methodName, methodDesc); int suspendable = UNKNOWN; if (susp1 == null) suspendable = UNKNOWN; else if (susp1 == SuspendableType.SUSPENDABLE) suspendable = SUSPENDABLE; else if (susp1 == SuspendableType.SUSPENDABLE_SUPER) suspendable = SUSPENDABLE_ABSTRACT; else if (susp1 == SuspendableType.NON_SUSPENDABLE) suspendable = NONSUSPENDABLE; if (suspendable == UNKNOWN) { if (opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKESPECIAL) { if (entry.getSuperName() != null) suspendable = isMethodSuspendable0(entry.getSuperName(), methodName, methodDesc, opcode); } if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) { // can be INVOKEVIRTUAL on an abstract class implementing the interface for (String iface : entry.getInterfaces()) { int s = isMethodSuspendable0(iface, methodName, methodDesc, opcode); if (s > suspendable) suspendable = s; if (suspendable > MAYBE_CORE) break; } } } return suspendable; }
From source file:com.android.ide.eclipse.apt.internal.analysis.EnhancedForLoopAnalyzer.java
License:Apache License
@Override protected Collection<Problem> analyzeMethod(MethodNode methodNode) { final LinkedList<Problem> problems = new LinkedList<Problem>(); final LinkedList<Problem> iterators = new LinkedList<Problem>(); final InsnList instructions = methodNode.instructions; for (int i = 0; i < instructions.size(); i++) { final AbstractInsnNode insnNode = instructions.get(i); if (insnNode.getOpcode() == Opcodes.INVOKEINTERFACE) { final MethodInsnNode interfaceInst = (MethodInsnNode) insnNode; if (interfaceInst.owner.equals(ITERATOR_CLASS)) { final Problem problem = new Problem(insnNode); if (iterators.contains(problem)) { iterators.remove(problem); problems.add(problem); } else { iterators.add(problem); }/* ww w .j a v a 2 s .c om*/ } } } return problems; }
From source file:com.android.ide.eclipse.apt.internal.analysis.VirtualInterfaceAnalyzer.java
License:Apache License
@Override protected Collection<Problem> analyzeMethod(final MethodNode methodNode) { final LinkedList<Problem> problems = new LinkedList<Problem>(); final InsnList instructions = methodNode.instructions; for (int i = 0; i < instructions.size(); i++) { final AbstractInsnNode insnNode = instructions.get(i); if (insnNode.getOpcode() == Opcodes.INVOKEINTERFACE) { final Problem problem = new Problem(insnNode); problems.add(problem);/* www . j a v a2 s . c om*/ } } return problems; }
From source file:com.asakusafw.dag.compiler.builtin.Util.java
License:Apache License
static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {// www . j a v a 2s .c o m DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds {@link Result#add(Object)} method invocation. * @param method the current method visitor *///from ww w. j a v a 2 s . co m public static void invokeResultAdd(MethodVisitor method) { method.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(RESULT_TYPE).getInternalName(), "add", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), true); }
From source file:com.asakusafw.dag.compiler.codegen.EdgeDataTableAdapterGenerator.java
License:Apache License
private static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {/*ww w. j ava 2 s .c om*/ DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.ExtractAdapterGenerator.java
License:Apache License
/** * Generates the class./* ww w .j av a2 s. c om*/ * @param successor the successor * @param target the target class * @return the generated class */ public ClassData generate(VertexElement successor, ClassDescription target) { Arguments.require(successor.getRuntimeType().equals(RESULT_TYPE)); ClassWriter writer = newWriter(target, Object.class, Result.class); List<Tuple<VertexElement, FieldRef>> pairs = defineDependenciesConstructor(target, writer, Arrays.asList(successor), Lang.discard()); Invariants.require(pairs.size() == 1); defineResultAdd(writer, method -> { pairs.get(0).right().load(method); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitTypeInsn(Opcodes.CHECKCAST, typeOf(ExtractOperation.Input.class).getInternalName()); method.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(ExtractOperation.Input.class).getInternalName(), "getObject", Type.getMethodDescriptor(typeOf(Object.class)), true); invokeResultAdd(method); }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java
License:Apache License
private static void putSerialize(String methodName, DataModelReference reference, List<PropertyReference> properties, ClassWriter writer) { MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, methodName, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null, new String[] { typeOf(IOException.class).getInternalName(), typeOf(InterruptedException.class).getInternalName(), }); if (properties.isEmpty()) { LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2); output.load(v);//from ww w . ja v a 2s. co m getConst(v, 0); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataOutput.class).getInternalName(), "writeByte", Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), true); } else { LocalVarRef object = cast(v, 1, reference.getDeclaration()); LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2); for (PropertyReference property : properties) { object.load(v); getOption(v, property); output.load(v); v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "serialize", Type .getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataOutput.class)), false); } } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }