Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#8890] Implemented findClass in Java9ClassLoader #9897

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ protected URL findResource(String moduleName, String name) throws IOException {
return null;
}

@Override
protected Class<?> findClass(String moduleName, String name) {
if (getName().equals(moduleName)) {
try {
return this.findClass(name);
} catch (ClassNotFoundException e) {
return null;
}
}
return null;
}

@Override
public InputStream getResourceAsStream(String name) {
return super.getResourceAsStream(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@


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;

/**
Expand All @@ -40,15 +37,14 @@ public class ModuleSupport {

private final JavaModule javaBaseModule;
private final JavaModule bootstrapModule;
private final List<String> allowedProviders;

ModuleSupport(Instrumentation instrumentation, List<String> 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();
Expand All @@ -65,8 +61,8 @@ public void setup() {

}

@SuppressWarnings("unused") // Used implicitly
public void defineAgentModule(ClassLoader classLoader, URL[] jarFileList) {

final JavaModule agentModule = newAgentModule(classLoader, jarFileList);

prepareAgentModule(classLoader, agentModule);
Expand All @@ -92,7 +88,7 @@ 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(classLoader.getName(), classLoader, jarFileList);
return wrapJavaModule(agentModule);
}

Expand Down Expand Up @@ -229,32 +225,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<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);
}
}
}

public boolean isAllowedProvider(String serviceName) {
return allowedProviders.contains(serviceName);
}

private List<Class<?>> loadProviderClassList(List<String> classNameList, ClassLoader classLoader) {
List<Class<?>> providerClassList = new ArrayList<>();
for (String providerClassName : classNameList) {
Class<?> providerClass = forName(providerClassName, classLoader);
providerClassList.add(providerClass);
}
return providerClassList;
}

private Class<?> forName(String className, ClassLoader classLoader) {
Expand All @@ -281,7 +251,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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,16 +26,6 @@ public ModuleSupportFactory() {
}

public ModuleSupport newModuleSupport(Instrumentation instrumentation) {
// Dynamic changes are required?
// move to pinpoint.config?
List<String> 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);
}
}