Skip to content

Commit 03b7a85

Browse files
committedMay 29, 2024
8332259: JvmtiTrace::safe_get_thread_name fails if current thread is in native state
Reviewed-by: dholmes, sspitsyn
1 parent 43a2f17 commit 03b7a85

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎src/hotspot/share/prims/jvmtiEnter.xsl

+9
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ struct jvmtiInterface_1_ jvmti</xsl:text>
450450
<xsl:value-of select="$space"/>
451451
<xsl:text>PreserveExceptionMark __em(this_thread);</xsl:text>
452452
</xsl:if>
453+
<xsl:value-of select="$space"/>
454+
<xsl:if test="$trace='Trace'">
455+
<xsl:text>if (trace_flags) {</xsl:text>
456+
<xsl:value-of select="$space"/>
457+
<xsl:text> curr_thread_name = JvmtiTrace::safe_get_current_thread_name();</xsl:text>
458+
<xsl:value-of select="$space"/>
459+
<xsl:text>}</xsl:text>
460+
<xsl:value-of select="$space"/>
461+
</xsl:if>
453462
</xsl:if>
454463
</xsl:template>
455464

‎src/hotspot/share/prims/jvmtiTrace.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, 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
@@ -30,6 +30,7 @@
3030
#include "memory/resourceArea.hpp"
3131
#include "prims/jvmtiTrace.hpp"
3232
#include "runtime/javaThread.hpp"
33+
#include "runtime/javaThread.inline.hpp"
3334

3435
//
3536
// class JvmtiTrace
@@ -277,6 +278,12 @@ const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
277278
if (!thread->is_Java_thread()) {
278279
return thread->name();
279280
}
281+
if (Thread::current()->is_Java_thread()) {
282+
JavaThreadState current_state = JavaThread::cast(Thread::current())->thread_state();
283+
if (current_state == _thread_in_native || current_state == _thread_blocked) {
284+
return "not readable";
285+
}
286+
}
280287
JavaThread* java_thread = JavaThread::cast(thread);
281288
oop threadObj = java_thread->jvmti_vthread();
282289
if (threadObj == nullptr) {

0 commit comments

Comments
 (0)