< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahMark.inline.hpp

Print this page
*** 1,7 ***
--- 1,8 ---
  /*
   * Copyright (c) 2015, 2022, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * 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.

*** 56,13 ***
      }
    }
  }
  
  template <class T, ShenandoahGenerationType GENERATION, StringDedupMode STRING_DEDUP>
! void ShenandoahMark::do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveData* live_data, StringDedup::Requests* const req, ShenandoahMarkTask* task) {
    oop obj = task->obj();
  
    shenandoah_assert_not_forwarded(nullptr, obj);
    shenandoah_assert_marked(nullptr, obj);
    shenandoah_assert_not_in_cset_except(nullptr, obj, ShenandoahHeap::heap()->cancelled_gc());
  
    // Are we in weak subgraph scan?
--- 57,17 ---
      }
    }
  }
  
  template <class T, ShenandoahGenerationType GENERATION, StringDedupMode STRING_DEDUP>
! void ShenandoahMark::do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveData* live_data, StringDedup::Requests* const req, ShenandoahMarkTask* task, uint worker_id) {
    oop obj = task->obj();
  
+   // TODO: This will push array chunks into the mark queue with no regard for
+   // generations. I don't think it will break anything, but the young generation
+   // scan might end up processing some old generation array chunks.
+ 
    shenandoah_assert_not_forwarded(nullptr, obj);
    shenandoah_assert_marked(nullptr, obj);
    shenandoah_assert_not_in_cset_except(nullptr, obj, ShenandoahHeap::heap()->cancelled_gc());
  
    // Are we in weak subgraph scan?

*** 93,27 ***
      }
      // Count liveness the last: push the outstanding work to the queues first
      // Avoid double-counting objects that are visited twice due to upgrade
      // from final- to strong mark.
      if (task->count_liveness()) {
!       count_liveness<GENERATION>(live_data, obj);
      }
    } else {
      // Case 4: Array chunk, has sensible chunk id. Process it.
      do_chunked_array<T>(q, cl, obj, task->chunk(), task->pow(), weak);
    }
  }
  
  template <ShenandoahGenerationType GENERATION>
! inline void ShenandoahMark::count_liveness(ShenandoahLiveData* live_data, oop obj) {
!   ShenandoahHeap* const heap = ShenandoahHeap::heap();
!   size_t region_idx = heap->heap_region_index_containing(obj);
!   ShenandoahHeapRegion* region = heap->get_region(region_idx);
!   size_t size = obj->size();
  
    if (!region->is_humongous_start()) {
      assert(!region->is_humongous(), "Cannot have continuations here");
      ShenandoahLiveData cur = live_data[region_idx];
      size_t new_val = size + cur;
      if (new_val >= SHENANDOAH_LIVEDATA_MAX) {
        // overflow, flush to region data
        region->increase_live_data_gc_words(new_val);
--- 98,39 ---
      }
      // Count liveness the last: push the outstanding work to the queues first
      // Avoid double-counting objects that are visited twice due to upgrade
      // from final- to strong mark.
      if (task->count_liveness()) {
!       count_liveness<GENERATION>(live_data, obj, worker_id);
      }
    } else {
      // Case 4: Array chunk, has sensible chunk id. Process it.
      do_chunked_array<T>(q, cl, obj, task->chunk(), task->pow(), weak);
    }
  }
  
  template <ShenandoahGenerationType GENERATION>
! inline void ShenandoahMark::count_liveness(ShenandoahLiveData* live_data, oop obj, uint worker_id) {
!   const ShenandoahHeap* const heap = ShenandoahHeap::heap();
!   const size_t region_idx = heap->heap_region_index_containing(obj);
!   ShenandoahHeapRegion* const region = heap->get_region(region_idx);
!   const size_t size = obj->size();
+ 
+   // Age census for objects in the young generation
+   if (GENERATION == YOUNG || (GENERATION == GLOBAL && region->is_young())) {
+     assert(heap->mode()->is_generational(), "Only if generational");
+     if (ShenandoahGenerationalAdaptiveTenuring && !ShenandoahGenerationalCensusAtEvac) {
+       assert(region->is_young(), "Only for young objects");
+       uint age = ShenandoahHeap::get_object_age(obj);
+       CENSUS_NOISE(heap->age_census()->add(age, region->age(), region->youth(), size, worker_id);)
+       NO_CENSUS_NOISE(heap->age_census()->add(age, region->age(), size, worker_id);)
+     }
+   }
  
    if (!region->is_humongous_start()) {
      assert(!region->is_humongous(), "Cannot have continuations here");
+     assert(region->is_affiliated(), "Do not count live data within Free Regular Region " SIZE_FORMAT, region_idx);
      ShenandoahLiveData cur = live_data[region_idx];
      size_t new_val = size + cur;
      if (new_val >= SHENANDOAH_LIVEDATA_MAX) {
        // overflow, flush to region data
        region->increase_live_data_gc_words(new_val);

*** 124,13 ***
--- 141,15 ---
      }
    } else {
      shenandoah_assert_in_correct_region(nullptr, obj);
      size_t num_regions = ShenandoahHeapRegion::required_regions(size * HeapWordSize);
  
+     assert(region->is_affiliated(), "Do not count live data within FREE Humongous Start Region " SIZE_FORMAT, region_idx);
      for (size_t i = region_idx; i < region_idx + num_regions; i++) {
        ShenandoahHeapRegion* chain_reg = heap->get_region(i);
        assert(chain_reg->is_humongous(), "Expecting a humongous region");
+       assert(chain_reg->is_affiliated(), "Do not count live data within FREE Humongous Continuation Region " SIZE_FORMAT, i);
        chain_reg->increase_live_data_gc_words(chain_reg->used() >> LogHeapWordSize);
      }
    }
  }
  

*** 233,57 ***
  
  template <ShenandoahGenerationType GENERATION>
  class ShenandoahSATBBufferClosure : public SATBBufferClosure {
  private:
    ShenandoahObjToScanQueue* _queue;
    ShenandoahHeap* _heap;
    ShenandoahMarkingContext* const _mark_context;
  public:
!   ShenandoahSATBBufferClosure(ShenandoahObjToScanQueue* q) :
      _queue(q),
      _heap(ShenandoahHeap::heap()),
      _mark_context(_heap->marking_context())
    {
    }
  
    void do_buffer(void **buffer, size_t size) {
!     assert(size == 0 || !_heap->has_forwarded_objects(), "Forwarded objects are not expected here");
      for (size_t i = 0; i < size; ++i) {
        oop *p = (oop *) &buffer[i];
!       ShenandoahMark::mark_through_ref<oop, GENERATION>(p, _queue, _mark_context, false);
      }
    }
  };
  
  template<class T, ShenandoahGenerationType GENERATION>
! inline void ShenandoahMark::mark_through_ref(T* p, ShenandoahObjToScanQueue* q, ShenandoahMarkingContext* const mark_context, bool weak) {
    T o = RawAccess<>::oop_load(p);
    if (!CompressedOops::is_null(o)) {
      oop obj = CompressedOops::decode_not_null(o);
  
      shenandoah_assert_not_forwarded(p, obj);
!     shenandoah_assert_not_in_cset_except(p, obj, ShenandoahHeap::heap()->cancelled_gc());
! 
!     bool skip_live = false;
!     bool marked;
!     if (weak) {
!       marked = mark_context->mark_weak(obj);
!     } else {
!       marked = mark_context->mark_strong(obj, /* was_upgraded = */ skip_live);
!     }
!     if (marked) {
!       bool pushed = q->push(ShenandoahMarkTask(obj, skip_live, weak));
!       assert(pushed, "overflow queue should always succeed pushing");
      }
  
!     shenandoah_assert_marked(p, obj);
    }
  }
  
  ShenandoahObjToScanQueueSet* ShenandoahMark::task_queues() const {
    return _task_queues;
  }
  
  ShenandoahObjToScanQueue* ShenandoahMark::get_queue(uint index) const {
    return _task_queues->queue(index);
  }
  #endif // SHARE_GC_SHENANDOAH_SHENANDOAHMARK_INLINE_HPP
--- 252,115 ---
  
  template <ShenandoahGenerationType GENERATION>
  class ShenandoahSATBBufferClosure : public SATBBufferClosure {
  private:
    ShenandoahObjToScanQueue* _queue;
+   ShenandoahObjToScanQueue* _old_queue;
    ShenandoahHeap* _heap;
    ShenandoahMarkingContext* const _mark_context;
  public:
!   ShenandoahSATBBufferClosure(ShenandoahObjToScanQueue* q, ShenandoahObjToScanQueue* old_q) :
      _queue(q),
+     _old_queue(old_q),
      _heap(ShenandoahHeap::heap()),
      _mark_context(_heap->marking_context())
    {
    }
  
    void do_buffer(void **buffer, size_t size) {
!     assert(size == 0 || !_heap->has_forwarded_objects() || _heap->is_concurrent_old_mark_in_progress(), "Forwarded objects are not expected here");
      for (size_t i = 0; i < size; ++i) {
        oop *p = (oop *) &buffer[i];
!       ShenandoahMark::mark_through_ref<oop, GENERATION>(p, _queue, _old_queue, _mark_context, false);
      }
    }
  };
  
+ template<ShenandoahGenerationType GENERATION>
+ bool ShenandoahMark::in_generation(ShenandoahHeap* const heap, oop obj) {
+   // Each in-line expansion of in_generation() resolves GENERATION at compile time.
+   if (GENERATION == YOUNG) {
+     return heap->is_in_young(obj);
+   } else if (GENERATION == OLD) {
+     return heap->is_in_old(obj);
+   } else if (GENERATION == GLOBAL || GENERATION == NON_GEN) {
+     return true;
+   } else {
+     return false;
+   }
+ }
+ 
  template<class T, ShenandoahGenerationType GENERATION>
! inline void ShenandoahMark::mark_through_ref(T *p, ShenandoahObjToScanQueue* q, ShenandoahObjToScanQueue* old_q, ShenandoahMarkingContext* const mark_context, bool weak) {
+   // Note: This is a very hot code path, so the code should be conditional on GENERATION template
+   // parameter where possible, in order to generate the most efficient code.
+ 
    T o = RawAccess<>::oop_load(p);
    if (!CompressedOops::is_null(o)) {
      oop obj = CompressedOops::decode_not_null(o);
  
+     ShenandoahHeap* heap = ShenandoahHeap::heap();
      shenandoah_assert_not_forwarded(p, obj);
!     shenandoah_assert_not_in_cset_except(p, obj, heap->cancelled_gc());
!     if (in_generation<GENERATION>(heap, obj)) {
!       mark_ref(q, mark_context, weak, obj);
!       shenandoah_assert_marked(p, obj);
!       // TODO: As implemented herein, GLOBAL collections reconstruct the card table during GLOBAL concurrent
!       // marking. Note that the card table is cleaned at init_mark time so it needs to be reconstructed to support
!       // future young-gen collections.  It might be better to reconstruct card table in a different phase.  We could
!       // either mark all live memory as dirty, or could use the GLOBAL update-refs scanning of pointers to determine
!       // precisely which cards to flag as dirty.
!       if (GENERATION == YOUNG && heap->is_in_old(p)) {
!         // Mark card as dirty because remembered set scanning still finds interesting pointer.
!         heap->mark_card_as_dirty((HeapWord*)p);
+       } else if (GENERATION == GLOBAL && heap->is_in_old(p) && heap->is_in_young(obj)) {
+         // Mark card as dirty because GLOBAL marking finds interesting pointer.
+         heap->mark_card_as_dirty((HeapWord*)p);
+       }
+     } else if (old_q != nullptr) {
+       // Young mark, bootstrapping old_q or concurrent with old_q marking.
+       mark_ref(old_q, mark_context, weak, obj);
+       shenandoah_assert_marked(p, obj);
+     } else if (GENERATION == OLD) {
+       // Old mark, found a young pointer.
+       // TODO:  Rethink this: may be redundant with dirtying of cards identified during young-gen remembered set scanning
+       // and by mutator write barriers.  Assert
+       if (heap->is_in(p)) {
+         assert(heap->is_in_young(obj), "Expected young object.");
+         heap->mark_card_as_dirty(p);
+       }
      }
+   }
+ }
  
! inline void ShenandoahMark::mark_ref(ShenandoahObjToScanQueue* q,
+                               ShenandoahMarkingContext* const mark_context,
+                               bool weak, oop obj) {
+   bool skip_live = false;
+   bool marked;
+   if (weak) {
+     marked = mark_context->mark_weak(obj);
+   } else {
+     marked = mark_context->mark_strong(obj, /* was_upgraded = */ skip_live);
+   }
+   if (marked) {
+     bool pushed = q->push(ShenandoahMarkTask(obj, skip_live, weak));
+     assert(pushed, "overflow queue should always succeed pushing");
    }
  }
  
  ShenandoahObjToScanQueueSet* ShenandoahMark::task_queues() const {
    return _task_queues;
  }
  
  ShenandoahObjToScanQueue* ShenandoahMark::get_queue(uint index) const {
    return _task_queues->queue(index);
  }
+ 
+ ShenandoahObjToScanQueue* ShenandoahMark::get_old_queue(uint index) const {
+   if (_old_gen_task_queues != nullptr) {
+     return _old_gen_task_queues->queue(index);
+   }
+   return nullptr;
+ }
+ 
  #endif // SHARE_GC_SHENANDOAH_SHENANDOAHMARK_INLINE_HPP
< prev index next >