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:com.offbynull.coroutines.instrumenter.asm.SearchUtils.java
License:Open Source License
/** * Get the number of items that need to be on the stack for an invocation of some method. * @param invokeNode the invocation instruction (either normal invocation or invokedynamic) * @return number of items required on the stack for this method * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code invokeNode} is neither of type {@link MethodInsnNode} nor {@link InvokeDynamicInsnNode}, * or if type of invocation ({@link MethodInsnNode}) cannot be determined *//*ww w.jav a 2 s. c om*/ public static int getRequiredStackCountForInvocation(AbstractInsnNode invokeNode) { Validate.notNull(invokeNode); if (invokeNode instanceof MethodInsnNode) { MethodInsnNode methodInsnNode = (MethodInsnNode) invokeNode; int extra; int paramCount; switch (methodInsnNode.getOpcode()) { case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKEINTERFACE: extra = 1; break; case Opcodes.INVOKESTATIC: extra = 0; break; default: throw new IllegalArgumentException(); // unknown invocation type? probably badly generated instruction node } Type methodType = Type.getType(methodInsnNode.desc); paramCount = methodType.getArgumentTypes().length; return paramCount + extra; } else if (invokeNode instanceof InvokeDynamicInsnNode) { InvokeDynamicInsnNode invokeDynamicInsnNode = (InvokeDynamicInsnNode) invokeNode; int paramCount; Type methodType = Type.getType(invokeDynamicInsnNode.desc); paramCount = methodType.getArgumentTypes().length; return paramCount; } else { throw new IllegalArgumentException(); } }
From source file:com.offbynull.coroutines.instrumenter.asm.SearchUtilsTest.java
License:Open Source License
@Test public void mustProperlyDetermineStackSizeForStaticMethod() { Type type = Type.getType(MethodUtils.getAccessibleMethod(Integer.class, "decode", String.class)); MethodInsnNode methodInsnNode = new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Integer", "decode", type.getDescriptor(), false); int reqStackCount = SearchUtils.getRequiredStackCountForInvocation(methodInsnNode); assertEquals(1, reqStackCount);/* w w w . j a v a 2s . com*/ }
From source file:com.offbynull.coroutines.instrumenter.ContinuationPointInstructionUtils.java
License:Open Source License
static InsnList castToObjectAndSave(Type originalType, Variable variable) { Validate.notNull(originalType);/* ww w. ja va2s . c o m*/ Validate.notNull(variable); Validate.isTrue(variable.getType().equals(Type.getType(Object.class))); InsnList ret = new InsnList(); switch (originalType.getSort()) { case Type.BOOLEAN: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.BYTE: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.SHORT: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.CHAR: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.INT: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.FLOAT: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.LONG: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.DOUBLE: ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false)); ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.ARRAY: case Type.OBJECT: ret.add(saveVar(variable)); // save it in to the returnValObj break; case Type.VOID: break; case Type.METHOD: default: throw new IllegalArgumentException(); } return ret; }
From source file:com.redhat.byteman.jli.agentasm.JliMethodVisitor.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); super.visitMethodInsn(Opcodes.INVOKESTATIC, "com/redhat/byteman/jli/agentasm/JliEnhancer", "doMonitoring", "()V", false); }
From source file:com.spotify.missinglink.ClassLoader.java
License:Apache License
private static void handleMethodCall(Set<CalledMethod> thisCalls, int lineNumber, MethodInsnNode insn) { boolean isStatic; switch (insn.getOpcode()) { case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKEINTERFACE: isStatic = false;/*from w ww .j a va 2 s . c om*/ break; case Opcodes.INVOKESPECIAL: isStatic = false; break; case Opcodes.INVOKESTATIC: isStatic = true; break; default: throw new RuntimeException("Unexpected method call opcode: " + insn.getOpcode()); } if (insn.owner.charAt(0) != '[') { thisCalls.add(new CalledMethodBuilder().owner(TypeDescriptors.fromClassName(insn.owner)) .descriptor(MethodDescriptors.fromDesc(insn.desc, insn.name)).isStatic(isStatic) .lineNumber(lineNumber).build()); } }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.DefUseChains.java
License:Open Source License
private static void removeUnboxedValueInsns(AbstractInterpretationValue val, ByteCodeMethodVisitor bcmv) { for (Insn i : val.getDefs()) removeInsn(bcmv, i, val, "RemovingBoxedValueDefinition"); for (Insn i : val.getUses()) { if (i.isBoxingMethod()) { removeInsn(bcmv, i, val, "RemoveBoxingMethod"); } else if (i.isUnBoxingMethod()) { removeInsn(bcmv, i, val, "UnboxingMethod"); } else if (i.isCheckCast()) { removeInsn(bcmv, i, val, "CheckCast"); // FIXME CHF } else if (i instanceof VarInsn) { VarInsn vi = (VarInsn) i;//from w ww.j a v a 2 s.c o m if (vi.opcode == Opcodes.ASTORE) { int j = bcmv.insns.indexOf(i); removeInsn(bcmv, i, val, "astoreconversion" + val.getType()); if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ32;")) bcmv.insns.add(j, new VarInsn("ISTORE", Opcodes.ISTORE, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ64;")) bcmv.insns.add(j, new VarInsn("LSTORE", Opcodes.LSTORE, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR32;")) bcmv.insns.add(j, new VarInsn("FSTORE", Opcodes.FSTORE, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR64;")) bcmv.insns.add(j, new VarInsn("DSTORE", Opcodes.DSTORE, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FBoolean;")) bcmv.insns.add(j, new VarInsn("ISTORE", Opcodes.ISTORE, val.getValueNumber(), vi.index)); else bcmv.insns.add(j, new VarInsn("ASTORE", Opcodes.ASTORE, val.getValueNumber(), vi.index)); } else if (vi.opcode == Opcodes.ALOAD) { int j = bcmv.insns.indexOf(i); removeInsn(bcmv, i, val, "Aloadconversion" + val.getType()); if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ32;")) bcmv.insns.add(j, new VarInsn("ILOAD", Opcodes.ILOAD, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ64;")) bcmv.insns.add(j, new VarInsn("LLOAD", Opcodes.LLOAD, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR32;")) bcmv.insns.add(j, new VarInsn("FLOAD", Opcodes.FLOAD, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR64;")) bcmv.insns.add(j, new VarInsn("DLOAD", Opcodes.DLOAD, val.getValueNumber(), vi.index)); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FBoolean;")) bcmv.insns.add(j, new VarInsn("ILOAD", Opcodes.ILOAD, val.getValueNumber(), vi.index)); else bcmv.insns.add(j, new VarInsn("ALOAD", Opcodes.ALOAD, val.getValueNumber(), vi.index)); } } else if (i instanceof SingleInsn) { SingleInsn si = (SingleInsn) i; if (si.opcode == Opcodes.ARETURN) { int j = bcmv.insns.indexOf(i); if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ32;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FZZ32", "make", "(I)Lcom/sun/fortress/compiler/runtimeValues/FZZ32;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FZZ64;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FZZ64", "make", "(J)Lcom/sun/fortress/compiler/runtimeValues/FZZ64;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR32;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FRR32", "make", "(F)Lcom/sun/fortress/compiler/runtimeValues/FRR32;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FRR64;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FRR64", "make", "(D)Lcom/sun/fortress/compiler/runtimeValues/FRR64;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FVoid;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FVoid", "make", "()Lcom/sun/fortress/compiler/runtimeValues/FVoid;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FBoolean;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FBoolean", "make", "(Z)Lcom/sun/fortress/compiler/runtimeValues/FBoolean;", "ReboxingReturnValue")); else if (val.getType().equals("Lcom/sun/fortress/compiler/runtimeValues/FJavaString;")) bcmv.insns.add(j, new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "com/sun/fortress/compiler/runtimeValues/FJavaString", "make", "(java.lang.String)Lcom/sun/fortress/compiler/runtimeValues/FJavaString;", "ReboxingReturnValue")); else throw new RuntimeException("Don't recognize var type " + val.getType()); } } } }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.Inlining.java
License:Open Source License
public static boolean isBuiltinStaticMethod(ByteCodeMethodVisitor bcmv, Insn insn) { if (insn instanceof MethodInsn) { MethodInsn mi = (MethodInsn) insn; if ((mi.opcode == Opcodes.INVOKESTATIC) && (isCompilerBuiltin(mi.owner))) { return true; }//from w w w . j ava 2 s . c o m } return false; }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.Inlining.java
License:Open Source License
public static boolean isLibraryStaticMethod(ByteCodeMethodVisitor bcmv, Insn insn) { if (insn instanceof MethodInsn) { MethodInsn mi = (MethodInsn) insn; if ((mi.opcode == Opcodes.INVOKESTATIC) && (isCompilerLibrary(mi.owner))) { return true; }//ww w. ja va 2 s. c om } return false; }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.MethodInsn.java
License:Open Source License
public boolean isStaticMethod() { return this.opcode == Opcodes.INVOKESTATIC; }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.RemoveLiteralCoercions.java
License:Open Source License
public static Substitution removeIntLiterals(ByteCodeMethodVisitor bcmv) { String intLiteral = "com/sun/fortress/compiler/runtimeValues/FIntLiteral"; String ZZ32 = "com/sun/fortress/compiler/runtimeValues/FZZ32"; ArrayList<Insn> matches = new ArrayList<Insn>(); matches.add(new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, intLiteral, "make", "(I)L" + intLiteral + ";", "targetedForRemoval")); matches.add(new LabelInsn("LabelInsn", new Label(), "targetedForRemoval")); matches.add(new VisitLineNumberInsn("visitlinenumber", 0, new Label(), "targetedForRemoval")); matches.add(new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, "fortress/CompilerBuiltin", "coerce_ZZ32", "(Lfortress/CompilerBuiltin$IntLiteral;)L" + ZZ32 + ";", "targetedForRemoval")); ArrayList<Insn> replacements = new ArrayList<Insn>(); replacements.add(new MethodInsn("INVOKESTATIC", Opcodes.INVOKESTATIC, ZZ32, "make", "(I)L" + ZZ32 + ";", "ReplacementInsn")); return new Substitution(matches, replacements); }