src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp

Print this page
rev 5917 : [mq]: cleanup-parcopyclosure

*** 696,722 **** assert(!_in_cset_fast_test_base[index], "invariant"); _in_cset_fast_test_base[index] = true; } // This is a fast test on whether a reference points into the ! // collection set or not. It does not assume that the reference ! // points into the heap; if it doesn't, it will return false. bool in_cset_fast_test(oop obj) { assert(_in_cset_fast_test != NULL, "sanity"); ! if (_g1_committed.contains((HeapWord*) obj)) { // no need to subtract the bottom of the heap from obj, // _in_cset_fast_test is biased uintx index = cast_from_oop<uintx>(obj) >> HeapRegion::LogOfHRGrainBytes; bool ret = _in_cset_fast_test[index]; // let's make sure the result is consistent with what the slower // test returns assert( ret || !obj_in_cs(obj), "sanity"); assert(!ret || obj_in_cs(obj), "sanity"); return ret; - } else { - return false; - } } void clear_cset_fast_test() { assert(_in_cset_fast_test_base != NULL, "sanity"); memset(_in_cset_fast_test_base, false, --- 696,719 ---- assert(!_in_cset_fast_test_base[index], "invariant"); _in_cset_fast_test_base[index] = true; } // This is a fast test on whether a reference points into the ! // collection set or not. Assume that the reference ! // points into the heap. bool in_cset_fast_test(oop obj) { assert(_in_cset_fast_test != NULL, "sanity"); ! assert(_g1_committed.contains((HeapWord*) obj), "invariant"); // no need to subtract the bottom of the heap from obj, // _in_cset_fast_test is biased uintx index = cast_from_oop<uintx>(obj) >> HeapRegion::LogOfHRGrainBytes; bool ret = _in_cset_fast_test[index]; // let's make sure the result is consistent with what the slower // test returns assert( ret || !obj_in_cs(obj), "sanity"); assert(!ret || obj_in_cs(obj), "sanity"); return ret; } void clear_cset_fast_test() { assert(_in_cset_fast_test_base != NULL, "sanity"); memset(_in_cset_fast_test_base, false,
*** 1879,1891 **** ageTable _age_table; size_t _alloc_buffer_waste; size_t _undo_waste; OopsInHeapRegionClosure* _evac_failure_cl; - G1ParScanHeapEvacClosure* _evac_cl; - G1ParScanPartialArrayClosure* _partial_scan_cl; int _hash_seed; uint _queue_num; size_t _term_attempts; --- 1876,1887 ---- ageTable _age_table; size_t _alloc_buffer_waste; size_t _undo_waste; + G1ParScanClosure _scanner; OopsInHeapRegionClosure* _evac_failure_cl; int _hash_seed; uint _queue_num; size_t _term_attempts;
*** 1928,1938 **** } } } public: ! G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num); ~G1ParScanThreadState() { FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC); } --- 1924,1934 ---- } } } public: ! G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp); ~G1ParScanThreadState() { FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC); }
*** 2007,2024 **** } OopsInHeapRegionClosure* evac_failure_closure() { return _evac_failure_cl; } - void set_evac_closure(G1ParScanHeapEvacClosure* evac_cl) { - _evac_cl = evac_cl; - } - - void set_partial_scan_closure(G1ParScanPartialArrayClosure* partial_scan_cl) { - _partial_scan_cl = partial_scan_cl; - } - int* hash_seed() { return &_hash_seed; } uint queue_num() { return _queue_num; } size_t term_attempts() const { return _term_attempts; } void note_term_attempt() { _term_attempts++; } --- 2003,2012 ----
*** 2063,2082 **** true /* end_of_gc */, false /* retain */); } } ! template <class T> void deal_with_reference(T* ref_to_scan) { ! if (has_partial_array_mask(ref_to_scan)) { ! _partial_scan_cl->do_oop_nv(ref_to_scan); } else { // Note: we can use "raw" versions of "region_containing" because // "obj_to_scan" is definitely in the heap, and is not in a // humongous region. HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan); ! _evac_cl->set_region(r); ! _evac_cl->do_oop_nv(ref_to_scan); } } void deal_with_reference(StarTask ref) { assert(verify_task(ref), "sanity"); --- 2051,2189 ---- true /* end_of_gc */, false /* retain */); } } ! private: ! #define G1_PARTIAL_ARRAY_MASK 0x2 ! ! inline bool has_partial_array_mask(oop* const 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* const 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) { ! assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); ! return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); ! } ! ! // We always encode continuations as oop*, so we only need clear_partial_array_mask() ! // with an oop* parameter. ! inline oop clear_partial_array_mask(oop* ref) const { ! return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); ! } ! ! static int min_array_chunking_size() { ! return 2 * ParGCArrayScanChunk; ! } ! ! static bool obj_needs_chunking(oop obj, size_t word_size) { ! return (word_size > (size_t)min_array_chunking_size()) && obj->is_objArray(); ! } ! ! void do_oop_partial_array(oop* p) { ! assert(has_partial_array_mask(p), "invariant"); ! oop from_obj = clear_partial_array_mask(p); ! ! assert(Universe::heap()->is_in_reserved(from_obj), "must be in heap."); ! assert(from_obj->is_objArray(), "must be obj array"); ! objArrayOop from_obj_array = objArrayOop(from_obj); ! // The from-space object contains the real length. ! int length = from_obj_array->length(); ! ! assert(from_obj->is_forwarded(), "must be forwarded"); ! oop to_obj = from_obj->forwardee(); ! assert(from_obj != to_obj, "should not be chunking self-forwarded objects"); ! objArrayOop to_obj_array = objArrayOop(to_obj); ! // We keep track of the next start index in the length field of the ! // to-space object. ! int next_index = to_obj_array->length(); ! assert(0 <= next_index && next_index < length, ! err_msg("invariant, next index: %d, length: %d", next_index, length)); ! ! int start = next_index; ! int end = length; ! assert(start <= end, "invariant"); ! int remainder = end - start; ! // We'll try not to push a range that's smaller than ParGCArrayScanChunk. ! if (remainder > min_array_chunking_size()) { ! end = start + ParGCArrayScanChunk; ! to_obj_array->set_length(end); ! // Push the remainder before we process the range in case another ! // worker has run out of things to do and can steal it. ! oop* from_obj_p = set_partial_array_mask(from_obj); ! push_on_queue(from_obj_p); } else { + assert(length == end, "sanity"); + // We'll process the final range for this object. Restore the length + // so that the heap remains parsable in case of evacuation failure. + to_obj_array->set_length(end); + } + _scanner.set_region(_g1h->heap_region_containing_raw(to_obj)); + // Process indexes [start,end). It will also process the header + // along with the first chunk (i.e., the chunk with start == 0). + // Note that at this point the length field of to_obj_array is not + // correct given that we are using it to keep track of the next + // start index. oop_iterate_range() (thankfully!) ignores the length + // field and only relies on the start / end parameters. It does + // however return the size of the object which will be incorrect. So + // we have to ignore it even if we wanted to use it. + to_obj_array->oop_iterate_range(&_scanner, start, end); + } + + // This method is applied to the fields of the objects that have just been copied. + template <class T> void do_oop_evac(T* p, HeapRegion* from) { + assert(!oopDesc::is_null(oopDesc::load_decode_heap_oop(p)), + "Reference should not be NULL here as such are never pushed to the task queue."); + oop obj = oopDesc::load_decode_heap_oop_not_null(p); + + // Although we never intentionally push references outside of the collection + // set, due to (benign) races in the claim mechanism during RSet scanning more + // than one thread might claim the same card. So the same card may be + // processed multiple times. So redo this check. + if (_g1h->in_cset_fast_test(obj)) { + oop forwardee; + if (obj->is_forwarded()) { + forwardee = obj->forwardee(); + } else { + forwardee = copy_to_survivor_space(obj); + } + assert(forwardee != NULL, "forwardee should not be NULL"); + oopDesc::encode_store_heap_oop(p, forwardee); + } + + assert(obj != NULL, "Must be"); + update_rs(from, p, queue_num()); + } + + public: + + oop copy_to_survivor_space(oop old); + + template <class T> void deal_with_reference(T* ref_to_scan) { + if (!has_partial_array_mask(ref_to_scan)) { // Note: we can use "raw" versions of "region_containing" because // "obj_to_scan" is definitely in the heap, and is not in a // humongous region. HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan); ! do_oop_evac(ref_to_scan, r); ! } else { ! // Partial arrays are always encoded as oop*. Cast here to avoid generating ! // the superfluous additional method. ! do_oop_partial_array((oop*)ref_to_scan); } } void deal_with_reference(StarTask ref) { assert(verify_task(ref), "sanity");