Is it possible to add JRE and JDK modules in child layers?

Alan Bateman Alan.Bateman at oracle.com
Thu Jan 18 09:04:54 UTC 2024


On 17/01/2024 17:22, PavelTurk wrote:
> Hello all.
>
> We use JPMS for our framework where we have the following layers:
>
> 1) boot layer: framework + JRE/JDK modules (to add them we use 
> --add-modules ALL-DEFAULT)
> 2) child layers [with child layers..] where every child layer is 
> dynamically added component.
>
> As I understand Layrry framework does the same.  I asked several days 
> ago about practical use
> of JPMS layers and got only one response about Layrry. So, I can 
> conclude that layers are used
> primarily for creating dynamic substems, plugins, components, 
> extensions etc.
>
> However, we couldn't find a way to add JRE and JDK modules in child 
> layers. Because of this we
> have to add all default modules to boot layer what is a very very 
> serious flaw.
>
> Why do we need it? As components are created dynamically when/if they 
> are required we don't
> know what JRE/JDK modules will be required we create boot layer. 
> That's why add all of them to
> boot layer.
>
> Could anyone say if it is possible to add JRE/JDK modules to child 
> layers? Is there any way to do it?
> Are there any plans to add such possibility?

This is the topic that was on the original requirements wish list as 
"Run-time augmentation of the platform modules". There isn't any general 
support for this in the JDK. One reason is that module layers, and in 
this case the boot layer, are immutable. Another reason is that 
integrity of the platform requires that classes in the java.* packages 
be defined to the boot or platform class loaders. In other words, you 
can't have child layers containing modules with java.* classes that are 
mapped to custom class loaders.

That said, there are two things to be aware of:

1. ALL-DEFAULT. You've already found that. As explained in JEP 261, this 
is there to support cases where a container module is in the boot layer 
but it does dynamic configuration with modules that require standard 
modules that might not be in the boot layer.

2. Java agents and the JMX/management agent. If an agent is started in a 
running VM, and the required java.instrument or java.management modules 
are not in the boot layer, then a child layer will magically comes into 
being with the required standard + JDK modules. This it possible because 
the starting of these agents is under the control of the VM with the 
original mapping of modules to class loaders.

To your question, you can't use the API to do dynamic configuration and 
create module layers that contain the standard modules. The solution for 
containers is ALL-DEFAULT to ensure that all modules in the system image 
that export an API are in the boot layer.

-Alan


More information about the jigsaw-dev mailing list