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();
}
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);
}
}
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);
}
}
}
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);
}
}
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));
}
Aggregations