[External] : Re: How to open a package from a module in the boot layer to a module in another layer?
Andrew Dinn
adinn at redhat.com
Tue Jan 14 13:45:28 UTC 2025
On 14/01/2025 13:26, Code Ranger wrote:
> In other words, you’re saying:
>
> --add-opens java.base/java.time=json //this is bad, but the JDK
> supports it because it’s unavoidable.
> bootLayerController.addOpen(baseModule, "java.time", jsonModule) //this
> is bad, the JDK will not support it because it’s bad, very bad,
> unacceptably bad.
>
> But I’m saying that these two solutions are equivalent—at least they
> should be (I haven’t tested it). However, the second solution is more
> flexible, convenient, and even safer. Yes, it is safer. Please, see this
> SO answer that is the most upvoted - https://stackoverflow.com/a/70878195
The two solutions are not and cannot be equivalent in one very
significant aspect. In the first case JDK and JVM knows about the
opening of the module from bootstrap. In the second case they both find
out about it after some amount of running.
This has very significant consequences. If you only have to allow for
the first case then from the get go you can optimize execution on the
basis that private elements of closed modules are guaranteed to remain
private. If you have to allow for the second case then you either have
to avoid such optimizations or make them 'speculative' i.e. implement
them with a bail-out strategy which guarantees at the point where the
module is opened to trap and reset/undo any operations that is in
progress based on the speculation.
n.b. That's why we have a default policy of not allowing agents to be
loaded dynamically (absence of an agent on the command line is not
enough warning to the JDK/JVM).
regards,
Andrew Dinn
-----------
Red Hat Distinguished Engineer
Red Hat UK Ltd
Registered in England and Wales under Company Registration No. 03798903
Directors: Michael Cunningham, Michael ("Mike") O'Neill
More information about the jigsaw-dev
mailing list