Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9 Jigsaw support for javaagent

Is there any plan in Java 9 (specifically Jigsaw) to support the special requirements of Java monitoring agents?

Typically, monitoring agents require the ability to access class, packages, and modules that are not available by default to original Java applications. Monitoring agents loaded into the JVM via the -javaagent command line argument are not loaded as modules, even if the jar file contains a module-info.class file. The only way that I have been able to provide my monitoring agent with the permissions it need is by adding command line arguments which provide these permissions to all unnamed modules.

like image 433
BradW Avatar asked Feb 22 '17 21:02

BradW


1 Answers

The Instrumentation class was extended with a method that allows the redefinition of any module. It allows you to add additional module reads, exports, opens, service usages and providings:

void redefineModule(Module module,
                    Set<Module> extraReads,
                    Map<String,Set<Module>> extraExports,
                    Map<String,Set<Module>> extraOpens,
                    Set<Class<?>> extraUses,
                    Map<Class<?>,List<Class<?>>> extraProvides);

Also, the ClassFileTransformer API was extended to register a Java Module upon a transformation:

default byte[] transform(Module module,
                         ClassLoader loader,
                         String className,
                         Class<?> classBeingRedefined,
                         ProtectionDomain protectionDomain,
                         byte[] classfileBuffer)
                  throws IllegalClassFormatException;

This module, in combination with the instrumentation API allows for any necessary adjustment.

Currently, Java agents are still loaded on the class path without applying any modularization; this can however change as Java 9 is not yet final.

like image 119
Rafael Winterhalter Avatar answered Sep 22 '22 05:09

Rafael Winterhalter