2018-02-26 09:34:12 +01:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
2018-02-26 09:34:12 +01: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_G1CARDTABLE_HPP
|
|
|
|
#define SHARE_GC_G1_G1CARDTABLE_HPP
|
2018-02-26 09:34:12 +01:00
|
|
|
|
|
|
|
#include "gc/g1/g1RegionToSpaceMapper.hpp"
|
|
|
|
#include "gc/shared/cardTable.hpp"
|
|
|
|
#include "oops/oopsHierarchy.hpp"
|
|
|
|
#include "utilities/macros.hpp"
|
|
|
|
|
|
|
|
class G1CardTable;
|
|
|
|
class G1RegionToSpaceMapper;
|
|
|
|
|
|
|
|
class G1CardTableChangedListener : public G1MappingChangedListener {
|
|
|
|
private:
|
|
|
|
G1CardTable* _card_table;
|
|
|
|
public:
|
|
|
|
G1CardTableChangedListener() : _card_table(NULL) { }
|
|
|
|
|
|
|
|
void set_card_table(G1CardTable* card_table) { _card_table = card_table; }
|
|
|
|
|
|
|
|
virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
|
|
|
|
};
|
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
class G1CardTable : public CardTable {
|
2018-02-26 09:34:12 +01:00
|
|
|
friend class VMStructs;
|
|
|
|
friend class G1CardTableChangedListener;
|
|
|
|
|
|
|
|
G1CardTableChangedListener _listener;
|
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
public:
|
2018-02-26 09:34:12 +01:00
|
|
|
enum G1CardValues {
|
2019-06-27 11:48:32 +02:00
|
|
|
g1_young_gen = CT_MR_BS_last_reserved << 1,
|
|
|
|
|
|
|
|
// During evacuation we use the card table to consolidate the cards we need to
|
|
|
|
// scan for roots onto the card table from the various sources. Further it is
|
|
|
|
// used to record already completely scanned cards to avoid re-scanning them
|
|
|
|
// when incrementally evacuating the old gen regions of a collection set.
|
|
|
|
// This means that already scanned cards should be preserved.
|
|
|
|
//
|
|
|
|
// The merge at the start of each evacuation round simply sets cards to dirty
|
|
|
|
// that are clean; scanned cards are set to 0x1.
|
|
|
|
//
|
|
|
|
// This means that the LSB determines what to do with the card during evacuation
|
|
|
|
// given the following possible values:
|
|
|
|
//
|
|
|
|
// 11111111 - clean, do not scan
|
|
|
|
// 00000001 - already scanned, do not scan
|
|
|
|
// 00000000 - dirty, needs to be scanned.
|
|
|
|
//
|
|
|
|
g1_card_already_scanned = 0x1
|
2018-02-26 09:34:12 +01:00
|
|
|
};
|
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
static const size_t WordAllClean = SIZE_MAX;
|
|
|
|
static const size_t WordAllDirty = 0;
|
|
|
|
|
|
|
|
STATIC_ASSERT(BitsPerByte == 8);
|
|
|
|
static const size_t WordAlreadyScanned = (SIZE_MAX / 255) * g1_card_already_scanned;
|
|
|
|
|
2018-02-26 09:34:12 +01:00
|
|
|
G1CardTable(MemRegion whole_heap): CardTable(whole_heap, /* scanned concurrently */ true), _listener() {
|
|
|
|
_listener.set_card_table(this);
|
|
|
|
}
|
|
|
|
|
2019-03-13 21:01:56 +01:00
|
|
|
static CardValue g1_young_card_val() { return g1_young_gen; }
|
2018-02-26 09:34:12 +01:00
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN;
|
|
|
|
void g1_mark_as_young(const MemRegion& mr);
|
2018-02-26 09:34:12 +01:00
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
size_t index_for_cardvalue(CardValue const* p) const {
|
|
|
|
return pointer_delta(p, _byte_map, sizeof(CardValue));
|
2018-02-26 09:34:12 +01:00
|
|
|
}
|
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
// Mark the given card as Dirty if it is Clean.
|
|
|
|
inline void mark_clean_as_dirty(size_t card_index);
|
2018-02-26 09:34:12 +01:00
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
// Change Clean cards in a (large) area on the card table as Dirty, preserving
|
|
|
|
// already scanned cards. Assumes that most cards in that area are Clean.
|
|
|
|
inline void mark_region_dirty(size_t start_card_index, size_t num_cards);
|
2018-02-26 09:34:12 +01:00
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
// Mark the given range of cards as Scanned. All of these cards must be Dirty.
|
|
|
|
inline void mark_as_scanned(size_t start_card_index, size_t num_cards);
|
2018-02-26 09:34:12 +01:00
|
|
|
|
2019-06-27 11:48:32 +02:00
|
|
|
inline uint region_idx_for(CardValue* p);
|
2018-02-26 09:34:12 +01:00
|
|
|
|
|
|
|
static size_t compute_size(size_t mem_region_size_in_words) {
|
|
|
|
size_t number_of_slots = (mem_region_size_in_words / card_size_in_words);
|
|
|
|
return ReservedSpace::allocation_align_size_up(number_of_slots);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns how many bytes of the heap a single byte of the Card Table corresponds to.
|
|
|
|
static size_t heap_map_factor() { return card_size; }
|
|
|
|
|
|
|
|
void initialize() {}
|
|
|
|
void initialize(G1RegionToSpaceMapper* mapper);
|
|
|
|
|
|
|
|
virtual void resize_covered_region(MemRegion new_region) { ShouldNotReachHere(); }
|
|
|
|
|
|
|
|
virtual bool is_in_young(oop obj) const;
|
|
|
|
};
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_GC_G1_G1CARDTABLE_HPP
|