Search in sources :

Example 1 with MatchableClassFileTransformer

use of com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer in project pinpoint by naver.

the class DefaultTranslator method customTransformer.

private byte[] customTransformer(String jvmClassName) {
    logger.info("Modify find classname:{}, loader:{}", jvmClassName, loader);
    MatchableClassFileTransformer transformer = transformerMap.get(jvmClassName);
    if (transformer == null) {
        return null;
    }
    logger.info("Modify jvmClassName:{},  modifier{}, loader:{}", jvmClassName, transformer, loader);
    final Thread thread = Thread.currentThread();
    final ClassLoader beforeClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(loader);
    try {
        String javaClassName = JavaAssistUtils.jvmNameToJavaName(jvmClassName);
        byte[] transformBytes = transformer.transform(loader, javaClassName, null, null, null);
        return transformBytes;
    } catch (IllegalClassFormatException e) {
        throw new RuntimeException(jvmClassName + " transform fail", e);
    } finally {
        thread.setContextClassLoader(beforeClassLoader);
    }
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) IllegalClassFormatException(java.lang.instrument.IllegalClassFormatException)

Example 2 with MatchableClassFileTransformer

use of com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer in project pinpoint by naver.

the class JavassistTranslator method addTransformer0.

private void addTransformer0(MatchableClassFileTransformer transformer, String className) {
    final String checkClassInternalName = JavaAssistUtils.javaNameToJvmName(className);
    MatchableClassFileTransformer old = transformerMap.put(checkClassInternalName, transformer);
    if (old != null) {
        throw new IllegalStateException("Modifier already exist new:" + transformer.getClass() + " old:" + old.getMatcher());
    }
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer)

Example 3 with MatchableClassFileTransformer

use of com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer in project pinpoint by naver.

the class JavassistTranslator method customTransformer.

private byte[] customTransformer(ClassPool pool, String jvmClassName) {
    logger.info("Modify find classname:{}, loader:{}", jvmClassName, loader);
    MatchableClassFileTransformer transformer = transformerMap.get(jvmClassName);
    if (transformer == null) {
        return null;
    }
    logger.info("Modify jvmClassName:{},  modifier{}, loader:{}", jvmClassName, transformer, loader);
    final Thread thread = Thread.currentThread();
    final ClassLoader beforeClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(loader);
    try {
        String javaClassName = JavaAssistUtils.jvmNameToJavaName(jvmClassName);
        byte[] transformBytes = transformer.transform(loader, javaClassName, null, null, null);
        makeClass(pool, transformBytes, jvmClassName);
        return transformBytes;
    } catch (IllegalClassFormatException e) {
        throw new RuntimeException(jvmClassName + " transform fail", e);
    } finally {
        thread.setContextClassLoader(beforeClassLoader);
    }
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) IllegalClassFormatException(java.lang.instrument.IllegalClassFormatException)

Example 4 with MatchableClassFileTransformer

use of com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer in project pinpoint by naver.

the class DefaultTranslator method addTransformer0.

private void addTransformer0(MatchableClassFileTransformer transformer, String className) {
    final String checkClassInternalName = JavaAssistUtils.javaNameToJvmName(className);
    MatchableClassFileTransformer old = transformerMap.put(checkClassInternalName, transformer);
    if (old != null) {
        throw new IllegalStateException("Modifier already exist new:" + transformer.getClass() + " old:" + old.getMatcher());
    }
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer)

Example 5 with MatchableClassFileTransformer

use of com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer in project pinpoint by naver.

the class DefaultClassFileTransformerDispatcher method createTransformerRegistry.

private TransformerRegistry createTransformerRegistry(PluginContextLoadResult pluginContexts) {
    DefaultTransformerRegistry registry = new DefaultTransformerRegistry();
    for (ClassFileTransformer transformer : pluginContexts.getClassFileTransformer()) {
        if (transformer instanceof MatchableClassFileTransformer) {
            MatchableClassFileTransformer t = (MatchableClassFileTransformer) transformer;
            logger.info("Registering class file transformer {} for {} ", t, t.getMatcher());
            registry.addTransformer(t.getMatcher(), t);
        } else {
            logger.warn("Ignore class file transformer {}", transformer);
        }
    }
    return registry;
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) DefaultTransformerRegistry(com.navercorp.pinpoint.profiler.instrument.transformer.DefaultTransformerRegistry)

Aggregations

MatchableClassFileTransformer (com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer)5 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)2 DefaultTransformerRegistry (com.navercorp.pinpoint.profiler.instrument.transformer.DefaultTransformerRegistry)1 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1