Sharing experiences with the latest EA build // #ReflectiveAccessToNonExportedTypes #ResourceEncapsulation
adinn at redhat.com
Fri Sep 30 14:17:41 UTC 2016
On 30/09/16 14:42, Alan Bateman wrote:
>> I currently experiment with a Java agent to force Java 9 to adopt this
>> desired behavior by manipulating the boot layer's module graph or by
>> stubbing AccessibleObject::checkCanSetAccessible.
> That sounds like a gross hack, something that could break at any time.
I believe that's the frist gross hack I came up with some moths back. As
Alan pointed out then this only works contingent on the current
implementation staying the way it is. I foudn a coupl eof slightly less
gross hacks but only found a reliable, simple solution following a
change to the Instrumentation API made a couple of months ago. You might
want to look at that which I did in the context of the Byteman code base.
The proper solution  is for agent to use the addExports capability of
Instrumentation. The agent creates a module and associated class that is
under the agent's sole control and has the ability to enable access for
specific Members without opening up an opportunity for app code to do
the same. My solution was used as a proof of concept to show that the
fix for Jigsaw issue #ReflectiveAccessByInstrumentationAgents was adequate.
n.b. I am just about to release a new version of this fix which profits
from the use of multi-release jar to bundle the necessary functionality
in with the agent and also provides a cleaner API. The key piece of
Jigsaw-specific code in my solution is also available in its own jar so
that it can be bundled into other agents. The use of a multi-release jar
allows the bulk of the agent code to remain at level JDK6 with one
variant class controlling whether access is managed using JDK9 ore
pre-JDK9 capabilities. This latest version has not yet been released
because it only works with the current jake tree. Unfoirtunately,
jigsaw-9ea-b136 does not yet contain a critical fix for a bug in
multi-rlelease jar processing. Once that is fixed I intend to publish
the code as part of Byteman release 4.0.0-BETA.
Senior Principal Software Engineer
Red Hat UK Ltd
Registered in England and Wales under Company Registration No. 03798903
Directors: Michael Cunningham, Michael ("Mike") O'Neill, Eric Shander
More information about the jigsaw-dev