use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.
the class ClassReloadingStrategyTest method testResetEmptyNoEffectImplicitLocator.
@Test
public void testResetEmptyNoEffectImplicitLocator() throws Exception {
Instrumentation instrumentation = mock(Instrumentation.class);
when(instrumentation.isRedefineClassesSupported()).thenReturn(true);
ClassReloadingStrategy.of(instrumentation).reset();
verify(instrumentation, times(2)).isRedefineClassesSupported();
verifyNoMoreInteractions(instrumentation);
}
use of java.lang.instrument.Instrumentation in project jdk8u_jdk by JetBrains.
the class BasicTest method main.
public static void main(String[] args) throws IOException {
JarFile bootclasses = new JarFile("BootSupport.jar");
JarFile agentclasses = new JarFile("AgentSupport.jar");
Instrumentation ins = Agent.getInstrumentation();
// Test 1: Add BootSupport.jar to boot class path and check that
// BootSupport is loaded by the bootstrap class loader
ins.appendToBootstrapClassLoaderSearch(bootclasses);
checkLoadedByLoader("BootSupport", null);
// AgentSupport is loaded by the system class loader.
try {
ins.appendToSystemClassLoaderSearch(agentclasses);
checkLoadedByLoader("AgentSupport", ClassLoader.getSystemClassLoader());
} catch (UnsupportedOperationException x) {
System.out.println("System class loader does not support adding to class path");
}
// throw exception if a test failed
if (failures > 0) {
throw new RuntimeException(failures + " test(s) failed.");
}
}
use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.
the class ByteBuddyAgentTest method testInstrumentationExtraction.
@Test
public void testInstrumentationExtraction() throws Exception {
Field field = Installer.class.getDeclaredField(INSTRUMENTATION);
field.setAccessible(true);
Instrumentation instrumentation = mock(Instrumentation.class);
field.set(STATIC_FIELD, instrumentation);
assertThat(ByteBuddyAgent.getInstrumentation(), is(instrumentation));
}
use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.
the class ByteBuddyAgent method install.
/**
* Installs a Java agent using the Java attach API. This API is available under different
* access routes for different JVMs and JVM versions or it might not be available at all.
* If a Java agent cannot be installed by using the supplied attachment provider and process
* provider, an {@link IllegalStateException} is thrown.
*
* @param attachmentProvider The attachment provider to use for the installation.
* @param processProvider The provider for the current JVM's process id.
* @return An instrumentation instance representing the currently running JVM.
*/
public static synchronized Instrumentation install(AttachmentProvider attachmentProvider, ProcessProvider processProvider) {
Instrumentation instrumentation = doGetInstrumentation();
if (instrumentation != null) {
return instrumentation;
}
install(attachmentProvider, processProvider.resolve(), WITHOUT_ARGUMENT, AgentProvider.ForByteBuddyAgent.INSTANCE);
return doGetInstrumentation();
}
use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.
the class ClassReloadingStrategyTest method testResetEmptyNoEffect.
@Test
public void testResetEmptyNoEffect() throws Exception {
Instrumentation instrumentation = mock(Instrumentation.class);
ClassFileLocator classFileLocator = mock(ClassFileLocator.class);
when(instrumentation.isRedefineClassesSupported()).thenReturn(true);
ClassReloadingStrategy.of(instrumentation).reset(classFileLocator);
verify(instrumentation, times(2)).isRedefineClassesSupported();
verifyNoMoreInteractions(instrumentation);
verifyZeroInteractions(classFileLocator);
}
Aggregations