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 |
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); |