changeset 59289:40c00294e1df nestmates

Summary: Fix symbol count issue in classFileParser.cpp when changing _class_name. Reviewed-by: lfoltan, mchung, coleenp
author hseigel
date Mon, 23 Mar 2020 17:05:02 +0000
parents 65bc09903227
children 130434292f7a
files src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/classfile/classFileParser.hpp
diffstat 2 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Fri Mar 20 14:26:50 2020 -0700
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Mon Mar 23 17:05:02 2020 +0000
@@ -5881,6 +5881,17 @@
   debug_only(ik->verify();)
 }
 
+void ClassFileParser::update_class_name(Symbol* new_class_name) {
+  // Decrement the refcount in the old name, since we're clobbering it.
+  _class_name->decrement_refcount();
+
+  _class_name = new_class_name;
+  // Increment the refcount of the new name.
+  // Now the ClassFileParser owns this name and will decrement in
+  // the destructor.
+  _class_name->increment_refcount();
+}
+
 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
 // package by prepending its host class's package name to its class name and setting
 // its _class_name field.
@@ -6295,9 +6306,7 @@
     char* new_name = NEW_RESOURCE_ARRAY(char, new_name_len);
     jio_snprintf(new_name, new_name_len, "%s+%s",
                  _class_name->as_C_string(), addr_buf);
-    _class_name->decrement_refcount();
-    _class_name = SymbolTable::new_symbol(new_name);
-    _class_name->increment_refcount();
+    update_class_name(SymbolTable::new_symbol(new_name));
 
     // Add a Utf8 entry containing the hidden name.
     assert(_class_name != NULL, "Unexpected null _class_name");
@@ -6320,11 +6329,8 @@
   // package.  Otherwise, throw IAE if it is in a different package than
   // its host class.
   } else if (_unsafe_anonymous_host != NULL) {
-    Symbol* old_class_name = _class_name;
-    _class_name = class_name_in_cp;
-    _class_name->increment_refcount();
+    update_class_name(class_name_in_cp);
     fix_unsafe_anonymous_class_name(CHECK);
-    old_class_name->decrement_refcount();
 
   } else {
     // Check if name in class file matches given name
@@ -6341,8 +6347,7 @@
       } else {
         // The class name was not known by the caller so we set it from
         // the value in the CP.
-        _class_name = class_name_in_cp;
-        _class_name->increment_refcount();
+        update_class_name(class_name_in_cp);
       }
       // else nothing to do: the expected class name matches what is in the CP
     }
--- a/src/hotspot/share/classfile/classFileParser.hpp	Fri Mar 20 14:26:50 2020 -0700
+++ b/src/hotspot/share/classfile/classFileParser.hpp	Mon Mar 23 17:05:02 2020 +0000
@@ -531,6 +531,8 @@
                      FieldLayoutInfo* info,
                      TRAPS);
 
+  void update_class_name(Symbol* new_name);
+
  public:
   ClassFileParser(ClassFileStream* stream,
                   Symbol* name,