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