2011-01-19 19:30:42 -05:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
2011-01-19 19:30:42 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_GC_G1_HEAPREGIONSET_HPP
|
|
|
|
#define SHARE_GC_G1_HEAPREGIONSET_HPP
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/heapRegion.hpp"
|
2018-04-09 20:36:04 -04:00
|
|
|
#include "utilities/macros.hpp"
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
#define assert_heap_region_set(p, message) \
|
|
|
|
do { \
|
|
|
|
assert((p), "[%s] %s ln: %u", \
|
|
|
|
name(), message, length()); \
|
2015-11-02 14:28:19 +01:00
|
|
|
} while (0)
|
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
#define guarantee_heap_region_set(p, message) \
|
|
|
|
do { \
|
|
|
|
guarantee((p), "[%s] %s ln: %u", \
|
|
|
|
name(), message, length()); \
|
2015-11-02 14:28:19 +01:00
|
|
|
} while (0)
|
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
#define assert_free_region_list(p, message) \
|
|
|
|
do { \
|
|
|
|
assert((p), "[%s] %s ln: %u hd: " PTR_FORMAT " tl: " PTR_FORMAT, \
|
|
|
|
name(), message, length(), p2i(_head), p2i(_tail)); \
|
2015-11-02 14:28:19 +01:00
|
|
|
} while (0)
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2018-08-22 20:37:07 +02:00
|
|
|
// Interface collecting various instance specific verification methods of
|
|
|
|
// HeapRegionSets.
|
|
|
|
class HeapRegionSetChecker : public CHeapObj<mtGC> {
|
2014-03-14 10:15:46 +01:00
|
|
|
public:
|
2018-08-22 20:37:07 +02:00
|
|
|
// Verify MT safety for this HeapRegionSet.
|
|
|
|
virtual void check_mt_safety() = 0;
|
|
|
|
// Returns true if the given HeapRegion is of the correct type for this HeapRegionSet.
|
|
|
|
virtual bool is_correct_type(HeapRegion* hr) = 0;
|
|
|
|
// Return a description of the type of regions this HeapRegionSet contains.
|
|
|
|
virtual const char* get_description() = 0;
|
2014-03-14 10:15:46 +01:00
|
|
|
};
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
// Base class for all the classes that represent heap region sets. It
|
|
|
|
// contains the basic attributes that each set needs to maintain
|
|
|
|
// (e.g., length, region num, used bytes sum) plus any shared
|
|
|
|
// functionality (e.g., verification).
|
|
|
|
|
2018-03-14 07:27:19 -04:00
|
|
|
class HeapRegionSetBase {
|
2012-01-18 10:30:12 -05:00
|
|
|
friend class VMStructs;
|
2018-08-22 20:37:07 +02:00
|
|
|
|
2018-08-22 20:37:07 +02:00
|
|
|
HeapRegionSetChecker* _checker;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
protected:
|
2015-12-11 13:48:52 +01:00
|
|
|
// The number of regions in to the set.
|
|
|
|
uint _length;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
const char* _name;
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
bool _verify_in_progress;
|
2011-11-07 22:11:12 -05:00
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
// verify_region() is used to ensure that the contents of a region
|
2014-03-14 10:15:46 +01:00
|
|
|
// added to / removed from a set are consistent.
|
|
|
|
void verify_region(HeapRegion* hr) PRODUCT_RETURN;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
void check_mt_safety() {
|
2018-08-22 20:37:07 +02:00
|
|
|
if (_checker != NULL) {
|
|
|
|
_checker->check_mt_safety();
|
2014-03-14 10:15:46 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2018-08-22 20:37:07 +02:00
|
|
|
HeapRegionSetBase(const char* name, HeapRegionSetChecker* verifier);
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
const char* name() { return _name; }
|
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
uint length() const { return _length; }
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
bool is_empty() { return _length == 0; }
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
// It updates the fields of the set to reflect hr being added to
|
|
|
|
// the set and tags the region appropriately.
|
|
|
|
inline void add(HeapRegion* hr);
|
|
|
|
|
|
|
|
// It updates the fields of the set to reflect hr being removed
|
|
|
|
// from the set and tags the region appropriately.
|
|
|
|
inline void remove(HeapRegion* hr);
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
virtual void verify();
|
|
|
|
void verify_start();
|
|
|
|
void verify_next_region(HeapRegion* hr);
|
|
|
|
void verify_end();
|
|
|
|
|
2018-04-09 20:36:04 -04:00
|
|
|
void verify_optional() { DEBUG_ONLY(verify();) }
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
virtual void print_on(outputStream* out, bool print_contents = false);
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class represents heap region sets whose members are not
|
|
|
|
// explicitly tracked. It's helpful to group regions using such sets
|
|
|
|
// so that we can reason about all the region groups in the heap using
|
|
|
|
// the same interface (namely, the HeapRegionSetBase API).
|
|
|
|
|
|
|
|
class HeapRegionSet : public HeapRegionSetBase {
|
|
|
|
public:
|
2018-08-22 20:37:07 +02:00
|
|
|
HeapRegionSet(const char* name, HeapRegionSetChecker* checker):
|
|
|
|
HeapRegionSetBase(name, checker) {
|
2018-08-22 20:37:07 +02:00
|
|
|
}
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2015-12-11 13:48:52 +01:00
|
|
|
void bulk_remove(const uint removed) {
|
|
|
|
_length -= removed;
|
2014-03-14 10:15:46 +01:00
|
|
|
}
|
2011-01-19 19:30:42 -05:00
|
|
|
};
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
// A set that links all the regions added to it in a doubly-linked
|
2014-08-18 16:10:44 +02:00
|
|
|
// sorted list. We should try to avoid doing operations that iterate over
|
2011-01-19 19:30:42 -05:00
|
|
|
// such lists in performance critical paths. Typically we should
|
2014-08-18 16:10:44 +02:00
|
|
|
// add / remove one region at a time or concatenate two lists.
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
class FreeRegionListIterator;
|
2019-11-13 10:51:41 -08:00
|
|
|
class G1NUMA;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
class FreeRegionList : public HeapRegionSetBase {
|
|
|
|
friend class FreeRegionListIterator;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
private:
|
2019-11-13 10:51:41 -08:00
|
|
|
|
|
|
|
// This class is only initialized if there are multiple active nodes.
|
|
|
|
class NodeInfo : public CHeapObj<mtGC> {
|
|
|
|
G1NUMA* _numa;
|
|
|
|
uint* _length_of_node;
|
|
|
|
uint _num_nodes;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NodeInfo();
|
|
|
|
~NodeInfo();
|
|
|
|
|
|
|
|
inline void increase_length(uint node_index);
|
|
|
|
inline void decrease_length(uint node_index);
|
|
|
|
|
|
|
|
inline uint length(uint index) const;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void add(NodeInfo* info);
|
|
|
|
};
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
HeapRegion* _head;
|
|
|
|
HeapRegion* _tail;
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
// _last is used to keep track of where we added an element the last
|
2014-08-18 16:10:44 +02:00
|
|
|
// time. It helps to improve performance when adding several ordered items in a row.
|
2014-02-28 15:27:09 +01:00
|
|
|
HeapRegion* _last;
|
|
|
|
|
2019-11-13 10:51:41 -08:00
|
|
|
NodeInfo* _node_info;
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
static uint _unrealistically_long_length;
|
|
|
|
|
2014-08-18 16:10:44 +02:00
|
|
|
inline HeapRegion* remove_from_head_impl();
|
|
|
|
inline HeapRegion* remove_from_tail_impl();
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2019-11-13 10:51:41 -08:00
|
|
|
inline void increase_length(uint node_index);
|
|
|
|
inline void decrease_length(uint node_index);
|
|
|
|
|
2019-12-09 10:26:41 +01:00
|
|
|
// Common checks for adding a list.
|
|
|
|
void add_list_common_start(FreeRegionList* from_list);
|
|
|
|
void add_list_common_end(FreeRegionList* from_list);
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
protected:
|
|
|
|
// See the comment for HeapRegionSetBase::clear()
|
|
|
|
virtual void clear();
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
public:
|
2019-11-13 10:51:41 -08:00
|
|
|
FreeRegionList(const char* name, HeapRegionSetChecker* checker = NULL);
|
|
|
|
~FreeRegionList();
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
void verify_list();
|
|
|
|
|
2014-08-18 16:10:44 +02:00
|
|
|
#ifdef ASSERT
|
|
|
|
bool contains(HeapRegion* hr) const {
|
|
|
|
return hr->containing_set() == this;
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-14 10:15:46 +01:00
|
|
|
|
|
|
|
static void set_unrealistically_long_length(uint len);
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
// Add hr to the list. The region should not be a member of another set.
|
|
|
|
// Assumes that the list is ordered and will preserve that order. The order
|
2014-08-26 09:36:53 +02:00
|
|
|
// is determined by hrm_index.
|
2014-02-28 15:27:09 +01:00
|
|
|
inline void add_ordered(HeapRegion* hr);
|
2019-12-09 10:26:41 +01:00
|
|
|
// Same restrictions as above, but adds the region last in the list.
|
|
|
|
inline void add_to_tail(HeapRegion* region_to_add);
|
2014-02-28 15:27:09 +01:00
|
|
|
|
|
|
|
// Removes from head or tail based on the given argument.
|
2014-08-18 16:10:44 +02:00
|
|
|
HeapRegion* remove_region(bool from_head);
|
2014-02-28 15:27:09 +01:00
|
|
|
|
2019-11-13 10:49:12 -08:00
|
|
|
HeapRegion* remove_region_with_node_index(bool from_head,
|
2019-11-13 10:51:41 -08:00
|
|
|
uint requested_node_index);
|
2019-11-13 10:49:12 -08:00
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
// Merge two ordered lists. The result is also ordered. The order is
|
2014-08-26 09:36:53 +02:00
|
|
|
// determined by hrm_index.
|
2014-02-28 15:27:09 +01:00
|
|
|
void add_ordered(FreeRegionList* from_list);
|
2019-12-09 10:26:41 +01:00
|
|
|
void append_ordered(FreeRegionList* from_list);
|
2014-02-28 15:27:09 +01:00
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
// It empties the list by removing all regions from it.
|
|
|
|
void remove_all();
|
|
|
|
|
2019-12-09 10:26:41 +01:00
|
|
|
// Abandon current free list. Requires that all regions in the current list
|
|
|
|
// are taken care of separately, to allow a rebuild.
|
|
|
|
void abandon();
|
|
|
|
|
2014-08-18 16:10:44 +02:00
|
|
|
// Remove all (contiguous) regions from first to first + num_regions -1 from
|
|
|
|
// this list.
|
2020-04-08 18:38:31 +02:00
|
|
|
// Num_regions must be >= 1.
|
2014-08-18 16:10:44 +02:00
|
|
|
void remove_starting_at(HeapRegion* first, uint num_regions);
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
virtual void verify();
|
2018-12-21 08:18:59 -08:00
|
|
|
|
|
|
|
uint num_of_regions_in_range(uint start, uint end) const;
|
2019-11-13 10:51:41 -08:00
|
|
|
|
|
|
|
using HeapRegionSetBase::length;
|
|
|
|
uint length(uint node_index) const;
|
2011-01-19 19:30:42 -05:00
|
|
|
};
|
|
|
|
|
2011-03-04 17:13:19 -05:00
|
|
|
// Iterator class that provides a convenient way to iterate over the
|
2014-08-18 16:10:44 +02:00
|
|
|
// regions of a FreeRegionList.
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
class FreeRegionListIterator : public StackObj {
|
2011-01-19 19:30:42 -05:00
|
|
|
private:
|
2014-03-14 10:15:46 +01:00
|
|
|
FreeRegionList* _list;
|
2014-02-28 15:27:09 +01:00
|
|
|
HeapRegion* _curr;
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool more_available() {
|
|
|
|
return _curr != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapRegion* get_next() {
|
|
|
|
assert(more_available(),
|
|
|
|
"get_next() should be called when more regions are available");
|
|
|
|
|
|
|
|
// If we are going to introduce a count in the iterator we should
|
|
|
|
// do the "cycle" check.
|
|
|
|
|
|
|
|
HeapRegion* hr = _curr;
|
2014-03-14 10:15:46 +01:00
|
|
|
_list->verify_region(hr);
|
2011-01-19 19:30:42 -05:00
|
|
|
_curr = hr->next();
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:31:06 +02:00
|
|
|
FreeRegionListIterator(FreeRegionList* list)
|
|
|
|
: _list(list),
|
|
|
|
_curr(list->_head) {
|
2011-01-19 19:30:42 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_GC_G1_HEAPREGIONSET_HPP
|