< prev index next >

src/share/vm/classfile/stringTable.cpp

Print this page


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/compactHashtable.inline.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/gcLocker.inline.hpp"
  33 #include "logging/log.hpp"
  34 #include "memory/allocation.inline.hpp"
  35 #include "memory/filemap.hpp"

  36 #include "memory/resourceArea.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/mutexLocker.hpp"
  40 #include "utilities/hashtable.inline.hpp"
  41 #include "utilities/macros.hpp"
  42 #if INCLUDE_ALL_GCS
  43 #include "gc/g1/g1CollectedHeap.hpp"
  44 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  45 #include "gc/g1/g1StringDedup.hpp"
  46 #endif
  47 
  48 // the number of buckets a thread claims
  49 const int ClaimChunkSize = 32;
  50 
  51 #ifdef ASSERT
  52 class StableMemoryChecker : public StackObj {
  53   enum { _bufsize = wordSize*4 };
  54 
  55   address _region;


 713       if (new_s == NULL) {
 714         return false;
 715       }
 716 
 717       s->identity_hash();
 718       v->identity_hash();
 719 
 720       // copy the objects' data
 721       Copy::aligned_disjoint_words((HeapWord*)s, (HeapWord*)new_s, s_len);
 722       Copy::aligned_disjoint_words((HeapWord*)v, (HeapWord*)new_v, v_len);
 723 
 724       // adjust the pointer to the 'value' field in the new String oop. Also pre-compute and set the
 725       // 'hash' field. That avoids "write" to the shared strings at runtime by the deduplication process.
 726       java_lang_String::set_value_raw(new_s, new_v);
 727       if (java_lang_String::hash(new_s) == 0) {
 728         java_lang_String::set_hash(new_s, hash);
 729       }
 730 
 731       // add to the compact table
 732       writer->add(hash, new_s);



 733     }
 734   }
 735 
 736   G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity());
 737   assert(string_space->length() <= 2, "sanity");
 738 #endif
 739   return true;
 740 }
 741 
 742 void StringTable::serialize(SerializeClosure* soc, GrowableArray<MemRegion> *string_space,
 743                             size_t* space_size) {
 744 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
 745   _shared_table.reset();
 746   if (soc->writing()) {
 747     if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) {
 748       log_info(cds)(
 749           "Shared strings are excluded from the archive as UseG1GC, "
 750           "UseCompressedOops and UseCompressedClassPointers are required."
 751           "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.",
 752           BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops),
 753           BOOL_TO_STR(UseCompressedClassPointers));
 754     } else {
 755       int num_buckets = the_table()->number_of_entries() /
 756                              SharedSymbolTableBucketSize;
 757       // calculation of num_buckets can result in zero buckets, we need at least one
 758       CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1,
 759                                       &MetaspaceShared::stats()->string);
 760 
 761       // Copy the interned strings into the "string space" within the java heap
 762       if (copy_shared_string(string_space, &writer)) {
 763         for (int i = 0; i < string_space->length(); i++) {
 764           *space_size += string_space->at(i).byte_size();
 765         }
 766         writer.dump(&_shared_table);
 767       }
 768     }
 769   }

 770 


 771   _shared_table.set_type(CompactHashtable<oop, char>::_string_table);
 772   _shared_table.serialize(soc);
 773 
 774   if (soc->writing()) {
 775     _shared_table.reset(); // Sanity. Make sure we don't use the shared table at dump time
 776   } else if (_ignore_shared_strings) {
 777     _shared_table.reset();
 778   }
 779 #endif
 780 }
 781 
 782 void StringTable::shared_oops_do(OopClosure* f) {
 783 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
 784   _shared_table.oops_do(f);
 785 #endif
 786 }
 787 


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/compactHashtable.inline.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/gcLocker.inline.hpp"
  33 #include "logging/log.hpp"
  34 #include "memory/allocation.inline.hpp"
  35 #include "memory/filemap.hpp"
  36 #include "memory/metaspaceShared.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/atomic.hpp"
  40 #include "runtime/mutexLocker.hpp"
  41 #include "utilities/hashtable.inline.hpp"
  42 #include "utilities/macros.hpp"
  43 #if INCLUDE_ALL_GCS
  44 #include "gc/g1/g1CollectedHeap.hpp"
  45 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  46 #include "gc/g1/g1StringDedup.hpp"
  47 #endif
  48 
  49 // the number of buckets a thread claims
  50 const int ClaimChunkSize = 32;
  51 
  52 #ifdef ASSERT
  53 class StableMemoryChecker : public StackObj {
  54   enum { _bufsize = wordSize*4 };
  55 
  56   address _region;


 714       if (new_s == NULL) {
 715         return false;
 716       }
 717 
 718       s->identity_hash();
 719       v->identity_hash();
 720 
 721       // copy the objects' data
 722       Copy::aligned_disjoint_words((HeapWord*)s, (HeapWord*)new_s, s_len);
 723       Copy::aligned_disjoint_words((HeapWord*)v, (HeapWord*)new_v, v_len);
 724 
 725       // adjust the pointer to the 'value' field in the new String oop. Also pre-compute and set the
 726       // 'hash' field. That avoids "write" to the shared strings at runtime by the deduplication process.
 727       java_lang_String::set_value_raw(new_s, new_v);
 728       if (java_lang_String::hash(new_s) == 0) {
 729         java_lang_String::set_hash(new_s, hash);
 730       }
 731 
 732       // add to the compact table
 733       writer->add(hash, new_s);
 734 
 735       MetaspaceShared::relocate_klass_ptr(new_s);
 736       MetaspaceShared::relocate_klass_ptr(new_v);
 737     }
 738   }
 739 
 740   G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity());
 741   assert(string_space->length() <= 2, "sanity");
 742 #endif
 743   return true;
 744 }
 745 
 746 void StringTable::write_to_archive(GrowableArray<MemRegion> *string_space,
 747                                    size_t* space_size) {
 748 #if INCLUDE_CDS
 749   _shared_table.reset();

 750   if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) {
 751       log_info(cds)(
 752         "Shared strings are excluded from the archive as UseG1GC, "
 753         "UseCompressedOops and UseCompressedClassPointers are required."
 754         "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.",
 755         BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops),
 756         BOOL_TO_STR(UseCompressedClassPointers));
 757   } else {
 758     int num_buckets = the_table()->number_of_entries() /
 759                            SharedSymbolTableBucketSize;
 760     // calculation of num_buckets can result in zero buckets, we need at least one
 761     CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1,
 762                                     &MetaspaceShared::stats()->string);
 763 
 764     // Copy the interned strings into the "string space" within the java heap
 765     if (copy_shared_string(string_space, &writer)) {
 766       for (int i = 0; i < string_space->length(); i++) {
 767         *space_size += string_space->at(i).byte_size();
 768       }
 769       writer.dump(&_shared_table);
 770     }
 771   }
 772 #endif
 773 }
 774 
 775 void StringTable::serialize(SerializeClosure* soc) {
 776 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
 777   _shared_table.set_type(CompactHashtable<oop, char>::_string_table);
 778   _shared_table.serialize(soc);
 779 
 780   if (soc->writing()) {
 781     _shared_table.reset(); // Sanity. Make sure we don't use the shared table at dump time
 782   } else if (_ignore_shared_strings) {
 783     _shared_table.reset();
 784   }
 785 #endif
 786 }
 787 
 788 void StringTable::shared_oops_do(OopClosure* f) {
 789 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
 790   _shared_table.oops_do(f);
 791 #endif
 792 }
 793 
< prev index next >