Example usage for org.objectweb.asm Opcodes ASM6

List of usage examples for org.objectweb.asm Opcodes ASM6

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ASM6.

Prototype

int ASM6

To view the source code for org.objectweb.asm Opcodes ASM6.

Click Source Link

Usage

From source file:co.paralleluniverse.vtime.VirtualTimeClassTransformer.java

License:Open Source License

private ClassVisitor createVisitor(ClassVisitor next) {
    int api;/*from w  ww.j  a  va  2s .c om*/
    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.dragovorn.dragonbot.api.bot.plugin.PluginAnnotationVisitor.java

License:Open Source License

PluginAnnotationVisitor(PluginInfo.Builder builder) {
    super(Opcodes.ASM6);
    this.builder = builder;
}

From source file:com.dragovorn.dragonbot.api.bot.plugin.PluginClassVisitor.java

License:Open Source License

PluginClassVisitor(PluginInfo.Builder builder, String path) {
    super(Opcodes.ASM6);
    this.builder = builder;
    this.path = path;
}

From source file:com.facebook.buck.jvm.java.abi.SourceAbiCompatibleSignatureVisitor.java

License:Apache License

public SourceAbiCompatibleSignatureVisitor(SignatureVisitor sv) {
    super(Opcodes.ASM6, sv);
}

From source file:com.github.nfalco79.junit4osgi.registry.internal.asm.BundleTestClassVisitor.java

License:Apache License

public BundleTestClassVisitor(Bundle bundle) {
    super(Opcodes.ASM6);
    this.bundle = bundle;

    // cache is for bundle, if bundle is stopped and started, byte code could be changed
    cache = new HashSet<String>();
    cache.add("junit/framework/TestCase");
    cache.add("junit/framework/TestSuite");
    cache.add("junit/framework/Test");
}

From source file:com.github.veithen.cosmos.osgi.runtime.MemberInjector.java

License:Apache License

MemberInjector(ClassVisitor cv, ClassNode classNode) {
    super(Opcodes.ASM6, cv);
    this.classNode = classNode;
}

From source file:com.github.veithen.cosmos.osgi.runtime.RelocatingClassVisitor.java

License:Apache License

RelocatingClassVisitor(ClassVisitor cv, String from, String to) {
    super(Opcodes.ASM6, cv);
    this.from = from;
    this.to = to;
}

From source file:com.github.veithen.cosmos.osgi.runtime.RelocatingMethodVisitor.java

License:Apache License

RelocatingMethodVisitor(MethodVisitor mv, String from, String to) {
    super(Opcodes.ASM6, mv);
    this.from = from;
    this.to = to;
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

License:Open Source License

public BytecodeTypeInference(int access, String owner, String name, String methodDescriptor) {
    super(Opcodes.ASM6);
    localVariableSlots = createInitialLocalVariableTypes(access, owner, name, methodDescriptor);
    previousFrame = FrameInfo.create(ImmutableList.copyOf(localVariableSlots), ImmutableList.of());
    this.methodSignature = owner + "." + name + methodDescriptor;
}

From source file:com.google.devtools.build.android.desugar.CloseResourceMethodScanner.java

License:Open Source License

public CloseResourceMethodScanner() {
    super(Opcodes.ASM6);
}