use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.
the class MockPluginContextLoadResult method getClassFileTransformer.
@Override
public List<ClassFileTransformer> getClassFileTransformer() {
List<ClassFileTransformer> classFileTransformerList = new ArrayList<>();
PluginsSetupResult pluginsSetupResult = getPluginsSetupResult();
for (PluginSetupResult pluginContext : pluginsSetupResult.getPluginSetupResults()) {
List<ClassFileTransformer> classFileTransformer = pluginContext.getClassTransformerList();
classFileTransformerList.addAll(classFileTransformer);
}
return classFileTransformerList;
}
use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.
the class MockApplicationContextModuleTest method testMockApplicationContext.
@Test
public void testMockApplicationContext() {
ProfilerConfig profilerConfig = spy(new DefaultProfilerConfig());
when(profilerConfig.getStaticResourceCleanup()).thenReturn(true);
Instrumentation instrumentation = Mockito.mock(Instrumentation.class);
AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgentId", "mockAgentName", "mockApplicationName", false, profilerConfig, Collections.<String>emptyList(), Collections.<String>emptyList());
Module pluginModule = new PluginApplicationContextModule();
InterceptorRegistryBinder interceptorRegistryBinder = new TestInterceptorRegistryBinder();
Module testInterceptorRegistryModule = InterceptorRegistryModule.wrap(interceptorRegistryBinder);
ModuleFactory moduleFactory = new OverrideModuleFactory(pluginModule, testInterceptorRegistryModule);
DefaultApplicationContext applicationContext = new DefaultApplicationContext(agentOption, moduleFactory);
Injector injector = applicationContext.getInjector();
// singleton check
AgentInfoSender instance1 = injector.getInstance(AgentInfoSender.class);
AgentInfoSender instance2 = injector.getInstance(AgentInfoSender.class);
Assert.assertSame(instance1, instance2);
ClassFileTransformer instance4 = injector.getInstance(ClassFileTransformer.class);
applicationContext.close();
}
use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.
the class DefaultTransformerRegistry method addModifier0.
private void addModifier0(Map<String, ClassFileTransformer> registry, ClassFileTransformer transformer, String className) {
final String classInternalName = JavaAssistUtils.javaNameToJvmName(className);
final ClassFileTransformer old = registry.put(classInternalName, transformer);
if (old != null) {
throw new IllegalStateException("Transformer already exist. className:" + classInternalName + " new:" + transformer.getClass() + " old:" + old.getClass());
}
}
use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.
the class LambdaTransformBootloader method retransform.
private void retransform(Instrumentation instrumentation) {
final String lambdaMetaFactoryName = "java.lang.invoke.InnerClassLambdaMetafactory";
try {
final Class<?> lamdbaFactoryClazz = Class.forName(lambdaMetaFactoryName, false, null);
logger.info("retransformClasses:{}", lamdbaFactoryClazz);
final ClassFileTransformer classFileTransfomrer = new InnerClassLambdaMetafactoryTransformer();
instrumentation.addTransformer(classFileTransfomrer, true);
try {
instrumentation.retransformClasses(lamdbaFactoryClazz);
} finally {
instrumentation.removeTransformer(classFileTransfomrer);
}
} catch (Exception e) {
logger.warn("retransform fail class:{}", lambdaMetaFactoryName, e);
}
}
use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.
the class DynamicTransformServiceTest method testRetransform_Fail_memoryleak_prevent.
@Test()
public void testRetransform_Fail_memoryleak_prevent() throws Exception {
final Instrumentation instrumentation = mock(Instrumentation.class);
when(instrumentation.isModifiableClass(any(Class.class))).thenReturn(true);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
throw new UnmodifiableClassException();
}
}).when(instrumentation).retransformClasses(any(Class.class));
DefaultDynamicTransformerRegistry listener = new DefaultDynamicTransformerRegistry();
final ClassFileTransformer classFileTransformer = mock(ClassFileTransformer.class);
DynamicTransformService dynamicTransformService = new DynamicTransformService(instrumentation, listener);
try {
dynamicTransformService.retransform(String.class, classFileTransformer);
Assert.fail("expected retransform fail");
} catch (Exception e) {
}
Assert.assertEquals(listener.size(), 0);
}
Aggregations