Skip to content

jvm: Support HotSpot LTS JDK 21 and 25 via VMStructs - #425

Open
mnalmahmud wants to merge 2 commits into
frida-packages:mainfrom
mnalmahmud:jvm-lts-21-25
Open

mnalmahmud wants to merge 2 commits into
frida-packages:mainfrom
mnalmahmud:jvm-lts-21-25

Conversation

@mnalmahmud

@mnalmahmud mnalmahmud commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

Adds HotSpot JVM support for LTS releases after JDK 17 (JDK 21 and JDK 25) by reading HotSpot's own gHotSpotVMStructs / gHotSpotVMTypes metadata dynamically across all supported JDKs (8, 11, 17, 21, and 25) with a clean fallback when symbols are stripped.

Related PRs (each independent on main):

Once #423 merges, JDK 21 and 25 can be added directly to the jvm CI matrix in .github/workflows/tests.yml (already verified green on all 5 LTS releases below).

Commits

  1. jvm: Read HotSpot struct layouts from VMStructs
    • Parse gHotSpotVMStructs and gHotSpotVMTypes (when exported by libjvm) to resolve Method, ConstMethod, ConstantPool, InstanceKlass (vtable offset via sizeof(InstanceKlass)), and AccessFlags size dynamically across JDK 8–25, falling back to hardcoded offsets if stripped.
    • Add readAccessFlags() / writeAccessFlags() to handle both 16-bit (u2, JDK 25 / JDK-8347147) and 32-bit (u4, JDK 8–24) AccessFlags.
    • Resolve ConstMethod::_adapter (stackmapDataOffset + pointerSize) on JDK 9–16 when neither Method::_adapter nor ConstMethod::_adapter is exported in gHotSpotVMStructs.
  2. jvm: Support HotSpot JDK 21 and 25
    • Update MethodFlags bits (is_old, is_obsolete, is_not_c1_compilable, is_not_c2_compilable, is_not_c2_osr_compilable) in Method::_flags on JDK 21+ (JDK-8306851), restoring them on revert.
    • Treat NMethodSweeper::* and JVM_Sleep as optional and no-op forceSweep() when the sweeper has been removed (JDK-8290025).
    • Wrap the zero-argument VM_RedefineClasses::flush_dependent_code() overload used on JDK 21+ when mark_dependent_code() is absent.
    • Fall back to Abstract_VM_Version::vm_release() when jre_release_version() is absent (JDK 25).
    • Resolve jni_FindClass directly and widen the instruction scan window to 24 instructions in makeThreadFromJniHelper() to handle JDK 25's prologue and -Xcheck:jni wrappers.

Verification

Parse HotSpot's exported gHotSpotVMStructs and gHotSpotVMTypes metadata
tables in lib/jvm.js to resolve Method, ConstMethod, ConstantPool, and
InstanceKlass field offsets and AccessFlags/InstanceKlass sizes
dynamically across JDK versions, keeping the existing version formulas
and vtable disassembly as a fallback when VMStructs symbols are absent.

Also handle both 16-bit and 32-bit AccessFlags widths and avoid reading
InstanceKlass::_member_names when ResolvedMethodTable is available.
Extend the HotSpot JVM backend to support LTS releases after JDK 17
(JDK 21 and JDK 25):

- Update MethodFlags bits (is_old, is_obsolete, and C1/C2/OSR
  non-compilable flags) on JDK 21+, where JDK-8306851 moved HotSpot's
  internal method flags out of AccessFlags into Method::_flags.
- Treat NMethodSweeper symbols and JVM_Sleep as optional and no-op
  forceSweep() when the sweeper has been removed (JDK-8290025).
- Wrap the zero-argument VM_RedefineClasses::flush_dependent_code()
  overload used on JDK 21+ when mark_dependent_code() is absent.
- Fall back to Abstract_VM_Version::vm_release() when
  jre_release_version() is absent (JDK 25).
- Resolve jni_FindClass directly and widen the instruction scan window
  to 24 instructions in makeThreadFromJniHelper() so JDK 25's prologue
  and -Xcheck:jni wrappers are handled reliably.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant