tschatzl@6937: /* tschatzl@6937: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. tschatzl@6937: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tschatzl@6937: * tschatzl@6937: * This code is free software; you can redistribute it and/or modify it tschatzl@6937: * under the terms of the GNU General Public License version 2 only, as tschatzl@6937: * published by the Free Software Foundation. tschatzl@6937: * tschatzl@6937: * This code is distributed in the hope that it will be useful, but WITHOUT tschatzl@6937: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tschatzl@6937: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tschatzl@6937: * version 2 for more details (a copy is included in the LICENSE file that tschatzl@6937: * accompanied this code). tschatzl@6937: * tschatzl@6937: * You should have received a copy of the GNU General Public License version tschatzl@6937: * 2 along with this work; if not, write to the Free Software Foundation, tschatzl@6937: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tschatzl@6937: * tschatzl@6937: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tschatzl@6937: * or visit www.oracle.com if you need additional information or have any tschatzl@6937: * questions. tschatzl@6937: * tschatzl@6937: */ tschatzl@6937: tschatzl@6937: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP tschatzl@6937: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP tschatzl@6937: tschatzl@6937: #include "gc_implementation/g1/dirtyCardQueue.hpp" tschatzl@6937: #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" tschatzl@6937: #include "gc_implementation/g1/g1CollectedHeap.hpp" tschatzl@6937: #include "gc_implementation/g1/g1CollectorPolicy.hpp" tschatzl@6937: #include "gc_implementation/g1/g1OopClosures.hpp" tschatzl@6937: #include "gc_implementation/g1/g1RemSet.hpp" tschatzl@6937: #include "gc_implementation/shared/ageTable.hpp" tschatzl@6937: #include "memory/allocation.hpp" tschatzl@6937: #include "oops/oop.hpp" tschatzl@6937: tschatzl@6937: class HeapRegion; tschatzl@6937: class outputStream; tschatzl@6937: tschatzl@6937: class G1ParScanThreadState : public StackObj { tschatzl@6938: private: tschatzl@6937: G1CollectedHeap* _g1h; tschatzl@6937: RefToScanQueue* _refs; tschatzl@6937: DirtyCardQueue _dcq; tschatzl@6937: G1SATBCardTableModRefBS* _ct_bs; tschatzl@6937: G1RemSet* _g1_rem; tschatzl@6937: tschatzl@7651: G1ParGCAllocator* _g1_par_allocator; sjohanss@7118: tschatzl@7651: ageTable _age_table; tschatzl@7651: InCSetState _dest[InCSetState::Num]; tschatzl@7651: // Local tenuring threshold. tschatzl@7651: uint _tenuring_threshold; tschatzl@7651: G1ParScanClosure _scanner; tschatzl@6937: tschatzl@7651: size_t _alloc_buffer_waste; tschatzl@7651: size_t _undo_waste; tschatzl@6937: tschatzl@6937: OopsInHeapRegionClosure* _evac_failure_cl; tschatzl@6937: tschatzl@6937: int _hash_seed; tschatzl@6937: uint _queue_num; tschatzl@6937: tschatzl@6937: size_t _term_attempts; tschatzl@6937: tschatzl@6937: double _start; tschatzl@6937: double _start_strong_roots; tschatzl@6937: double _strong_roots_time; tschatzl@6937: double _start_term; tschatzl@6937: double _term_time; tschatzl@6937: tschatzl@6937: // Map from young-age-index (0 == not young, 1 is youngest) to tschatzl@6937: // surviving words. base is what we get back from the malloc call tschatzl@6937: size_t* _surviving_young_words_base; tschatzl@6937: // this points into the array, as we use the first few entries for padding tschatzl@6937: size_t* _surviving_young_words; tschatzl@6937: tschatzl@6937: #define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t)) tschatzl@6937: tschatzl@6937: void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; } tschatzl@6937: void add_to_undo_waste(size_t waste) { _undo_waste += waste; } tschatzl@6937: tschatzl@6937: DirtyCardQueue& dirty_card_queue() { return _dcq; } tschatzl@6937: G1SATBCardTableModRefBS* ctbs() { return _ct_bs; } tschatzl@6937: tschatzl@7651: InCSetState dest(InCSetState original) const { tschatzl@7651: assert(original.is_valid(), tschatzl@7651: err_msg("Original state invalid: " CSETSTATE_FORMAT, original.value())); tschatzl@7651: assert(_dest[original.value()].is_valid_gen(), tschatzl@7651: err_msg("Dest state is invalid: " CSETSTATE_FORMAT, _dest[original.value()].value())); tschatzl@7651: return _dest[original.value()]; tschatzl@7651: } tschatzl@7651: tschatzl@6938: public: tschatzl@6937: G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp); tschatzl@6938: ~G1ParScanThreadState(); tschatzl@6937: tschatzl@6937: ageTable* age_table() { return &_age_table; } tschatzl@6937: tschatzl@6937: #ifdef ASSERT tschatzl@6938: bool queue_is_empty() const { return _refs->is_empty(); } tschatzl@6938: tschatzl@6937: bool verify_ref(narrowOop* ref) const; tschatzl@6937: bool verify_ref(oop* ref) const; tschatzl@6937: bool verify_task(StarTask ref) const; tschatzl@6937: #endif // ASSERT tschatzl@6937: tschatzl@6937: template void push_on_queue(T* ref) { tschatzl@6937: assert(verify_ref(ref), "sanity"); tschatzl@6938: _refs->push(ref); tschatzl@6937: } tschatzl@6937: tschatzl@7218: template void update_rs(HeapRegion* from, T* p, int tid) { tschatzl@7218: // If the new value of the field points to the same region or tschatzl@7218: // is the to-space, we don't need to include it in the Rset updates. tschatzl@7218: if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) { tschatzl@7218: size_t card_index = ctbs()->index_for(p); tschatzl@7218: // If the card hasn't been added to the buffer, do it. tschatzl@7218: if (ctbs()->mark_card_deferred(card_index)) { tschatzl@7218: dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index)); tschatzl@7218: } tschatzl@7218: } tschatzl@7218: } tschatzl@6937: tschatzl@6937: void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) { tschatzl@6937: _evac_failure_cl = evac_failure_cl; tschatzl@6937: } tschatzl@6938: tschatzl@6938: OopsInHeapRegionClosure* evac_failure_closure() { return _evac_failure_cl; } tschatzl@6937: tschatzl@6937: int* hash_seed() { return &_hash_seed; } tschatzl@6937: uint queue_num() { return _queue_num; } tschatzl@6937: tschatzl@6937: size_t term_attempts() const { return _term_attempts; } tschatzl@6937: void note_term_attempt() { _term_attempts++; } tschatzl@6937: tschatzl@6937: void start_strong_roots() { tschatzl@6937: _start_strong_roots = os::elapsedTime(); tschatzl@6937: } tschatzl@6937: void end_strong_roots() { tschatzl@6937: _strong_roots_time += (os::elapsedTime() - _start_strong_roots); tschatzl@6937: } tschatzl@6937: double strong_roots_time() const { return _strong_roots_time; } tschatzl@6937: tschatzl@6937: void start_term_time() { tschatzl@6937: note_term_attempt(); tschatzl@6937: _start_term = os::elapsedTime(); tschatzl@6937: } tschatzl@6937: void end_term_time() { tschatzl@6937: _term_time += (os::elapsedTime() - _start_term); tschatzl@6937: } tschatzl@6937: double term_time() const { return _term_time; } tschatzl@6937: tschatzl@6937: double elapsed_time() const { tschatzl@6937: return os::elapsedTime() - _start; tschatzl@6937: } tschatzl@6937: tschatzl@6938: static void print_termination_stats_hdr(outputStream* const st = gclog_or_tty); tschatzl@6938: void print_termination_stats(int i, outputStream* const st = gclog_or_tty) const; tschatzl@6937: tschatzl@6937: size_t* surviving_young_words() { tschatzl@6937: // We add on to hide entry 0 which accumulates surviving words for tschatzl@6937: // age -1 regions (i.e. non-young ones) tschatzl@6937: return _surviving_young_words; tschatzl@6937: } tschatzl@6937: tschatzl@6937: private: tschatzl@6937: #define G1_PARTIAL_ARRAY_MASK 0x2 tschatzl@6937: tschatzl@6937: inline bool has_partial_array_mask(oop* ref) const { tschatzl@6937: return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; tschatzl@6937: } tschatzl@6937: tschatzl@6937: // We never encode partial array oops as narrowOop*, so return false immediately. tschatzl@6937: // This allows the compiler to create optimized code when popping references from tschatzl@6937: // the work queue. tschatzl@6937: inline bool has_partial_array_mask(narrowOop* ref) const { tschatzl@6937: assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*"); tschatzl@6937: return false; tschatzl@6937: } tschatzl@6937: tschatzl@6937: // Only implement set_partial_array_mask() for regular oops, not for narrowOops. tschatzl@6937: // We always encode partial arrays as regular oop, to allow the tschatzl@6937: // specialization for has_partial_array_mask() for narrowOops above. tschatzl@6937: // This means that unintentional use of this method with narrowOops are caught tschatzl@6937: // by the compiler. tschatzl@6937: inline oop* set_partial_array_mask(oop obj) const { tschatzl@6937: assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); tschatzl@6937: return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); tschatzl@6937: } tschatzl@6937: tschatzl@6937: inline oop clear_partial_array_mask(oop* ref) const { tschatzl@6937: return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); tschatzl@6937: } tschatzl@6937: tschatzl@6937: inline void do_oop_partial_array(oop* p); tschatzl@6937: tschatzl@6937: // This method is applied to the fields of the objects that have just been copied. tschatzl@6938: template inline void do_oop_evac(T* p, HeapRegion* from); tschatzl@6937: tschatzl@6938: template inline void deal_with_reference(T* ref_to_scan); tschatzl@6937: tschatzl@6938: inline void dispatch_reference(StarTask ref); tschatzl@7651: tschatzl@7651: // Tries to allocate word_sz in the PLAB of the next "generation" after trying to tschatzl@7651: // allocate into dest. State is the original (source) cset state for the object tschatzl@7651: // that is allocated for. tschatzl@7651: // Returns a non-NULL pointer if successful, and updates dest if required. tschatzl@7651: HeapWord* allocate_in_next_plab(InCSetState const state, tschatzl@7651: InCSetState* dest, tschatzl@7651: size_t word_sz, tschatzl@7651: AllocationContext_t const context); tschatzl@7651: tschatzl@7651: inline InCSetState next_state(InCSetState const state, markOop const m, uint& age); tschatzl@6938: public: tschatzl@6937: tschatzl@7651: oop copy_to_survivor_space(InCSetState const state, oop const obj, markOop const old_mark); tschatzl@6937: tschatzl@6938: void trim_queue(); tschatzl@6937: tschatzl@6938: inline void steal_and_trim_queue(RefToScanQueueSet *task_queues); tschatzl@6937: }; tschatzl@6937: tschatzl@6937: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP