Search in sources :

Example 41 with ClassFileTransformer

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<ClassFileTransformer>();
    for (SetupResult pluginContext : getProfilerPluginContextList()) {
        List<ClassFileTransformer> classFileTransformer = pluginContext.getClassTransformerList();
        classFileTransformerList.addAll(classFileTransformer);
    }
    return classFileTransformerList;
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) SetupResult(com.navercorp.pinpoint.profiler.plugin.SetupResult) ArrayList(java.util.ArrayList)

Example 42 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer 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)

Example 43 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.

the class DefaultTransformerRegistry method addModifier0.

private void addModifier0(ClassFileTransformer transformer, String className) {
    final String classInternalName = JavaAssistUtils.javaNameToJvmName(className);
    ClassFileTransformer old = registry.put(classInternalName, transformer);
    if (old != null) {
        throw new IllegalStateException("Transformer already exist. className:" + classInternalName + " new:" + transformer.getClass() + " old:" + old.getClass());
    }
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer)

Example 44 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project intellij-community by JetBrains.

the class ResetAgent method premain.

public static void premain(String options, Instrumentation inst) {
    // Handle duplicate agents
    if (initialized) {
        return;
    }
    initialized = true;
    inst.addTransformer(new ClassFileTransformer() {

        public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
            if (classBeingRedefined != null) {
                try {
                    Field callSiteArrayField = classBeingRedefined.getDeclaredField("$callSiteArray");
                    callSiteArrayField.setAccessible(true);
                    callSiteArrayField.set(null, null);
                } catch (Throwable ignored) {
                }
            }
            return removeTimestampField(classfileBuffer);
        }
    });
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Field(java.lang.reflect.Field) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) IllegalClassFormatException(java.lang.instrument.IllegalClassFormatException) String(java.lang.String)

Example 45 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project byte-buddy by raphw.

the class AgentBuilderDefaultApplicationRedefineTest method testRedefinitionOptionalType.

@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
@IntegrationRule.Enforce
public void testRedefinitionOptionalType() throws Exception {
    // A redefinition reflects on loaded types which are eagerly validated types (Java 7- for redefinition).
    // This causes type equality for outer/inner classes to fail which is why an external class is used.
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    // ensure that class is loaded
    assertThat(optionalTypeLoader.loadClass(SimpleOptionalType.class.getName()).getName(), is(SimpleOptionalType.class.getName()));
    ClassFileTransformer classFileTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED)).ignore(none()).disableClassFormatChanges().with(AgentBuilder.RedefinitionStrategy.REDEFINITION).with(descriptionStrategy).type(ElementMatchers.is(SimpleOptionalType.class), ElementMatchers.is(optionalTypeLoader)).transform(new FooTransformer()).installOnByteBuddyAgent();
    try {
        Class<?> type = optionalTypeLoader.loadClass(SimpleOptionalType.class.getName());
        // The hybrid strategy cannot transform optional types.
        assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) BAR));
    } finally {
        ByteBuddyAgent.getInstrumentation().removeTransformer(classFileTransformer);
    }
}
Also used : SimpleOptionalType(net.bytebuddy.test.packaging.SimpleOptionalType) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) Instrumentation(java.lang.instrument.Instrumentation) ByteBuddy(net.bytebuddy.ByteBuddy) Test(org.junit.Test)

Aggregations

ClassFileTransformer (java.lang.instrument.ClassFileTransformer)56 Test (org.junit.Test)38 Instrumentation (java.lang.instrument.Instrumentation)35 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)9 ByteArrayClassLoader (net.bytebuddy.dynamic.loading.ByteArrayClassLoader)9 Callable (java.util.concurrent.Callable)7 ProtectionDomain (java.security.ProtectionDomain)6 SimpleType (net.bytebuddy.test.packaging.SimpleType)6 ByteBuddy (net.bytebuddy.ByteBuddy)5 URLClassLoader (java.net.URLClassLoader)3 MatchableClassFileTransformer (com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 TypeDescription (net.bytebuddy.description.type.TypeDescription)2 SimpleOptionalType (net.bytebuddy.test.packaging.SimpleOptionalType)2 TempClassLoader (org.apache.openejb.core.TempClassLoader)2 PersistenceClassLoaderHandler (org.apache.openejb.persistence.PersistenceClassLoaderHandler)2 PersistenceUnitInfoImpl (org.apache.openejb.persistence.PersistenceUnitInfoImpl)2