8362203: assert(state == nullptr || state->get_thread_oop() != nullptr) failed: incomplete state

Reviewed-by: sspitsyn, amenkov
This commit is contained in:
Leonid Mesnik 2025-07-17 16:25:40 +00:00
parent 2b11a28997
commit bd55d7a495
4 changed files with 19 additions and 3 deletions

View File

@ -675,6 +675,13 @@ void JvmtiExport::post_early_vm_start() {
void JvmtiExport::post_vm_start() {
EVT_TRIG_TRACE(JVMTI_EVENT_VM_START, ("Trg VM start event triggered" ));
// The JvmtiThreadState is incomplete if initialized in post_early_vm_start
// before classes are initialized. It should be updated now.
JavaThread *thread = JavaThread::current();
if (thread->jvmti_thread_state() != nullptr) {
thread->jvmti_thread_state()->update_thread_oop_during_vm_start();
}
// can now enable some events
JvmtiEventController::vm_start();
@ -684,7 +691,6 @@ void JvmtiExport::post_vm_start() {
if (!env->early_vmstart_env() && env->is_enabled(JVMTI_EVENT_VM_START)) {
EVT_TRACE(JVMTI_EVENT_VM_START, ("Evt VM start event sent" ));
JavaThread *thread = JavaThread::current();
JvmtiThreadEventMark jem(thread);
JvmtiJavaThreadEventTransition jet(thread);
jvmtiEventVMStart callback = env->callbacks()->VMStart;

View File

@ -1041,6 +1041,13 @@ oop JvmtiThreadState::get_thread_oop() {
return _thread_oop_h.resolve();
}
void JvmtiThreadState::update_thread_oop_during_vm_start() {
assert(_thread->threadObj() != nullptr, "santity check");
if (get_thread_oop() == nullptr) {
_thread_oop_h.replace(_thread->threadObj());
}
}
void JvmtiThreadState::set_thread(JavaThread* thread) {
_thread_saved = nullptr; // Common case.
if (!_is_virtual && thread == nullptr) {

View File

@ -312,6 +312,8 @@ class JvmtiThreadState : public CHeapObj<mtInternal> {
void set_thread(JavaThread* thread);
oop get_thread_oop();
void update_thread_oop_during_vm_start();
inline bool is_virtual() { return _is_virtual; } // the _thread is virtual
inline bool is_exception_detected() { return _exception_state == ES_DETECTED; }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,12 +23,13 @@
/**
* @test
* @bug 8172970
* @bug 8172970 8362203
* @summary Verify the functions that are allowed to operate in the start phase
* with and without can_generate_early_vmstart capability.
* @requires vm.jvmti
* @run main/othervm/native -agentlib:AllowedFunctions AllowedFunctions
* @run main/othervm/native -agentlib:AllowedFunctions=with_early_vmstart AllowedFunctions
* @run main/othervm/native -agentlib:AllowedFunctions=with_early_vmstart -Xrunjdwp:transport=dt_socket,address=0,server=y,suspend=n AllowedFunctions
*/
public class AllowedFunctions {