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:com.codename1.tools.translator.bytecodes.CustomInvoke.java
License:Open Source License
@Override public void addDependencies(List<String> dependencyList) { String t = owner.replace('.', '_').replace('/', '_').replace('$', '_'); t = unarray(t);/*from w w w . ja v a 2s .c o m*/ if (t != null && !dependencyList.contains(t)) { dependencyList.add(t); } StringBuilder bld = new StringBuilder(); if (origOpcode != Opcodes.INVOKEINTERFACE && origOpcode != Opcodes.INVOKEVIRTUAL) { return; } bld.append(owner.replace('/', '_').replace('$', '_')); bld.append("_"); if (name.equals("<init>")) { bld.append("__INIT__"); } else { if (name.equals("<clinit>")) { bld.append("__CLINIT__"); } else { bld.append(name); } } bld.append("__"); ArrayList<String> args = new ArrayList<String>(); String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args); String str = bld.toString(); BytecodeMethod.addVirtualMethodsInvoked(str); }
From source file:com.codename1.tools.translator.bytecodes.CustomInvoke.java
License:Open Source License
public boolean appendExpression(StringBuilder b) { // special case for clone on an array which isn't a real method invocation if (name.equals("clone") && owner.indexOf('[') > -1) { if (targetObjectLiteral != null) { b.append("cloneArray(").append(targetObjectLiteral).append(")"); } else {// w w w. ja v a 2s.c om b.append("cloneArray(POP_OBJ(1))"); } return true; } StringBuilder bld = new StringBuilder(); if (origOpcode == Opcodes.INVOKEINTERFACE || origOpcode == Opcodes.INVOKEVIRTUAL) { //b.append(" "); bld.append("virtual_"); } if (origOpcode == Opcodes.INVOKESTATIC) { // find the actual class of the static method to workaround javac not defining it correctly ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_')); owner = findActualOwner(bc); } bld.append(owner.replace('/', '_').replace('$', '_')); bld.append("_"); if (name.equals("<init>")) { bld.append("__INIT__"); } else { if (name.equals("<clinit>")) { bld.append("__CLINIT__"); } else { bld.append(name); } } bld.append("__"); ArrayList<String> args = new ArrayList<String>(); String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args); int numLiteralArgs = this.getNumLiteralArgs(); if (numLiteralArgs > 0) { b.append("/* CustomInvoke */"); } boolean noPop = false; b.append(bld); b.append("(threadStateData"); if (origOpcode != Opcodes.INVOKESTATIC) { if (targetObjectLiteral == null) { //b.append(", SP[-"); //b.append(args.size() + 1 - numLiteralArgs); //b.append("].data.o"); return false; } else { b.append(", ").append(targetObjectLiteral); numLiteralArgs++; } } //int offset = args.size(); //int numArgs = offset; int argIndex = 0; for (String a : args) { b.append(", "); if (literalArgs != null && literalArgs[argIndex] != null) { b.append(literalArgs[argIndex]); } else { return false; //b.append("SP[-"); //b.append(offset); //b.append("].data."); //b.append(a); //offset--; } argIndex++; } if (returnVal == null) { return false; } b.append(")"); return true; }
From source file:com.codename1.tools.translator.bytecodes.CustomInvoke.java
License:Open Source License
@Override public void appendInstruction(StringBuilder b) { // special case for clone on an array which isn't a real method invocation if (name.equals("clone") && owner.indexOf('[') > -1) { if (targetObjectLiteral != null) { b.append(" PUSH_OBJ(cloneArray(").append(targetObjectLiteral).append("));\n"); } else {/* w w w .ja v a 2s . c o m*/ b.append(" POP_MANY_AND_PUSH_OBJ(cloneArray(PEEK_OBJ(1)), 1);\n"); } return; } StringBuilder bld = new StringBuilder(); if (origOpcode == Opcodes.INVOKEINTERFACE || origOpcode == Opcodes.INVOKEVIRTUAL) { b.append(" "); bld.append("virtual_"); } else { b.append(" "); } if (origOpcode == Opcodes.INVOKESTATIC) { // find the actual class of the static method to workaround javac not defining it correctly ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_')); owner = findActualOwner(bc); } //if(owner.replace('/', '_').replace('$', '_').equals("java_lang_System_1") && name.equals("sleep")) { // System.out.println("Break"); //} bld.append(owner.replace('/', '_').replace('$', '_')); bld.append("_"); if (name.equals("<init>")) { bld.append("__INIT__"); } else { if (name.equals("<clinit>")) { bld.append("__CLINIT__"); } else { bld.append(name); } } bld.append("__"); ArrayList<String> args = new ArrayList<String>(); String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args); int numLiteralArgs = this.getNumLiteralArgs(); if (numLiteralArgs > 0) { b.append("/* CustomInvoke */"); } boolean noPop = false; if (returnVal == null || noReturn) { b.append(bld); } else { if (args.size() - numLiteralArgs == 0 && origOpcode == Opcodes.INVOKESTATIC) { // special case for static method if (returnVal.equals("JAVA_OBJECT")) { b.append("PUSH_OBJ"); } else { if (returnVal.equals("JAVA_INT")) { b.append("PUSH_INT"); } else { if (returnVal.equals("JAVA_LONG")) { b.append("PUSH_LONG"); } else { if (returnVal.equals("JAVA_DOUBLE")) { b.append("PUSH_DOUBLE"); } else { if (returnVal.equals("JAVA_FLOAT")) { b.append("PUSH_FLOAT"); } else { throw new UnsupportedOperationException("Unknown type: " + returnVal); } } } } } //b.append(returnVal); noPop = true; b.append("("); } else { //b.append("POP_MANY_AND_"); //b.append(returnVal); b.append("{ "); b.append(returnVal); b.append(" tmpResult = "); } b.append(bld); } b.append("(threadStateData"); if (origOpcode != Opcodes.INVOKESTATIC) { if (targetObjectLiteral == null) { b.append(", SP[-"); b.append(args.size() + 1 - numLiteralArgs); b.append("].data.o"); } else { b.append(", " + targetObjectLiteral); numLiteralArgs++; } } int offset = args.size(); //int numArgs = offset; int argIndex = 0; for (String a : args) { b.append(", "); if (literalArgs != null && literalArgs[argIndex] != null) { b.append(literalArgs[argIndex]); } else { b.append("SP[-"); b.append(offset); b.append("].data."); b.append(a); offset--; } argIndex++; } if (noPop) { b.append("));\n"); return; } if (returnVal != null && !noReturn) { b.append(");\n"); if (origOpcode != Opcodes.INVOKESTATIC) { if (args.size() - numLiteralArgs > 0) { b.append(" SP -= "); b.append(args.size() - numLiteralArgs); b.append(";\n"); } } else { if (args.size() - numLiteralArgs > 1) { b.append(" SP -= "); b.append(args.size() - numLiteralArgs - 1); b.append(";\n"); } } if (targetObjectLiteral == null) { if (returnVal.equals("JAVA_OBJECT")) { b.append(" SP[-1].data.o = tmpResult; SP[-1].type = CN1_TYPE_OBJECT; }\n"); } else { if (returnVal.equals("JAVA_INT")) { b.append(" SP[-1].data.i = tmpResult; SP[-1].type = CN1_TYPE_INT; }\n"); } else { if (returnVal.equals("JAVA_LONG")) { b.append(" SP[-1].data.l = tmpResult; SP[-1].type = CN1_TYPE_LONG; }\n"); } else { if (returnVal.equals("JAVA_DOUBLE")) { b.append(" SP[-1].data.d = tmpResult; SP[-1].type = CN1_TYPE_DOUBLE; }\n"); } else { if (returnVal.equals("JAVA_FLOAT")) { b.append(" SP[-1].data.f = tmpResult; SP[-1].type = CN1_TYPE_FLOAT; }\n"); } else { throw new UnsupportedOperationException("Unknown type: " + returnVal); } } } } } } else { if (returnVal.equals("JAVA_OBJECT")) { b.append(" PUSH_OBJ(tmpResult); }\n"); } else { if (returnVal.equals("JAVA_INT")) { b.append(" PUSH_INT(tmpResult); }\n"); } else { if (returnVal.equals("JAVA_LONG")) { b.append(" PUSH_LONG(tmpResult); }\n"); } else { if (returnVal.equals("JAVA_DOUBLE")) { b.append(" PUSH_DOUBLE(tmpResult); }\n"); } else { if (returnVal.equals("JAVA_FLOAT")) { b.append(" PUSH_FLOAT(tmpResult); }\n"); } else { throw new UnsupportedOperationException("Unknown type: " + returnVal); } } } } } } return; } b.append("); "); int val; if (origOpcode != Opcodes.INVOKESTATIC) { val = args.size() + 1 - numLiteralArgs; } else { val = args.size() - numLiteralArgs; } if (val > 0) { b.append(" SP -= "); b.append(val); b.append(";\n"); } else { b.append("\n"); } }
From source file:com.codename1.tools.translator.bytecodes.Invoke.java
License:Open Source License
@Override public void addDependencies(List<String> dependencyList) { String t = owner.replace('.', '_').replace('/', '_').replace('$', '_'); t = unarray(t);/*from w w w . j av a2s . c o m*/ if (t != null && !dependencyList.contains(t)) { dependencyList.add(t); } StringBuilder bld = new StringBuilder(); if (opcode != Opcodes.INVOKEINTERFACE && opcode != Opcodes.INVOKEVIRTUAL) { return; } bld.append(owner.replace('/', '_').replace('$', '_')); bld.append("_"); if (name.equals("<init>")) { bld.append("__INIT__"); } else { if (name.equals("<clinit>")) { bld.append("__CLINIT__"); } else { bld.append(name); } } bld.append("__"); ArrayList<String> args = new ArrayList<String>(); String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args); String str = bld.toString(); BytecodeMethod.addVirtualMethodsInvoked(str); }
From source file:com.codename1.tools.translator.bytecodes.Invoke.java
License:Open Source License
@Override public void appendInstruction(StringBuilder b) { // special case for clone on an array which isn't a real method invocation if (name.equals("clone") && owner.indexOf('[') > -1) { b.append(" POP_MANY_AND_PUSH_OBJ(cloneArray(PEEK_OBJ(1)), 1);\n"); return;/* w w w. jav a2 s .c o m*/ } StringBuilder bld = new StringBuilder(); if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) { b.append(" "); bld.append("virtual_"); } else { b.append(" "); } if (opcode == Opcodes.INVOKESTATIC) { // find the actual class of the static method to workaround javac not defining it correctly ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_')); owner = findActualOwner(bc); } //if(owner.replace('/', '_').replace('$', '_').equals("java_lang_System_1") && name.equals("sleep")) { // System.out.println("Break"); //} bld.append(owner.replace('/', '_').replace('$', '_')); bld.append("_"); if (name.equals("<init>")) { bld.append("__INIT__"); } else { if (name.equals("<clinit>")) { bld.append("__CLINIT__"); } else { bld.append(name); } } bld.append("__"); ArrayList<String> args = new ArrayList<String>(); String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args); boolean noPop = false; if (returnVal == null) { b.append(bld); } else { if (args.size() == 0 && opcode == Opcodes.INVOKESTATIC) { // special case for static method if (returnVal.equals("JAVA_OBJECT")) { b.append("PUSH_OBJ"); } else { if (returnVal.equals("JAVA_INT")) { b.append("PUSH_INT"); } else { if (returnVal.equals("JAVA_LONG")) { b.append("PUSH_LONG"); } else { if (returnVal.equals("JAVA_DOUBLE")) { b.append("PUSH_DOUBLE"); } else { if (returnVal.equals("JAVA_FLOAT")) { b.append("PUSH_FLOAT"); } else { throw new UnsupportedOperationException("Unknown type: " + returnVal); } } } } } //b.append(returnVal); noPop = true; b.append("("); } else { //b.append("POP_MANY_AND_"); //b.append(returnVal); b.append("{ "); b.append(returnVal); b.append(" tmpResult = "); } b.append(bld); } b.append("(threadStateData"); if (opcode != Opcodes.INVOKESTATIC) { b.append(", SP[-"); b.append(args.size() + 1); b.append("].data.o"); } int offset = args.size(); //int numArgs = offset; int argIndex = 0; for (String a : args) { b.append(", "); b.append("SP[-"); b.append(offset); b.append("].data."); b.append(a); offset--; argIndex++; } if (noPop) { b.append("));\n"); return; } if (returnVal != null) { b.append(");\n"); if (opcode != Opcodes.INVOKESTATIC) { if (args.size() > 0) { b.append(" SP-="); b.append(args.size()); b.append(";\n"); } } else { if (args.size() > 1) { b.append(" SP-="); b.append(args.size() - 1); b.append(";\n"); } } if (returnVal.equals("JAVA_OBJECT")) { b.append(" SP[-1].data.o = tmpResult; SP[-1].type = CN1_TYPE_OBJECT; }\n"); } else { if (returnVal.equals("JAVA_INT")) { b.append(" SP[-1].data.i = tmpResult; SP[-1].type = CN1_TYPE_INT; }\n"); } else { if (returnVal.equals("JAVA_LONG")) { b.append(" SP[-1].data.l = tmpResult; SP[-1].type = CN1_TYPE_LONG; }\n"); } else { if (returnVal.equals("JAVA_DOUBLE")) { b.append(" SP[-1].data.d = tmpResult; SP[-1].type = CN1_TYPE_DOUBLE; }\n"); } else { if (returnVal.equals("JAVA_FLOAT")) { b.append(" SP[-1].data.f = tmpResult; SP[-1].type = CN1_TYPE_FLOAT; }\n"); } else { throw new UnsupportedOperationException("Unknown type: " + returnVal); } } } } } /*if(opcode != Opcodes.INVOKESTATIC) { b.append(args.size() + 1); } else { b.append(args.size()); } b.append(");\n"); */ return; } b.append("); "); int val; if (opcode != Opcodes.INVOKESTATIC) { val = args.size() + 1; } else { val = args.size(); } if (val > 0) { /*b.append("popMany(threadStateData, "); b.append(val); b.append(", stack, &stackPointer); \n"); */ b.append(" SP-= "); b.append(val); b.append(";\n"); } else { b.append("\n"); } }
From source file:com.devexperts.aprof.transformer.Context.java
License:Open Source License
public boolean isMethodInvocationTracked(String cname, int opcode, String owner, String name, String desc) { if (owner.startsWith("[")) return false; // do not track array method invocations if (config.isMethodTracked(cname, name)) return true; // direct invocation of tracked method through its actual class if (opcode != Opcodes.INVOKEVIRTUAL && opcode != Opcodes.INVOKEINTERFACE) return false; // special or static invocation cannot got though superclass/super interface // Check for invocation via super class or interface // Load target class information ClassInfo classInfo = ciCache.getClassInfo(owner, loader); if (classInfo == null) return false; // we don't have class info, which means we don't track it, then // Check if tracked method Set<String> descSet = classInfo.getTrackedMethodInvocations().get(name); return descSet != null && descSet.contains(desc); }
From source file:com.dragome.callbackevictor.serverside.bytecode.transformation.asm.ContinuationMethodAnalyzer.java
License:Apache License
boolean needsFrameGuard(int opcode, String owner, String name, String desc) { /* TODO: need to customize a way enchancer skips classes/methods if (owner.startsWith("java/")) { System.out.println("SKIP:: " + owner + "." + name + desc); return false;/*from w ww . j a va 2 s.c o m*/ } */ if (opcode == Opcodes.INVOKEINTERFACE || (opcode == Opcodes.INVOKESPECIAL && !"<init>".equals(name)) || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) { return true; } return false; }
From source file:com.enea.jcarder.agent.instrument.StackAnalyzeMethodVisitor.java
License:GNU General Public License
public void visitMethodInsn(int opCode, String owner, String name, String desc) { mMethodVisitor.visitMethodInsn(opCode, owner, name, desc); switch (opCode) { case Opcodes.INVOKEVIRTUAL: // pass through to next case. case Opcodes.INVOKESPECIAL: // pass through to next case. case Opcodes.INVOKESTATIC: if ("forName".equals(name) && "java/lang/Class".equals(owner) && "(Ljava/lang/String;)Ljava/lang/Class;".equals(desc)) { Object stackObject = popObject(); if (stackObject instanceof String) { String classDescription = ((String) stackObject) + ".class"; pushTextualDescription(classDescription); break; }/*from ww w. j av a 2 s. c o m*/ } // pass through to next case. case Opcodes.INVOKEINTERFACE: clear(); if (isNonVoidMethod(name, desc)) { pushTextualDescription(owner + "." + name + "()"); } break; default: clear(); } }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.CompilerConstants.java
License:Open Source License
/** * Create a call representing an invokeinterface to a given method. Don't * attempt to look this up at compile time * * @param clazz the class/*from w ww.ja v a 2 s . co m*/ * @param name the method name * @param rtype the return type * @param ptypes the parameter types * * @return Call representing specified invokeinterface call */ public static Call interfaceCallNoLookup(final Class<?> clazz, final String name, final Class<?> rtype, final Class<?>... ptypes) { return new Call(null, className(clazz), name, methodDescriptor(rtype, ptypes)) { @Override MethodEmitter invoke(final MethodEmitter method) { return method.invokeinterface(className, name, descriptor); } @Override public void invoke(final MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, name, descriptor, true); } }; }
From source file:com.geeksaga.light.profiler.util.ASMUtil.java
License:Apache License
public static MethodInsnNode createMethodInsn(int opcode, String className, String methodName, String desc) { return new MethodInsnNode(opcode, getInternalName(className), methodName, desc, opcode == Opcodes.INVOKEINTERFACE); }