Search in sources :

Example 11 with Instrumentation

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);
}
Also used : Instrumentation(java.lang.instrument.Instrumentation) Test(org.junit.Test)

Example 12 with 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.");
    }
}
Also used : Instrumentation(java.lang.instrument.Instrumentation) JarFile(java.util.jar.JarFile)

Example 13 with Instrumentation

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));
}
Also used : Field(java.lang.reflect.Field) Instrumentation(java.lang.instrument.Instrumentation) Test(org.junit.Test)

Example 14 with 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();
}
Also used : Instrumentation(java.lang.instrument.Instrumentation)

Example 15 with Instrumentation

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);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) Instrumentation(java.lang.instrument.Instrumentation) Test(org.junit.Test)

Aggregations

Instrumentation (java.lang.instrument.Instrumentation)31 Test (org.junit.Test)21 TypeDescription (net.bytebuddy.description.type.TypeDescription)8 DynamicType (net.bytebuddy.dynamic.DynamicType)8 JavaModule (net.bytebuddy.utility.JavaModule)6 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)4 InterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder)3 TestInterceptorRegistryBinder (com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder)3 ByteBuddy (net.bytebuddy.ByteBuddy)3 AgentOption (com.navercorp.pinpoint.bootstrap.AgentOption)2 DefaultAgentOption (com.navercorp.pinpoint.bootstrap.DefaultAgentOption)2 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)2 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 DefaultAnnotationKeyRegistryService (com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService)2 DefaultServiceTypeRegistryService (com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService)2 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)2 ObjectBinderFactory (com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory)2 Properties (java.util.Properties)2 Callable (java.util.concurrent.Callable)2 JarFile (java.util.jar.JarFile)2