< prev index next >

src/share/vm/memory/universe.cpp

Print this page
rev 8853 : 8133821: Refactor initialization of the heap and the collector policy


 677     // Read the data structures supporting the shared spaces (shared
 678     // system dictionary, symbol table, etc.).  After that, access to
 679     // the file (other than the mapped regions) is no longer needed, and
 680     // the file is closed. Closing the file does not affect the
 681     // currently mapped regions.
 682     MetaspaceShared::initialize_shared_spaces();
 683     StringTable::create_table();
 684   } else {
 685     SymbolTable::create_table();
 686     StringTable::create_table();
 687     ClassLoader::create_package_info_table();
 688 
 689     if (DumpSharedSpaces) {
 690       MetaspaceShared::prepare_for_dumping();
 691     }
 692   }
 693 
 694   return JNI_OK;
 695 }
 696 
 697 template <class Heap, class Policy>
 698 jint Universe::create_heap() {
 699   assert(_collectedHeap == NULL, "Heap already created");
 700   Policy* policy = new Policy();
 701   policy->initialize_all();
 702   _collectedHeap = new Heap(policy);
 703   return _collectedHeap->initialize();
 704 }
 705 
 706 // Choose the heap base address and oop encoding mode
 707 // when compressed oops are used:
 708 // Unscaled  - Use 32-bits oops without encoding when
 709 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 710 // ZeroBased - Use zero based compressed oops with encoding when
 711 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 712 // HeapBased - Use compressed oops with heap base + encoding.
 713 
 714 jint Universe::initialize_heap() {
 715   jint status = JNI_ERR;
 716 
 717 #if !INCLUDE_ALL_GCS
 718   if (UseParallelGC) {
 719     fatal("UseParallelGC not supported in this VM.");
 720   } else if (UseG1GC) {
 721     fatal("UseG1GC not supported in this VM.");
 722   } else if (UseConcMarkSweepGC) {
 723     fatal("UseConcMarkSweepGC not supported in this VM.");
 724 #else
 725   if (UseParallelGC) {
 726     status = Universe::create_heap<ParallelScavengeHeap, GenerationSizer>();
 727   } else if (UseG1GC) {
 728     status = Universe::create_heap<G1CollectedHeap, G1CollectorPolicyExt>();
 729   } else if (UseConcMarkSweepGC) {
 730     status = Universe::create_heap<GenCollectedHeap, ConcurrentMarkSweepPolicy>();
 731 #endif
 732   } else if (UseSerialGC) {
 733     status = Universe::create_heap<GenCollectedHeap, MarkSweepPolicy>();
 734   } else {

 735     ShouldNotReachHere();

















 736   }
 737 

 738   if (status != JNI_OK) {
 739     return status;
 740   }
 741 
 742   ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
 743 
 744 #ifdef _LP64
 745   if (UseCompressedOops) {
 746     // Subtract a page because something can get allocated at heap base.
 747     // This also makes implicit null checking work, because the
 748     // memory+1 page below heap_base needs to cause a signal.
 749     // See needs_explicit_null_check.
 750     // Only set the heap base for compressed oops because it indicates
 751     // compressed oops for pstack code.
 752     if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
 753       // Didn't reserve heap below 4Gb.  Must shift.
 754       Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
 755     }
 756     if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
 757       // Did reserve heap below 32Gb. Can use base == 0;




 677     // Read the data structures supporting the shared spaces (shared
 678     // system dictionary, symbol table, etc.).  After that, access to
 679     // the file (other than the mapped regions) is no longer needed, and
 680     // the file is closed. Closing the file does not affect the
 681     // currently mapped regions.
 682     MetaspaceShared::initialize_shared_spaces();
 683     StringTable::create_table();
 684   } else {
 685     SymbolTable::create_table();
 686     StringTable::create_table();
 687     ClassLoader::create_package_info_table();
 688 
 689     if (DumpSharedSpaces) {
 690       MetaspaceShared::prepare_for_dumping();
 691     }
 692   }
 693 
 694   return JNI_OK;
 695 }
 696 
 697 CollectedHeap* Universe::create_heap() {

 698   assert(_collectedHeap == NULL, "Heap already created");

















 699 #if !INCLUDE_ALL_GCS
 700   if (UseParallelGC) {
 701     fatal("UseParallelGC not supported in this VM.");
 702   } else if (UseG1GC) {
 703     fatal("UseG1GC not supported in this VM.");
 704   } else if (UseConcMarkSweepGC) {
 705     fatal("UseConcMarkSweepGC not supported in this VM.");
 706 #else
 707   if (UseParallelGC) {
 708      return Universe::create_heap_with_policy<ParallelScavengeHeap, GenerationSizer>();
 709   } else if (UseG1GC) {
 710     return Universe::create_heap_with_policy<G1CollectedHeap, G1CollectorPolicyExt>();
 711   } else if (UseConcMarkSweepGC) {
 712     return Universe::create_heap_with_policy<GenCollectedHeap, ConcurrentMarkSweepPolicy>();
 713 #endif
 714   } else if (UseSerialGC) {
 715     return Universe::create_heap_with_policy<GenCollectedHeap, MarkSweepPolicy>();
 716   }
 717 
 718   ShouldNotReachHere();
 719   return NULL;
 720 }
 721 
 722 // Choose the heap base address and oop encoding mode
 723 // when compressed oops are used:
 724 // Unscaled  - Use 32-bits oops without encoding when
 725 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 726 // ZeroBased - Use zero based compressed oops with encoding when
 727 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 728 // HeapBased - Use compressed oops with heap base + encoding.
 729 
 730 jint Universe::initialize_heap() {
 731   jint status = JNI_ERR;
 732 
 733   _collectedHeap = create_heap_ext();
 734   if (_collectedHeap == NULL) {
 735     _collectedHeap = create_heap();
 736   }
 737 
 738   status = _collectedHeap->initialize();
 739   if (status != JNI_OK) {
 740     return status;
 741   }
 742 
 743   ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
 744 
 745 #ifdef _LP64
 746   if (UseCompressedOops) {
 747     // Subtract a page because something can get allocated at heap base.
 748     // This also makes implicit null checking work, because the
 749     // memory+1 page below heap_base needs to cause a signal.
 750     // See needs_explicit_null_check.
 751     // Only set the heap base for compressed oops because it indicates
 752     // compressed oops for pstack code.
 753     if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
 754       // Didn't reserve heap below 4Gb.  Must shift.
 755       Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
 756     }
 757     if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
 758       // Did reserve heap below 32Gb. Can use base == 0;


< prev index next >