Search in sources :

Example 1 with ASMClassNodeAdapter

use of com.navercorp.pinpoint.profiler.instrument.ASMClassNodeAdapter in project pinpoint by naver.

the class MethodInterfaceTest method addField.

@Test(expected = ClassFormatError.class)
public void addField() throws Exception {
    final String targetInterfaceName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterface";
    final String targetClassName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterfaceClass";
    final String accessorClassName = "com.navercorp.test.pinpoint.jdk8.interfaces.SimpleAccessor";
    TestClassLoader classLoader = new TestClassLoader();
    classLoader.addTargetClassName(targetClassName);
    classLoader.addTargetClassName(targetInterfaceName);
    classLoader.setTrace(false);
    classLoader.setCallbackHandler(new CallbackHandler() {

        @Override
        public void handle(ClassNode classNode) {
            logger.debug("Add field class={}", classNode.name);
            ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginContext, null, null, classNode);
            classNodeAdapter.addField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), Type.getDescriptor(int.class));
            classNodeAdapter.addInterface(accessorClassName);
            ASMFieldNodeAdapter fieldNodeAdapter = classNodeAdapter.getField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), null);
            classNodeAdapter.addGetterMethod("_$PINPOINT$_getTraceInt", fieldNodeAdapter);
            classNodeAdapter.addSetterMethod("_$PINPOINT$_setTraceInt", fieldNodeAdapter);
        }
    });
    logger.debug("Interface static method");
    Class<?> clazz = classLoader.loadClass(targetInterfaceName);
    Method method = clazz.getDeclaredMethod("currentTimeMillis");
    method.invoke(null);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ASMClassNodeAdapter(com.navercorp.pinpoint.profiler.instrument.ASMClassNodeAdapter) Method(java.lang.reflect.Method) ASMFieldNodeAdapter(com.navercorp.pinpoint.profiler.instrument.ASMFieldNodeAdapter) Test(org.junit.Test)

Example 2 with ASMClassNodeAdapter

use of com.navercorp.pinpoint.profiler.instrument.ASMClassNodeAdapter in project pinpoint by naver.

the class MethodInterfaceTest method addMethod.

@Test
public void addMethod() throws Exception {
    final MethodNode methodNode = TestClassLoader.get("com.navercorp.test.pinpoint.jdk8.interfaces.SimpleClass", "welcome");
    final ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter("com/navercorp/test/pinpoint/jdk8/interfaces/SimpleClass", methodNode);
    final String targetInterfaceName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterface";
    TestClassLoader classLoader = new TestClassLoader();
    classLoader.addTargetClassName(targetInterfaceName);
    classLoader.setTrace(false);
    classLoader.setCallbackHandler(new CallbackHandler() {

        @Override
        public void handle(ClassNode classNode) {
            logger.debug("Add method class={}", classNode.name);
            ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginContext, null, null, classNode);
            classNodeAdapter.copyMethod(methodNodeAdapter);
        }
    });
    logger.debug("Interface static method");
    Class<?> clazz = classLoader.loadClass(targetInterfaceName);
    Method method = clazz.getDeclaredMethod("welcome");
    method.invoke(null);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ASMMethodNodeAdapter(com.navercorp.pinpoint.profiler.instrument.ASMMethodNodeAdapter) MethodNode(org.objectweb.asm.tree.MethodNode) ASMClassNodeAdapter(com.navercorp.pinpoint.profiler.instrument.ASMClassNodeAdapter) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

ASMClassNodeAdapter (com.navercorp.pinpoint.profiler.instrument.ASMClassNodeAdapter)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 ASMFieldNodeAdapter (com.navercorp.pinpoint.profiler.instrument.ASMFieldNodeAdapter)1 ASMMethodNodeAdapter (com.navercorp.pinpoint.profiler.instrument.ASMMethodNodeAdapter)1 MethodNode (org.objectweb.asm.tree.MethodNode)1