提交 52087b0d 编写于 作者: S shade

8059677: Thread.getName() instantiates Strings

Reviewed-by: coleenp, dholmes, sla
上级 5abb9f95
/*
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2016, 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
......@@ -219,7 +219,7 @@ public class OopUtilities implements /* imports */ JVMTIThreadState {
if (threadNameField == null) {
SystemDictionary sysDict = VM.getVM().getSystemDictionary();
InstanceKlass k = sysDict.getThreadKlass();
threadNameField = (OopField) k.findField("name", "[C");
threadNameField = (OopField) k.findField("name", "Ljava/lang/String;");
threadGroupField = (OopField) k.findField("group", "Ljava/lang/ThreadGroup;");
threadEETopField = (LongField) k.findField("eetop", "J");
threadTIDField = (LongField) k.findField("tid", "J");
......@@ -258,7 +258,7 @@ public class OopUtilities implements /* imports */ JVMTIThreadState {
public static String threadOopGetName(Oop threadOop) {
initThreadFields();
return charArrayToString((TypeArray) threadNameField.getValue(threadOop));
return stringOopToString(threadNameField.getValue(threadOop));
}
/** May return null if, e.g., thread was not started */
......
/*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2016, 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
......@@ -936,7 +936,7 @@ void java_lang_Thread::compute_offsets() {
assert(_group_offset == 0, "offsets should be initialized only once");
Klass* k = SystemDictionary::Thread_klass();
compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::char_array_signature());
compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature());
compute_offset(_group_offset, k, vmSymbols::group_name(), vmSymbols::threadgroup_signature());
compute_offset(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), vmSymbols::classloader_signature());
compute_offset(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), vmSymbols::accesscontrolcontext_signature());
......@@ -966,15 +966,12 @@ void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) {
}
typeArrayOop java_lang_Thread::name(oop java_thread) {
oop name = java_thread->obj_field(_name_offset);
assert(name == NULL || (name->is_typeArray() && TypeArrayKlass::cast(name->klass())->element_type() == T_CHAR), "just checking");
return typeArrayOop(name);
oop java_lang_Thread::name(oop java_thread) {
return java_thread->obj_field(_name_offset);
}
void java_lang_Thread::set_name(oop java_thread, typeArrayOop name) {
assert(java_thread->obj_field(_name_offset) == NULL, "name should be NULL");
void java_lang_Thread::set_name(oop java_thread, oop name) {
java_thread->obj_field_put(_name_offset, name);
}
......
/*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2016, 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
......@@ -343,8 +343,8 @@ class java_lang_Thread : AllStatic {
// Set JavaThread for instance
static void set_thread(oop java_thread, JavaThread* thread);
// Name
static typeArrayOop name(oop java_thread);
static void set_name(oop java_thread, typeArrayOop name);
static oop name(oop java_thread);
static void set_name(oop java_thread, oop name);
// Priority
static ThreadPriority priority(oop java_thread);
static void set_priority(oop java_thread, ThreadPriority priority);
......
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2016, 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
......@@ -946,7 +946,7 @@ JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
return JVMTI_ERROR_INVALID_THREAD;
Handle thread_obj(current_thread, thread_oop);
typeArrayHandle name;
Handle name;
ThreadPriority priority;
Handle thread_group;
Handle context_class_loader;
......@@ -954,7 +954,7 @@ JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
{ MutexLocker mu(Threads_lock);
name = typeArrayHandle(current_thread, java_lang_Thread::name(thread_obj()));
name = Handle(current_thread, java_lang_Thread::name(thread_obj()));
priority = java_lang_Thread::priority(thread_obj());
thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj()));
is_daemon = java_lang_Thread::is_daemon(thread_obj());
......@@ -965,7 +965,7 @@ JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
{ const char *n;
if (name() != NULL) {
n = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
n = java_lang_String::as_utf8_string(name());
} else {
n = UNICODE::as_utf8(NULL, 0);
}
......
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2016, 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
......@@ -266,11 +266,11 @@ const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
if (threadObj == NULL) {
return "NULL";
}
typeArrayOop name = java_lang_Thread::name(threadObj);
oop name = java_lang_Thread::name(threadObj);
if (name == NULL) {
return "<NOT FILLED IN>";
}
return UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
return java_lang_String::as_utf8_string(name);
}
......
/*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2016, 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
......@@ -2926,13 +2926,13 @@ const char* JavaThread::get_thread_name_string(char* buf, int buflen) const {
const char* name_str;
oop thread_obj = threadObj();
if (thread_obj != NULL) {
typeArrayOop name = java_lang_Thread::name(thread_obj);
oop name = java_lang_Thread::name(thread_obj);
if (name != NULL) {
if (buf == NULL) {
name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
name_str = java_lang_String::as_utf8_string(name);
}
else {
name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen);
name_str = java_lang_String::as_utf8_string(name, buf, buflen);
}
}
else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册