How many times one module can exist in layer graph

Alex Buckley alex.buckley at oracle.com
Fri Dec 15 01:26:37 UTC 2023


Since layer A and layer B each have their own class loader, there is no 
problem with each layer loading the same module.

Unfortunately, Guava is still not an explicit module 
(https://github.com/google/guava/issues/2970). It is an automatic 
module. This means it gets a "boost" in terms of the modules that it 
reads. In fact, we think the implementation of module resolution is 
giving it _too much_ of a boost, because Guava in layer B ends up 
reading both Gson in layer B and Gson in layer A. Alan is investigating.

FWIW, Gson is an explicit module 
(https://github.com/google/gson/blob/main/gson/src/main/java/module-info.java). 
This is great for developers, and also saves this layer A+B scenario 
from being even more complicated.

Alex

On 12/14/2023 3:58 PM, Anand Beh wrote:
> Hi Pavel,
> 
> It seems to be the issue that you're loading the Gson jar twice -- once 
> in layer A and once in layer B. The problem is analogous to loading the 
> same jar file in different ClassLoaders (in fact, that's what is 
> happening behind the scenes). You'll get different Class instances, 
> which quickly turns into a debugging nightmare, a hellish classloading 
> situation which was one of the original motivations for JPMS.
> 
> If, by saying "moduleY can only be located in ONE layer," you mean that 
> moduleY must only be /loaded/ by one layer, then yes, I would say that 
> you are correct. However, in terms of usability, and this is what Alan 
> seems to be getting at, you can indeed have Gson be visible to multiple 
> layers at the same time.
> 
> Hope this helps.
> 
> Anand
> 
> On Thu, Dec 14, 2023 at 11:55 AM PavelTurk <pavelturk2000 at gmail.com 
> <mailto:pavelturk2000 at gmail.com>> wrote:
> 
>     Hello, Alan
> 
>     Thank you very much for your answer. I could reproduce this problem.
>     Please, see https://github.com/PavelTurk/jpms-test1
>     <https://github.com/PavelTurk/jpms-test1>
>     There is a detailed readme and only one class that throws
>     ResolutionException.
> 
>     Best regards, Pavel
> 
>     On 12/14/23 3:07 PM, Alan Bateman wrote:
>      > On 14/12/2023 10:56, PavelTurk wrote:
>      >> Hello all.
>      >>
>      >> Let's suppose that we have 4 layers:
>      >> 1) boot
>      >> 2) layerA (parent - boot)
>      >> 3) layerB (parent-boot)
>      >> 4) layerC (parents - layerA, layerB)
>      >>
>      >> Layers A,B,C were created using defineModulesWithOneLoader​(...).
>      >>
>      >> And we have two modules - moduleX and moduleY. ModuleX uses moduleY.
>      >> ModuleX is located in layerC.
>      >>
>      >>
>     Do I understand correctly that moduleY can be located in any layer, but only
>      >>
>     in ONE layer? I mean, that it is impossible to place moduleY in any TWO layers
>      >> at the same time - for example in boot layer and layerB.
>      >>
>      >> I am asking this because I read that it was possible but I tried
>     all variants and
>      >> always got ResolutionException: Module ModuleX reads more than
>     one module named
>      >> ModuleY.
>      >
>      > It's possible to have a module "X" n several module layers at the
>     same time.
>      >
>      > It's hard to diagnose things from the info in your mail. Can you
>     print the Configuration object for layer A, B and C and paste it
>     into a reply? There may be implied readability in the picture, or it
>     may be related to using a multi-parent Configuration, I can't tell.
>     Also when you say X uses Y then I assume you don't mean services,
>     instead you mean X requires Y, is that right?
>      >
>      > -Alan
> 


More information about the jigsaw-dev mailing list