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 HeapRegion* _curr; 41 42 uint _length; 43 uint _survivor_length; 44 45 size_t _last_sampled_rs_lengths; 46 size_t _sampled_rs_lengths; 47 48 void empty_list(HeapRegion* list); 49 50 public: 51 YoungList(G1CollectedHeap* g1h); 52 53 void push_region(HeapRegion* hr); 54 void add_survivor_region(HeapRegion* hr); 55 56 void empty_list(); 57 bool is_empty() { return _length == 0; } 58 uint length() { return _length; } 59 uint eden_length() { return length() - survivor_length(); } 60 uint survivor_length() { return _survivor_length; } 61 62 // Currently we do not keep track of the used byte sum for the 63 // young list and the survivors and it'd be quite a lot of work to 64 // do so. When we'll eventually replace the young list with 65 // instances of HeapRegionLinkedList we'll get that for free. So, 66 // we'll report the more accurate information then. 67 size_t eden_used_bytes() { 68 assert(length() >= survivor_length(), "invariant"); 69 return (size_t) eden_length() * HeapRegion::GrainBytes; 70 } 71 size_t survivor_used_bytes() { 72 return (size_t) survivor_length() * HeapRegion::GrainBytes; 73 } 74 75 void rs_length_sampling_init(); 76 bool rs_length_sampling_more(); 77 void rs_length_sampling_next(); 78 79 void reset_sampled_info() { 80 _last_sampled_rs_lengths = 0; 81 } 82 size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; } 83 84 // for development purposes 85 void reset_auxilary_lists(); 86 void clear() { _head = NULL; _length = 0; } 87 88 void clear_survivors() { 89 _survivor_head = NULL; 90 _survivor_tail = NULL; 91 _survivor_length = 0; 92 } 93 94 HeapRegion* first_region() { return _head; } 95 HeapRegion* first_survivor_region() { return _survivor_head; } 96 HeapRegion* last_survivor_region() { return _survivor_tail; } 97 98 // debugging 99 bool check_list_well_formed(); 100 bool check_list_empty(bool check_sample = true); 101 void print(); 102 }; 103 104 #endif // SHARE_VM_GC_G1_YOUNGLIST_HPP