8059677: Thread.getName() instantiates Strings
authorshade
Thu, 13 Nov 2014 01:57:09 +0300
changeset 27654 4e508c2376f7
parent 27621 854d2d4d3077
child 27655 8b23ee35ec75
child 27661 1ab3ff7fdd27
8059677: Thread.getName() instantiates Strings Reviewed-by: coleenp, dholmes, sla
hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java
hotspot/src/share/vm/classfile/javaClasses.cpp
hotspot/src/share/vm/classfile/javaClasses.hpp
hotspot/src/share/vm/prims/jvmtiEnv.cpp
hotspot/src/share/vm/prims/jvmtiTrace.cpp
hotspot/src/share/vm/runtime/thread.cpp
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java	Thu Nov 13 01:57:09 2014 +0300
@@ -219,7 +219,7 @@
     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 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 */
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp	Thu Nov 13 01:57:09 2014 +0300
@@ -944,7 +944,7 @@
   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());
@@ -974,15 +974,12 @@
 }
 
 
-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);
-}
-
-
-void java_lang_Thread::set_name(oop java_thread, typeArrayOop name) {
-  assert(java_thread->obj_field(_name_offset) == NULL, "name should be NULL");
+oop java_lang_Thread::name(oop java_thread) {
+  return java_thread->obj_field(_name_offset);
+}
+
+
+void java_lang_Thread::set_name(oop java_thread, oop name) {
   java_thread->obj_field_put(_name_offset, name);
 }
 
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp	Thu Nov 13 01:57:09 2014 +0300
@@ -345,8 +345,8 @@
   // 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);
--- a/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Thu Nov 13 01:57:09 2014 +0300
@@ -942,7 +942,7 @@
     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;
@@ -950,7 +950,7 @@
 
   { 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());
@@ -961,7 +961,7 @@
   { 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);
     }
--- a/hotspot/src/share/vm/prims/jvmtiTrace.cpp	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/src/share/vm/prims/jvmtiTrace.cpp	Thu Nov 13 01:57:09 2014 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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 @@
   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);
 }
 
 
--- a/hotspot/src/share/vm/runtime/thread.cpp	Tue Nov 11 19:42:52 2014 +0000
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Thu Nov 13 01:57:09 2014 +0300
@@ -2872,14 +2872,12 @@
   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
       name_str = "<no-name - thread is attaching>";