Java Code Examples for org.objectweb.asm.commons.GeneratorAdapter#invokeStatic()
The following examples show how to use
org.objectweb.asm.commons.GeneratorAdapter#invokeStatic() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallChainInstrument.java From dacapobench with Apache License 2.0 | 7 votes |
@SuppressWarnings("unchecked") public void visitEnd() { if (!done && found) { done = true; try { GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this); Label start = mg.mark(); mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME))); mg.returnValue(); Label end = mg.mark(); mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE); mg.returnValue(); mg.endMethod(); } catch (NoSuchMethodException nsme) { System.err.println("Unable to find Agent.rlogCallChain method"); System.err.println("M:"+nsme); nsme.printStackTrace(); } } super.visitEnd(); }
Example 2
Source File: ClinitInstrument.java From dacapobench with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void visitEnd() { if (!foundClinit && instrument()) { // didn't find <clinit> so lets make one try { GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this); Label start = mg.mark(); mg.push(className); mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class))); Label end = mg.mark(); mg.returnValue(); mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE); mg.returnValue(); mg.endMethod(); } catch (NoSuchMethodException nsme) { System.out.println("Unable to find Agent.reportClass method"); } } super.visitEnd(); }
Example 3
Source File: IncrementalVisitor.java From Aceso with Apache License 2.0 | 5 votes |
protected static void trace( GeneratorAdapter mv, int argsNumber) { StringBuilder methodSignature = new StringBuilder("void trace(String"); for (int i = 0; i < argsNumber - 1; i++) { methodSignature.append(", String"); } methodSignature.append(")"); mv.invokeStatic(Type.getObjectType(PACKAGE + "/AndroidInstantRuntime"), Method.getMethod(methodSignature.toString())); }
Example 4
Source File: IncrementalVisitor.java From AnoleFix with MIT License | 5 votes |
protected static void trace(GeneratorAdapter mv, String s1, String s2) { mv.push(s1); mv.push(s2); mv.invokeStatic(Type.getType(PACKAGE + ".AndroidInstantRuntime"), Method.getMethod("void trace(String, String)")); }
Example 5
Source File: IncrementalVisitor.java From AnoleFix with MIT License | 5 votes |
protected static void trace(GeneratorAdapter mv, String s1, String s2, String s3) { mv.push(s1); mv.push(s2); mv.push(s3); mv.invokeStatic(Type.getType(PACKAGE + ".AndroidInstantRuntime"), Method.getMethod("void trace(String, String, String)")); }
Example 6
Source File: IncrementalVisitor.java From AnoleFix with MIT License | 5 votes |
protected static void trace(GeneratorAdapter mv, String s1, String s2, String s3, String s4) { mv.push(s1); mv.push(s2); mv.push(s3); mv.push(s4); mv.invokeStatic(Type.getType(PACKAGE + ".AndroidInstantRuntime"), Method.getMethod("void trace(String, String, String, String)")); }
Example 7
Source File: IncrementalVisitor.java From AnoleFix with MIT License | 5 votes |
protected static void trace(GeneratorAdapter mv, int argsNumber) { StringBuilder methodSignature = new StringBuilder("void trace(String"); for (int i = 0; i < argsNumber - 1; i++) { methodSignature.append(", String"); } methodSignature.append(")"); mv.invokeStatic(Type.getType(PACKAGE + ".AndroidInstantRuntime"), Method.getMethod(methodSignature.toString())); }
Example 8
Source File: TestThreadExecutionGenerator.java From lin-check with GNU Lesser General Public License v3.0 | 5 votes |
private static void storeExceptionResultFromThrowable(GeneratorAdapter mv, int resLocal, int iLocal) { int eLocal = mv.newLocal(THROWABLE_TYPE); mv.storeLocal(eLocal); mv.loadLocal(resLocal); mv.loadLocal(iLocal); mv.loadLocal(eLocal); mv.invokeVirtual(OBJECT_TYPE, OBJECT_GET_CLASS); mv.invokeStatic(RESULT_TYPE, RESULT_CREATE_EXCEPTION_RESULT); mv.arrayStore(RESULT_TYPE); }
Example 9
Source File: IncrementalVisitor.java From Aceso with Apache License 2.0 | 4 votes |
protected static void trace( GeneratorAdapter mv, String s) { mv.push(s); mv.invokeStatic(Type.getObjectType(PACKAGE + "/AndroidInstantRuntime"), Method.getMethod("void trace(String)")); }
Example 10
Source File: IncrementalVisitor.java From AnoleFix with MIT License | 4 votes |
protected static void trace(GeneratorAdapter mv, String s) { mv.push(s); mv.invokeStatic(Type.getType(PACKAGE + ".AndroidInstantRuntime"), Method.getMethod("void trace(String)")); }
Example 11
Source File: TestThreadExecutionGenerator.java From lin-check with GNU Lesser General Public License v3.0 | 4 votes |
private static void generateRun(ClassVisitor cv, Type testType, int iThread, List<Actor> actors, List<Object> objArgs, boolean waitsEnabled) { int access = ACC_PUBLIC; Method m = new Method("call", RESULT_ARRAY_TYPE, NO_ARGS); GeneratorAdapter mv = new GeneratorAdapter(access, m, // Try-catch blocks sorting is required new TryCatchBlockSorter(cv.visitMethod(access, m.getName(), m.getDescriptor(), null, null), access, m.getName(), m.getDescriptor(), null, null) ); mv.visitCode(); // Create Result[] array and store it to a local variable int resLocal = createResultArray(mv, actors.size()); // Call runner's onStart(iThread) method mv.loadThis(); mv.getField(TEST_THREAD_EXECUTION_TYPE, "runner", RUNNER_TYPE); mv.push(iThread); mv.invokeVirtual(RUNNER_TYPE, RUNNER_ON_START_METHOD); // Number of current operation (starts with 0) int iLocal = mv.newLocal(Type.INT_TYPE); mv.push(0); mv.storeLocal(iLocal); // Invoke actors for (int i = 0; i < actors.size(); i++) { Actor actor = actors.get(i); // Add busy-wait before operation execution (for non-first operations only) if (waitsEnabled && i > 0) { mv.loadThis(); mv.getField(TEST_THREAD_EXECUTION_TYPE, "waits", INT_ARRAY_TYPE); mv.push(i - 1); mv.arrayLoad(Type.INT_TYPE); mv.invokeStatic(UTILS_TYPE, UTILS_CONSUME_CPU); } // Start of try-catch block for exceptions which this actor should handle Label start, end = null, handler = null, handlerEnd = null; if (actor.handlesExceptions()) { start = mv.newLabel(); end = mv.newLabel(); handler = mv.newLabel(); handlerEnd = mv.newLabel(); for (Class<? extends Throwable> ec : actor.handledExceptions) mv.visitTryCatchBlock(start, end, handler, Type.getType(ec).getInternalName()); mv.visitLabel(start); } // Load result array and index to store the current result mv.loadLocal(resLocal); mv.push(i); // Load test instance mv.loadThis(); mv.getField(TEST_THREAD_EXECUTION_TYPE, "testInstance", OBJECT_TYPE); mv.checkCast(testType); // Load arguments for operation for (int j = 0; j < actor.arguments.length; j++) { pushArgumentOnStack(mv, objArgs, actor.arguments[j], actor.method.getParameterTypes()[j]); } // Invoke operation Method actorMethod = Method.getMethod(actor.method); mv.invokeVirtual(testType, actorMethod); // Create result mv.box(actorMethod.getReturnType()); // box if needed if (actor.method.getReturnType() == void.class) { mv.pop(); mv.invokeStatic(RESULT_TYPE, RESULT_CREATE_VOID_RESULT); } else { mv.invokeStatic(RESULT_TYPE, RESULT_CREATE_VALUE_RESULT); } // Store result to array mv.arrayStore(RESULT_TYPE); // End of try-catch block if (actor.handlesExceptions()) { mv.visitLabel(end); mv.goTo(handlerEnd); mv.visitLabel(handler); storeExceptionResultFromThrowable(mv, resLocal, iLocal); mv.visitLabel(handlerEnd); } // Increment number of current operation mv.iinc(iLocal, 1); } // Call runner's onFinish(iThread) method mv.loadThis(); mv.getField(TEST_THREAD_EXECUTION_TYPE, "runner", RUNNER_TYPE); mv.push(iThread); mv.invokeVirtual(RUNNER_TYPE, RUNNER_ON_FINISH_METHOD); // Return results mv.loadThis(); mv.loadLocal(resLocal); mv.returnValue(); mv.visitMaxs(1, 1); mv.visitEnd(); }
Example 12
Source File: ExpressionHash.java From datakernel with Apache License 2.0 | 4 votes |
@Override public Type load(Context ctx) { GeneratorAdapter g = ctx.getGeneratorAdapter(); int resultVar = g.newLocal(INT_TYPE); boolean firstIteration = true; for (Expression argument : arguments) { if (firstIteration) { g.push(0); firstIteration = false; } else { g.push(31); g.loadLocal(resultVar); g.math(IMUL, INT_TYPE); } Type fieldType = argument.load(ctx); if (isPrimitiveType(fieldType)) { if (fieldType.getSort() == Type.LONG) { g.dup2(); g.push(32); g.visitInsn(LUSHR); g.visitInsn(LXOR); g.visitInsn(L2I); } if (fieldType.getSort() == Type.FLOAT) { g.invokeStatic(getType(Float.class), getMethod("int floatToRawIntBits (float)")); } if (fieldType.getSort() == Type.DOUBLE) { g.invokeStatic(getType(Double.class), getMethod("long doubleToRawLongBits (double)")); g.dup2(); g.push(32); g.visitInsn(LUSHR); g.visitInsn(LXOR); g.visitInsn(L2I); } g.visitInsn(IADD); } else { int tmpVar = g.newLocal(fieldType); g.storeLocal(tmpVar); g.loadLocal(tmpVar); Label ifNullLabel = g.newLabel(); g.ifNull(ifNullLabel); g.loadLocal(tmpVar); g.invokeVirtual(fieldType, getMethod("int hashCode()")); g.visitInsn(IADD); g.mark(ifNullLabel); } g.storeLocal(resultVar); } if (firstIteration) { g.push(0); } else { g.loadLocal(resultVar); } return INT_TYPE; }
Example 13
Source File: ExpressionComparator.java From datakernel with Apache License 2.0 | 4 votes |
@Override public Type load(Context ctx) { GeneratorAdapter g = ctx.getGeneratorAdapter(); Label labelReturn = new Label(); for (ComparablePair pair : pairs) { Type leftPropertyType = pair.left.load(ctx); Type rightPropertyType = pair.right.load(ctx); checkArgument(leftPropertyType.equals(rightPropertyType), "Types of compared values should match"); if (isPrimitiveType(leftPropertyType)) { g.invokeStatic(wrap(leftPropertyType), new Method("compare", INT_TYPE, new Type[]{leftPropertyType, leftPropertyType})); g.dup(); g.ifZCmp(NE, labelReturn); g.pop(); } else if (!pair.nullable) { g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)})); g.dup(); g.ifZCmp(NE, labelReturn); g.pop(); } else { VarLocal varRight = ctx.newLocal(rightPropertyType); varRight.store(ctx); VarLocal varLeft = ctx.newLocal(leftPropertyType); varLeft.store(ctx); Label continueLabel = new Label(); Label nonNulls = new Label(); Label leftNonNull = new Label(); varLeft.load(ctx); g.ifNonNull(leftNonNull); varRight.load(ctx); g.ifNull(continueLabel); g.push(-1); g.returnValue(); g.mark(leftNonNull); varRight.load(ctx); g.ifNonNull(nonNulls); g.push(1); g.returnValue(); g.mark(nonNulls); varLeft.load(ctx); varRight.load(ctx); g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)})); g.dup(); g.ifZCmp(NE, labelReturn); g.pop(); g.mark(continueLabel); } } g.push(0); g.mark(labelReturn); return INT_TYPE; }
Example 14
Source File: ExpressionToString.java From datakernel with Apache License 2.0 | 4 votes |
@Override public Type load(Context ctx) { GeneratorAdapter g = ctx.getGeneratorAdapter(); g.newInstance(getType(StringBuilder.class)); g.dup(); g.invokeConstructor(getType(StringBuilder.class), getMethod("void <init> ()")); boolean first = true; for (Object key : arguments.keySet()) { String str = first ? begin : separator; first = false; if (key instanceof String) { str += key; } if (!str.isEmpty()) { g.dup(); g.push(str); g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)")); g.pop(); } g.dup(); Expression expression = arguments.get(key); Type type = expression.load(ctx); if (isPrimitiveType(type)) { g.invokeStatic(wrap(type), new Method("toString", getType(String.class), new Type[]{type})); } else { Label nullLabel = new Label(); Label afterToString = new Label(); g.dup(); g.ifNull(nullLabel); g.invokeVirtual(type, getMethod("String toString()")); g.goTo(afterToString); g.mark(nullLabel); g.pop(); g.push("null"); g.mark(afterToString); } g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)")); g.pop(); } if (!end.isEmpty()) { g.dup(); g.push(end); g.invokeVirtual(getType(StringBuilder.class), getMethod("StringBuilder append(String)")); g.pop(); } g.invokeVirtual(getType(StringBuilder.class), getMethod("String toString()")); return getType(String.class); }