Skip to content

Refactor: JVM implementation separation and JVMThread abstraction#435

Draft
zhengyu123 wants to merge 26 commits intomainfrom
zgu/jvm_refactor
Draft

Refactor: JVM implementation separation and JVMThread abstraction#435
zhengyu123 wants to merge 26 commits intomainfrom
zgu/jvm_refactor

Conversation

@zhengyu123
Copy link
Copy Markdown
Contributor

@zhengyu123 zhengyu123 commented Mar 23, 2026

What does this PR do?:
Reorganizes JVM-specific C++ source into dedicated subdirectories and introduces a new JVMThread class as a JVM-agnostic thread bridge.

  • hotspot/ — vmStructs.cpp/h/inline.h moved here; HotSpot-specific thread initialization and execution state logic consolidated into VMThread methods
  • j9/ — j9Ext, j9WallClock moved here
  • jvmThread.h/cpp (new) — JVM-agnostic JVMThread class that wraps both HotSpot's TLS-based thread lookup and J9's j9thread_self() under a single interface; owns the pthread key and the Java tid field ID previously scattered across VMStructs

Why
Previously VMStructs::initThreadBridge() handled both HotSpot and J9 initialization paths in a single monolithic function. The TLS key, java thread ID field, and thread execution state logic were split across VMStructs, threadState.inline.h, and call sites. This made it difficult to conditionally compile or reason about JVM-specific behavior.

Key changes

  • VMStructs::initThreadBridge() removed — replaced by JVMThread::initialize() (JVM-agnostic, called unconditionally in VM::ready()) + VMThread::initialize() (HotSpot-only)
  • VMThread::getExecutionMode() / getOSThreadState() — thread state→execution mode conversion moved from threadState.inline.h into VMThread methods; threadState.inline.h now simply delegates to them
  • wallClock.cpp signal handler simplified — ~15 lines of inline thread state inspection replaced by getOSThreadState() / getThreadExecutionMode()
  • _tls_index / _tid removed from VMStructs — now owned by JVMThread
  • Dead code removed — j9StackTraces.h, javaApi.h (empty), stackFrame_{arm,i386,loongarch64,ppc64,riscv64}.cpp (unsupported architectures), VM::_libjava

Motivation:

  • This is part one of PROF-13889 that focuses on providing an abstraction on Thread - to avoid PR growing to large. Followup PRs will address other areas, especially, in stack walking.

  • In addition, this PR removes some of dead code and files that related to the platforms that we don't support.

Additional Notes:
How to test the change?:

  • Regular CI tests
  • Stress tests

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-13889

Unsure? Have a question? Request a review!

@dd-octo-sts
Copy link
Copy Markdown

dd-octo-sts bot commented Mar 23, 2026

CI Test Results

Run: #23610765440 | Commit: 307b21b | Duration: 9m 50s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-03-26 18:28:35 UTC

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 23, 2026

Integration Tests

All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 532b14e0

@dd-octo-sts
Copy link
Copy Markdown

dd-octo-sts bot commented Mar 25, 2026

Scan-Build Report

User:runner@runnervm46oaq
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Thu Mar 26 18:17:06 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs1
Logic error
Stack address stored into global variable1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Logic errorStack address stored into global variablestackWalker.cppwalkVM84836

@zhengyu123 zhengyu123 changed the title WIP: Refactor Refactor: JVM implementation separation and JVMThread abstraction Mar 26, 2026
@zhengyu123 zhengyu123 marked this pull request as ready for review March 26, 2026 15:25
@zhengyu123 zhengyu123 requested a review from a team as a code owner March 26, 2026 15:25
Copy link
Copy Markdown
Contributor

@rkennke rkennke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactoring. I have some comments.

@zhengyu123 zhengyu123 marked this pull request as draft March 27, 2026 20:39
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.

2 participants