diff --git a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoader.java b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoader.java index d18aa7e2d1ac..0a87ba9c76e4 100644 --- a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoader.java +++ b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoader.java @@ -38,6 +38,8 @@ public class Java9ClassLoader extends URLClassLoader { private final ClassLoader parent; private final ProfilerLibClass profilerLibClass; + private volatile String moduleName = null; + public Java9ClassLoader(String name, URL[] urls, ClassLoader parent, List libClass) { super(name, urls, parent); this.parent = parent; @@ -55,6 +57,18 @@ protected URL findResource(String moduleName, String name) throws IOException { return null; } + @Override + protected Class findClass(String moduleName, String name) { + if (this.moduleName != null || this.moduleName.equals(moduleName)) { + try { + return this.findClass(name); + } catch (ClassNotFoundException e) { + return null; + } + } + return null; + } + @Override public InputStream getResourceAsStream(String name) { return super.getResourceAsStream(name); @@ -125,6 +139,10 @@ private boolean onLoadClass(String name) { return profilerLibClass.onLoadClass(name); } + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + @Override public String toString() { return "Java9ClassLoader{" + diff --git a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java index 6eefd77b3809..351e17e4dbd9 100644 --- a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java +++ b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java @@ -17,15 +17,13 @@ package com.navercorp.pinpoint.bootstrap.java9.module; +import com.navercorp.pinpoint.bootstrap.java9.classloader.Java9ClassLoader; import com.navercorp.pinpoint.bootstrap.module.JavaModule; -import com.navercorp.pinpoint.bootstrap.module.Providers; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.common.util.JvmVersion; import java.lang.instrument.Instrumentation; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; /** @@ -34,21 +32,22 @@ */ public class ModuleSupport { + private static final String JAVA9_PINPOINT_AGENT_MODULE_NAME = "pinpoint.agent"; + private final Instrumentation instrumentation; private final ModuleLogger logger = ModuleLogger.getLogger(this.getClass().getName()); private final JavaModule javaBaseModule; private final JavaModule bootstrapModule; - private final List allowedProviders; - ModuleSupport(Instrumentation instrumentation, List allowedProviders) { + ModuleSupport(Instrumentation instrumentation) { this.instrumentation = Objects.requireNonNull(instrumentation, "instrumentation"); - this.allowedProviders = Objects.requireNonNull(allowedProviders, "allowedProviders"); this.javaBaseModule = wrapJavaModule(Object.class); this.bootstrapModule = wrapJavaModule(this.getClass()); } + @SuppressWarnings("unused") // Used implicitly public void setup() { // pinpoint module name : unnamed JavaModule bootstrapModule = getBootstrapModule(); @@ -65,8 +64,8 @@ public void setup() { } + @SuppressWarnings("unused") // Used implicitly public void defineAgentModule(ClassLoader classLoader, URL[] jarFileList) { - final JavaModule agentModule = newAgentModule(classLoader, jarFileList); prepareAgentModule(classLoader, agentModule); @@ -92,7 +91,12 @@ private void addPermissionToValueAnnotation(JavaModule agentModule) { private JavaModule newAgentModule(ClassLoader classLoader, URL[] jarFileList) { ModuleBuilder moduleBuilder = new ModuleBuilder(); - final Module agentModule = moduleBuilder.defineModule("pinpoint.agent", classLoader, jarFileList); + final Module agentModule = moduleBuilder.defineModule(JAVA9_PINPOINT_AGENT_MODULE_NAME, classLoader, jarFileList); + + if (classLoader instanceof Java9ClassLoader) { + ((Java9ClassLoader) classLoader).setModuleName(JAVA9_PINPOINT_AGENT_MODULE_NAME); + } + return wrapJavaModule(agentModule); } @@ -229,32 +233,6 @@ private void prepareAgentModule(final ClassLoader classLoader, JavaModule agentM final String watchEventServiceName = "org.apache.logging.log4j.core.util.WatchEventService"; Class watchEventServiceClazz = forName(watchEventServiceName, classLoader); agentModule.addUses(watchEventServiceClazz); - - List 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> providerClassList = loadProviderClassList(providers.getProviders(), classLoader); - agentModule.addProvides(serviceClass, providerClassList); - } else { - logger.info("discard provider:" + providers); - } - } - } - - public boolean isAllowedProvider(String serviceName) { - return allowedProviders.contains(serviceName); - } - - private List> loadProviderClassList(List classNameList, ClassLoader classLoader) { - List> providerClassList = new ArrayList<>(); - for (String providerClassName : classNameList) { - Class providerClass = forName(providerClassName, classLoader); - providerClassList.add(providerClass); - } - return providerClassList; } private Class forName(String className, ClassLoader classLoader) { @@ -281,7 +259,7 @@ private JavaModule loadModule(String moduleName) { // throw new ModuleException(moduleName + " not found"); } - private JavaModule wrapJavaModule(Class clazz) { + private JavaModule wrapJavaModule(Class clazz) { return new Java9Module(instrumentation, clazz.getModule()); } diff --git a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupportFactory.java b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupportFactory.java index cd31f5b64581..50a99d4b5a2d 100644 --- a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupportFactory.java +++ b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupportFactory.java @@ -17,8 +17,6 @@ package com.navercorp.pinpoint.bootstrap.java9.module; import java.lang.instrument.Instrumentation; -import java.util.Arrays; -import java.util.List; /** * @author Woonduk Kang(emeroad) @@ -28,16 +26,6 @@ public ModuleSupportFactory() { } public ModuleSupport newModuleSupport(Instrumentation instrumentation) { - // Dynamic changes are required? - // move to pinpoint.config? - List allowedProviders = Arrays.asList( - "io.grpc.NameResolverProvider", - "com.navercorp.pinpoint.agent.plugin.proxy.common.ProxyRequestMetadataProvider", - "com.navercorp.pinpoint.profiler.context.recorder.proxy.ProxyRequestParserProvider", - "io.grpc.ManagedChannelProvider", - "io.grpc.LoadBalancerProvider" - ); - - return new ModuleSupport(instrumentation, allowedProviders); + return new ModuleSupport(instrumentation); } }