2014-06-26 15:45:07 +02:00
|
|
|
/*
|
2015-04-22 17:05:00 +02:00
|
|
|
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
2014-06-26 15:45:07 +02: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#ifndef SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP
|
|
|
|
#define SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP
|
|
|
|
|
|
|
|
#include "gc/g1/dirtyCardQueue.hpp"
|
|
|
|
#include "gc/g1/g1CollectedHeap.hpp"
|
|
|
|
#include "gc/g1/g1CollectorPolicy.hpp"
|
|
|
|
#include "gc/g1/g1OopClosures.hpp"
|
|
|
|
#include "gc/g1/g1RemSet.hpp"
|
|
|
|
#include "gc/g1/g1SATBCardTableModRefBS.hpp"
|
|
|
|
#include "gc/shared/ageTable.hpp"
|
2014-06-26 15:45:07 +02:00
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "oops/oop.hpp"
|
|
|
|
|
2015-08-19 13:50:50 +02:00
|
|
|
class G1PLABAllocator;
|
2015-10-14 14:50:43 +02:00
|
|
|
class G1EvacuationRootClosures;
|
2014-06-26 15:45:07 +02:00
|
|
|
class HeapRegion;
|
|
|
|
class outputStream;
|
|
|
|
|
2015-08-20 15:17:43 +02:00
|
|
|
class G1ParScanThreadState : public CHeapObj<mtGC> {
|
2014-06-26 15:48:05 +02:00
|
|
|
private:
|
2014-06-26 15:45:07 +02:00
|
|
|
G1CollectedHeap* _g1h;
|
|
|
|
RefToScanQueue* _refs;
|
|
|
|
DirtyCardQueue _dcq;
|
|
|
|
G1SATBCardTableModRefBS* _ct_bs;
|
2015-10-14 14:50:43 +02:00
|
|
|
G1EvacuationRootClosures* _closures;
|
2014-06-26 15:45:07 +02:00
|
|
|
|
2015-08-06 15:49:50 +02:00
|
|
|
G1PLABAllocator* _plab_allocator;
|
2014-09-05 09:49:19 +02:00
|
|
|
|
2014-12-19 09:21:06 +01:00
|
|
|
ageTable _age_table;
|
|
|
|
InCSetState _dest[InCSetState::Num];
|
|
|
|
// Local tenuring threshold.
|
|
|
|
uint _tenuring_threshold;
|
|
|
|
G1ParScanClosure _scanner;
|
2014-06-26 15:45:07 +02:00
|
|
|
|
|
|
|
int _hash_seed;
|
2015-08-06 15:52:33 +02:00
|
|
|
uint _worker_id;
|
2014-06-26 15:45:07 +02:00
|
|
|
|
|
|
|
// Map from young-age-index (0 == not young, 1 is youngest) to
|
|
|
|
// surviving words. base is what we get back from the malloc call
|
|
|
|
size_t* _surviving_young_words_base;
|
|
|
|
// this points into the array, as we use the first few entries for padding
|
|
|
|
size_t* _surviving_young_words;
|
|
|
|
|
2015-08-19 13:47:40 +02:00
|
|
|
// Indicates whether in the last generation (old) there is no more space
|
|
|
|
// available for allocation.
|
|
|
|
bool _old_gen_is_full;
|
|
|
|
|
2014-06-26 15:45:07 +02:00
|
|
|
#define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t))
|
|
|
|
|
|
|
|
DirtyCardQueue& dirty_card_queue() { return _dcq; }
|
|
|
|
G1SATBCardTableModRefBS* ctbs() { return _ct_bs; }
|
|
|
|
|
2014-12-19 09:21:06 +01:00
|
|
|
InCSetState dest(InCSetState original) const {
|
|
|
|
assert(original.is_valid(),
|
2015-09-29 11:02:08 +02:00
|
|
|
"Original state invalid: " CSETSTATE_FORMAT, original.value());
|
2014-12-19 09:21:06 +01:00
|
|
|
assert(_dest[original.value()].is_valid_gen(),
|
2015-09-29 11:02:08 +02:00
|
|
|
"Dest state is invalid: " CSETSTATE_FORMAT, _dest[original.value()].value());
|
2014-12-19 09:21:06 +01:00
|
|
|
return _dest[original.value()];
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:48:05 +02:00
|
|
|
public:
|
2015-09-09 14:22:45 +02:00
|
|
|
G1ParScanThreadState(G1CollectedHeap* g1h, uint worker_id, size_t young_cset_length);
|
2014-06-26 15:48:05 +02:00
|
|
|
~G1ParScanThreadState();
|
2014-06-26 15:45:07 +02:00
|
|
|
|
2015-08-20 15:17:43 +02:00
|
|
|
void set_ref_processor(ReferenceProcessor* rp) { _scanner.set_ref_processor(rp); }
|
|
|
|
|
2014-06-26 15:45:07 +02:00
|
|
|
#ifdef ASSERT
|
2014-06-26 15:48:05 +02:00
|
|
|
bool queue_is_empty() const { return _refs->is_empty(); }
|
|
|
|
|
2014-06-26 15:45:07 +02:00
|
|
|
bool verify_ref(narrowOop* ref) const;
|
|
|
|
bool verify_ref(oop* ref) const;
|
|
|
|
bool verify_task(StarTask ref) const;
|
|
|
|
#endif // ASSERT
|
|
|
|
|
2015-04-27 09:51:06 +02:00
|
|
|
template <class T> void push_on_queue(T* ref);
|
2014-06-26 15:45:07 +02:00
|
|
|
|
2015-10-15 10:10:13 -04:00
|
|
|
template <class T> void update_rs(HeapRegion* from, T* p) {
|
2014-09-16 10:28:15 +02:00
|
|
|
// If the new value of the field points to the same region or
|
|
|
|
// is the to-space, we don't need to include it in the Rset updates.
|
|
|
|
if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) {
|
|
|
|
size_t card_index = ctbs()->index_for(p);
|
|
|
|
// If the card hasn't been added to the buffer, do it.
|
|
|
|
if (ctbs()->mark_card_deferred(card_index)) {
|
|
|
|
dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 15:45:07 +02:00
|
|
|
|
2015-10-14 14:50:43 +02:00
|
|
|
G1EvacuationRootClosures* closures() { return _closures; }
|
2015-08-06 15:52:33 +02:00
|
|
|
uint worker_id() { return _worker_id; }
|
2014-06-26 15:45:07 +02:00
|
|
|
|
2015-08-20 15:17:43 +02:00
|
|
|
// Returns the current amount of waste due to alignment or not being able to fit
|
|
|
|
// objects within LABs and the undo waste.
|
|
|
|
virtual void waste(size_t& wasted, size_t& undo_wasted);
|
2014-06-26 15:45:07 +02:00
|
|
|
|
|
|
|
size_t* surviving_young_words() {
|
2015-08-20 15:17:43 +02:00
|
|
|
// We add one to hide entry 0 which accumulates surviving words for
|
2014-06-26 15:45:07 +02:00
|
|
|
// age -1 regions (i.e. non-young ones)
|
2015-08-20 15:17:43 +02:00
|
|
|
return _surviving_young_words + 1;
|
2014-06-26 15:45:07 +02:00
|
|
|
}
|
|
|
|
|
2015-09-09 14:22:45 +02:00
|
|
|
void flush(size_t* surviving_young_words);
|
2015-09-09 10:34:22 +02:00
|
|
|
|
2014-06-26 15:45:07 +02:00
|
|
|
private:
|
|
|
|
#define G1_PARTIAL_ARRAY_MASK 0x2
|
|
|
|
|
|
|
|
inline bool has_partial_array_mask(oop* ref) const {
|
|
|
|
return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We never encode partial array oops as narrowOop*, so return false immediately.
|
|
|
|
// This allows the compiler to create optimized code when popping references from
|
|
|
|
// the work queue.
|
|
|
|
inline bool has_partial_array_mask(narrowOop* ref) const {
|
|
|
|
assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only implement set_partial_array_mask() for regular oops, not for narrowOops.
|
|
|
|
// We always encode partial arrays as regular oop, to allow the
|
|
|
|
// specialization for has_partial_array_mask() for narrowOops above.
|
|
|
|
// This means that unintentional use of this method with narrowOops are caught
|
|
|
|
// by the compiler.
|
|
|
|
inline oop* set_partial_array_mask(oop obj) const {
|
|
|
|
assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!");
|
|
|
|
return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline oop clear_partial_array_mask(oop* ref) const {
|
|
|
|
return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void do_oop_partial_array(oop* p);
|
|
|
|
|
|
|
|
// This method is applied to the fields of the objects that have just been copied.
|
2014-06-26 15:48:05 +02:00
|
|
|
template <class T> inline void do_oop_evac(T* p, HeapRegion* from);
|
2014-06-26 15:45:07 +02:00
|
|
|
|
|
|
|
template <class T> inline void deal_with_reference(T* ref_to_scan);
|
|
|
|
|
2014-06-26 15:48:05 +02:00
|
|
|
inline void dispatch_reference(StarTask ref);
|
2014-12-19 09:21:06 +01:00
|
|
|
|
|
|
|
// Tries to allocate word_sz in the PLAB of the next "generation" after trying to
|
|
|
|
// allocate into dest. State is the original (source) cset state for the object
|
2015-08-19 13:47:40 +02:00
|
|
|
// that is allocated for. Previous_plab_refill_failed indicates whether previously
|
|
|
|
// a PLAB refill into "state" failed.
|
2014-12-19 09:21:06 +01:00
|
|
|
// Returns a non-NULL pointer if successful, and updates dest if required.
|
2015-08-19 13:47:40 +02:00
|
|
|
// Also determines whether we should continue to try to allocate into the various
|
|
|
|
// generations or just end trying to allocate.
|
2014-12-19 09:21:06 +01:00
|
|
|
HeapWord* allocate_in_next_plab(InCSetState const state,
|
|
|
|
InCSetState* dest,
|
|
|
|
size_t word_sz,
|
2015-08-19 13:47:40 +02:00
|
|
|
AllocationContext_t const context,
|
|
|
|
bool previous_plab_refill_failed);
|
2014-12-19 09:21:06 +01:00
|
|
|
|
|
|
|
inline InCSetState next_state(InCSetState const state, markOop const m, uint& age);
|
2015-09-02 09:51:05 +02:00
|
|
|
|
|
|
|
void report_promotion_event(InCSetState const dest_state,
|
|
|
|
oop const old, size_t word_sz, uint age,
|
|
|
|
HeapWord * const obj_ptr, const AllocationContext_t context) const;
|
2014-06-26 15:48:05 +02:00
|
|
|
public:
|
|
|
|
|
2014-12-19 09:21:06 +01:00
|
|
|
oop copy_to_survivor_space(InCSetState const state, oop const obj, markOop const old_mark);
|
2014-06-26 15:45:07 +02:00
|
|
|
|
|
|
|
void trim_queue();
|
2014-06-26 15:48:05 +02:00
|
|
|
|
|
|
|
inline void steal_and_trim_queue(RefToScanQueueSet *task_queues);
|
2015-07-23 11:14:47 +02:00
|
|
|
|
|
|
|
// An attempt to evacuate "obj" has failed; take necessary steps.
|
|
|
|
oop handle_evacuation_failure_par(oop obj, markOop m);
|
2014-06-26 15:45:07 +02:00
|
|
|
};
|
|
|
|
|
2015-09-09 10:34:22 +02:00
|
|
|
class G1ParScanThreadStateSet : public StackObj {
|
|
|
|
G1CollectedHeap* _g1h;
|
|
|
|
G1ParScanThreadState** _states;
|
2015-09-09 14:22:45 +02:00
|
|
|
size_t* _surviving_young_words_total;
|
|
|
|
size_t* _cards_scanned;
|
|
|
|
size_t _total_cards_scanned;
|
2015-09-09 10:34:22 +02:00
|
|
|
uint _n_workers;
|
|
|
|
bool _flushed;
|
|
|
|
|
|
|
|
public:
|
2015-09-09 14:22:45 +02:00
|
|
|
G1ParScanThreadStateSet(G1CollectedHeap* g1h, uint n_workers, size_t young_cset_length) :
|
2015-09-09 10:34:22 +02:00
|
|
|
_g1h(g1h),
|
|
|
|
_states(NEW_C_HEAP_ARRAY(G1ParScanThreadState*, n_workers, mtGC)),
|
2015-09-09 14:22:45 +02:00
|
|
|
_surviving_young_words_total(NEW_C_HEAP_ARRAY(size_t, young_cset_length, mtGC)),
|
|
|
|
_cards_scanned(NEW_C_HEAP_ARRAY(size_t, n_workers, mtGC)),
|
|
|
|
_total_cards_scanned(0),
|
2015-09-09 10:34:22 +02:00
|
|
|
_n_workers(n_workers),
|
|
|
|
_flushed(false) {
|
|
|
|
for (uint i = 0; i < n_workers; ++i) {
|
2015-09-09 14:22:45 +02:00
|
|
|
_states[i] = new_par_scan_state(i, young_cset_length);
|
2015-09-09 10:34:22 +02:00
|
|
|
}
|
2015-09-09 14:22:45 +02:00
|
|
|
memset(_surviving_young_words_total, 0, young_cset_length * sizeof(size_t));
|
|
|
|
memset(_cards_scanned, 0, n_workers * sizeof(size_t));
|
2015-09-09 10:34:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~G1ParScanThreadStateSet() {
|
|
|
|
assert(_flushed, "thread local state from the per thread states should have been flushed");
|
|
|
|
FREE_C_HEAP_ARRAY(G1ParScanThreadState*, _states);
|
2015-09-09 14:22:45 +02:00
|
|
|
FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_total);
|
|
|
|
FREE_C_HEAP_ARRAY(size_t, _cards_scanned);
|
2015-09-09 10:34:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void flush();
|
|
|
|
|
|
|
|
G1ParScanThreadState* state_for_worker(uint worker_id);
|
|
|
|
|
2015-09-09 14:22:45 +02:00
|
|
|
void add_cards_scanned(uint worker_id, size_t cards_scanned);
|
|
|
|
size_t total_cards_scanned() const;
|
|
|
|
const size_t* surviving_young_words() const;
|
|
|
|
|
2015-09-09 10:34:22 +02:00
|
|
|
private:
|
2015-09-09 14:22:45 +02:00
|
|
|
G1ParScanThreadState* new_par_scan_state(uint worker_id, size_t young_cset_length);
|
2015-09-09 10:34:22 +02:00
|
|
|
};
|
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#endif // SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP
|