Search in sources :

Example 1 with NamedClassPool

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

the class JavassistEngine method getContextClassPool.

private ClassPool getContextClassPool(InstrumentContext instrumentContext, NamedClassPool parent, String jvmInternalClassName, byte[] classfileBuffer) throws NotFoundException {
    final ClassPool contextCassPool = new ClassPool(parent);
    contextCassPool.childFirstLookup = true;
    final String javaName = JavaAssistUtils.jvmNameToJavaName(jvmInternalClassName);
    if (isDebug) {
        logger.debug("getContextClassPool() className={}", javaName);
    }
    final ClassPath byteArrayClassPath = new ByteArrayClassPath(javaName, classfileBuffer);
    contextCassPool.insertClassPath(byteArrayClassPath);
    // plugin class not found in jboss classLoader
    if (instrumentContext instanceof PluginInstrumentContext) {
        final PluginConfig pluginConfig = ((PluginInstrumentContext) instrumentContext).getPluginConfig();
        if (pluginConfig != null) {
            String jarPath = pluginConfig.getPluginJar().getPath();
            contextCassPool.appendClassPath(jarPath);
        }
    }
    return contextCassPool;
}
Also used : PluginConfig(com.navercorp.pinpoint.profiler.plugin.PluginConfig) PluginInstrumentContext(com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext) NamedClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool) IsolateMultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.IsolateMultipleClassPool) MultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.MultipleClassPool)

Example 2 with NamedClassPool

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

the class HierarchyMultipleClassPoolTest method testTestClass.

@Test
public void testTestClass() throws Exception {
    NamedClassPool pool = new NamedClassPool("test");
    pool.childFirstLookup = true;
    HierarchyMultipleClassPool multipleClassPool = new HierarchyMultipleClassPool(pool);
    ClassLoader classLoader = new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
    multipleClassPool.getClassPool(classLoader);
    logger.debug("size {}", multipleClassPool.size());
    for (NamedClassPool classPool1 : multipleClassPool.values()) {
        logger.debug("classPool:{} name:{}", classPool1, classPool1.getName());
    }
    Assert.assertEquals(2, multipleClassPool.size());
}
Also used : URLClassLoader(java.net.URLClassLoader) NamedClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool) HierarchyMultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.HierarchyMultipleClassPool) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 3 with NamedClassPool

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

the class IsolateMultipleClassPoolTest method testPoolSize.

@Test
public void testPoolSize() throws Exception {
    IsolateMultipleClassPool pool = new IsolateMultipleClassPool();
    NamedClassPool systemPool = pool.getClassPool(systemClassLoader);
    Assert.assertEquals(0, pool.size());
    pool.getClassPool(null);
    Assert.assertEquals(0, pool.size());
    Assert.assertSame(systemPool, pool.getClassPool(systemClassLoader));
    NamedClassPool child1Pool = pool.getClassPool(child1);
    Assert.assertEquals(1, pool.size());
    NamedClassPool child1Pool_recheck = pool.getClassPool(child1);
    Assert.assertEquals(1, pool.size());
    Assert.assertSame(child1Pool, child1Pool_recheck);
    Assert.assertNotSame(systemPool, child1Pool);
    NamedClassPool classPool2 = pool.getClassPool(child2);
    Assert.assertEquals(2, pool.size());
    pool.getClassPool(child2);
    Assert.assertEquals(2, pool.size());
    Assert.assertNotSame(systemPool, classPool2);
}
Also used : IsolateMultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.IsolateMultipleClassPool) NamedClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool) Test(org.junit.Test)

Example 4 with NamedClassPool

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

the class IsolateMultipleClassPoolTest method testGetClass_childLookupFirst.

@Test
public void testGetClass_childLookupFirst() throws Exception {
    IsolateMultipleClassPool pool = new IsolateMultipleClassPool(false, IsolateMultipleClassPool.EMPTY_EVENT_LISTENER, null);
    NamedClassPool systemPool = pool.getClassPool(systemClassLoader);
    CtClass systemLogger = systemPool.get(TEST_CLASS);
    NamedClassPool rootPool = pool.getClassPool(root);
    CtClass rootLogger = rootPool.get(TEST_CLASS);
    Assert.assertSame(systemLogger, rootLogger);
    NamedClassPool childPool = pool.getClassPool(child1);
    CtClass childLogger = childPool.get(TEST_CLASS);
    Assert.assertSame(systemLogger, childLogger);
    NamedClassPool childPool2 = pool.getClassPool(child2);
    CtClass child2Logger = childPool2.get(TEST_CLASS);
    Assert.assertSame(systemLogger, child2Logger);
}
Also used : CtClass(javassist.CtClass) IsolateMultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.IsolateMultipleClassPool) NamedClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool) Test(org.junit.Test)

Example 5 with NamedClassPool

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

the class IsolateMultipleClassPoolTest method testGetClass.

@Test
public void testGetClass() throws Exception {
    IsolateMultipleClassPool pool = new IsolateMultipleClassPool();
    NamedClassPool systemPool = pool.getClassPool(systemClassLoader);
    String classname = "java.lang.String";
    CtClass systemString = systemPool.get(classname);
    NamedClassPool childPool = pool.getClassPool(child1);
    CtClass childPoolString = childPool.get("java.lang.String");
    Assert.assertNotSame(systemString, childPoolString);
    Assert.assertNotSame(systemString.getClassPool(), childPoolString.getClassPool());
    CtClass testClass = childPool.get(this.getClass().getName());
    Assert.assertNotSame(systemString.getClassPool(), testClass.getClassPool());
    NamedClassPool childPool2 = pool.getClassPool(child2);
    CtClass testClass2 = childPool2.get(this.getClass().getName());
    Assert.assertNotSame(systemString.getClassPool(), testClass2.getClassPool());
    CtClass testCtClass = childPool2.get(TEST_CLASS);
    logger.debug("className:{}", Arrays.toString(testCtClass.getConstructors()));
}
Also used : CtClass(javassist.CtClass) IsolateMultipleClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.IsolateMultipleClassPool) NamedClassPool(com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool) Test(org.junit.Test)

Aggregations

NamedClassPool (com.navercorp.pinpoint.profiler.instrument.classpool.NamedClassPool)6 Test (org.junit.Test)5 IsolateMultipleClassPool (com.navercorp.pinpoint.profiler.instrument.classpool.IsolateMultipleClassPool)4 CtClass (javassist.CtClass)3 HierarchyMultipleClassPool (com.navercorp.pinpoint.profiler.instrument.classpool.HierarchyMultipleClassPool)2 URLClassLoader (java.net.URLClassLoader)2 MultipleClassPool (com.navercorp.pinpoint.profiler.instrument.classpool.MultipleClassPool)1 PluginConfig (com.navercorp.pinpoint.profiler.plugin.PluginConfig)1 PluginInstrumentContext (com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext)1