4566 } |
4565 } |
4567 |
4566 |
4568 G1ParGCAllocBuffer::G1ParGCAllocBuffer(size_t gclab_word_size) : |
4567 G1ParGCAllocBuffer::G1ParGCAllocBuffer(size_t gclab_word_size) : |
4569 ParGCAllocBuffer(gclab_word_size), _retired(true) { } |
4568 ParGCAllocBuffer(gclab_word_size), _retired(true) { } |
4570 |
4569 |
4571 G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp) |
|
4572 : _g1h(g1h), |
|
4573 _refs(g1h->task_queue(queue_num)), |
|
4574 _dcq(&g1h->dirty_card_queue_set()), |
|
4575 _ct_bs(g1h->g1_barrier_set()), |
|
4576 _g1_rem(g1h->g1_rem_set()), |
|
4577 _hash_seed(17), _queue_num(queue_num), |
|
4578 _term_attempts(0), |
|
4579 _surviving_alloc_buffer(g1h->desired_plab_sz(GCAllocForSurvived)), |
|
4580 _tenured_alloc_buffer(g1h->desired_plab_sz(GCAllocForTenured)), |
|
4581 _age_table(false), _scanner(g1h, this, rp), |
|
4582 _strong_roots_time(0), _term_time(0), |
|
4583 _alloc_buffer_waste(0), _undo_waste(0) { |
|
4584 // we allocate G1YoungSurvRateNumRegions plus one entries, since |
|
4585 // we "sacrifice" entry 0 to keep track of surviving bytes for |
|
4586 // non-young regions (where the age is -1) |
|
4587 // We also add a few elements at the beginning and at the end in |
|
4588 // an attempt to eliminate cache contention |
|
4589 uint real_length = 1 + _g1h->g1_policy()->young_cset_region_length(); |
|
4590 uint array_length = PADDING_ELEM_NUM + |
|
4591 real_length + |
|
4592 PADDING_ELEM_NUM; |
|
4593 _surviving_young_words_base = NEW_C_HEAP_ARRAY(size_t, array_length, mtGC); |
|
4594 if (_surviving_young_words_base == NULL) |
|
4595 vm_exit_out_of_memory(array_length * sizeof(size_t), OOM_MALLOC_ERROR, |
|
4596 "Not enough space for young surv histo."); |
|
4597 _surviving_young_words = _surviving_young_words_base + PADDING_ELEM_NUM; |
|
4598 memset(_surviving_young_words, 0, (size_t) real_length * sizeof(size_t)); |
|
4599 |
|
4600 _alloc_buffers[GCAllocForSurvived] = &_surviving_alloc_buffer; |
|
4601 _alloc_buffers[GCAllocForTenured] = &_tenured_alloc_buffer; |
|
4602 |
|
4603 _start = os::elapsedTime(); |
|
4604 } |
|
4605 |
|
4606 void |
|
4607 G1ParScanThreadState::print_termination_stats_hdr(outputStream* const st) |
|
4608 { |
|
4609 st->print_raw_cr("GC Termination Stats"); |
|
4610 st->print_raw_cr(" elapsed --strong roots-- -------termination-------" |
|
4611 " ------waste (KiB)------"); |
|
4612 st->print_raw_cr("thr ms ms % ms % attempts" |
|
4613 " total alloc undo"); |
|
4614 st->print_raw_cr("--- --------- --------- ------ --------- ------ --------" |
|
4615 " ------- ------- -------"); |
|
4616 } |
|
4617 |
|
4618 void |
|
4619 G1ParScanThreadState::print_termination_stats(int i, |
|
4620 outputStream* const st) const |
|
4621 { |
|
4622 const double elapsed_ms = elapsed_time() * 1000.0; |
|
4623 const double s_roots_ms = strong_roots_time() * 1000.0; |
|
4624 const double term_ms = term_time() * 1000.0; |
|
4625 st->print_cr("%3d %9.2f %9.2f %6.2f " |
|
4626 "%9.2f %6.2f " SIZE_FORMAT_W(8) " " |
|
4627 SIZE_FORMAT_W(7) " " SIZE_FORMAT_W(7) " " SIZE_FORMAT_W(7), |
|
4628 i, elapsed_ms, s_roots_ms, s_roots_ms * 100 / elapsed_ms, |
|
4629 term_ms, term_ms * 100 / elapsed_ms, term_attempts(), |
|
4630 (alloc_buffer_waste() + undo_waste()) * HeapWordSize / K, |
|
4631 alloc_buffer_waste() * HeapWordSize / K, |
|
4632 undo_waste() * HeapWordSize / K); |
|
4633 } |
|
4634 |
|
4635 #ifdef ASSERT |
|
4636 bool G1ParScanThreadState::verify_ref(narrowOop* ref) const { |
|
4637 assert(ref != NULL, "invariant"); |
|
4638 assert(UseCompressedOops, "sanity"); |
|
4639 assert(!has_partial_array_mask(ref), err_msg("ref=" PTR_FORMAT, ref)); |
|
4640 oop p = oopDesc::load_decode_heap_oop(ref); |
|
4641 assert(_g1h->is_in_g1_reserved(p), |
|
4642 err_msg("ref=" PTR_FORMAT " p=" PTR_FORMAT, ref, (void *)p)); |
|
4643 return true; |
|
4644 } |
|
4645 |
|
4646 bool G1ParScanThreadState::verify_ref(oop* ref) const { |
|
4647 assert(ref != NULL, "invariant"); |
|
4648 if (has_partial_array_mask(ref)) { |
|
4649 // Must be in the collection set--it's already been copied. |
|
4650 oop p = clear_partial_array_mask(ref); |
|
4651 assert(_g1h->obj_in_cs(p), |
|
4652 err_msg("ref=" PTR_FORMAT " p=" PTR_FORMAT, ref, (void *)p)); |
|
4653 } else { |
|
4654 oop p = oopDesc::load_decode_heap_oop(ref); |
|
4655 assert(_g1h->is_in_g1_reserved(p), |
|
4656 err_msg("ref=" PTR_FORMAT " p=" PTR_FORMAT, ref, (void *)p)); |
|
4657 } |
|
4658 return true; |
|
4659 } |
|
4660 |
|
4661 bool G1ParScanThreadState::verify_task(StarTask ref) const { |
|
4662 if (ref.is_narrow()) { |
|
4663 return verify_ref((narrowOop*) ref); |
|
4664 } else { |
|
4665 return verify_ref((oop*) ref); |
|
4666 } |
|
4667 } |
|
4668 #endif // ASSERT |
|
4669 |
|
4670 void G1ParScanThreadState::trim_queue() { |
|
4671 assert(_evac_failure_cl != NULL, "not set"); |
|
4672 |
|
4673 StarTask ref; |
|
4674 do { |
|
4675 // Drain the overflow stack first, so other threads can steal. |
|
4676 while (refs()->pop_overflow(ref)) { |
|
4677 deal_with_reference(ref); |
|
4678 } |
|
4679 |
|
4680 while (refs()->pop_local(ref)) { |
|
4681 deal_with_reference(ref); |
|
4682 } |
|
4683 } while (!refs()->is_empty()); |
|
4684 } |
|
4685 |
|
4686 G1ParClosureSuper::G1ParClosureSuper(G1CollectedHeap* g1, |
|
4687 G1ParScanThreadState* par_scan_state) : |
|
4688 _g1(g1), _par_scan_state(par_scan_state), |
|
4689 _worker_id(par_scan_state->queue_num()) { } |
|
4690 |
|
4691 void G1ParCopyHelper::mark_object(oop obj) { |
4570 void G1ParCopyHelper::mark_object(oop obj) { |
4692 #ifdef ASSERT |
4571 #ifdef ASSERT |
4693 HeapRegion* hr = _g1->heap_region_containing(obj); |
4572 HeapRegion* hr = _g1->heap_region_containing(obj); |
4694 assert(hr != NULL, "sanity"); |
4573 assert(hr != NULL, "sanity"); |
4695 assert(!hr->in_collection_set(), "should not mark objects in the CSet"); |
4574 assert(!hr->in_collection_set(), "should not mark objects in the CSet"); |
4717 // The object might be in the process of being copied by another |
4596 // The object might be in the process of being copied by another |
4718 // worker so we cannot trust that its to-space image is |
4597 // worker so we cannot trust that its to-space image is |
4719 // well-formed. So we have to read its size from its from-space |
4598 // well-formed. So we have to read its size from its from-space |
4720 // image which we know should not be changing. |
4599 // image which we know should not be changing. |
4721 _cm->grayRoot(to_obj, (size_t) from_obj->size(), _worker_id); |
4600 _cm->grayRoot(to_obj, (size_t) from_obj->size(), _worker_id); |
4722 } |
|
4723 |
|
4724 oop G1ParScanThreadState::copy_to_survivor_space(oop const old) { |
|
4725 size_t word_sz = old->size(); |
|
4726 HeapRegion* from_region = _g1h->heap_region_containing_raw(old); |
|
4727 // +1 to make the -1 indexes valid... |
|
4728 int young_index = from_region->young_index_in_cset()+1; |
|
4729 assert( (from_region->is_young() && young_index > 0) || |
|
4730 (!from_region->is_young() && young_index == 0), "invariant" ); |
|
4731 G1CollectorPolicy* g1p = _g1h->g1_policy(); |
|
4732 markOop m = old->mark(); |
|
4733 int age = m->has_displaced_mark_helper() ? m->displaced_mark_helper()->age() |
|
4734 : m->age(); |
|
4735 GCAllocPurpose alloc_purpose = g1p->evacuation_destination(from_region, age, |
|
4736 word_sz); |
|
4737 HeapWord* obj_ptr = allocate(alloc_purpose, word_sz); |
|
4738 #ifndef PRODUCT |
|
4739 // Should this evacuation fail? |
|
4740 if (_g1h->evacuation_should_fail()) { |
|
4741 if (obj_ptr != NULL) { |
|
4742 undo_allocation(alloc_purpose, obj_ptr, word_sz); |
|
4743 obj_ptr = NULL; |
|
4744 } |
|
4745 } |
|
4746 #endif // !PRODUCT |
|
4747 |
|
4748 if (obj_ptr == NULL) { |
|
4749 // This will either forward-to-self, or detect that someone else has |
|
4750 // installed a forwarding pointer. |
|
4751 return _g1h->handle_evacuation_failure_par(this, old); |
|
4752 } |
|
4753 |
|
4754 oop obj = oop(obj_ptr); |
|
4755 |
|
4756 // We're going to allocate linearly, so might as well prefetch ahead. |
|
4757 Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes); |
|
4758 |
|
4759 oop forward_ptr = old->forward_to_atomic(obj); |
|
4760 if (forward_ptr == NULL) { |
|
4761 Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz); |
|
4762 |
|
4763 // alloc_purpose is just a hint to allocate() above, recheck the type of region |
|
4764 // we actually allocated from and update alloc_purpose accordingly |
|
4765 HeapRegion* to_region = _g1h->heap_region_containing_raw(obj_ptr); |
|
4766 alloc_purpose = to_region->is_young() ? GCAllocForSurvived : GCAllocForTenured; |
|
4767 |
|
4768 if (g1p->track_object_age(alloc_purpose)) { |
|
4769 // We could simply do obj->incr_age(). However, this causes a |
|
4770 // performance issue. obj->incr_age() will first check whether |
|
4771 // the object has a displaced mark by checking its mark word; |
|
4772 // getting the mark word from the new location of the object |
|
4773 // stalls. So, given that we already have the mark word and we |
|
4774 // are about to install it anyway, it's better to increase the |
|
4775 // age on the mark word, when the object does not have a |
|
4776 // displaced mark word. We're not expecting many objects to have |
|
4777 // a displaced marked word, so that case is not optimized |
|
4778 // further (it could be...) and we simply call obj->incr_age(). |
|
4779 |
|
4780 if (m->has_displaced_mark_helper()) { |
|
4781 // in this case, we have to install the mark word first, |
|
4782 // otherwise obj looks to be forwarded (the old mark word, |
|
4783 // which contains the forward pointer, was copied) |
|
4784 obj->set_mark(m); |
|
4785 obj->incr_age(); |
|
4786 } else { |
|
4787 m = m->incr_age(); |
|
4788 obj->set_mark(m); |
|
4789 } |
|
4790 age_table()->add(obj, word_sz); |
|
4791 } else { |
|
4792 obj->set_mark(m); |
|
4793 } |
|
4794 |
|
4795 if (G1StringDedup::is_enabled()) { |
|
4796 G1StringDedup::enqueue_from_evacuation(from_region->is_young(), |
|
4797 to_region->is_young(), |
|
4798 queue_num(), |
|
4799 obj); |
|
4800 } |
|
4801 |
|
4802 size_t* surv_young_words = surviving_young_words(); |
|
4803 surv_young_words[young_index] += word_sz; |
|
4804 |
|
4805 if (obj->is_objArray() && arrayOop(obj)->length() >= ParGCArrayScanChunk) { |
|
4806 // We keep track of the next start index in the length field of |
|
4807 // the to-space object. The actual length can be found in the |
|
4808 // length field of the from-space object. |
|
4809 arrayOop(obj)->set_length(0); |
|
4810 oop* old_p = set_partial_array_mask(old); |
|
4811 push_on_queue(old_p); |
|
4812 } else { |
|
4813 // No point in using the slower heap_region_containing() method, |
|
4814 // given that we know obj is in the heap. |
|
4815 _scanner.set_region(_g1h->heap_region_containing_raw(obj)); |
|
4816 obj->oop_iterate_backwards(&_scanner); |
|
4817 } |
|
4818 } else { |
|
4819 undo_allocation(alloc_purpose, obj_ptr, word_sz); |
|
4820 obj = forward_ptr; |
|
4821 } |
|
4822 return obj; |
|
4823 } |
4601 } |
4824 |
4602 |
4825 template <class T> |
4603 template <class T> |
4826 void G1ParCopyHelper::do_klass_barrier(T* p, oop new_obj) { |
4604 void G1ParCopyHelper::do_klass_barrier(T* p, oop new_obj) { |
4827 if (_g1->heap_region_containing_raw(new_obj)->is_young()) { |
4605 if (_g1->heap_region_containing_raw(new_obj)->is_young()) { |