Fix jdk.internal.misc.Unsafe.registerNatives not called in -server17 - #158
Open
luchsh wants to merge 1 commit into
Open
Fix jdk.internal.misc.Unsafe.registerNatives not called in -server17#158luchsh wants to merge 1 commit into
luchsh wants to merge 1 commit into
Conversation
luchsh
force-pushed
the
bugfix/jdk-internal-misc-unsafe-registration
branch
2 times, most recently
from
July 31, 2026 09:18
601c8c3 to
d0c097b
Compare
…n -server17
rt17.jar is built from cvm/alt_kernel/src17u/share/classes and ships
jdk.internal.misc.Unsafe for the -server17 kernel. The static
initializer of this class is expected to call registerNatives() so
that JVM_RegisterJDKInternalMiscUnsafeMethods installs the private
native implementations (objectFieldOffset0/1, allocateMemory0,
staticFieldOffset0, etc.) required by the rest of jdk.internal.*.
The registerNatives() call was commented out in the alt_kernel source,
which produced rt17.jar classfiles whose <clinit> does not invoke
registerNatives(). As a consequence, any code path that reaches
jdk.internal.misc.Unsafe.<clinit> followed by a call to a private
native (e.g. InnocuousThread.<clinit> calling objectFieldOffset ->
objectFieldOffset1 during Cleaner.start) fails with:
java.lang.UnsatisfiedLinkError:
'long jdk.internal.misc.Unsafe.objectFieldOffset1(Class,String)'
at jdk.internal.misc.InnocuousThread.<clinit>
at jdk.internal.ref.CleanerImpl$InnocuousThreadFactory.newThread
at java.lang.ref.Cleaner.create
Fix: re-enable the registerNatives() call in the static initializer
of cvm/alt_kernel/src17u/share/classes/jdk/internal/misc/Unsafe.java
so rebuilt rt17.jar ships with the correct <clinit> bytecode.
Add jtreg-style regression test
cvm/test/hotspot/runtime/Unsafe/JDKInternalMiscUnsafeRegisterNatives.java
which runs with -server17 and exercises objectFieldOffset1 vs
sun.misc.Unsafe.objectFieldOffset, staticFieldOffset0, and the
end-to-end Cleaner.create() -> InnocuousThread path that tripped the
original UnsatisfiedLinkError.
Co-authored-by: TRAE CLI <noreply@bytedance.com>
luchsh
force-pushed
the
bugfix/jdk-internal-misc-unsafe-registration
branch
from
July 31, 2026 09:29
d0c097b to
aa8f333
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rt17.jar is built from cvm/alt_kernel/src17u/share/classes and ships jdk.internal.misc.Unsafe for the -server17 kernel. The static initializer of this class is expected to call registerNatives() so that JVM_RegisterJDKInternalMiscUnsafeMethods installs the private native implementations (objectFieldOffset0/1, allocateMemory0, staticFieldOffset0, etc.) required by the rest of jdk.internal.*.
The registerNatives() call was commented out in the alt_kernel source, which produced rt17.jar classfiles whose does not invoke registerNatives(). As a consequence, any code path that reaches jdk.internal.misc.Unsafe. followed by a call to a private native (e.g. InnocuousThread. calling objectFieldOffset -> objectFieldOffset1 during Cleaner.start) fails with:
Fix: re-enable the registerNatives() call in the static initializer of cvm/alt_kernel/src17u/share/classes/jdk/internal/misc/Unsafe.java so rebuilt rt17.jar ships with the correct bytecode.
Add jtreg-style regression test
cvm/test/hotspot/runtime/Unsafe/JDKInternalMiscUnsafeRegisterNatives.java which runs with -server17 and exercises objectFieldOffset1 vs sun.misc.Unsafe.objectFieldOffset, staticFieldOffset0, and the end-to-end Cleaner.create() -> InnocuousThread path that tripped the original UnsatisfiedLinkError.