Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahConcurrentMark.inline.hpp
38920 views
/*1* Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223#ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_INLINE_HPP24#define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_INLINE_HPP2526#include "gc_implementation/shenandoah/shenandoahAsserts.hpp"27#include "gc_implementation/shenandoah/shenandoahBarrierSet.inline.hpp"28#include "gc_implementation/shenandoah/shenandoahConcurrentMark.hpp"29#include "gc_implementation/shenandoah/shenandoahMarkingContext.inline.hpp"30#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"31#include "gc_implementation/shenandoah/shenandoahOopClosures.inline.hpp"32#include "gc_implementation/shenandoah/shenandoahStringDedup.hpp"33#include "gc_implementation/shenandoah/shenandoahTaskqueue.inline.hpp"34#include "memory/iterator.inline.hpp"35#include "oops/oop.inline.hpp"36#include "runtime/prefetch.inline.hpp"3738template <class T>39void ShenandoahConcurrentMark::do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveData* live_data, ShenandoahMarkTask* task) {40oop obj = task->obj();4142shenandoah_assert_not_forwarded(NULL, obj);43shenandoah_assert_marked(NULL, obj);44shenandoah_assert_not_in_cset_except(NULL, obj, _heap->cancelled_gc());4546if (task->is_not_chunked()) {47if (obj->is_instance()) {48// Case 1: Normal oop, process as usual.49obj->oop_iterate(cl);50} else if (obj->is_objArray()) {51// Case 2: Object array instance and no chunk is set. Must be the first52// time we visit it, start the chunked processing.53do_chunked_array_start<T>(q, cl, obj);54} else {55// Case 3: Primitive array. Do nothing, no oops there. We use the same56// performance tweak TypeArrayKlass::oop_oop_iterate_impl is using:57// We skip iterating over the klass pointer since we know that58// Universe::TypeArrayKlass never moves.59assert (obj->is_typeArray(), "should be type array");60}61// Count liveness the last: push the outstanding work to the queues first62count_liveness(live_data, obj);63} else {64// Case 4: Array chunk, has sensible chunk id. Process it.65do_chunked_array<T>(q, cl, obj, task->chunk(), task->pow());66}67}6869inline void ShenandoahConcurrentMark::count_liveness(ShenandoahLiveData* live_data, oop obj) {70size_t region_idx = _heap->heap_region_index_containing(obj);71ShenandoahHeapRegion* region = _heap->get_region(region_idx);72size_t size = obj->size();7374if (!region->is_humongous_start()) {75assert(!region->is_humongous(), "Cannot have continuations here");76ShenandoahLiveData cur = live_data[region_idx];77size_t new_val = size + cur;78if (new_val >= SHENANDOAH_LIVEDATA_MAX) {79// overflow, flush to region data80region->increase_live_data_gc_words(new_val);81live_data[region_idx] = 0;82} else {83// still good, remember in locals84live_data[region_idx] = (ShenandoahLiveData) new_val;85}86} else {87shenandoah_assert_in_correct_region(NULL, obj);88size_t num_regions = ShenandoahHeapRegion::required_regions(size * HeapWordSize);8990for (size_t i = region_idx; i < region_idx + num_regions; i++) {91ShenandoahHeapRegion* chain_reg = _heap->get_region(i);92assert(chain_reg->is_humongous(), "Expecting a humongous region");93chain_reg->increase_live_data_gc_words(chain_reg->used() >> LogHeapWordSize);94}95}96}9798template <class T>99inline void ShenandoahConcurrentMark::do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop obj) {100assert(obj->is_objArray(), "expect object array");101objArrayOop array = objArrayOop(obj);102int len = array->length();103104if (len <= (int) ObjArrayMarkingStride*2) {105// A few slices only, process directly106array->oop_iterate_range(cl, 0, len);107} else {108int bits = log2_long(len);109// Compensate for non-power-of-two arrays, cover the array in excess:110if (len != (1 << bits)) bits++;111112// Only allow full chunks on the queue. This frees do_chunked_array() from checking from/to113// boundaries against array->length(), touching the array header on every chunk.114//115// To do this, we cut the prefix in full-sized chunks, and submit them on the queue.116// If the array is not divided in chunk sizes, then there would be an irregular tail,117// which we will process separately.118119int last_idx = 0;120121int chunk = 1;122int pow = bits;123124// Handle overflow125if (pow >= 31) {126assert (pow == 31, "sanity");127pow--;128chunk = 2;129last_idx = (1 << pow);130bool pushed = q->push(ShenandoahMarkTask(array, 1, pow));131assert(pushed, "overflow queue should always succeed pushing");132}133134// Split out tasks, as suggested in ShenandoahMarkTask docs. Record the last135// successful right boundary to figure out the irregular tail.136while ((1 << pow) > (int)ObjArrayMarkingStride &&137(chunk*2 < ShenandoahMarkTask::chunk_size())) {138pow--;139int left_chunk = chunk*2 - 1;140int right_chunk = chunk*2;141int left_chunk_end = left_chunk * (1 << pow);142if (left_chunk_end < len) {143bool pushed = q->push(ShenandoahMarkTask(array, left_chunk, pow));144assert(pushed, "overflow queue should always succeed pushing");145chunk = right_chunk;146last_idx = left_chunk_end;147} else {148chunk = left_chunk;149}150}151152// Process the irregular tail, if present153int from = last_idx;154if (from < len) {155array->oop_iterate_range(cl, from, len);156}157}158}159160template <class T>161inline void ShenandoahConcurrentMark::do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop obj, int chunk, int pow) {162assert(obj->is_objArray(), "expect object array");163objArrayOop array = objArrayOop(obj);164165assert (ObjArrayMarkingStride > 0, "sanity");166167// Split out tasks, as suggested in ShenandoahMarkTask docs. Avoid pushing tasks that168// are known to start beyond the array.169while ((1 << pow) > (int)ObjArrayMarkingStride && (chunk*2 < ShenandoahMarkTask::chunk_size())) {170pow--;171chunk *= 2;172bool pushed = q->push(ShenandoahMarkTask(array, chunk - 1, pow));173assert(pushed, "overflow queue should always succeed pushing");174}175176int chunk_size = 1 << pow;177178int from = (chunk - 1) * chunk_size;179int to = chunk * chunk_size;180181#ifdef ASSERT182int len = array->length();183assert (0 <= from && from < len, err_msg("from is sane: %d/%d", from, len));184assert (0 < to && to <= len, err_msg("to is sane: %d/%d", to, len));185#endif186187array->oop_iterate_range(cl, from, to);188}189190class ShenandoahSATBBufferClosure : public SATBBufferClosure {191private:192ShenandoahObjToScanQueue* _queue;193ShenandoahStrDedupQueue* _dedup_queue;194ShenandoahHeap* _heap;195ShenandoahMarkingContext* const _mark_context;196public:197ShenandoahSATBBufferClosure(ShenandoahObjToScanQueue* q, ShenandoahStrDedupQueue* dq) :198_queue(q),199_dedup_queue(dq),200_heap(ShenandoahHeap::heap()),201_mark_context(_heap->marking_context())202{203}204205void do_buffer(void **buffer, size_t size) {206assert(size == 0 || !_heap->has_forwarded_objects(), "Forwarded objects are not expected here");207if (ShenandoahStringDedup::is_enabled()) {208do_buffer_impl<ENQUEUE_DEDUP>(buffer, size);209} else {210do_buffer_impl<NO_DEDUP>(buffer, size);211}212}213214template<StringDedupMode STRING_DEDUP>215void do_buffer_impl(void **buffer, size_t size) {216for (size_t i = 0; i < size; ++i) {217oop *p = (oop *) &buffer[i];218ShenandoahConcurrentMark::mark_through_ref<oop, NONE, STRING_DEDUP>(p, _heap, _queue, _mark_context, _dedup_queue);219}220}221};222223template<class T, UpdateRefsMode UPDATE_REFS, StringDedupMode STRING_DEDUP>224inline void ShenandoahConcurrentMark::mark_through_ref(T *p, ShenandoahHeap* heap, ShenandoahObjToScanQueue* q, ShenandoahMarkingContext* const mark_context, ShenandoahStrDedupQueue* dq) {225T o = oopDesc::load_heap_oop(p);226if (! oopDesc::is_null(o)) {227oop obj = oopDesc::decode_heap_oop_not_null(o);228switch (UPDATE_REFS) {229case NONE:230break;231case RESOLVE:232obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);233break;234case SIMPLE:235// We piggy-back reference updating to the marking tasks.236obj = heap->update_with_forwarded_not_null(p, obj);237break;238case CONCURRENT:239obj = heap->maybe_update_with_forwarded_not_null(p, obj);240break;241default:242ShouldNotReachHere();243}244245// Note: Only when concurrently updating references can obj be different246// (that is, really different, not just different from-/to-space copies of the same)247// from the one we originally loaded. Mutator thread can beat us by writing something248// else into the location. In that case, we would mark through that updated value,249// on the off-chance it is not handled by other means (e.g. via SATB). However,250// if that write was NULL, we don't need to do anything else.251if (UPDATE_REFS != CONCURRENT || !oopDesc::is_null(obj)) {252shenandoah_assert_not_forwarded(p, obj);253shenandoah_assert_not_in_cset_except(p, obj, heap->cancelled_gc());254255if (mark_context->mark(obj)) {256bool pushed = q->push(ShenandoahMarkTask(obj));257assert(pushed, "overflow queue should always succeed pushing");258259if ((STRING_DEDUP == ENQUEUE_DEDUP) && ShenandoahStringDedup::is_candidate(obj)) {260assert(ShenandoahStringDedup::is_enabled(), "Must be enabled");261assert(dq != NULL, "Dedup queue not set");262ShenandoahStringDedup::enqueue_candidate(obj, dq);263}264}265266shenandoah_assert_marked(p, obj);267}268}269}270271#endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_INLINE_HPP272273274