Skip to content

Commit bd55d7a

Browse files
committed
8362203: assert(state == nullptr || state->get_thread_oop() != nullptr) failed: incomplete state
Reviewed-by: sspitsyn, amenkov
1 parent 2b11a28 commit bd55d7a

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/hotspot/share/prims/jvmtiExport.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ void JvmtiExport::post_early_vm_start() {
675675
void JvmtiExport::post_vm_start() {
676676
EVT_TRIG_TRACE(JVMTI_EVENT_VM_START, ("Trg VM start event triggered" ));
677677

678+
// The JvmtiThreadState is incomplete if initialized in post_early_vm_start
679+
// before classes are initialized. It should be updated now.
680+
JavaThread *thread = JavaThread::current();
681+
if (thread->jvmti_thread_state() != nullptr) {
682+
thread->jvmti_thread_state()->update_thread_oop_during_vm_start();
683+
}
684+
678685
// can now enable some events
679686
JvmtiEventController::vm_start();
680687

@@ -684,7 +691,6 @@ void JvmtiExport::post_vm_start() {
684691
if (!env->early_vmstart_env() && env->is_enabled(JVMTI_EVENT_VM_START)) {
685692
EVT_TRACE(JVMTI_EVENT_VM_START, ("Evt VM start event sent" ));
686693

687-
JavaThread *thread = JavaThread::current();
688694
JvmtiThreadEventMark jem(thread);
689695
JvmtiJavaThreadEventTransition jet(thread);
690696
jvmtiEventVMStart callback = env->callbacks()->VMStart;

src/hotspot/share/prims/jvmtiThreadState.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,13 @@ oop JvmtiThreadState::get_thread_oop() {
10411041
return _thread_oop_h.resolve();
10421042
}
10431043

1044+
void JvmtiThreadState::update_thread_oop_during_vm_start() {
1045+
assert(_thread->threadObj() != nullptr, "santity check");
1046+
if (get_thread_oop() == nullptr) {
1047+
_thread_oop_h.replace(_thread->threadObj());
1048+
}
1049+
}
1050+
10441051
void JvmtiThreadState::set_thread(JavaThread* thread) {
10451052
_thread_saved = nullptr; // Common case.
10461053
if (!_is_virtual && thread == nullptr) {

src/hotspot/share/prims/jvmtiThreadState.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class JvmtiThreadState : public CHeapObj<mtInternal> {
312312
void set_thread(JavaThread* thread);
313313
oop get_thread_oop();
314314

315+
void update_thread_oop_during_vm_start();
316+
315317
inline bool is_virtual() { return _is_virtual; } // the _thread is virtual
316318

317319
inline bool is_exception_detected() { return _exception_state == ES_DETECTED; }

test/hotspot/jtreg/serviceability/jvmti/StartPhase/AllowedFunctions/AllowedFunctions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,12 +23,13 @@
2323

2424
/**
2525
* @test
26-
* @bug 8172970
26+
* @bug 8172970 8362203
2727
* @summary Verify the functions that are allowed to operate in the start phase
2828
* with and without can_generate_early_vmstart capability.
2929
* @requires vm.jvmti
3030
* @run main/othervm/native -agentlib:AllowedFunctions AllowedFunctions
3131
* @run main/othervm/native -agentlib:AllowedFunctions=with_early_vmstart AllowedFunctions
32+
* @run main/othervm/native -agentlib:AllowedFunctions=with_early_vmstart -Xrunjdwp:transport=dt_socket,address=0,server=y,suspend=n AllowedFunctions
3233
*/
3334

3435
public class AllowedFunctions {

0 commit comments

Comments
 (0)