GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `VMStructs::initJvmFunctions` is called before `VM::init` · Issue #1657 · async-profiler/async-profiler

VMStructs::initJvmFunctions is called before VM::init #1657

New issue
Copy link
New issue
Copy link
Closed
#1658
Closed
VMStructs::initJvmFunctions is called before VM::init#1657
#1658
Copy link
Labels
bug

Description

@fandreuz
fandreuz
opened on Jan 14, 2026
Issue body actions

Describe the bug

I observed that VMStructs::initJvmFunctions is called before VM::init. Thus, VM::hotspot_version() is always zero, which means that no field gets initialized during initJvmFunctions. I observed this both in agent mode and attach mode.

If I'm not mistaken, this implies that:

  • The workaround for JDK-8313796 in Profiler::crashHandler won't work;
  • _has_class_loader_data is always false, so this might be dead code:

    async-profiler/src/vmEntry.cpp

    Lines 368 to 381 in f789c4f

    if (VMStructs::hasClassLoaderData()) {
    VMKlass* vmklass = VMKlass::fromJavaClass(jni, klass);
    int method_count = vmklass->methodCount();
    if (method_count > 0) {
    ClassLoaderData* cld = vmklass->classLoaderData();
    cld->lock();
    // Workaround for JVM bug: preallocate space for jmethodIDs
    // at the beginning of the list (rather than at the end)
    for (int i = 0; i < method_count; i += MethodList::SIZE) {
    *cld->methodList() = new MethodList(*cld->methodList());
    }
    cld->unlock();
    }
    }

Expected vs. actual behavior

VMStructs::initJvmFunctions should not be called before VM::init.

Reproduction Steps

gdb -ex 'set breakpoint pending on' \
    -ex 'break initJvmFunctions' \
    -ex 'break VM::init' \
    -ex run \
    --args java -agentpath:./build/lib/libasyncProfiler.so -version

Additional Information/Context

Agent mode

LateInitializer ends up calling initJvmFunctions:

#0  VMStructs::initJvmFunctions () at src/vmStructs.cpp:560
#1  0x00007ffff6771bfe in VMStructs::init (libjvm=0x7ffff00d2db0) at src/vmStructs.cpp:136
#2  0x00007ffff677534b in LateInitializer::checkJvmLoaded (this=0x7ffff67fefb0 <_late_initializer>) at src/zInit.cpp:41
#3  0x00007ffff677525c in LateInitializer::LateInitializer (this=0x7ffff67fefb0 <_late_initializer>) at src/zInit.cpp:26
#4  0x00007ffff67a259a in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at src/zInit.cpp:65
#5  0x00007ffff67a25b4 in _GLOBAL__sub_I__stdin_ () at src/zInit.cpp:65
#6  0x00007ffff7fce9ce in call_init (env=0x7fffffffe248, argv=0x7fffffffe228, argc=3, l=<optimized out>) at ./elf/dl-init.c:74
#7  call_init (l=<optimized out>, argc=3, argv=0x7fffffffe228, env=0x7fffffffe248) at ./elf/dl-init.c:26
#8  0x00007ffff7fceab4 in _dl_init (main_map=0x7ffff0004ad0, argc=3, argv=0x7fffffffe228, env=0x7fffffffe248) at ./elf/dl-init.c:121
#9  0x00007ffff7b6e234 in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:182
#10 0x00007ffff7fd521e in dl_open_worker (a=a@entry=0x7ffff7a1c400) at ./elf/dl-open.c:808
#11 0x00007ffff7b6e1da in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#12 0x00007ffff7fd55b8 in _dl_open (file=0x7ffff0003da0 "./build/lib/libasyncProfiler.so", mode=<optimized out>, caller_dlopen=0x7ffff7169521 <os::dll_load(char const*, char*, int)+65>, 
    nsid=<optimized out>, argc=3, argv=0x7fffffffe228, env=0x7fffffffe248) at ./elf/dl-open.c:884
#13 0x00007ffff7aa44b8 in dlopen_doit (a=a@entry=0x7ffff7a1c670) at ./dlfcn/dlopen.c:56
#14 0x00007ffff7b6e1da in __GI__dl_catch_exception (exception=exception@entry=0x7ffff7a1c5d0, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#15 0x00007ffff7b6e28f in __GI__dl_catch_error (objname=0x7ffff7a1c628, errstring=0x7ffff7a1c630, mallocedp=0x7ffff7a1c627, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:227
#16 0x00007ffff7aa3fa7 in _dlerror_run (operate=operate@entry=0x7ffff7aa4460 <dlopen_doit>, args=args@entry=0x7ffff7a1c670) at ./dlfcn/dlerror.c:138
#17 0x00007ffff7aa4569 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at ./dlfcn/dlopen.c:71
#18 ___dlopen (file=<optimized out>, mode=<optimized out>) at ./dlfcn/dlopen.c:81
#19 0x00007ffff7169521 in os::dll_load(char const*, char*, int) () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#20 0x00007ffff72d8207 in lookup_on_load(AgentLibrary*, char const**, unsigned long) [clone .constprop.168] () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#21 0x00007ffff72e3097 in Threads::create_vm(JavaVMInitArgs*, bool*) () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#22 0x00007ffff6f263ff in JNI_CreateJavaVM () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#23 0x00007ffff7c080e0 in JavaMain () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/../lib/amd64/jli/libjli.so
#24 0x00007ffff7aa81f5 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#25 0x00007ffff7b2889c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

VM::_hotspot_version is only initialized later during Agent_OnLoad:

#0  VM::init (vm=0x7ffff78106a0 <main_vm>, attach=false) at src/vmEntry.cpp:139
#1  0x00007ffff6771945 in Agent_OnLoad (vm=0x7ffff78106a0 <main_vm>, options=0x0, reserved=0x0) at src/vmEntry.cpp:474
#2  0x00007ffff72e30af in Threads::create_vm(JavaVMInitArgs*, bool*) () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#3  0x00007ffff6f263ff in JNI_CreateJavaVM () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so
#4  0x00007ffff7c080e0 in JavaMain () from /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/../lib/amd64/jli/libjli.so
#5  0x00007ffff7aa81f5 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#6  0x00007ffff7b2889c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Attach mode

#0  VMStructs::initJvmFunctions () at src/vmStructs.cpp:560
#1  0x00007fff31c87bfe in VMStructs::init (libjvm=0x7ffefc284b70) at src/vmStructs.cpp:136
#2  0x00007fff31c8b34b in LateInitializer::checkJvmLoaded (this=0x7fff31d14fb0 <_late_initializer>) at src/zInit.cpp:41
#3  0x00007fff31c8b25c in LateInitializer::LateInitializer (this=0x7fff31d14fb0 <_late_initializer>) at src/zInit.cpp:26
#4  0x00007fff31cb859a in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at src/zInit.cpp:65
#5  0x00007fff31cb85b4 in _GLOBAL__sub_I__stdin_ () at src/zInit.cpp:65
#6  0x00007ffff7fce9ce in call_init (env=0x7fffffffe240, argv=0x7fffffffe228, argc=2, l=<optimized out>) at ./elf/dl-init.c:74
#7  call_init (l=<optimized out>, argc=2, argv=0x7fffffffe228, env=0x7fffffffe240) at ./elf/dl-init.c:26
#8  0x00007ffff7fceab4 in _dl_init (main_map=0x7ffefc0669a0, argc=2, argv=0x7fffffffe228, env=0x7fffffffe240) at ./elf/dl-init.c:121
#9  0x00007ffff7efb234 in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:182
#10 0x00007ffff7fd521e in dl_open_worker (a=a@entry=0x7fff32614440) at ./elf/dl-open.c:808
#11 0x00007ffff7efb1da in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#12 0x00007ffff7fd55b8 in _dl_open (file=0x7ffefc02d569 "/workspaces/async-profiler/build/bin/../lib/libasyncProfiler.so", mode=<optimized out>, 
    caller_dlopen=0x7ffff766a254 <os::Linux::dlopen_helper(char const*, char*, int)+36>, nsid=<optimized out>, argc=2, argv=0x7fffffffe228, env=0x7fffffffe240) at ./elf/dl-open.c:884
#13 0x00007ffff7e314b8 in dlopen_doit (a=a@entry=0x7fff326146b0) at ./dlfcn/dlopen.c:56
#14 0x00007ffff7efb1da in __GI__dl_catch_exception (exception=exception@entry=0x7fff32614610, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#15 0x00007ffff7efb28f in __GI__dl_catch_error (objname=0x7fff32614668, errstring=0x7fff32614670, mallocedp=0x7fff32614667, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:227
#16 0x00007ffff7e30fa7 in _dlerror_run (operate=operate@entry=0x7ffff7e31460 <dlopen_doit>, args=args@entry=0x7fff326146b0) at ./dlfcn/dlerror.c:138
#17 0x00007ffff7e31569 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at ./dlfcn/dlopen.c:71
#18 ___dlopen (file=<optimized out>, mode=<optimized out>) at ./dlfcn/dlopen.c:81
#19 0x00007ffff766a254 in os::Linux::dlopen_helper(char const*, char*, int) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#20 0x00007ffff766a4de in os::dll_load(char const*, char*, int) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#21 0x00007ffff746adf4 in JvmtiExport::load_agent_library(char const*, char const*, char const*, outputStream*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#22 0x00007ffff6e58589 in attach_listener_thread_entry(JavaThread*, JavaThread*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#23 0x00007ffff78dd8af in JavaThread::thread_main_inner() () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#24 0x00007ffff78e10d5 in Thread::call_run() () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#25 0x00007ffff7669b53 in thread_native_entry(Thread*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#26 0x00007ffff7e351f5 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#27 0x00007ffff7eb589c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
#0  VM::init (vm=0x7ffff7d214e0 <main_vm>, attach=true) at src/vmEntry.cpp:139
#1  0x00007fff31c87a24 in Agent_OnAttach (vm=0x7ffff7d214e0 <main_vm>, options=0x7ffefc02dd6b "start,file=/tmp/asprof.42984.42741,collapsed,log=/tmp/asprof-log.42984.42741", reserved=0x0)
    at src/vmEntry.cpp:494
#2  0x00007ffff746afa3 in JvmtiExport::load_agent_library(char const*, char const*, char const*, outputStream*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#3  0x00007ffff6e58589 in attach_listener_thread_entry(JavaThread*, JavaThread*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#4  0x00007ffff78dd8af in JavaThread::thread_main_inner() () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#5  0x00007ffff78e10d5 in Thread::call_run() () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#6  0x00007ffff7669b53 in thread_native_entry(Thread*) () from /usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so
#7  0x00007ffff7e351f5 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#8  0x00007ffff7eb589c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Async-profiler version

master

Environment details

Tested with JDK8 and JDK17, the behavior does not seem to depend on the version.

Activity

  1. fandreuz
    added
    bug
    on Jan 14, 2026
  2. apangin commented on Jan 15, 2026

    @apangin
    apangin
    on Jan 15, 2026
    Collaborator
    More actions

    Nice catch, thanks.
    I think the workaround for JDK-8313796 is not relevant anymore and can be safely removed, since the bug has been fixed in the JDK, and async-profiler has switched to vm stack walker.
    As to _has_class_loader_data detection, it can be moved to VMStructs::ready().

    Reacted by Francesco Andreuzzi
  3. apangin
    closed this as completedin #1658on Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.