List of usage examples for org.objectweb.asm Opcodes INVOKEDYNAMIC
int INVOKEDYNAMIC
To view the source code for org.objectweb.asm Opcodes INVOKEDYNAMIC.
Click Source Link
From source file:co.paralleluniverse.fibers.instrument.LabelSuspendableCallSitesClassVisitor.java
License:Open Source License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if ((access & Opcodes.ACC_NATIVE) == 0 && !isYieldMethod(className, name)) { // Bytecode-level AST of a method, being a MethodVisitor itself can be filled through delegation from another visitor // Analyze, fill and enqueue method ASTs final MethodVisitor outMV = super.visitMethod(access, name, desc, signature, exceptions); return new MethodVisitor(ASMAPI, outMV) { private int currLineNumber = -1; @Override/* ww w . j a va 2 s. c o m*/ public void visitLineNumber(int i, Label label) { currLineNumber = i; super.visitLineNumber(i, label); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) { final int type = AbstractInsnNode.METHOD_INSN; if (InstrumentMethod.isSuspendableCall(db, type, opcode, owner, name, desc)) { final Label l = new Label(); super.visitLabel(l); super.visitLineNumber(currLineNumber, l); // Force label } super.visitMethodInsn(opcode, owner, name, desc, isInterface); } @Override public void visitInvokeDynamicInsn(String name, String desc, Handle handle, Object... objects) { final int type = AbstractInsnNode.INVOKE_DYNAMIC_INSN; final int opcode = Opcodes.INVOKEDYNAMIC; if (InstrumentMethod.isSuspendableCall(db, type, opcode, handle.getOwner(), name, desc)) { final Label l = new Label(); super.visitLabel(l); super.visitLineNumber(currLineNumber, l); // Force label } super.visitInvokeDynamicInsn(name, desc, handle, objects); } }; } return super.visitMethod(access, name, desc, signature, exceptions); }
From source file:co.paralleluniverse.fibers.instrument.SuspOffsetsAfterInstrClassVisitor.java
License:Open Source License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if ((access & Opcodes.ACC_NATIVE) == 0 && !isYieldMethod(className, name)) { // Bytecode-level AST of a method, being a MethodVisitor itself can be filled through delegation from another visitor final MethodNode mn = new MethodNode(access, name, desc, signature, exceptions); // Analyze, fill and enqueue method ASTs final MethodVisitor outMV = super.visitMethod(access, name, desc, signature, exceptions); return new MethodVisitor(ASMAPI, outMV) { private Label currLabel = null; private int prevOffset = -1; private boolean instrumented; private boolean optimized = false; private int methodStart = -1, methodEnd = -1; private List<Integer> suspOffsetsAfterInstrL = new ArrayList<>(); private int[] suspCallSites = new int[0]; @Override/* w w w. ja v a2 s. c o m*/ public AnnotationVisitor visitAnnotation(final String adesc, boolean visible) { if (Classes.INSTRUMENTED_DESC.equals(adesc)) { instrumented = true; return new AnnotationVisitor(ASMAPI) { // Only collect info @Override public void visit(String name, Object value) { if (Instrumented.FIELD_NAME_METHOD_START.equals(name)) methodStart = (Integer) value; else if (Instrumented.FIELD_NAME_METHOD_END.equals(name)) methodEnd = (Integer) value; else if (Instrumented.FIELD_NAME_METHOD_OPTIMIZED.equals(name)) optimized = (Boolean) value; else if (Instrumented.FIELD_NAME_SUSPENDABLE_CALL_SITES.equals(name)) suspCallSites = (int[]) value; else //noinspection StatementWithEmptyBody if (Instrumented.FIELD_NAME_SUSPENDABLE_CALL_SITES_OFFSETS_AFTER_INSTR.equals(name)) ; // Ignore, we're filling it else throw new RuntimeException("Unexpected `@Instrumented` field: " + name); } }; } return super.visitAnnotation(adesc, visible); } @Override public void visitLocalVariable(String name, String desc, String sig, Label lStart, Label lEnd, int slot) { super.visitLocalVariable(name, desc, sig, lStart, lEnd, slot); } @Override public void visitLabel(Label label) { if (instrumented) { currLabel = label; } super.visitLabel(label); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) { if (instrumented) { final int type = AbstractInsnNode.METHOD_INSN; if (InstrumentMethod.isSuspendableCall(db, type, opcode, owner, name, desc) && !Classes.STACK_NAME.equals(owner) && // postRestore currLabel != null && currLabel.info instanceof Integer) addLine(); } super.visitMethodInsn(opcode, owner, name, desc, isInterface); } @Override public void visitInvokeDynamicInsn(String name, String desc, Handle handle, Object... objects) { if (instrumented) { final int type = AbstractInsnNode.INVOKE_DYNAMIC_INSN; final int opcode = Opcodes.INVOKEDYNAMIC; if (InstrumentMethod.isSuspendableCall(db, type, opcode, handle.getOwner(), name, desc) && !Classes.STACK_NAME.equals(handle.getOwner()) && // postRestore currLabel != null && currLabel.info instanceof Integer) addLine(); } super.visitInvokeDynamicInsn(name, desc, handle, objects); } @Override public void visitEnd() { if (instrumented) InstrumentMethod.emitInstrumentedAnn(db, outMV, mn, sourceName, className, optimized, methodStart, methodEnd, suspCallSites, toIntArray(suspOffsetsAfterInstrL)); super.visitEnd(); } private void addLine() { final int currOffset = (Integer) currLabel.info; if (currOffset > prevOffset) { suspOffsetsAfterInstrL.add(currOffset); prevOffset = currOffset; } } }; } return super.visitMethod(access, name, desc, signature, exceptions); }
From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java
License:Open Source License
@Override public void visitInvokeDynamicInsn(final String name, final String desc, final Handle bsm, final Object... bsmArgs) { final StringBuilder sb = new StringBuilder(); appendOpcode(sb, Opcodes.INVOKEDYNAMIC).append(' '); sb.append(name);//from www . j av a 2 s .com appendDescriptor(sb, METHOD_DESCRIPTOR, desc); final int len = sb.length(); for (int i = 0; i < 80 - len; i++) { sb.append(' '); } sb.append(" ["); appendHandle(sb, bsm); if (bsmArgs.length == 0) { sb.append("none"); } else { for (final Object cst : bsmArgs) { if (cst instanceof String) { appendStr(sb, (String) cst); } else if (cst instanceof Type) { sb.append(((Type) cst).getDescriptor()).append(".class"); } else if (cst instanceof Handle) { appendHandle(sb, (Handle) cst); } else if (cst instanceof Integer) { final int c = (Integer) cst; final int pp = c >> CALLSITE_PROGRAM_POINT_SHIFT; if (pp != 0) { sb.append(" pp=").append(pp); } sb.append(NashornCallSiteDescriptor.toString(c & FLAGS_MASK)); } else { sb.append(cst); } sb.append(", "); } sb.setLength(sb.length() - 2); } sb.append("]\n"); addText(sb); }
From source file:com.mebigfatguy.baremetal4j.Sourcifier.java
License:Apache License
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { lines.add(//from ww w. j a v a2 s . com "\t\tBCO = " + String.format("%05d", byteOffset) + "; // " + Printer.OPCODES[Opcodes.INVOKEDYNAMIC] + " " + name + argumentSignature(desc) + " ===> " + methodReturnType(desc)); byteOffset += 1; }
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performMethodInsn(int opcode, String owner, String name, String desc) { switch (opcode) { case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEINTERFACE: String[] parmSigs = SignatureUtils.splitMethodParameterSignatures(desc); int numParms = parmSigs.length; while ((numParms--) > 0) { pop();//from ww w. j a v a 2 s .c o m } if (opcode != Opcodes.INVOKESTATIC) { pop(); } String returnSig = SignatureUtils.getReturnSignature(desc); if (!"V".equals(returnSig)) { Operand op = new Operand(); op.setSignature(returnSig); push(op); } break; case Opcodes.INVOKEDYNAMIC: //no idea break; } }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { Type[] argsTypes = Type.getArgumentTypes(desc); Class<?>[] parameterTypes = new Class<?>[argsTypes.length]; for (int i = 0; i < argsTypes.length; i++) parameterTypes[i] = _classVisitor.getClass(argsTypes[i]); Expression[] arguments = new Expression[argsTypes.length]; for (int i = argsTypes.length; i > 0;) { i--;/*from w ww. j a v a 2s .c om*/ arguments[i] = TypeConverter.convert(_exprStack.pop(), parameterTypes[i]); } Expression e; switch (opcode) { case Opcodes.INVOKESPECIAL: if (name.equals("<init>")) { try { e = Expression.newInstance(_exprStack.pop().getResultType(), parameterTypes, arguments); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); } _exprStack.pop(); // going to re-add it, which is not the JVM // semantics break; } case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKEINTERFACE: try { e = Expression.invoke( TypeConverter.convert(_exprStack.pop(), _classVisitor.getClass(Type.getObjectType(owner))), name, parameterTypes, arguments); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); } break; case Opcodes.INVOKESTATIC: case Opcodes.INVOKEDYNAMIC: try { e = Expression.invoke(_classVisitor.getClass(Type.getObjectType(owner)), name, parameterTypes, arguments); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); } break; default: throw new IllegalArgumentException("opcode: " + opcode); } _exprStack.push(e); }
From source file:de.fhkoeln.gm.cui.javahardener.CheckNullMethodVisitor.java
License:Open Source License
/** * Delegates the implementation dependend on the argument cound to * {@link #invokeMethodWithoutArguments(int, String, String, String)} or * {@link #invokeMethodWithOneArgument(int, String, String, String)}. * //w w w .j a va 2 s. c o m * All other method calls will be handled by the original implementation * which just call the next visitor in the visitor chain. */ @Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKEDYNAMIC) { Type type = Type.getType(desc); int argumentCount = type.getArgumentTypes().length; if (argumentCount == 0) { // can handle with dup invokeMethodWithoutArguments(opcode, owner, name, desc); } else if (argumentCount == 1 && type.getArgumentTypes()[0].getSize() < 2) { // can handle with dup2 (works not if the argument is a long or double) invokeMethodWithOneArgument(opcode, owner, name, desc); } else { //System.out.println(Printer.OPCODES[opcode] + "\tUnsupported method: " + owner + "." + name + " " + desc); super.visitMethodInsn(opcode, owner, name, desc); } } else { super.visitMethodInsn(opcode, owner, name, desc); } }
From source file:de.loskutov.bco.asm.CommentedASMifierClassVisitor.java
License:Open Source License
@Override public void visitInvokeDynamicInsn(String name1, String desc, Handle bsm, Object... bsmArgs) { addIndex(Opcodes.INVOKEDYNAMIC); super.visitInvokeDynamicInsn(name1, desc, bsm, bsmArgs); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
/** * Objects that are not parameters and not written before * these can be:// w w w.j av a2 s . c o m * getField * getStatic * new * new array * new multi array * return type of method call */ private Type resolveType(final AbstractInsnNode node) { int arrayCount = 0; AbstractInsnNode currentNode = NodeHelper.getPrevious(node); while (currentNode != null) { final int opcode2 = currentNode.getOpcode(); if (opcode2 == Opcodes.NEWARRAY) { final int operand = ((IntInsnNode) currentNode).operand; return getObjectType(operand); } else if (opcode2 == Opcodes.ANEWARRAY) { return getObjectType(((TypeInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.MULTIANEWARRAY) { return getObjectType(((MultiANewArrayInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.NEW) { final String desc = ((TypeInsnNode) currentNode).desc; return getObjectType(desc); } else if ((opcode2 >= Opcodes.IALOAD) && (opcode2 <= Opcodes.AALOAD)) { arrayCount++; } else if ((opcode2 == Opcodes.GETFIELD) || (opcode2 == Opcodes.GETSTATIC)) { final String desc = ((FieldInsnNode) currentNode).desc; return getObjectType(removeArrayType(desc, arrayCount)); } else if ((opcode2 == Opcodes.ALOAD)) { final Type type2 = readers.getFirstVar(((VarInsnNode) currentNode).var).getParameterType(); return getObjectType(removeArrayType(type2.getDescriptor(), arrayCount)); } else if ((opcode2 >= Opcodes.INVOKEVIRTUAL) && (opcode2 <= Opcodes.INVOKEDYNAMIC)) { return Type.getReturnType(((MethodInsnNode) currentNode).desc); } currentNode = NodeHelper.getPrevious(currentNode); } return Type.VOID_TYPE; }
From source file:org.apache.commons.javaflow.providers.asm4.ContinuableMethodNode.java
License:Apache License
boolean needsFrameGuard(int opcode, String owner, String name, String desc) { if (owner.startsWith("java/") || owner.startsWith("javax/")) { //System.out.println("SKIP:: " + owner + "." + name + desc); return false; }//from w ww. ja va 2 s . c o m // Always create save-point before Continuation methods (like suspend) if (CONTINUATION_CLASS_INTERNAL_NAME.equals(owner)) { return CONTINUATION_CLASS_CONTINUABLE_METHODS.contains(name); } // No need to create save-point before constructors -- it's forbidden to suspend in constructors anyway if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) { return false; } if (opcode == Opcodes.INVOKEDYNAMIC) { // TODO verify CallSite to be continuable? return true; } if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) { final ContinuableClassInfo classInfo; try { classInfo = cciResolver.resolve(owner); } catch (final IOException ex) { throw new RuntimeException(ex); } return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc); } return false; }