On Fri, 14 Aug 2026 01:31:55 GMT, Leonid Mesnik <[email protected]> wrote:
> The class `ThreadSnapshot$ThreadLock` is internal ThreadSnapshot class.
> The `ThreadSnapshot` and `ThreadSnapshot$ThreadLock` are created and filled
> by VM. The objects for `ThreadLock` are
>
> The crash originally appeared when jcmd ThreadDump was called for timed-out
> test `compiler/c2/Test6603011.java`. The test is executed with `-Xcomp
> -XX:-Inline` which is required to reproduce the issue.
> In other cases the klass initialized by interpreter or compiler.
>
> This is why this crash was not find by jcmd test that test how jcmd works for
> monitors.
> created but the class is not initialized.
>
> BTW, the `ThreadSnapshot` is initialized
>
> if (snapshot_klass->should_be_initialized()) {
> snapshot_klass->initialize(CHECK_NULL);
> }
>
>
> Note: `-XX:CompileCommand=compileonly,*ThreadSnapshot*::*` in test is to
> reduce execution time only, test fails without it.
>
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK
> Interim AI Policy](https://openjdk.org/legal/ai).
src/hotspot/share/services/threadService.cpp line 1511:
> 1509: if (lock_klass->should_be_initialized()) {
> 1510: lock_klass->initialize(CHECK_NULL);
> 1511: }
Just before this block is the assignment to lock_klass, and it is only
referenced inside this block. Shouldn't the assignment move into this block so
the scope of lock_klass is limited to this block? In fact I think all of the
following should be moved inside this block:
1502 Symbol* lock_sym = vmSymbols::jdk_internal_vm_ThreadLock();
1503 Klass* lock_k = SystemDictionary::resolve_or_fail(lock_sym, true,
CHECK_NULL);
1504 InstanceKlass* lock_klass = InstanceKlass::cast(lock_k);
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/32363#discussion_r3785937773