Is it safe to update jar that are used for dynamic layers?
Alan Bateman
Alan.Bateman at oracle.com
Fri May 6 13:08:52 UTC 2022
On 06/05/2022 12:26, Alex Orlov wrote:
> Hello.
>
> Please, consider the following situation. We have /home/user/temp/foo.jar that is used in dynamically created jpms
> layer bar.
>
> Could anyone say if it is safe to do the following: destroy layer bar, update /home/user/temp/foo.jar (modify some code in this jar)and create a new jpms layer (bar_2) that will use /home/user/temp/foo.jar.
>
This isn't really a module system issue, it's more about whether about
you know if a JAR file is still open (and in use) and whether you can
replace a JAR file that is open. In general it is not safe/reliable to
do this. If you search JBS you will find dozens of bug reports on this
topic, most going back many years. Many of the older bug reports are
crashes because the central directory of a zip file was historically
memory mapped and accessing a memory mapped region after the file has
been replaced will typically SIGBUS. You'll also see bug reports on
Windows with errors replacing zip or JAR files that are open. For the
module system then you could use a weak reference and have it be queued
when the module layer is GC'ed. However, I suspect this may not be
timely enough for what you are doing and maybe you could look at using a
unique name/location for each update instead.
-Alan
More information about the jigsaw-dev
mailing list