Issue in combination with JLink/JPackage
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Feb 10 10:05:02 UTC 2022
I have managed to create a simple reproducer on Windows:
import jdk.incubator.foreign.CLinker;
public class TestLookup {
public static void main(String[] args) {
System.load("C:\\Windows\\System32\\ucrtbase.dll");
CLinker.systemCLinker().lookup("foo");
}
}
The call to CLinker::lookup fails with UnsatisfiedLinkError as ucrtbase
is already loaded by the application class loader.
This seems to be a bug in the library loading mechanism - we do have a
"raw" library loading mechanism that is not subject to JNI restrictions:
https://github.com/openjdk/jdk/blob/309acbf0e86a0d248294503fccc7a936fa0a846e/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java#L99
This library loader ends up calling this method which contains a class
loader check:
https://github.com/openjdk/jdk/blob/309acbf0e86a0d248294503fccc7a936fa0a846e/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java#L203
I believe this loader check should be guarded by a "isJNI" flag, as we
did for other checks - e.g. whether JNI_OnLoad should be called.
Cheers
Maurizio
On 07/02/2022 12:19, Maurizio Cimadamore wrote:
> No problem.
>
> I've filed this:
>
> https://bugs.openjdk.java.net/browse/JDK-8281335
>
> Cheers
> Maurizio
>
> On 07/02/2022 12:15, clemens.lanthaler at itarchitects.at wrote:
>> Hi Maurizio,
>>
>> thanks allot for your help and for the investigation.
>>
>> best regards,
>> Clemens
>>
>>
>>> On 7. Feb 2022, at 13:03, Maurizio Cimadamore
>>> <maurizio.cimadamore at oracle.com> wrote:
>>>
>>>
>>>
>>> Hi Clemens (it seems like your message got dropped by the mailing
>>> list, not sure why).
>>>
>>> Your message seems to point at some bad interaction between jpackage
>>> and Panama both trying to load ucrtbase.dll (and only one can win).
>>> Apparently, the Panama code isn't executed early enough in the
>>> jpackage case.
>>>
>>> We'll need to investigate more.
>>>
>>> Maurizio
>>>
>>> On 05/02/2022 15:31, Clemens Lanthaler wrote:
>>>> Hello everybody,
>>>>
>>>> I am the developer of project librawfx
>>>> (github.com/lanthale/librawfx) and the app Photoslide
>>>> (github.com/lanthale/photoslide).
>>>>
>>>> At the begining of Photoslide the whole app was modularized and
>>>> therefore all was working including librawfx which is using project
>>>> Panama. After a while I had to change to a mixed (modulepath for
>>>> jdk+javafx libs and classpath for the rest) environment and
>>>> deployed my app PhotoSlide again. Under Linux and OSX all is
>>>> working as expected. The problem exists only under Windows.
>>>> Furthermore it exists only if I am creating a Jlink/Jpackage
>>>> distribution. Running the app from maven was working as expected.
>>>> Only the JPackage launcher have the issue and I have no clue what
>>>> the root cause is.
>>>>
>>>> The exception I am always seeing is:
>>>> Feb. 03, 2022 7:44:58 PM org.librawfx.RAWImageLoader load
>>>> SCHWERWIEGEND: null
>>>> java.lang.UnsatisfiedLinkError: Native Library
>>>> C:\Windows\System32\ucrtbase.dll already loaded in another classloader
>>>> (Full stacktrace below)
>>>>
>>>> How can you reproduce the issue:
>>>>
>>>> 1. Git clone project https://github.com/lanthale/JeditFX.git
>>>> 2. Start the app with "mvn javafx:run at default-cli"
>>>> 3. Click on the open icon in the toolbar and select file
>>>> "...\Documents\NetBeansProjects\JeditFX\JeditFX\src\main\resources\RAW-ADOBE_DNG_Sample.dng"
>>>> 4. The app is showing the image below the textarea
>>>> 5. Create the jlink/jpackage app-image with "mvn -Ppackage clean
>>>> install"
>>>> 6. Start the exe jeditfx.exe in directory ".\target\jeditfx"
>>>> 7. Open the same file again -> No image is shown below the text
>>>> area and the exception is thrown in the background
>>>>
>>>>
>>>> I have tried many things but it is only happening if I have
>>>> OpenJFX+JDK Modules on the module path and the rest of the jar
>>>> files on the classpath. All libs which are not having any Panama
>>>> code inside of the app are working perfectly and it is only
>>>> happening on Windows.
>>>>
>>>> Thank you in advance for your help!
>>>>
>>>> best regards,
>>>> Clemens
>>>>
>>>>
>>>>
>>>>
>>>> *Full stacktrace from Photoslide:*
>>>>
>>>> Feb. 03, 2022 7:44:41 PM org.photoslide.search.SearchIndex
>>>> createSearchIndex
>>>> INFORMATION: Start time create searchDB: 2022-02-03T19:44:41.693455
>>>> Feb. 03, 2022 7:44:42 PM org.photoslide.SoftwareUpdater
>>>> lambda$checkForSoftwareUpdates$2
>>>> INFORMATION: No new version found!
>>>> Feb. 03, 2022 7:44:43 PM org.photoslide.search.SearchIndex
>>>> lambda$createSearchIndex$0
>>>> INFORMATION: End time create searchDB: 2022-02-03T19:44:43.186194400
>>>> Feb. 03, 2022 7:44:58 PM org.librawfx.RAWImageLoader load
>>>> SCHWERWIEGEND: null
>>>> java.lang.UnsatisfiedLinkError: Native Library
>>>> C:\Windows\System32\ucrtbase.dll already loaded in another classloader
>>>> at
>>>> java.base/jdk.internal.loader.NativeLibraries.loadLibrary(Unknown
>>>> Source)
>>>> at
>>>> java.base/jdk.internal.loader.NativeLibraries.loadLibrary(Unknown
>>>> Source)
>>>> at
>>>> jdk.incubator.foreign/jdk.internal.foreign.SystemLookup.lambda$makeWindowsLookup$1(Unknown
>>>> Source)
>>>> at
>>>> jdk.incubator.foreign/jdk.internal.foreign.SystemLookup.libLookup(Unknown
>>>> Source)
>>>> at
>>>> jdk.incubator.foreign/jdk.internal.foreign.SystemLookup.makeWindowsLookup(Unknown
>>>> Source)
>>>> at jdk.incubator.foreign/jdk.internal.foreign.SystemLookup.(Unknown
>>>> Source)
>>>> at
>>>> jdk.incubator.foreign/jdk.incubator.foreign.CLinker.systemLookup(Unknown
>>>> Source)
>>>> at org.libraw.win.RuntimeHelper.lookup(RuntimeHelper.java:33)
>>>> at org.libraw.win.libraw_h.(libraw_h.java:15)
>>>> at
>>>> org.librawfx.LibrawImage.readPixelDataFromStream(LibrawImage.java:113)
>>>> at org.librawfx.RAWImageLoader.getImageData(RAWImageLoader.java:168)
>>>> at org.librawfx.RAWImageLoader.load(RAWImageLoader.java:84)
>>>> at
>>>> javafx.graphics at 18-ea/com.sun.javafx.iio.ImageStorage.loadAll(Unknown
>>>> Source)
>>>> at
>>>> javafx.graphics at 18-ea/com.sun.javafx.iio.ImageStorage.loadAll(Unknown
>>>> Source)
>>>> at
>>>> javafx.graphics at 18-ea/com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(Unknown
>>>> Source)
>>>> at
>>>> javafx.graphics at 18-ea/com.sun.javafx.tk.quantum.PrismImageLoader2.(Unknown
>>>> Source)
>>>> at
>>>> javafx.graphics at 18-ea/com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(Unknown
>>>> Source)
>>>> at javafx.graphics at 18-ea/javafx.scene.image.Image.loadImage(Unknown
>>>> Source)
>>>> at
>>>> javafx.graphics at 18-ea/javafx.scene.image.Image.initialize(Unknown
>>>> Source)
>>>> at javafx.graphics at 18-ea/javafx.scene.image.Image.(Unknown Source)
>>>> at
>>>> org.photoslide.datamodel.MediaFileLoader$1.call(MediaFileLoader.java:46)
>>>>
>>>> at
>>>> org.photoslide.datamodel.MediaFileLoader$1.call(MediaFileLoader.java:43)
>>>>
>>>> at
>>>> javafx.graphics at 18-ea/javafx.concurrent.Task$TaskCallable.call(Unknown
>>>> Source)
>>>> at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
>>>> at
>>>> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown
>>>> Source)
>>>> at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
>>>> at
>>>> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
>>>> Source)
>>>> at
>>>> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
>>>> Source)
>>>> at java.base/java.lang.Thread.run(Unknown Source)
More information about the panama-dev
mailing list