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:dimmunix.InstrumentationMethodAdapter.java
License:Open Source License
public void visitInsn(int opcode) { mv.visitInsn(opcode);//from w w w .j av a2 s . c o m if (opcode == Opcodes.MONITORENTER) { Vector<Pair<Integer, Integer>> sigsToSkipAfter = DimmunixDeadlock.instance .getIdsSignaturesToSkip(className, methodName, this.curLine, false); for (Pair<Integer, Integer> sig : sigsToSkipAfter) { mv.visitLdcInsn(sig.v1); mv.visitLdcInsn(sig.v2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "dimmunix/deadlock/DimmunixDeadlock", "skipAvoidance", "(II)V"); } } }
From source file:dimmunix.InstrumentationMethodAdapter.java
License:Open Source License
public void visitMethodInsn(int opcode, String owner, String name, String desc) { if (DimmunixDeadlock.instance.inlineMatching) { //code to match sigs inline for (Signature sig : DimmunixDeadlock.instance.history.historyQueue) { for (int i = 0; i < sig.size(); i++) { CallStack stack = sig.positions.get(i).value.callStack; for (int d = stack.size() - 1; d >= 0; d--) { MatchPosition mpos = new MatchPosition(className, methodName, curLine, sig.id, i, d + 1); if (!this.inlineCallStackMatchingPositions.contains(mpos) && this.matchFrame(className, methodName, curLine, stack.get(d))) { mv.visitLdcInsn((Integer) sig.id); mv.visitLdcInsn((Integer) i); mv.visitLdcInsn((Integer) (d + 1)); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "dimmunix/deadlock/DimmunixDeadlock", "match", "(III)V"); this.inlineCallStackMatchingPositions.add(mpos); // System.out.println("method "+ className+ ":"+ curLine+ " index "+ i+ " sigId "+ sig.id+ " depth "+ d); }//from w w w. j a v a 2 s . c o m } } } } if (DimmunixCondVar.instance.inlineMatching) { for (int i = 0; i < ExecutionPositions.instance.getPositions().size(); i++) { StackTraceElement p = ExecutionPositions.instance.getPositions().get(i); if (!this.matchedExecutionPositions.contains(i) && this.matchFrame(className, methodName, curLine, p)) { mv.visitLdcInsn((Integer) i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "org/aspectj/weaver/loadtime/ExecutionPositions", "matchPosition", "(I)V"); this.matchedExecutionPositions.add(i); } } } mv.visitMethodInsn(opcode, owner, name, desc); }
From source file:dodola.anole.lib.IncrementalChangeVisitor.java
License:Apache License
/** * To each class, add the dispatch method called by the original code that acts as a trampoline to * invoke the changed methods./* w ww . j ava 2 s . c o m*/ * <p/> * Pseudo code: * <code> * Object access$dispatch(String name, object[] args) { * if (name.equals( * "firstMethod.(L$type;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;")) { * return firstMethod(($type)arg[0], (String)arg[1], arg[2]); * } * if (name.equals("secondMethod.(L$type;Ljava/lang/String;I;)V")) { * secondMethod(($type)arg[0], (String)arg[1], (int)arg[2]); * return; * } * ... * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " + visitedClassName + * "$dispatch implementation, restart the application"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void addDispatchMethod() { int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_VARARGS; Method m = new Method("access$dispatch", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); if (TRACING_ENABLED) { mv.push("Redirecting "); mv.loadArg(0); trace(mv, 2); } List<MethodNode> allMethods = new ArrayList<MethodNode>(); // if we are disabled, do not generate any dispatch, the method will throw an exception // if invoked which should never happen. if (!instantRunDisabled) { //noinspection unchecked allMethods.addAll(classNode.methods); allMethods.addAll(addedMethods); } final Map<String, MethodNode> methods = new HashMap<String, MethodNode>(); for (MethodNode methodNode : allMethods) { if (methodNode.name.equals("<clinit>") || methodNode.name.equals("<init>")) { continue; } if (!isAccessCompatibleWithInstantRun(methodNode.access)) { continue; } methods.put(methodNode.name + "." + methodNode.desc, methodNode); } new StringSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitCase(String methodName) { MethodNode methodNode = methods.get(methodName); String name = methodNode.name; boolean isStatic = (methodNode.access & Opcodes.ACC_STATIC) != 0; String newDesc = computeOverrideMethodDesc(methodNode.desc, isStatic); if (TRACING_ENABLED) { trace(mv, "M: " + name + " P:" + newDesc); } Type[] args = Type.getArgumentTypes(newDesc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } mv.visitMethodInsn(Opcodes.INVOKESTATIC, visitedClassName + "$override", isStatic ? computeOverrideMethodName(name, methodNode.desc) : name, newDesc, false); Type ret = Type.getReturnType(methodNode.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, methods.keySet()); mv.visitMaxs(0, 0); mv.visitEnd(); super.visitEnd(); }
From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java
License:BSD License
@Override public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc, final boolean itf) { for (final Type _type : Type.getArgumentTypes(desc)) { this.stackFrame.pop(); if (_type.getSize() == 2) this.stackFrame.pop(); }//from www . j a v a2 s. c om boolean _flag = false; switch (opcode) { case Opcodes.INVOKESTATIC: break; case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKEVIRTUAL: this.stackFrame.pop(); // objectref break; case Opcodes.INVOKESPECIAL: _flag = this.stackFrame.pop() == THIS && !this.thisIsInitialized; // objectref break; } /* * FIXME-1 * * After bug #8172282 (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8172282) in JDK is fixed, * delete lines with DELETE-ME-1 markers to ensure the call to super constructor is covered by the exception * handler. */ if (_flag) { this.thisIsInitialized = true; ((TracingMethodVisitor) this.mv).setThisInitialized(); ((TracingMethodVisitor) this.mv).endOutermostExceptionHandler(); // DELETE-ME-1 } super.visitMethodInsn(opcode, owner, name, desc, itf); if (_flag) { // DELETE-ME-1 ((TracingMethodVisitor) this.mv).beginOutermostExceptionHandler(); // DELETE-ME-1 } // DELETE-ME-1 final Type _returnType = Type.getReturnType(desc); if (_returnType != Type.VOID_TYPE) { this.stackFrame.push(OTHER); if (_returnType.getSize() == 2) this.stackFrame.push(OTHER); } }
From source file:dyco4j.instrumentation.LoggingHelper.java
License:BSD License
public static void emitConvertToString(final MethodVisitor mv, final Type type) { switch (type.getSort()) { case Type.ARRAY: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(Ljava/lang/Object;)Ljava/lang/String;" + "", false); break;/* w w w . ja va 2 s. c om*/ case Type.BOOLEAN: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(Z)Ljava/lang/String;", false); break; case Type.BYTE: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(B)Ljava/lang/String;", false); break; case Type.CHAR: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(C)Ljava/lang/String;", false); break; case Type.DOUBLE: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(D)Ljava/lang/String;", false); break; case Type.FLOAT: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(F)Ljava/lang/String;", false); break; case Type.INT: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(I)Ljava/lang/String;", false); break; case Type.LONG: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(J)Ljava/lang/String;", false); break; case Type.SHORT: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(S)Ljava/lang/String;", false); break; case Type.OBJECT: mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, "toString", "(Ljava/lang/Object;)Ljava/lang/String;" + "", false); break; default: throw new RuntimeException("Unknown type" + type.getInternalName()); } }
From source file:dyco4j.instrumentation.LoggingHelper.java
License:BSD License
static void emitInsnToLoadAndInitializeLogger(final MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER_INITIALIZER, LOGGER_INITIALIZER_INITIALIZE.getName(), LOGGER_INITIALIZER_INITIALIZE.getDescriptor(), false); }
From source file:dyco4j.instrumentation.LoggingHelper.java
License:BSD License
private static void emitInvokeLog(final MethodVisitor mv, final Method method) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER, method.getName(), method.getDescriptor(), false); }
From source file:dyco4j.LoggingHelper.java
License:BSD License
public static void emitInsnToLoadAndInitializeLogger(final MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER_INITIALIZER, LOGGER_INITIALIZER_INITIALIZE.getName(), LOGGER_INITIALIZER_INITIALIZE.getDescriptor(), false); }
From source file:edu.illinois.nondex.instr.ClassVisitorShufflingAdder.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { final String methodId = this.cn + "." + name; if (apisReturningShufflableArrays.contains(methodId)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override// w w w. j av a 2 s . c o m public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN && "java/text/DateFormatSymbols.getZoneStrings".equals(methodId)) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "extendZoneStrings", "([[Ljava/lang/String;)[[Ljava/lang/String;", false); } else if (opcode == Opcodes.ARETURN) { shuffleJustReturnedArray(); } super.visitInsn(opcode); } private void shuffleJustReturnedArray() { this.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); } }; } else { return super.visitMethod(access, name, desc, signature, exceptions); } }
From source file:edu.illinois.nondex.instr.ConcurrentHashMapShufflingAdder.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if ("<init>".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override/*from w w w . j a v a2 s .com*/ public void visitInsn(int opcode) { if (opcode == Opcodes.RETURN) { mv.visitVarInsn(Opcodes.ALOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "copyOf", "([Ljava/lang/Object;I)[Ljava/lang/Object;", false); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/util/concurrent/ConcurrentHashMap$Node;"); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/concurrent/ConcurrentHashMap$Traverser", "tab", "[Ljava/util/concurrent/ConcurrentHashMap$Node;"); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_FULL, 5, new Object[] { "java/util/concurrent/ConcurrentHashMap$Traverser", "[Ljava/util/concurrent/ConcurrentHashMap$Node;", Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER }, 0, new Object[] {}); mv.visitInsn(Opcodes.RETURN); } super.visitInsn(opcode); } }; } return super.visitMethod(access, name, desc, signature, exceptions); }