Search in sources :

Example 26 with Instrumentation

use of java.lang.instrument.Instrumentation in project pinpoint by naver.

the class JavassistClassTest method newJavassistEngine.

private InstrumentEngine newJavassistEngine() {
    Instrumentation instrumentation = mock(Instrumentation.class);
    ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
    Provider<ApiMetaDataService> apiMetaDataService = Providers.of(mock(ApiMetaDataService.class));
    return new JavassistEngine(instrumentation, objectBinderFactory, new GlobalInterceptorRegistryBinder(), apiMetaDataService, null);
}
Also used : JavassistEngine(com.navercorp.pinpoint.profiler.instrument.JavassistEngine) Instrumentation(java.lang.instrument.Instrumentation) ObjectBinderFactory(com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) GlobalInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.GlobalInterceptorRegistryBinder)

Example 27 with Instrumentation

use of java.lang.instrument.Instrumentation in project pinpoint by naver.

the class JavassistEngineTest method newJavassistEngine.

private InstrumentEngine newJavassistEngine() {
    Instrumentation instrumentation = mock(Instrumentation.class);
    ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
    Provider<ApiMetaDataService> apiMetaDataService = Providers.of(mock(ApiMetaDataService.class));
    InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
    return new JavassistEngine(instrumentation, objectBinderFactory, binder, apiMetaDataService, null);
}
Also used : TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) Instrumentation(java.lang.instrument.Instrumentation) ObjectBinderFactory(com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)

Example 28 with Instrumentation

use of java.lang.instrument.Instrumentation in project pinpoint by naver.

the class DependencyGraph method newApplicationContext.

private DefaultApplicationContext newApplicationContext() {
    ProfilerConfig profilerConfig = new DefaultProfilerConfig();
    InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
    Instrumentation instrumentation = mock(Instrumentation.class);
    AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgent", "mockApplicationName", profilerConfig, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
    return new DefaultApplicationContext(agentOption, binder);
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultServiceTypeRegistryService(com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService) TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) Instrumentation(java.lang.instrument.Instrumentation) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption) DefaultAnnotationKeyRegistryService(com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService)

Example 29 with Instrumentation

use of java.lang.instrument.Instrumentation in project jdk8u_jdk by JetBrains.

the class PrematureLoadTest method main.

public static void main(String[] args) throws IOException {
    try {
        new BootSupport();
        throw new RuntimeException("Test configuration error - BootSupport loaded unexpectedly!");
    } catch (NoClassDefFoundError x) {
    }
    try {
        new AgentSupport();
        throw new RuntimeException("Test configuration error - AgentSupport loaded unexpectedly!");
    } catch (NoClassDefFoundError x) {
    }
    JarFile bootclasses = new JarFile("BootSupport.jar");
    JarFile agentclasses = new JarFile("AgentSupport.jar");
    Instrumentation ins = Agent.getInstrumentation();
    ins.appendToBootstrapClassLoaderSearch(bootclasses);
    try {
        new BootSupport();
        System.out.println("FAIL: BootSupport resolved");
        failures++;
    } catch (NoClassDefFoundError x) {
        System.out.println("PASS: BootSupport failed to resolve");
    }
    try {
        ins.appendToSystemClassLoaderSearch(agentclasses);
        try {
            new AgentSupport();
            System.out.println("FAIL: AgentSupport resolved");
            failures++;
        } catch (NoClassDefFoundError x) {
            System.out.println("PASS: AgentSupport failed to resolve");
        }
    } catch (UnsupportedOperationException x) {
        System.out.println("System class loader does not support adding to class path");
    }
    if (failures > 0) {
        throw new RuntimeException(failures + " test(s) failed.");
    }
}
Also used : Instrumentation(java.lang.instrument.Instrumentation) JarFile(java.util.jar.JarFile)

Example 30 with Instrumentation

use of java.lang.instrument.Instrumentation in project tomee by apache.

the class UnenhancedTest method runTest.

private void runTest(final String methodName, final PersistenceUnitTransactionType transactionType, final boolean enhance) throws Exception {
    this.enhance = enhance;
    final ClassLoader loader = new FilteredChildFirstClassLoader(getClass().getClassLoader(), "org.apache.openejb.core.cmp.jpa");
    final PersistenceClassLoaderHandler persistenceClassLoaderHandler = new PersistenceClassLoaderHandler() {

        public void addTransformer(final String unitId, final ClassLoader classLoader, final ClassFileTransformer classFileTransformer) {
            final Instrumentation instrumentation = Agent.getInstrumentation();
            if (instrumentation != null) {
                instrumentation.addTransformer(new ControllableTransformer(classFileTransformer));
            }
        }

        public void destroy(final String unitId) {
        }

        public ClassLoader getNewTempClassLoader(final ClassLoader classLoader) {
            return new TempClassLoader(classLoader);
        }
    };
    final PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
    unitInfo.setPersistenceUnitName("CMP");
    unitInfo.setPersistenceProviderClassName(PERSISTENCE_PROVIDER);
    unitInfo.setClassLoader(loader);
    unitInfo.setExcludeUnlistedClasses(false);
    unitInfo.setJtaDataSource(jtaDs);
    unitInfo.setNonJtaDataSource(nonJtaDs);
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSuperclass");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSubclass");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexStandalone");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedStandalone");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSuperclass");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSubclass");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.OneStandalone");
    unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ManyStandalone");
    // Handle Properties
    final Properties properties = new Properties();
    properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys=true)");
    properties.setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    properties.setProperty("openjpa.Log", "DefaultLevel=INFO");
    unitInfo.setProperties(properties);
    unitInfo.setTransactionType(transactionType);
    unitInfo.getManagedClassNames().add("org.apache.openejb.core.cmp.jpa.Employee");
    final PersistenceProvider persistenceProvider = (PersistenceProvider) getClass().getClassLoader().loadClass(PERSISTENCE_PROVIDER).newInstance();
    entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap());
    // create the test object (via reflection)
    final Object testObject = loader.loadClass("org.apache.openejb.core.cmp.jpa.UnenhancedUnits").newInstance();
    set(testObject, "TransactionManager", TransactionManager.class, transactionManager);
    set(testObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
    // invoke the test (via reflection)
    Thread.currentThread().setContextClassLoader(loader);
    invoke(testObject, "setUp");
    try {
        invoke(testObject, methodName);
    } finally {
        invoke(testObject, "tearDown");
    }
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) TempClassLoader(org.apache.openejb.core.TempClassLoader) PersistenceUnitInfoImpl(org.apache.openejb.persistence.PersistenceUnitInfoImpl) HashMap(java.util.HashMap) PersistenceProvider(javax.persistence.spi.PersistenceProvider) Instrumentation(java.lang.instrument.Instrumentation) Properties(java.util.Properties) PersistenceClassLoaderHandler(org.apache.openejb.persistence.PersistenceClassLoaderHandler) URLClassLoader(java.net.URLClassLoader) TempClassLoader(org.apache.openejb.core.TempClassLoader)

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