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:co.paralleluniverse.fibers.instrument.MethodDatabase.java
License:Open Source License
private int isMethodSuspendable0(String className, String methodName, String methodDesc, int opcode) { if (methodName.charAt(0) == '<') return NONSUSPENDABLE; // special methods are never suspendable if (isYieldMethod(className, methodName)) return SUSPENDABLE; ClassEntry entry = getClassEntry(className); if (entry == null) { entry = CLASS_NOT_FOUND;//from w ww.j a va 2 s. c o m if (cl != null) { log(LogLevel.INFO, "Trying to read class: %s", className); CheckInstrumentationVisitor civ = checkClass(className); if (civ == null) log(LogLevel.WARNING, "Class not found: %s", className); else entry = civ.getClassEntry(); } else log(LogLevel.WARNING, "Can't check class: %s", className); recordSuspendableMethods(className, entry); } if (entry == CLASS_NOT_FOUND) { if (isJavaCore(className)) return MAYBE_CORE; // if (JavaAgent.isActive()) // throw new AssertionError(); return UNKNOWN; } SuspendableType susp1 = entry.check(methodName, methodDesc); int suspendable = UNKNOWN; if (susp1 == null) suspendable = UNKNOWN; else if (susp1 == SuspendableType.SUSPENDABLE) suspendable = SUSPENDABLE; else if (susp1 == SuspendableType.SUSPENDABLE_SUPER) suspendable = SUSPENDABLE_ABSTRACT; else if (susp1 == SuspendableType.NON_SUSPENDABLE) suspendable = NONSUSPENDABLE; if (suspendable == UNKNOWN) { if (opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKESPECIAL) { if (entry.getSuperName() != null) suspendable = isMethodSuspendable0(entry.getSuperName(), methodName, methodDesc, opcode); } if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) { // can be INVOKEVIRTUAL on an abstract class implementing the interface for (String iface : entry.getInterfaces()) { int s = isMethodSuspendable0(iface, methodName, methodDesc, opcode); if (s > suspendable) suspendable = s; if (suspendable > MAYBE_CORE) break; } } } return suspendable; }
From source file:co.paralleluniverse.vtime.VirtualTimeClassTransformer.java
License:Open Source License
private ClassVisitor createVisitor(ClassVisitor next) { int api;// w w w.j a va2 s .c o m if (System.getProperty("java.version").startsWith("1.8")) { api = Opcodes.ASM5; } else if (System.getProperty("java.version").startsWith("10")) { api = Opcodes.ASM6; } else { api = Opcodes.ASM7; } return new ClassVisitor(api, next) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) { @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (!captureTimeCall(owner, name, desc)) { super.visitMethodInsn(opcode, owner, name, desc, itf); } } private boolean captureTimeCall(String owner, String name, String desc) { switch (owner) { case "java/lang/Object": if ("wait".equals(name)) { return callClockMethod("Object_wait", instanceToStatic(owner, desc)); } break; case "java/lang/System": switch (name) { case "nanoTime": return callClockMethod("System_nanoTime", desc); case "currentTimeMillis": return callClockMethod("System_currentTimeMillis", desc); } break; case "java/lang/Thread": if ("sleep".equals(name)) { return callClockMethod("Thread_sleep", desc); } break; case "sun/misc/Unsafe": if ("park".equals(name)) { return callClockMethod("Unsafe_park", instanceToStatic(owner, desc)); } break; case "java/lang/management/RuntimeMXBean": if ("getStartTime".equals(name)) { return callClockMethod("RuntimeMXBean_getStartTime", instanceToStatic(owner, desc)); } break; } return false; } private boolean callClockMethod(String name, String desc) { if (includedMethods == null || includedMethods.contains(name)) { super.visitMethodInsn(Opcodes.INVOKESTATIC, CLOCK, name, desc, false); return true; } else { return false; } } private String instanceToStatic(String owner, String desc) { return "(L" + owner + ";" + desc.substring(1); } }; } }; }
From source file:com.alibaba.hotswap.processor.clinit.ClinitVisitor.java
License:Open Source License
/** * Generate <code><clinit></code>, call <code>__$$hotswap_clinit$$__</code> *//*from ww w . j ava 2 s. c o m*/ private void generateClinit() { MethodVisitor clinit = cv.visitMethod(Opcodes.ACC_STATIC, HotswapConstants.CLINIT, "()V", null, null); if (clinit != null) { clinit.visitCode(); clinit.visitMethodInsn(Opcodes.INVOKESTATIC, className, HotswapConstants.HOTSWAP_CLINIT, "()V"); clinit.visitInsn(Opcodes.RETURN); clinit.visitMaxs(0, 0); clinit.visitEnd(); } }
From source file:com.alibaba.hotswap.processor.constructor.modifier.ConstructorInvokeModifier.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.INVOKESPECIAL && name.equals(HotswapConstants.INIT)) { if (HotswapRuntime.hasClassMeta(owner)) { // Try to reload owner. ClassMeta classMeta = HotswapRuntime.getClassMeta(owner); String mk = HotswapMethodUtil.getMethodKey(name, desc); MethodMeta mm = classMeta.initMetas.get(mk); if (mm != null && mm.isAdded()) { Type[] argsType = Type.getArgumentTypes(desc); push(argsType.length);// www. j a v a 2 s.c om newArray(Type.getType(Object.class)); for (int i = argsType.length - 1; i >= 0; i--) { Type type = argsType[i]; swap(); box(type); push(i); swap(); // arrayStore(Type.getType(Object.class)); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "processConstructorArgs", "([Ljava/lang/Object;ILjava/lang/Object;)[Ljava/lang/Object;"); } mv.visitLdcInsn(Opcodes.ACONST_NULL); swap(); mv.visitLdcInsn(mm.getIndex()); swap(); super.visitMethodInsn(opcode, owner, name, HotswapConstants.UNIFORM_CONSTRUCTOR_DESC); return; } } } super.visitMethodInsn(opcode, owner, name, desc); }
From source file:com.alibaba.hotswap.processor.field.access.FieldAccessModifier.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (HotswapRuntime.getClassInitialized(className) && !name.equals(HotswapConstants.STATIC_FIELD_HOLDER) && !name.equals(HotswapConstants.FIELD_HOLDER)) { Queue<String> owners = new LinkedList<String>(); owners.offer(owner);//from w w w .j a va 2 s. c o m String tmpOwner = owners.poll(); while (tmpOwner != null) { if (HotswapRuntime.hasClassMeta(tmpOwner)) { // Try to reload owner. HotswapRuntime.try2Reload(tmpOwner); ClassMeta classMeta = HotswapRuntime.getClassMeta(tmpOwner); String fmKey = HotswapFieldUtil.getFieldKey(name, desc); FieldMeta fm = classMeta.getFieldMeta(fmKey); if (classMeta.isInterface) { if (fm != null && !fm.isDeleted(classMeta.loadedIndex) && (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.GETSTATIC)) { super.visitFieldInsn(opcode, Type.getInternalName(classMeta.vClass), fm.name, fm.desc); return; } } if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey) && !fm.isDeleted(classMeta.loadedIndex)) { break; } else if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey) && fm.isDeleted(classMeta.loadedIndex)) { // If this accessed field is primary and deleted, it perhaps is a alias field fm = classMeta.getFieldMeta(HotswapFieldUtil .getFieldKey(HotswapConstants.PREFIX_FIELD_ALIAS + fm.name, fm.desc)); } if (fm != null && fm.isAdded() && !fm.isDeleted(classMeta.loadedIndex)) { if (opcode == Opcodes.PUTSTATIC) { // put static box(Type.getType(fm.desc)); mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "setFieldValue", "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V"); return; } else if (opcode == Opcodes.GETSTATIC) { // get static mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "getFieldValue", "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); unbox(Type.getType(fm.desc)); return; } else if (opcode == Opcodes.PUTFIELD) { // put field // stack: obj fieldValue box(Type.getType(fm.desc)); mv.visitInsn(Opcodes.SWAP); mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "setFieldValue", "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V"); return; } else if (opcode == Opcodes.GETFIELD) { // get field // stack: obj mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "getFieldValue", "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); Label notnull = newLabel(); Type type = Type.getType(fm.desc); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNONNULL, notnull); Label end = newLabel(); switch (type.getSort()) { case Type.BOOLEAN: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Boolean(false)); break; case Type.CHAR: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Character(' ')); break; case Type.BYTE: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Byte((byte) 0)); break; case Type.SHORT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Short((short) 0)); break; case Type.INT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Integer(0)); break; case Type.FLOAT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Float(0)); break; case Type.LONG: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Long(0)); break; case Type.DOUBLE: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Double(0)); break; default: break; } mv.visitJumpInsn(Opcodes.GOTO, end); mark(notnull); unbox(type); mark(end); return; } } if (classMeta.clazz != null) { Class<?> superClass = classMeta.clazz.getSuperclass(); if (superClass != null) { owners.offer(HotswapUtil.getInternalClassName(superClass.getName())); } Class<?>[] superInterfaces = classMeta.clazz.getInterfaces(); if (superInterfaces != null) { for (Class<?> itf : superInterfaces) { owners.offer(HotswapUtil.getInternalClassName(itf.getName())); } } } } tmpOwner = owners.poll(); } } super.visitFieldInsn(opcode, owner, name, desc); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 1);//from www . j av a 2 s . c o m mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapConfiguration.class), "getClassPathInWorkspace", "(Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(Opcodes.DUP); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, old); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "updateClassMeta", "(Ljava/lang/String;Ljava/lang/ClassLoader;)V"); mv.visitVarInsn(Opcodes.ALOAD, 1); // className mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(CustomerLoadClassBytes.class), "loadBytesFromPath", "(Ljava/lang/String;Ljava/lang/String;)[B"); mv.visitVarInsn(Opcodes.ASTORE, 2);// store class bytes into 2 mv.visitVarInsn(Opcodes.ALOAD, 2);// load class bytes mv.visitInsn(Opcodes.ARRAYLENGTH); // length of the class bytes mv.visitVarInsn(Opcodes.ISTORE, 4);// store length into 4 Label end = new Label(); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(old); mv.visitInsn(Opcodes.POP); mv.visitLabel(end); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java
License:Open Source License
@Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label end = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, end); mv.visitInsn(Opcodes.DUP);/* ww w .j a va 2s .c o m*/ mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "updateClassMetaClass", "(Ljava/lang/String;Ljava/lang/Class;)V"); mv.visitLabel(end); } super.visitInsn(opcode); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.FindClassMethodModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); Label normal = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0);/*from w w w .j a v a 2 s .c o m*/ mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ClassLoaderHelper.class), "tryLoadVClass", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;"); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNULL, normal); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(normal); mv.visitInsn(Opcodes.POP); }
From source file:com.alibaba.hotswap.processor.jdk.lang.modifier.ClassNewInstanceModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0);/*from w ww.jav a 2s.co m*/ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, old); // check it as a primary constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "getClassMeta", "(Ljava/lang/String;)Lcom/alibaba/hotswap/meta/ClassMeta;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitLdcInsn("()V"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ClassMeta.class), "isPrimaryInitMethod", "(Ljava/lang/String;Ljava/lang/String;)Z"); mv.visitJumpInsn(Opcodes.IFNE, old); // get uniform constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getConstructorParamTypes", "()[Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"); // index and objs mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitLdcInsn("()V"); loadArgs(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getMethodParams", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)[Ljava/lang/Object;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(old); }
From source file:com.alibaba.hotswap.processor.jdk.lang.modifier.GetXConstructorsFilterModifier.java
License:Open Source License
@Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MethodReflectHelper.class), "filterHotswapConstructor", "([Ljava/lang/reflect/Constructor;)[Ljava/lang/reflect/Constructor;"); }// w w w . jav a 2 s . c o m super.visitInsn(opcode); }