1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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 #ifndef SHARE_VM_GC_CMS_CMSHEAP_HPP
  26 #define SHARE_VM_GC_CMS_CMSHEAP_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/gcCause.hpp"
  30 #include "gc/shared/genCollectedHeap.hpp"
  31 
  32 class CLDClosure;
  33 class GenCollectorPolicy;
  34 class OopsInGenClosure;
  35 class outputStream;
  36 class StrongRootsScope;
  37 class ThreadClosure;
  38 class WorkGang;
  39 
  40 class CMSHeap : public GenCollectedHeap {
  41 public:
  42   CMSHeap(GenCollectorPolicy *policy);
  43 
  44   // Returns JNI_OK on success
  45   virtual jint initialize();
  46 
  47   virtual void check_gen_kinds();
  48 
  49   // Convenience function to be used in situations where the heap type can be
  50   // asserted to be this type.
  51   static CMSHeap* heap();
  52 
  53   virtual Name kind() const {
  54     return CollectedHeap::CMSHeap;
  55   }
  56 
  57   virtual const char* name() const {
  58     return "Concurrent Mark Sweep";
  59   }
  60 
  61   WorkGang* workers() const { return _workers; }
  62 
  63   virtual void print_gc_threads_on(outputStream* st) const;
  64   virtual void gc_threads_do(ThreadClosure* tc) const;
  65   virtual void print_on_error(outputStream* st) const;
  66 
  67   // Perform a full collection of the heap; intended for use in implementing
  68   // "System.gc". This implies as full a collection as the CollectedHeap
  69   // supports. Caller does not hold the Heap_lock on entry.
  70   void collect(GCCause::Cause cause);
  71 
  72   bool is_in_closed_subset(const void* p) const {
  73     return is_in_reserved(p);
  74   }
  75 
  76   bool card_mark_must_follow_store() const {
  77     return true;
  78   }
  79 
  80   void stop();
  81 
  82   // If "young_gen_as_roots" is false, younger generations are
  83   // not scanned as roots; in this case, the caller must be arranging to
  84   // scan the younger generations itself.  (For example, a generation might
  85   // explicitly mark reachable objects in younger generations, to avoid
  86   // excess storage retention.)
  87   void cms_process_roots(StrongRootsScope* scope,
  88                          bool young_gen_as_roots,
  89                          ScanningOption so,
  90                          bool only_strong_roots,
  91                          OopsInGenClosure* root_closure,
  92                          CLDClosure* cld_closure);
  93 
  94 private:
  95   WorkGang* _workers;
  96 
  97   virtual void gc_prologue(bool full);
  98   virtual void gc_epilogue(bool full);
  99 
 100   // Accessor for memory state verification support
 101   NOT_PRODUCT(
 102     virtual size_t skip_header_HeapWords() { return CMSCollector::skip_header_HeapWords(); }
 103   )
 104 
 105   // Returns success or failure.
 106   void create_cms_collector();
 107 
 108   // In support of ExplicitGCInvokesConcurrent functionality
 109   bool should_do_concurrent_full_gc(GCCause::Cause cause);
 110 
 111   void collect_mostly_concurrent(GCCause::Cause cause);
 112 };
 113 
 114 #endif // SHARE_VM_GC_CMS_CMSHEAP_HPP