Search in sources :

Example 6 with JavaModule

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

the class ModuleSupport method defineAgentModule.

public void defineAgentModule(ClassLoader classLoader, URL[] jarFileList) {
    final JavaModule agentModule = newAgentModule(classLoader, jarFileList);
    prepareAgentModule(classLoader, agentModule);
    // addPermissionToLog4jModule(agentModule);
    addPermissionToLog4j2Module(agentModule);
    addPermissionToGuiceModule(agentModule);
    addPermissionToValueAnnotation(agentModule);
}
Also used : JavaModule(com.navercorp.pinpoint.bootstrap.module.JavaModule)

Example 7 with JavaModule

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

the class ModuleSupport method loadModule.

private JavaModule loadModule(String moduleName) {
    // force base-module loading
    logger.info("loadModule:" + moduleName);
    final Module module = InternalModules.loadModule(moduleName);
    return wrapJavaModule(module);
// final ModuleLayer boot = ModuleLayer.boot();
// Optional<Module> optionalModule = boot.findModule(moduleName);
// if (optionalModule.isPresent()) {
// Module module = optionalModule.get();
// return wrapJavaModule(module);
// }
// throw new ModuleException(moduleName + " not found");
}
Also used : JavaModule(com.navercorp.pinpoint.bootstrap.module.JavaModule)

Example 8 with JavaModule

use of com.navercorp.pinpoint.bootstrap.module.JavaModule 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 9 with JavaModule

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

the class ClassFileTransformerModuleHandler method transform.

@Override
public byte[] transform(Object transformedModuleObject, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    final byte[] transform = delegate.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
    if (transformedModuleObject == null) {
        return transform;
    }
    if (transform != null && transform != classfileBuffer) {
        if (!javaModuleFactory.isNamedModule(transformedModuleObject)) {
            return transform;
        }
        // bootstrap-core permission
        final JavaModule transformedModule = javaModuleFactory.wrapFromModule(transformedModuleObject);
        addModulePermission(transformedModule, className, bootstrapModule);
        if (loader != Object.class.getClassLoader()) {
            // plugin permission
            final Object pluginModuleObject = getPluginModule(loader);
            final JavaModule pluginModule = javaModuleFactory.wrapFromModule(pluginModuleObject);
            addModulePermission(transformedModule, className, pluginModule);
        }
    }
    return transform;
}
Also used : JavaModule(com.navercorp.pinpoint.bootstrap.module.JavaModule)

Aggregations

JavaModule (com.navercorp.pinpoint.bootstrap.module.JavaModule)9 Providers (com.navercorp.pinpoint.bootstrap.module.Providers)1 JvmVersion (com.navercorp.pinpoint.common.util.JvmVersion)1