src/hotspot/share/classfile/symbolTable.cpp
changeset 54942 2523496f5107
parent 54927 1512d88b24c6
child 55134 72474808e305
child 58678 9cf78a70fa4f
--- a/src/hotspot/share/classfile/symbolTable.cpp	Mon May 20 09:43:46 2019 -0400
+++ b/src/hotspot/share/classfile/symbolTable.cpp	Mon May 20 10:06:07 2019 -0400
@@ -481,14 +481,17 @@
   Thread* THREAD = Thread::current();
 
   do {
+    // Callers have looked up the symbol once, insert the symbol.
+    sym = allocate_symbol(name, len, heap);
+    if (_local_table->insert(THREAD, lookup, sym, &rehash_warning, &clean_hint)) {
+      break;
+    }
+    // In case another thread did a concurrent add, return value already in the table.
+    // This could fail if the symbol got deleted concurrently, so loop back until success.
     if (_local_table->get(THREAD, lookup, stg, &rehash_warning)) {
       sym = stg.get_res_sym();
       break;
     }
-    sym = allocate_symbol(name, len, heap);
-    if (_local_table->insert(THREAD, lookup, sym, &rehash_warning, &clean_hint)) {
-      break;
-    }
   } while(true);
 
   update_needs_rehash(rehash_warning);