use of com.navercorp.pinpoint.common.util.JvmVersion 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.common.util.JvmVersion in project pinpoint by naver.
the class CounterFactory method buildFactory.
private static ObjectFactory<Counter> buildFactory() {
JvmVersion version = JvmUtils.getVersion();
if (version.onOrAfter(JvmVersion.JAVA_8)) {
String counterName = "com.navercorp.pinpoint.profiler.util.Java8CounterFactory";
try {
Class<ObjectFactory<Counter>> counterClazz = (Class<ObjectFactory<Counter>>) Class.forName(counterName, false, CounterFactory.class.getClassLoader());
Constructor<ObjectFactory<Counter>> constructor = counterClazz.getDeclaredConstructor();
return constructor.newInstance();
} catch (Exception e) {
logger.warn("{} not found", counterName, e);
}
}
return new Java6CounterFactory();
}
use of com.navercorp.pinpoint.common.util.JvmVersion in project pinpoint by naver.
the class DefineClassFactory method newDefineClass.
private static DefineClass newDefineClass() {
final JvmVersion version = JvmUtils.getVersion();
if (version.onOrAfter(JvmVersion.JAVA_9)) {
final ClassLoader agentClassLoader = DefineClassFactory.class.getClassLoader();
final String name = "com.navercorp.pinpoint.profiler.instrument.classloading.Java9DefineClass";
try {
Class<DefineClass> defineClassClazz = (Class<DefineClass>) agentClassLoader.loadClass(name);
Constructor<DefineClass> constructor = defineClassClazz.getDeclaredConstructor();
return constructor.newInstance();
} catch (Exception e) {
throw new IllegalStateException(name + " create fail Caused by:" + e.getMessage(), e);
}
}
return new ReflectionDefineClass();
}
use of com.navercorp.pinpoint.common.util.JvmVersion in project pinpoint by naver.
the class BufferMetricProvider method get.
@Override
public BufferMetric get() {
final JvmVersion jvmVersion = JvmUtils.getVersion();
if (!jvmVersion.onOrAfter(JvmVersion.JAVA_7)) {
logger.debug("Unsupported JVM version. {}", jvmVersion);
return BufferMetric.UNSUPPORTED_BUFFER_METRIC;
}
BufferMetric bufferMetric = createBufferMetric(BUFFER_METRIC);
logger.info("loaded : {}", bufferMetric);
return bufferMetric;
}
use of com.navercorp.pinpoint.common.util.JvmVersion in project pinpoint by naver.
the class FileDescriptorMetricProvider method get.
@Override
public FileDescriptorMetric get() {
final JvmVersion jvmVersion = JvmUtils.getVersion();
final JvmType jvmType = getJvmType();
final OsType osType = getOsType();
final String classToLoad = getMetricClassName(osType, jvmVersion, jvmType);
FileDescriptorMetric fileDescriptorMetric = createFileDescriptorMetric(classToLoad);
logger.info("loaded : {}", fileDescriptorMetric);
return fileDescriptorMetric;
}
Aggregations