Search in sources :

Example 1 with ASMFieldNodeAdapter

use of com.navercorp.pinpoint.profiler.instrument.ASMFieldNodeAdapter 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)

Aggregations

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