Skip to content

Don't preload jmethodIDs when cstack=vm with hotspot JVM#549

Open
zhengyu123 wants to merge 28 commits into
mainfrom
hs_jmethod_id
Open

Don't preload jmethodIDs when cstack=vm with hotspot JVM#549
zhengyu123 wants to merge 28 commits into
mainfrom
hs_jmethod_id

Conversation

@zhengyu123

@zhengyu123 zhengyu123 commented May 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?:
Reduce memory overhead by storing raw Method pointers instead of pre-allocating jmethodIDs for classes loaded by system class loaders (bootstrap, platform and application)

This feature only applies to hotspot JVM when cstack=vm

Motivation:
Pre-allocating jmethodIDs can consume significant amount of native memory, e.g. 9G in some extreme cases.
By introducing optional lazy jmethodID resolution for system classes, HotSpot JVM profiling avoids loading jmethodIDs for every method, but only the methods on stacks, a significant optimization for native memory usage.

Additional Notes:
This feature is optional and is off by default. To enable the feature, set force_jmethodID=false

How to test the change?:
Running renaissance akka benchmark with NMT, exams jmethodID sites:

Mainline (without this PR)

[0x0000726344c5f43d] InstanceKlass::get_jmethod_id(methodHandle const&)+0x8d
[0x000072634500e78a] Method::jmethod_id()+0x6a
[0x0000726344e78f63] JvmtiEnv::GetClassMethods(oopDesc*, int*, _jmethodID***)+0x2b3
[0x0000726344e2eb86] jvmti_GetClassMethods+0x206
                             (malloc=430672 type=Class #3156) (at peak)

[0x000072634500d4d1] Method::ensure_jmethod_ids(ClassLoaderData*, int)+0xd1
[0x0000726344e78f57] JvmtiEnv::GetClassMethods(oopDesc*, int*, _jmethodID***)+0x2a7
[0x0000726344e2eb86] jvmti_GetClassMethods+0x206
[0x0000726344145374] _jvmtiEnv::GetClassMethods(_jclass*, int*, _jmethodID***)+0x34
                             (malloc=392776 type=Internal #2397) (at peak)

[0x000072634500d48d] Method::ensure_jmethod_ids(ClassLoaderData*, int)+0x8d
[0x0000726344e78f57] JvmtiEnv::GetClassMethods(oopDesc*, int*, _jmethodID***)+0x2a7
[0x0000726344e2eb86] jvmti_GetClassMethods+0x206
[0x0000726344145374] _jvmtiEnv::GetClassMethods(_jclass*, int*, _jmethodID***)+0x34
                             (malloc=57528 type=Class #2397) (at peak)

With force_jmethodID=false

[0x0000762891b93651] Method::ensure_jmethod_ids(ClassLoaderData*, int)+0x251
[0x00007628919fef57] JvmtiEnv::GetClassMethods(oopDesc*, int*, _jmethodID***)+0x2a7
[0x00007628919b4b86] jvmti_GetClassMethods+0x206
[0x0000762890ce9594] _jvmtiEnv::GetClassMethods(_jclass*, int*, _jmethodID***)+0x34
                             (malloc=3920 type=Class #98) (at peak)

[0x0000762891b93850] Method::make_jmethod_id(ClassLoaderData*, Method*)+0x90
[0x00007628917e548d] InstanceKlass::get_jmethod_id(methodHandle const&)+0xdd
[0x0000762891b9478a] Method::jmethod_id()+0x6a
[0x00007628918a0186] get_method_id(JNIEnv_*, _jclass*, char const*, char const*, bool, JavaThread*) [clone .constprop.0]+0x186
                             (malloc=1536 type=Class #64) (at peak)

[0x00007628917e543d] InstanceKlass::get_jmethod_id(methodHandle const&)+0x8d
[0x0000762891b9478a] Method::jmethod_id()+0x6a
[0x00007628919fef63] JvmtiEnv::GetClassMethods(oopDesc*, int*, _jmethodID***)+0x2b3
[0x00007628919b4b86] jvmti_GetClassMethods+0x206
                             (malloc=252656 type=Class #1792) (at peak)

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-13548

Unsure? Have a question? Request a review!

@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #27226908405 | Commit: 40505c9 | Duration: 12m 39s (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-06-09 18:58:57 UTC

@dd-octo-sts

dd-octo-sts Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervm3jyl0
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:Tue Jun 2 20:41:00 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs1
Logic error
Result of operation is garbage or undefined1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Logic errorResult of operation is garbage or undefinedhotspotSupport.cpploadMethodIDsImpl13092

@zhengyu123 zhengyu123 marked this pull request as ready for review June 2, 2026 15:26
@zhengyu123 zhengyu123 requested a review from a team as a code owner June 2, 2026 15:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13349c38df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
@zhengyu123 zhengyu123 marked this pull request as draft June 2, 2026 15:45
@zhengyu123 zhengyu123 changed the title WIP: Don't preload jmethodIDs when cstack=vm Don't preload jmethodIDs when cstack=vm with hotspot JVM Jun 2, 2026
@zhengyu123 zhengyu123 marked this pull request as ready for review June 2, 2026 17:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b95c88c66f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df5e992559

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
@zhengyu123 zhengyu123 requested a review from jbachorik June 2, 2026 20:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c26aeea66e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated

@jbachorik jbachorik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add tests for those changes. They are complex enough to warrant specialized tests. Thanks!

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment on lines +1326 to +1328
if (method_id != nullptr && method_id != JMETHODID_NOT_WALKABLE) {
return method_id;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, maybe useful to have a function or macro for method_id != nullptr && method_id != JMETHODID_NOT_WALKABLE condition, which seems to be used quite a lot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread ddprof-lib/src/main/cpp/hotspot/vmStructs.h Outdated
Comment thread ddprof-lib/src/main/cpp/j9/j9Support.h
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated

@jbachorik jbachorik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sphinx review findings (lines not in diff)

[MEDIUM] hotspof-lib/src/main/cpp/hotspot/hotspotSupport.cpp:680 · completeness
Direct VMMethod::id() callers at lines 680, 1089–1100, and 139 (fillFrameTypes) were not updated for the new JMETHODID_NOT_WALKABLE sentinel. Their != NULL guards now let the sentinel through, emitting a spurious frame that later collapses to "unknown"; the PROBE_SP retract logic at 1098 also misfires.

if (method_id != NULL) { fillFrame(..., method_id); }  // ← sentinel passes this guard

Fix: method_id != NULL && method_id != JMETHODID_NOT_WALKABLE at all direct id() call sites.


[MEDIUM] ddprof-lib/src/main/cpp/hotspot/vmStructs.h:928 · correctness (latent)
isStaleMethodId compares vm_method->id() == NULL, but id() now returns JMETHODID_NOT_WALKABLE on the bogus path. The staleness predicate (JDK-8313816 workaround) is logically broken. Currently zero callers, but worth fixing alongside the sentinel migration.

return vm_method == NULL || vm_method->id() == NULL;  // ← sentinel is not NULL

Fix: compare against both NULL and JMETHODID_NOT_WALKABLE.


[LOW / test-adequacy] ddprof-lib/src/main/cpp/frame.h · FrameType encode/decode/isRawPointer
No test covers the new bit-manipulation logic. Five mutants survive: inverting rawPointer ?, removing the mask OR, flipping & ~RAW_POINTER_MASK to & RAW_POINTER_MASK, bci > 0bci >= 0, and != 0== 0. Suggest adding a round-trip unit test asserting the type, the raw-pointer bit, and that isRawPointer(0) == false.

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/vmStructs.inline.h
Comment thread ddprof-lib/src/main/cpp/flightRecorder.cpp
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/jvmSupport.cpp
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Comment thread ddprof-lib/src/main/cpp/flightRecorder.cpp Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2a9a1d073

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b56c6b47e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/jvmSupport.cpp Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 756790479f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/arguments.h

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79adaea8da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/frame.h

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4702a6289d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (method_id != NULL) {
fillFrame(frames[depth++], FRAME_JIT_COMPILED, 0, method_id);
}
fillFrame(frames[depth++], FRAME_JIT_COMPILED, 0, method_id, method);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard null compiler tasks before filling raw frames

When features.comp_task is enabled and a marked compiler-entry frame is sampled while the compiler thread has no current CompileTask, vm_thread->compiledMethod() returns NULL; this now still calls the new overload with both method_id and method null. That overload falls into the raw-pointer path, which asserts in debug builds and records a raw null method in release builds instead of skipping the pseudo-frame as before, so idle compiler-thread samples can abort or produce spurious unknown Java frames.

Useful? React with 👍 / 👎.

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a great improvement!

Here comes my first pass of (manual) review. It's mostly minor stuff.

Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
msg = "jstackdepth must be > 0";
}

CASE("fjmethodid")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find it unintuitive/confusing that in order to turn the new feature on, we have to set the flag to false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't like to name, what do you suggest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I don't know either, it seems hard. I could only come up with dont-preload-methodIds or no-preload-methodIds, but it doesn't seem very much better. I leave that up to you.

Comment thread ddprof-lib/src/main/cpp/flightRecorder.h Outdated
Comment thread ddprof-lib/src/main/cpp/flightRecorder.h Outdated
HotspotSupport::initialize(jni);
}

loadAllMethodIDs(jvmti, jni);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is slightly confusing that this call says 'load all method IDs, even in case of HotSpot', even though we don't actually load all method IDs when running HotSpot - but this is only decided later.

Comment thread ddprof-lib/src/main/cpp/vmEntry.h Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39149aff27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1362 to +1365
method_id = jni->GetMethodID(clz, method_name, method_signature);
if (method_id == nullptr) {
jni->ExceptionClear();
method_id = jni->GetStaticMethodID(clz, method_name, method_signature);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve class-initializer frames when resolving raw methods

When fjmethodid=false skips preloading for system/application classes, samples taken in a class initializer reach this raw-Method* resolver with the VM name <clinit>. JNI has no jmethodID lookup for class initializers via GetMethodID or GetStaticMethodID, so both calls leave method_id null and Lookup::resolveMethod() serializes those Java frames as unknown even though the VM method metadata is available. This affects cstack=vm/raw-pointer recordings that sample application or JDK class initialization paths.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed1c0471bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +39 to +42
bool JVMSupport::isHidden(jint modifiers) {
// 0x1400 = ACC_SYNTHETIC(0x1000) | ACC_BRIDGE(0x0040)
return modifiers == 0 || (modifiers & 0x1040);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not treat zero modifiers as hidden

When fjmethodid=false, HotspotSupport::loadMethodIDsImpl() uses this helper to decide whether a system/application-loader class can skip GetClassMethods. JVMTI GetClassModifiers returns 0 for ordinary package-private classes, so those non-hidden classes are treated as hidden and fall through to JVMSupport::loadMethodIDsImpl(), preloading jmethodIDs for many package-private JDK/app classes even though the option is meant to avoid that memory cost for normal system-loader classes.

Useful? React with 👍 / 👎.

Comment on lines +1273 to +1275
if (!isHiddenClass(jvmti, klass) &&
jvmti->GetClassLoader(klass, &cl) == JVMTI_ERROR_NONE &&
isSystemClassLoader(jni, cl)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Initialize loader refs before class-prepare filtering

When fjmethodid=false is used at JVM startup, VM::initProfilerBridge() enables JVMTI_EVENT_CLASS_PREPARE before VMInit calls JVMSupport::initialize(), so early platform/application classes can reach this check while JAVA_PLATFORM_CLASSLOADER and JAVA_APPLICATION_CLASSLOADER are still null. In that window isSystemClassLoader() only matches bootstrap classes, so platform/app classes fall through to GetClassMethods and are preloaded anyway; initialize these globals before enabling ClassPrepare or defer the skip until they are ready.

Useful? React with 👍 / 👎.

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for making the changes. Some old comments are still un-addressed, and I also have some new comments.

if (method_id != NULL) {
fillFrame(frames[depth++], FRAME_JIT_COMPILED, 0, method_id);
}
fillFrame(frames[depth++], FRAME_JIT_COMPILED, 0, method_id, method);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a logic bug here, and Codex already pointed that out.

static name * load_then_cast(const void* ptr) { \
assert(ptr != nullptr); \
return cast(*(const void**)ptr); }
return cast_or_null(*(const void**)ptr); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old code asserted ptr to be != nullptr. The new code blindly dereferences ptr. I would either put the assert back or, if pr == nullptr is now a valid input, guard against ptr == nullptr.

method_id = JVMSupport::resolve(frame.method);
}

/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think commented-out code should be removed.

static jobject JAVA_APPLICATION_CLASSLOADER = nullptr;

void HotspotSupport::initialize(JNIEnv* jni) {
if (JAVA_PLATFORM_CLASSLOADER != nullptr || JAVA_APPLICATION_CLASSLOADER != nullptr) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This assumes that:

  • initialize() is not called concurrently by different threads
  • initialization finds both class-loaders, otherwise re-init would override already-initialized field

Are both assumptions reasonable?

}

bool JVMSupport::isHidden(jint modifiers) {
// 0x1400 = ACC_SYNTHETIC(0x1000) | ACC_BRIDGE(0x0040)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo: should be 0x1040 ?

strstr(signature, "$$Lambda.") != nullptr ||
strstr(signature, "$$Lambda$") != nullptr ||
strstr(signature, ".lambda$") != nullptr ||
strncmp(signature, FFM_PREFIX, strlen(FFM_PREFIX)) == 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can use sizeof(FFM_PREFIX) - 1 to avoid the runtime call, because the string is a constexpr.

jni->IsSameObject(cl, JAVA_APPLICATION_CLASSLOADER); // application class loader (system class loader)
}

bool isHiddenClass(jvmtiEnv *jvmti, jclass clazz) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this can/should be static.

* SPDX-License-Identifier: Apache-2.0
*/

#include "flightRecorder.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

leading space

VMMethod* vm_method = VMMethod::load_then_cast((const void*)id);
return vm_method == NULL || vm_method->id() == NULL;
// jmethod ID == nullptr, means the value is not yet populated
return vm_method == NULL || vm_method->id() == JMETHODID_NOT_WALKABLE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about the case vm_method->id() == NULL? (and why are we using NULL here, but nullptr elsewhere?)

}

// This method only resolves methods that are loaded by system class loaders
jmethodID HotspotSupport::resolve(const void* method) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This must only ever be called outside a signal-handler-context. If possible, this should be asserted, or otherwise at least documented.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5a898f44d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +86 to +89
if (VM::isHotspot() && HotspotSupport::shouldPreloadJmethodIDs()) {
return HotspotSupport::loadMethodIDsImpl(jvmti, jni, klass);
} else {
return loadMethodIDsImpl(jvmti, jni, klass);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route non-VM stack modes through full preloading

For cstack=fp/dwarf/lbr/no, shouldPreloadJmethodIDs() returns true, so this branch calls HotspotSupport::loadMethodIDsImpl, which skips GetClassMethods for normal bootstrap/platform/application classes. Those stack modes still use the ASGCT path (cstack < CSTACK_VM), which depends on pre-created jmethodIDs, so normal Java frames in those recordings can become missing/unknown; the same inversion makes explicit cstack=vm fall into the unconditional preloader instead of the raw Method* path.

Useful? React with 👍 / 👎.

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.

3 participants