1 /*
   2  * Copyright (c) 2015, 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_YOUNGLIST_HPP
  26 #define SHARE_VM_GC_G1_YOUNGLIST_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/globals.hpp"
  30 
  31 class YoungList : public CHeapObj<mtGC> {
  32 private:
  33   G1CollectedHeap* _g1h;
  34 
  35   HeapRegion* _head;
  36 
  37   HeapRegion* _survivor_head;
  38   HeapRegion* _survivor_tail;
  39 
  40   uint        _length;
  41   uint        _survivor_length;
  42 
  43   void         empty_list(HeapRegion* list);
  44 
  45 public:
  46   YoungList(G1CollectedHeap* g1h);
  47 
  48   void         push_region(HeapRegion* hr);
  49   void         add_survivor_region(HeapRegion* hr);
  50 
  51   void         empty_list();
  52   bool         is_empty() { return _length == 0; }
  53   uint         length() { return _length; }
  54   uint         eden_length() { return length() - survivor_length(); }
  55   uint         survivor_length() { return _survivor_length; }
  56 
  57   // Currently we do not keep track of the used byte sum for the
  58   // young list and the survivors and it'd be quite a lot of work to
  59   // do so. When we'll eventually replace the young list with
  60   // instances of HeapRegionLinkedList we'll get that for free. So,
  61   // we'll report the more accurate information then.
  62   size_t       eden_used_bytes() {
  63     assert(length() >= survivor_length(), "invariant");
  64     return (size_t) eden_length() * HeapRegion::GrainBytes;
  65   }
  66   size_t       survivor_used_bytes() {
  67     return (size_t) survivor_length() * HeapRegion::GrainBytes;
  68   }
  69 
  70   // for development purposes
  71   void reset_auxilary_lists();
  72   void clear() { _head = NULL; _length = 0; }
  73 
  74   void clear_survivors() {
  75     _survivor_head    = NULL;
  76     _survivor_tail    = NULL;
  77     _survivor_length  = 0;
  78   }
  79 
  80   HeapRegion* first_region() { return _head; }
  81   HeapRegion* first_survivor_region() { return _survivor_head; }
  82   HeapRegion* last_survivor_region() { return _survivor_tail; }
  83 
  84   // debugging
  85   bool          check_list_well_formed();
  86   bool          check_list_empty();
  87   void          print();
  88 };
  89 
  90 #endif // SHARE_VM_GC_G1_YOUNGLIST_HPP