1 /*
   2  * Copyright (c) 2001, 2018, 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_G1_VM_OPERATIONS_G1_HPP
  26 #define SHARE_VM_GC_G1_VM_OPERATIONS_G1_HPP
  27 
  28 #include "gc/g1/g1AllocationContext.hpp"
  29 #include "gc/shared/gcId.hpp"
  30 #include "gc/shared/vmGCOperations.hpp"
  31 
  32 // VM_operations for the G1 collector.
  33 // VM_GC_Operation:
  34 //   - VM_CGC_Operation
  35 //   - VM_G1CollectForAllocation
  36 //   - VM_G1CollectFull
  37 
  38 class VM_G1CollectFull: public VM_GC_Operation {
  39 public:
  40   VM_G1CollectFull(uint gc_count_before,
  41                    uint full_gc_count_before,
  42                    GCCause::Cause cause)
  43     : VM_GC_Operation(gc_count_before, cause, full_gc_count_before, true) { }
  44   virtual VMOp_Type type() const { return VMOp_G1CollectFull; }
  45   virtual void doit();
  46   virtual const char* name() const {
  47     return "G1 Full collection";
  48   }
  49 };
  50 
  51 class VM_G1CollectForAllocation: public VM_CollectForAllocation {
  52 private:
  53   bool      _pause_succeeded;
  54   AllocationContext_t _allocation_context;
  55 
  56   bool         _should_initiate_conc_mark;
  57   bool         _should_retry_gc;
  58   double       _target_pause_time_ms;
  59   uint         _old_marking_cycles_completed_before;
  60 public:
  61   VM_G1CollectForAllocation(size_t         word_size,
  62                             uint           gc_count_before,
  63                             GCCause::Cause gc_cause,
  64                             bool           should_initiate_conc_mark,
  65                             double         target_pause_time_ms,
  66                             AllocationContext_t allocation_context);
  67   virtual VMOp_Type type() const { return VMOp_G1CollectForAllocation; }
  68   virtual bool doit_prologue();
  69   virtual void doit();
  70   virtual void doit_epilogue();
  71   virtual const char* name() const {
  72     return "G1 collect for allocation";
  73   }
  74   bool should_retry_gc() const { return _should_retry_gc; }
  75   bool pause_succeeded() { return _pause_succeeded; }
  76 };
  77 
  78 // Concurrent GC stop-the-world operations such as remark and cleanup;
  79 // consider sharing these with CMS's counterparts.
  80 class VM_CGC_Operation: public VM_Operation {
  81   VoidClosure* _cl;
  82   const char*  _printGCMessage;
  83   uint         _gc_id;
  84 
  85 public:
  86   VM_CGC_Operation(VoidClosure* cl, const char *printGCMsg)
  87     : _cl(cl), _printGCMessage(printGCMsg), _gc_id(GCId::current()) {}
  88   virtual VMOp_Type type() const { return VMOp_CGC_Operation; }
  89   virtual void doit();
  90   virtual bool doit_prologue();
  91   virtual void doit_epilogue();
  92   virtual const char* name() const {
  93     return "concurrent gc";
  94   }
  95 };
  96 
  97 #endif // SHARE_VM_GC_G1_VM_OPERATIONS_G1_HPP