RFR: 8346433: Cannot use DllMain in hotspot for static builds [v2]
Magnus Ihse Bursie
ihse at openjdk.org
Mon Jan 13 13:50:54 UTC 2025
> To be able to properly support static builds on Windows in [JDK-8346377](https://bugs.openjdk.org/browse/JDK-8346377), we cannot use DllMain, for two reasons:
>
> 1) This is not called for statically linked libraries, and
> 2) There are multiple DllMain definitions throughout the JDK native libraries, causing name collisions.
>
> While it could have been possible to keep the DllMain function for non-static builds and just use an alternative solution for static builds, I think it is preferable to have a single solution that works as well for both static and dynamic builds.
>
> The DllMain in hotspot is doing work both at DLL load time, and at DLL unload time. Let's go through them to see why this patch is safe.
>
> During DLL load time, the library handle is set, and the hi-res timer is initialized. The `pre_initialize` method from `WindowsDbgHelp` and `SymbolEngine` is called. These two are basically identical; both setup a critical section (a Windows mutex). However, this mutex is only used from a stack local guard object, which is allocated only when calls are made into these classes, which are not happening at bootstrapping time, so this shift in initialization time is harmless.
>
> That shift in time is also very small. The `DllMain` method is called by Windows when the DLL is loaded (by libjli), and the very first thing that JLI does after that is to call `JNI_CreateJavaVM`, which ends up calling `Threads::create_vm`, which calls `os::init` early on.
Magnus Ihse Bursie has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
- Merge branch 'master' into dll-main-in-hotspot
- Add explanation
- Update comments and copyright year
- Restore DllMain
- 8346433: Cannot use DllMain in hotspot for static builds
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/22793/files
- new: https://git.openjdk.org/jdk/pull/22793/files/4aab62c0..b658c560
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=22793&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=22793&range=00-01
Stats: 34543 lines in 932 files changed: 14919 ins; 15656 del; 3968 mod
Patch: https://git.openjdk.org/jdk/pull/22793.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/22793/head:pull/22793
PR: https://git.openjdk.org/jdk/pull/22793
More information about the hotspot-runtime-dev
mailing list