Skip to content

Commit 87063c3

Browse files
jbachorikclaude
andcommitted
Scan all native libs for thread entry points
findJvmLibrary("libc") always returns libjvm on HotSpot, and findLibraryByName("libc") uses prefix strncmp that matches libcap/libcurl before libc.so.6. Replace both with a full scan of all loaded native libs using the isThreadEntry predicate, covering glibc, musl, and Rust binaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent be8ec0d commit 87063c3

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

ddprof-lib/src/main/cpp/vmEntry.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,17 @@ bool VM::initShared(JavaVM* vm) {
318318
// Mark thread entry points for all JVMs (critical for correct stack unwinding)
319319
lib->mark(isThreadEntry, MARK_THREAD_ENTRY);
320320

321-
// Also mark libc/pthread libraries which contain thread start/exit points
322-
CodeCache* libc = libraries->findJvmLibrary("libc");
323-
if (libc != NULL) {
324-
libc->mark(isThreadEntry, MARK_THREAD_ENTRY);
325-
}
326-
CodeCache* libpthread = libraries->findJvmLibrary("libpthread");
327-
if (libpthread != NULL) {
328-
libpthread->mark(isThreadEntry, MARK_THREAD_ENTRY);
321+
// Mark OS-level pthread entry points across ALL loaded native libraries.
322+
// On glibc these live in libc.so.6 or libpthread.so.0 (merged in glibc 2.34+);
323+
// on musl in libc.musl-<arch>.so.1; on Rust they may be in the app binary itself.
324+
// Scanning all libs avoids fragile name-based lookup (findLibraryByName uses a
325+
// prefix match that can return the wrong library, e.g. libcap instead of libc).
326+
// walkVM stops unwinding when it reaches the top of a pure-native thread stack
327+
// without finding an anchor; marking start_thread/thread_start here gives the
328+
// walker a clean stopping point for any pthread-managed thread.
329+
const CodeCacheArray& all_native_libs = libraries->native_libs();
330+
for (int i = 0; i < all_native_libs.count(); i++) {
331+
all_native_libs[i]->mark(isThreadEntry, MARK_THREAD_ENTRY);
329332
}
330333

331334
if (isOpenJ9()) {

0 commit comments

Comments
 (0)