Impossibility for invoking Module::addReads(Module)

Alan Bateman Alan.Bateman at oracle.com
Thu Jun 2 12:29:05 UTC 2016


On 02/06/2016 13:05, Rafael Winterhalter wrote:

> When instrumenting code, typically one adds calls of foreign methods to the
> instrumented class. For example, a Java agent might want to inject
> additional logging by adding log calls to code of the instrumented class.
> Wth Jigsaw, these log classes must also be read by the instrumented code's
> module.
>
> For adapting Jigsaw, I need the hypothetical log framework to be read from
> the instrumented class's module. However, calling addReads is impossible as
> the method is caller sensitive. Currently I found two operating work
> arounds but I think Java should offer a clean solutuion:
>
> 1. I avoid the check by calling implAddReads(Module, boolean) via
> reflection. This is guarded by a security manager but at least possible if
> the security manager is not set or if it allows that call.
>
> 2. I add a static initializer to the instrumented class from where I add
> the read edge to the added code. As I am now within a class of the module,
> this goes without a problem.
>
> Maybe the caller-sensitive methods should rather be checked by a security
> manager to allow such manipulations?
>
I don't know if the context here is JVM TI or java agents but the 
following links should help:

http://download.java.net/java/jdk9/docs/platform/jvmti/jvmti.html#bcimodules
http://download.java.net/java/jdk9/docs/technotes/guides/jni/spec/functions.html#module_operations

and the "Instrumenting code in modules" section in:

http://download.java.net/java/jdk9/docs/api/java/lang/instrument/package-summary.html

Your #2 is good to explore. As I've mentioned in several other threads, 
this is a possible way forward for some of the scenarios that have come 
up in other threads. it may be that we have to improve support for 
injecting new classes into existing modules. It's already possible with 
low-level JVM TI/JNI of course, also possible in some cases with java 
agents but not cases are possible yet without using Unsafe.

-Alan



More information about the jigsaw-dev mailing list