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