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);
}
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);
}
Aggregations