comparison src/share/vm/classfile/symbolTable.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 152cf4afc11f
children
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
34 #include "oops/oop.inline.hpp" 34 #include "oops/oop.inline.hpp"
35 #include "oops/oop.inline2.hpp" 35 #include "oops/oop.inline2.hpp"
36 #include "runtime/mutexLocker.hpp" 36 #include "runtime/mutexLocker.hpp"
37 #include "utilities/hashtable.inline.hpp" 37 #include "utilities/hashtable.inline.hpp"
38 #if INCLUDE_ALL_GCS 38 #if INCLUDE_ALL_GCS
39 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
39 #include "gc_implementation/g1/g1StringDedup.hpp" 40 #include "gc_implementation/g1/g1StringDedup.hpp"
40 #endif 41 #endif
41 42
42 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 43 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
43 44
71 } 72 }
72 73
73 void SymbolTable::initialize_symbols(int arena_alloc_size) { 74 void SymbolTable::initialize_symbols(int arena_alloc_size) {
74 // Initialize the arena for global symbols, size passed in depends on CDS. 75 // Initialize the arena for global symbols, size passed in depends on CDS.
75 if (arena_alloc_size == 0) { 76 if (arena_alloc_size == 0) {
76 _arena = new (mtSymbol) Arena(); 77 _arena = new (mtSymbol) Arena(mtSymbol);
77 } else { 78 } else {
78 _arena = new (mtSymbol) Arena(arena_alloc_size); 79 _arena = new (mtSymbol) Arena(mtSymbol, arena_alloc_size);
79 } 80 }
80 } 81 }
81 82
82 // Call function for all symbols in the symbol table. 83 // Call function for all symbols in the symbol table.
83 void SymbolTable::symbols_do(SymbolClosure *cl) { 84 void SymbolTable::symbols_do(SymbolClosure *cl) {
202 return sym; 203 return sym;
203 } 204 }
204 } 205 }
205 } 206 }
206 // If the bucket size is too deep check if this hash code is insufficient. 207 // If the bucket size is too deep check if this hash code is insufficient.
207 if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) { 208 if (count >= rehash_count && !needs_rehashing()) {
208 _needs_rehashing = check_rehash_table(count); 209 _needs_rehashing = check_rehash_table(count);
209 } 210 }
210 return NULL; 211 return NULL;
211 } 212 }
212 213
653 return l->literal(); 654 return l->literal();
654 } 655 }
655 } 656 }
656 } 657 }
657 // If the bucket size is too deep check if this hash code is insufficient. 658 // If the bucket size is too deep check if this hash code is insufficient.
658 if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) { 659 if (count >= rehash_count && !needs_rehashing()) {
659 _needs_rehashing = check_rehash_table(count); 660 _needs_rehashing = check_rehash_table(count);
660 } 661 }
661 return NULL; 662 return NULL;
662 } 663 }
663 664
702 int length; 703 int length;
703 jchar* chars = symbol->as_unicode(length); 704 jchar* chars = symbol->as_unicode(length);
704 return lookup(chars, length); 705 return lookup(chars, length);
705 } 706 }
706 707
708 // Tell the GC that this string was looked up in the StringTable.
709 static void ensure_string_alive(oop string) {
710 // A lookup in the StringTable could return an object that was previously
711 // considered dead. The SATB part of G1 needs to get notified about this
712 // potential resurrection, otherwise the marking might not find the object.
713 #if INCLUDE_ALL_GCS
714 if (UseG1GC && string != NULL) {
715 G1SATBCardTableModRefBS::enqueue(string);
716 }
717 #endif
718 }
707 719
708 oop StringTable::lookup(jchar* name, int len) { 720 oop StringTable::lookup(jchar* name, int len) {
709 unsigned int hash = hash_string(name, len); 721 unsigned int hash = hash_string(name, len);
710 int index = the_table()->hash_to_index(hash); 722 int index = the_table()->hash_to_index(hash);
711 return the_table()->lookup(index, name, len, hash); 723 oop string = the_table()->lookup(index, name, len, hash);
724
725 ensure_string_alive(string);
726
727 return string;
712 } 728 }
713 729
714 730
715 oop StringTable::intern(Handle string_or_null, jchar* name, 731 oop StringTable::intern(Handle string_or_null, jchar* name,
716 int len, TRAPS) { 732 int len, TRAPS) {
717 unsigned int hashValue = hash_string(name, len); 733 unsigned int hashValue = hash_string(name, len);
718 int index = the_table()->hash_to_index(hashValue); 734 int index = the_table()->hash_to_index(hashValue);
719 oop found_string = the_table()->lookup(index, name, len, hashValue); 735 oop found_string = the_table()->lookup(index, name, len, hashValue);
720 736
721 // Found 737 // Found
722 if (found_string != NULL) return found_string; 738 if (found_string != NULL) {
739 ensure_string_alive(found_string);
740 return found_string;
741 }
723 742
724 debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); 743 debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
725 assert(!Universe::heap()->is_in_reserved(name), 744 assert(!Universe::heap()->is_in_reserved(name),
726 "proposed name of symbol must be stable"); 745 "proposed name of symbol must be stable");
727 746
742 } 761 }
743 #endif 762 #endif
744 763
745 // Grab the StringTable_lock before getting the_table() because it could 764 // Grab the StringTable_lock before getting the_table() because it could
746 // change at safepoint. 765 // change at safepoint.
747 MutexLocker ml(StringTable_lock, THREAD); 766 oop added_or_found;
748 767 {
749 // Otherwise, add to symbol to table 768 MutexLocker ml(StringTable_lock, THREAD);
750 return the_table()->basic_add(index, string, name, len, 769 // Otherwise, add to symbol to table
751 hashValue, CHECK_NULL); 770 added_or_found = the_table()->basic_add(index, string, name, len,
771 hashValue, CHECK_NULL);
772 }
773
774 ensure_string_alive(added_or_found);
775
776 return added_or_found;
752 } 777 }
753 778
754 oop StringTable::intern(Symbol* symbol, TRAPS) { 779 oop StringTable::intern(Symbol* symbol, TRAPS) {
755 if (symbol == NULL) return NULL; 780 if (symbol == NULL) return NULL;
756 ResourceMark rm(THREAD); 781 ResourceMark rm(THREAD);