8332259: JvmtiTrace::safe_get_thread_name fails if current thread is in native state

Reviewed-by: dholmes, sspitsyn
This commit is contained in:
Leonid Mesnik 2024-05-29 14:59:19 +00:00
parent 43a2f17342
commit 03b7a8586a
2 changed files with 17 additions and 1 deletions

View File

@ -450,6 +450,15 @@ struct jvmtiInterface_1_ jvmti</xsl:text>
<xsl:value-of select="$space"/>
<xsl:text>PreserveExceptionMark __em(this_thread);</xsl:text>
</xsl:if>
<xsl:value-of select="$space"/>
<xsl:if test="$trace='Trace'">
<xsl:text>if (trace_flags) {</xsl:text>
<xsl:value-of select="$space"/>
<xsl:text> curr_thread_name = JvmtiTrace::safe_get_current_thread_name();</xsl:text>
<xsl:value-of select="$space"/>
<xsl:text>}</xsl:text>
<xsl:value-of select="$space"/>
</xsl:if>
</xsl:if>
</xsl:template>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, 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
@ -30,6 +30,7 @@
#include "memory/resourceArea.hpp"
#include "prims/jvmtiTrace.hpp"
#include "runtime/javaThread.hpp"
#include "runtime/javaThread.inline.hpp"
//
// class JvmtiTrace
@ -277,6 +278,12 @@ const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
if (!thread->is_Java_thread()) {
return thread->name();
}
if (Thread::current()->is_Java_thread()) {
JavaThreadState current_state = JavaThread::cast(Thread::current())->thread_state();
if (current_state == _thread_in_native || current_state == _thread_blocked) {
return "not readable";
}
}
JavaThread* java_thread = JavaThread::cast(thread);
oop threadObj = java_thread->jvmti_vthread();
if (threadObj == nullptr) {