< prev index next >

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Print this page

        

@@ -31,11 +31,10 @@
 #include "gc/g1/bufferingOopClosure.hpp"
 #include "gc/g1/concurrentMarkThread.inline.hpp"
 #include "gc/g1/g1Allocator.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1CollectionSet.hpp"
-#include "gc/g1/g1CollectorPolicy.hpp"
 #include "gc/g1/g1CollectorState.hpp"
 #include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/g1ConcurrentRefineThread.hpp"
 #include "gc/g1/g1EvacStats.inline.hpp"
 #include "gc/g1/g1FullCollector.hpp"

@@ -66,10 +65,11 @@
 #include "gc/shared/gcTrace.hpp"
 #include "gc/shared/gcTraceTime.inline.hpp"
 #include "gc/shared/generationSpec.hpp"
 #include "gc/shared/isGCActiveMark.hpp"
 #include "gc/shared/preservedMarks.inline.hpp"
+#include "gc/shared/softRefPolicy.hpp"
 #include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/shared/referenceProcessor.inline.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
 #include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"

@@ -1166,11 +1166,11 @@
     // Full GC was not completed.
     return false;
   }
 
   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
-      collector_policy()->should_clear_all_soft_refs();
+      soft_ref_policy()->should_clear_all_soft_refs();
 
   G1FullCollector collector(this, &_full_gc_memory_manager, explicit_gc, do_clear_all_soft_refs);
   GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause(), true);
 
   collector.prepare_collection();

@@ -1203,22 +1203,19 @@
   const double minimum_free_percentage = (double) MinHeapFreeRatio / 100.0;
   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
   const double maximum_free_percentage = (double) MaxHeapFreeRatio / 100.0;
   const double minimum_used_percentage = 1.0 - maximum_free_percentage;
 
-  const size_t min_heap_size = collector_policy()->min_heap_byte_size();
-  const size_t max_heap_size = collector_policy()->max_heap_byte_size();
-
   // We have to be careful here as these two calculations can overflow
   // 32-bit size_t's.
   double used_after_gc_d = (double) used_after_gc;
   double minimum_desired_capacity_d = used_after_gc_d / maximum_used_percentage;
   double maximum_desired_capacity_d = used_after_gc_d / minimum_used_percentage;
 
   // Let's make sure that they are both under the max heap size, which
   // by default will make them fit into a size_t.
-  double desired_capacity_upper_bound = (double) max_heap_size;
+  double desired_capacity_upper_bound = (double) _settings._max_heap_byte_size;
   minimum_desired_capacity_d = MIN2(minimum_desired_capacity_d,
                                     desired_capacity_upper_bound);
   maximum_desired_capacity_d = MIN2(maximum_desired_capacity_d,
                                     desired_capacity_upper_bound);
 

@@ -1234,15 +1231,15 @@
          minimum_desired_capacity, maximum_desired_capacity);
 
   // Should not be greater than the heap max size. No need to adjust
   // it with respect to the heap min size as it's a lower bound (i.e.,
   // we'll try to make the capacity larger than it, not smaller).
-  minimum_desired_capacity = MIN2(minimum_desired_capacity, max_heap_size);
+  minimum_desired_capacity = MIN2(minimum_desired_capacity, _settings._max_heap_byte_size);
   // Should not be less than the heap min size. No need to adjust it
   // with respect to the heap max size as it's an upper bound (i.e.,
   // we'll try to make the capacity smaller than it, not greater).
-  maximum_desired_capacity =  MAX2(maximum_desired_capacity, min_heap_size);
+  maximum_desired_capacity =  MAX2(maximum_desired_capacity, _settings._min_heap_byte_size);
 
   if (capacity_after_gc < minimum_desired_capacity) {
     // Don't expand unless it's significant
     size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
 

@@ -1341,11 +1338,11 @@
 
   if (result != NULL) {
     return result;
   }
 
-  assert(!collector_policy()->should_clear_all_soft_refs(),
+  assert(!soft_ref_policy()->should_clear_all_soft_refs(),
          "Flag should have been handled and cleared prior to this point");
 
   // What else?  We might try synchronous finalization later.  If the total
   // space available is large enough for the allocation, then a more
   // complete compaction phase than we've tried so far might be

@@ -1457,14 +1454,14 @@
   _verifier->verify_region_sets_optional();
 }
 
 // Public methods.
 
-G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* collector_policy) :
+G1CollectedHeap::G1CollectedHeap(const G1Settings& settings) :
   CollectedHeap(),
+  _settings(settings),
   _young_gen_sampling_thread(NULL),
-  _collector_policy(collector_policy),
   _memory_manager("G1 Young Generation", "end of minor GC"),
   _full_gc_memory_manager("G1 Old Generation", "end of major GC"),
   _eden_pool(NULL),
   _survivor_pool(NULL),
   _old_pool(NULL),

@@ -1584,18 +1581,14 @@
   // system which believe this to be true (e.g. oop->object_size in some
   // cases incorrectly returns the size in wordSize units rather than
   // HeapWordSize).
   guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
 
-  size_t init_byte_size = collector_policy()->initial_heap_byte_size();
-  size_t max_byte_size = collector_policy()->max_heap_byte_size();
-  size_t heap_alignment = collector_policy()->heap_alignment();
-
   // Ensure that the sizes are properly aligned.
-  Universe::check_alignment(init_byte_size, HeapRegion::GrainBytes, "g1 heap");
-  Universe::check_alignment(max_byte_size, HeapRegion::GrainBytes, "g1 heap");
-  Universe::check_alignment(max_byte_size, heap_alignment, "g1 heap");
+  Universe::check_alignment(_settings._initial_heap_byte_size, HeapRegion::GrainBytes, "g1 heap");
+  Universe::check_alignment(_settings._max_heap_byte_size, HeapRegion::GrainBytes, "g1 heap");
+  Universe::check_alignment(_settings._max_heap_byte_size, _settings._heap_alignment, "g1 heap");
 
   // Reserve the maximum.
 
   // When compressed oops are enabled, the preferred heap base
   // is calculated by subtracting the requested size from the

@@ -1606,12 +1599,11 @@
   // base of the reserved heap may end up differing from the
   // address that was requested (i.e. the preferred heap base).
   // If this happens then we could end up using a non-optimal
   // compressed oops mode.
 
-  ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size,
-                                                 heap_alignment);
+  ReservedSpace heap_rs = Universe::reserve_heap(_settings._max_heap_byte_size, _settings._heap_alignment);
 
   initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size()));
 
   // Create the barrier set for the entire reserved region.
   G1SATBCardTableLoggingModRefBS* bs

@@ -1622,22 +1614,22 @@
 
   // Create the hot card cache.
   _hot_card_cache = new G1HotCardCache(this);
 
   // Carve out the G1 part of the heap.
-  ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
+  ReservedSpace g1_rs = heap_rs.first_part(_settings._max_heap_byte_size);
   size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
   G1RegionToSpaceMapper* heap_storage =
     G1RegionToSpaceMapper::create_mapper(g1_rs,
                                          g1_rs.size(),
                                          page_size,
                                          HeapRegion::GrainBytes,
                                          1,
                                          mtJavaHeap);
   os::trace_page_sizes("Heap",
-                       collector_policy()->min_heap_byte_size(),
-                       max_byte_size,
+                       _settings._min_heap_byte_size,
+                       _settings._max_heap_byte_size,
                        page_size,
                        heap_rs.base(),
                        heap_rs.size());
   heap_storage->set_mapping_changed_listener(&_listener);
 

@@ -1703,11 +1695,11 @@
     return JNI_ENOMEM;
   }
   _cmThread = _cm->cm_thread();
 
   // Now expand into the initial heap size.
-  if (!expand(init_byte_size, _workers)) {
+  if (!expand(_settings._initial_heap_byte_size, _workers)) {
     vm_shutdown_during_initialization("Failed to allocate initial heap.");
     return JNI_ENOMEM;
   }
 
   // Perform any initialization actions delegated to the policy.

@@ -1887,14 +1879,10 @@
                            &_is_alive_closure_stw);
                                 // is alive closure
                                 // (for efficiency/performance)
 }
 
-CollectorPolicy* G1CollectedHeap::collector_policy() const {
-  return _collector_policy;
-}
-
 size_t G1CollectedHeap::capacity() const {
   return _hrm.length() * HeapRegion::GrainBytes;
 }
 
 size_t G1CollectedHeap::unused_committed_regions_in_bytes() const {

@@ -2263,10 +2251,18 @@
 
 size_t G1CollectedHeap::max_capacity() const {
   return _hrm.reserved().byte_size();
 }
 
+size_t G1CollectedHeap::space_alignment() const {
+  return _settings._space_alignment;
+}
+
+size_t G1CollectedHeap::heap_alignment() const {
+  return _settings._heap_alignment;
+}
+
 jlong G1CollectedHeap::millis_since_last_gc() {
   // See the notes in GenCollectedHeap::millis_since_last_gc()
   // for more information about the implementation.
   jlong ret_val = (os::javaTimeNanos() / NANOSECS_PER_MILLISEC) -
     _g1_policy->collection_pause_end_millis();
< prev index next >