Search in sources :

Example 1 with InstrumentationProxy

use of com.newrelic.agent.InstrumentationProxy in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceImpl method doStart.

@Override
protected void doStart() throws Exception {
    if (!isEnabled()) {
        getLogger().info("The class transformer is disabled.  No classes will be instrumented.");
        return;
    }
    InstrumentationProxy instrProxy = ServiceFactory.getCoreService().getInstrumentation();
    if (instrProxy == null) {
        getLogger().severe("Unable to initialize the class transformer because there is no instrumentation hook");
    } else {
        classTransformer = startClassTransformer(instrProxy);
    }
    queueRetransform();
}
Also used : InstrumentationProxy(com.newrelic.agent.InstrumentationProxy)

Example 2 with InstrumentationProxy

use of com.newrelic.agent.InstrumentationProxy in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceImpl method retransformMatchingClasses.

private void retransformMatchingClasses() {
    Set<ClassMatchVisitorFactory> matchers = retransformClassMatchers.getAndSet(createRetransformClassMatcherList());
    if (!matchers.isEmpty()) {
        InstrumentationProxy instrumentation = ServiceFactory.getCoreService().getInstrumentation();
        retransformMatchingClassesImmediately(instrumentation.getAllLoadedClasses(), matchers);
    }
}
Also used : InstrumentationProxy(com.newrelic.agent.InstrumentationProxy)

Example 3 with InstrumentationProxy

use of com.newrelic.agent.InstrumentationProxy in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceImpl method retransformMatchingClassesImmediately.

@Override
public void retransformMatchingClassesImmediately(Class<?>[] loadedClasses, Collection<ClassMatchVisitorFactory> matchers) {
    InstrumentationProxy instrumentation = ServiceFactory.getCoreService().getInstrumentation();
    InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
    Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(matchers, matcherHelper, loadedClasses);
    if (!classesToRetransform.isEmpty()) {
        try {
            instrumentation.retransformClasses(classesToRetransform.toArray(new Class[0]));
        } catch (UnmodifiableClassException e) {
            logger.log(Level.FINER, "Error retransforming classes: " + classesToRetransform, e);
        }
    }
}
Also used : UnmodifiableClassException(java.lang.instrument.UnmodifiableClassException) InstrumentationProxy(com.newrelic.agent.InstrumentationProxy)

Example 4 with InstrumentationProxy

use of com.newrelic.agent.InstrumentationProxy in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceImpl method doStop.

@Override
protected void doStop() throws Exception {
    executor.shutdown();
    InstrumentationProxy instrProxy = ServiceFactory.getCoreService().getInstrumentation();
    if (instrProxy == null) {
        return;
    }
    for (ClassFileTransformer classFileTransformer : classTransformers) {
        instrProxy.removeTransformer(classFileTransformer);
    }
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) InstrumentationProxy(com.newrelic.agent.InstrumentationProxy)

Example 5 with InstrumentationProxy

use of com.newrelic.agent.InstrumentationProxy in project newrelic-java-agent by newrelic.

the class RetransformPointCutTest method redefinePointCutClass.

@Test
public void redefinePointCutClass() throws Exception {
    InstrumentationProxy ip = ServiceFactory.getCoreService().getInstrumentation();
    System.out.println("Resource: " + ClassLoader.getSystemResource("com/newrelic/api/jruby/DoNothingClassThatExistsForTesting.class"));
    ip.redefineClasses(getClassDefinition(CLASS_LOADED_BEFORE_AGENT));
    Assert.assertTrue(CLASS_LOADED_BEFORE_AGENT.getName() + " should have been redefined.", PointCutClassTransformer.isInstrumented(CLASS_LOADED_BEFORE_AGENT));
    ip.redefineClasses(getClassDefinition(CLASS_LOADED_AFTER_AGENT));
    Assert.assertTrue(CLASS_LOADED_AFTER_AGENT.getName() + " should have been redefined.", PointCutClassTransformer.isInstrumented(CLASS_LOADED_AFTER_AGENT));
}
Also used : InstrumentationProxy(com.newrelic.agent.InstrumentationProxy) Test(org.junit.Test)

Aggregations

InstrumentationProxy (com.newrelic.agent.InstrumentationProxy)8 Test (org.junit.Test)3 MockCoreService (com.newrelic.agent.MockCoreService)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ClassTransformerService (com.newrelic.agent.instrumentation.ClassTransformerService)1 InstrumentationContextManager (com.newrelic.agent.instrumentation.context.InstrumentationContextManager)1 ClassRetransformer (com.newrelic.agent.instrumentation.custom.ClassRetransformer)1 ClassWeaverService (com.newrelic.agent.instrumentation.weaver.ClassWeaverService)1 JmxService (com.newrelic.agent.jmx.JmxService)1 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 UnmodifiableClassException (java.lang.instrument.UnmodifiableClassException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1