Search in sources :

Example 1 with Providers

use of com.navercorp.pinpoint.bootstrap.module.Providers in project pinpoint by naver.

the class Java9Module method getProviders.

@Override
public List<Providers> getProviders() {
    List<Providers> result = new ArrayList<>();
    Set<ModuleDescriptor.Provides> providesSet = this.module.getDescriptor().provides();
    for (ModuleDescriptor.Provides provides : providesSet) {
        String service = provides.service();
        List<String> providers = provides.providers();
        Providers newProviders = new Providers(service, providers);
        result.add(newProviders);
    }
    return result;
}
Also used : ModuleDescriptor(java.lang.module.ModuleDescriptor) ArrayList(java.util.ArrayList) Providers(com.navercorp.pinpoint.bootstrap.module.Providers)

Example 2 with Providers

use of com.navercorp.pinpoint.bootstrap.module.Providers in project pinpoint by naver.

the class ModuleSupport method prepareAgentModule.

private void prepareAgentModule(final ClassLoader classLoader, JavaModule agentModule) {
    JavaModule bootstrapModule = getBootstrapModule();
    // Error:class com.navercorp.pinpoint.bootstrap.AgentBootLoader$1 cannot access class com.navercorp.pinpoint.profiler.DefaultAgent (in module pinpoint.agent)
    // because module pinpoint.agent does not export com.navercorp.pinpoint.profiler to unnamed module @7bfcd12c
    agentModule.addExports("com.navercorp.pinpoint.profiler", bootstrapModule);
    // Error:class com.navercorp.pinpoint.bootstrap.AgentBootLoader$1 cannot access class com.navercorp.pinpoint.test.PluginTestAgent (in module pinpoint.agent)
    // because module pinpoint.agent does not export com.navercorp.pinpoint.test to unnamed module @4b9e13df
    final String pinpointTestModule = "com.navercorp.pinpoint.test";
    if (agentModule.getPackages().contains(pinpointTestModule)) {
        agentModule.addExports(pinpointTestModule, bootstrapModule);
    } else {
        logger.info(pinpointTestModule + " package not found");
    }
    agentModule.addReads(bootstrapModule);
    // Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.net.URLClassLoader.addURL(java.net.URL) accessible:
    // module java.base does not "opens java.net" to module pinpoint.agent
    // at pinpoint.agent/pinpoint.agent/com.navercorp.pinpoint.profiler.instrument.classloading.URLClassLoaderHandler.<clinit>(URLClassLoaderHandler.java:44)
    JavaModule baseModule = getJavaBaseModule();
    baseModule.addOpens("java.net", agentModule);
    // java.lang.reflect.InaccessibleObjectException: Unable to make private java.nio.DirectByteBuffer(long,int) accessible: module java.base does not "opens java.nio" to module pinpoint.agent
    // at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:337)
    baseModule.addOpens("java.nio", agentModule);
    // for Java9DefineClass
    baseModule.addExports("jdk.internal.misc", agentModule);
    final JvmVersion version = JvmUtils.getVersion();
    if (version.onOrAfter(JvmVersion.JAVA_11)) {
        final String internalAccessModule = "jdk.internal.access";
        if (baseModule.getPackages().contains(internalAccessModule)) {
            baseModule.addExports(internalAccessModule, agentModule);
        } else {
            logger.info(internalAccessModule + " package not found");
        }
    }
    agentModule.addReads(baseModule);
    final JavaModule instrumentModule = loadModule("java.instrument");
    agentModule.addReads(instrumentModule);
    final JavaModule managementModule = loadModule("java.management");
    agentModule.addReads(managementModule);
    // DefaultCpuLoadMetric : com.sun.management.OperatingSystemMXBean
    final JavaModule jdkManagement = loadModule("jdk.management");
    agentModule.addReads(jdkManagement);
    // for grpc's NameResolverProvider
    final JavaModule jdkUnsupported = loadModule("jdk.unsupported");
    agentModule.addReads(jdkUnsupported);
    // LongAdder
    // final Module unsupportedModule = loadModule("jdk.unsupported");
    // Set<Module> readModules = Set.of(instrumentModule, managementModule, jdkManagement, unsupportedModule);
    ClassLoader bootstrapClassLoader = Object.class.getClassLoader();
    Class<?> traceMataDataClass = forName("com.navercorp.pinpoint.common.trace.TraceMetadataProvider", bootstrapClassLoader);
    agentModule.addUses(traceMataDataClass);
    Class<?> pluginClazz = forName("com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin", bootstrapClassLoader);
    agentModule.addUses(pluginClazz);
    final String serviceClassName = "com.navercorp.pinpoint.profiler.context.recorder.proxy.ProxyRequestParserProvider";
    Class<?> serviceClazz = forName(serviceClassName, classLoader);
    agentModule.addUses(serviceClazz);
    final String nameResolverProviderName = "io.grpc.NameResolverProvider";
    Class<?> nameResolverProviderClazz = forName(nameResolverProviderName, classLoader);
    agentModule.addUses(nameResolverProviderClazz);
    final String loadBalancerProviderName = "io.grpc.LoadBalancerProvider";
    Class<?> loadBalancerProviderClazz = forName(loadBalancerProviderName, classLoader);
    agentModule.addUses(loadBalancerProviderClazz);
    List<Providers> providersList = agentModule.getProviders();
    for (Providers providers : providersList) {
        final String service = providers.getService();
        if (isAllowedProvider(service)) {
            logger.info("load provider:" + providers);
            Class<?> serviceClass = forName(providers.getService(), classLoader);
            List<Class<?>> providerClassList = loadProviderClassList(providers.getProviders(), classLoader);
            agentModule.addProvides(serviceClass, providerClassList);
        } else {
            logger.info("discard provider:" + providers);
        }
    }
}
Also used : JvmVersion(com.navercorp.pinpoint.common.util.JvmVersion) Providers(com.navercorp.pinpoint.bootstrap.module.Providers) JavaModule(com.navercorp.pinpoint.bootstrap.module.JavaModule)

Example 3 with Providers

use of com.navercorp.pinpoint.bootstrap.module.Providers in project pinpoint by naver.

the class JarFileAnalyzerTest method providers.

@Test
public void providers() throws IOException {
    // Jar
    URL url = CodeSourceUtils.getCodeLocation(com.mysql.jdbc.Driver.class);
    JarFile jarFile = new JarFile(url.getFile());
    PackageAnalyzer analyzer = new JarFileAnalyzer(jarFile);
    PackageInfo analyze = analyzer.analyze();
    List<Providers> providers = analyze.getProviders();
    Providers first = providers.get(0);
    Assert.assertEquals(first.getService(), "java.sql.Driver");
    Assert.assertTrue(first.getProviders().contains("com.mysql.cj.jdbc.Driver"));
}
Also used : JarFile(java.util.jar.JarFile) Providers(com.navercorp.pinpoint.bootstrap.module.Providers) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Providers

use of com.navercorp.pinpoint.bootstrap.module.Providers in project pinpoint by naver.

the class JarFileAnalyzer method analyze.

@Override
public PackageInfo analyze() {
    Set<String> packageSet = new HashSet<>();
    List<Providers> providesList = new ArrayList<>();
    final Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        final JarEntry jarEntry = entries.nextElement();
        final String packageName = this.filter.filter(jarEntry);
        if (packageName != null) {
            packageSet.add(packageName);
        }
        final Providers provides = this.serviceLoaderEntryFilter.filter(jarEntry);
        if (provides != null) {
            providesList.add(provides);
        }
    }
    return new PackageInfo(packageSet, providesList);
}
Also used : ArrayList(java.util.ArrayList) Providers(com.navercorp.pinpoint.bootstrap.module.Providers) JarEntry(java.util.jar.JarEntry) HashSet(java.util.HashSet)

Example 5 with Providers

use of com.navercorp.pinpoint.bootstrap.module.Providers in project pinpoint by naver.

the class ModuleBuilder method mergeServiceInfo.

private Map<String, Set<String>> mergeServiceInfo(List<PackageInfo> packageInfos) {
    Map<String, Set<String>> providesMap = new HashMap<>();
    for (PackageInfo packageInfo : packageInfos) {
        List<Providers> serviceLoader = packageInfo.getProviders();
        for (Providers provides : serviceLoader) {
            Set<String> providerSet = providesMap.computeIfAbsent(provides.getService(), s -> new HashSet<>());
            providerSet.addAll(provides.getProviders());
        }
    }
    return providesMap;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Providers(com.navercorp.pinpoint.bootstrap.module.Providers)

Aggregations

Providers (com.navercorp.pinpoint.bootstrap.module.Providers)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 JavaModule (com.navercorp.pinpoint.bootstrap.module.JavaModule)1 JvmVersion (com.navercorp.pinpoint.common.util.JvmVersion)1 ModuleDescriptor (java.lang.module.ModuleDescriptor)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Test (org.junit.Test)1