< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.cpp

Print this page

  1 /*
  2  * Copyright (c) 2013, 2022, Red Hat, Inc. All rights reserved.

  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "gc/shared/barrierSetNMethod.hpp"
 27 #include "gc/shenandoah/shenandoahBarrierSetClone.inline.hpp"
 28 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
 29 #include "gc/shenandoah/shenandoahBarrierSetNMethod.hpp"
 30 #include "gc/shenandoah/shenandoahBarrierSetStackChunk.hpp"
 31 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
 32 #include "gc/shenandoah/shenandoahHeap.inline.hpp"

 33 #include "gc/shenandoah/shenandoahStackWatermark.hpp"
 34 #ifdef COMPILER1
 35 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
 36 #endif
 37 #ifdef COMPILER2
 38 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
 39 #endif
 40 
 41 class ShenandoahBarrierSetC1;
 42 class ShenandoahBarrierSetC2;
 43 
 44 ShenandoahBarrierSet::ShenandoahBarrierSet(ShenandoahHeap* heap) :
 45   BarrierSet(make_barrier_set_assembler<ShenandoahBarrierSetAssembler>(),
 46              make_barrier_set_c1<ShenandoahBarrierSetC1>(),
 47              make_barrier_set_c2<ShenandoahBarrierSetC2>(),
 48              new ShenandoahBarrierSetNMethod(heap),
 49              new ShenandoahBarrierSetStackChunk(),
 50              BarrierSet::FakeRtti(BarrierSet::ShenandoahBarrierSet)),
 51   _heap(heap),
 52   _satb_mark_queue_buffer_allocator("SATB Buffer Allocator", ShenandoahSATBBufferSize),
 53   _satb_mark_queue_set(&_satb_mark_queue_buffer_allocator)
 54 {




 55 }
 56 
 57 ShenandoahBarrierSetAssembler* ShenandoahBarrierSet::assembler() {
 58   BarrierSetAssembler* const bsa = BarrierSet::barrier_set()->barrier_set_assembler();
 59   return reinterpret_cast<ShenandoahBarrierSetAssembler*>(bsa);
 60 }
 61 
 62 void ShenandoahBarrierSet::print_on(outputStream* st) const {
 63   st->print("ShenandoahBarrierSet");
 64 }
 65 
 66 bool ShenandoahBarrierSet::need_load_reference_barrier(DecoratorSet decorators, BasicType type) {
 67   if (!ShenandoahLoadRefBarrier) return false;
 68   // Only needed for references
 69   return is_reference_type(type);
 70 }
 71 
 72 bool ShenandoahBarrierSet::need_keep_alive_barrier(DecoratorSet decorators, BasicType type) {
 73   if (!ShenandoahSATBBarrier) return false;
 74   // Only needed for references

107       thread->set_nmethod_disarmed_guard_value(bs_nm->disarmed_guard_value());
108     }
109 
110     if (ShenandoahStackWatermarkBarrier) {
111       JavaThread* const jt = JavaThread::cast(thread);
112       StackWatermark* const watermark = new ShenandoahStackWatermark(jt);
113       StackWatermarkSet::add_watermark(jt, watermark);
114     }
115   }
116 }
117 
118 void ShenandoahBarrierSet::on_thread_detach(Thread *thread) {
119   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
120   _satb_mark_queue_set.flush_queue(queue);
121   if (thread->is_Java_thread()) {
122     PLAB* gclab = ShenandoahThreadLocalData::gclab(thread);
123     if (gclab != nullptr) {
124       gclab->retire();
125     }
126 









127     // SATB protocol requires to keep alive reachable oops from roots at the beginning of GC
128     if (ShenandoahStackWatermarkBarrier) {
129       if (_heap->is_concurrent_mark_in_progress()) {
130         ShenandoahKeepAliveClosure oops;
131         StackWatermarkSet::finish_processing(JavaThread::cast(thread), &oops, StackWatermarkKind::gc);
132       } else if (_heap->is_concurrent_weak_root_in_progress() && _heap->is_evacuation_in_progress()) {
133         ShenandoahContextEvacuateUpdateRootsClosure oops;
134         StackWatermarkSet::finish_processing(JavaThread::cast(thread), &oops, StackWatermarkKind::gc);
135       }
136     }
137   }
138 }
139 
140 void ShenandoahBarrierSet::clone_barrier_runtime(oop src) {
141   if (_heap->has_forwarded_objects() || (ShenandoahIUBarrier && _heap->is_concurrent_mark_in_progress())) {
142     clone_barrier(src);
143   }
144 }




















  1 /*
  2  * Copyright (c) 2013, 2022, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"
 27 #include "gc/shared/barrierSetNMethod.hpp"
 28 #include "gc/shenandoah/shenandoahBarrierSetClone.inline.hpp"
 29 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
 30 #include "gc/shenandoah/shenandoahBarrierSetNMethod.hpp"
 31 #include "gc/shenandoah/shenandoahBarrierSetStackChunk.hpp"
 32 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
 33 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 34 #include "gc/shenandoah/shenandoahScanRemembered.inline.hpp"
 35 #include "gc/shenandoah/shenandoahStackWatermark.hpp"
 36 #ifdef COMPILER1
 37 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
 38 #endif
 39 #ifdef COMPILER2
 40 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
 41 #endif
 42 
 43 class ShenandoahBarrierSetC1;
 44 class ShenandoahBarrierSetC2;
 45 
 46 ShenandoahBarrierSet::ShenandoahBarrierSet(ShenandoahHeap* heap, MemRegion heap_region) :
 47   BarrierSet(make_barrier_set_assembler<ShenandoahBarrierSetAssembler>(),
 48              make_barrier_set_c1<ShenandoahBarrierSetC1>(),
 49              make_barrier_set_c2<ShenandoahBarrierSetC2>(),
 50              new ShenandoahBarrierSetNMethod(heap),
 51              new ShenandoahBarrierSetStackChunk(),
 52              BarrierSet::FakeRtti(BarrierSet::ShenandoahBarrierSet)),
 53   _heap(heap),
 54   _satb_mark_queue_buffer_allocator("SATB Buffer Allocator", ShenandoahSATBBufferSize),
 55   _satb_mark_queue_set(&_satb_mark_queue_buffer_allocator)
 56 {
 57   if (ShenandoahCardBarrier) {
 58     _card_table = new ShenandoahCardTable(heap_region);
 59     _card_table->initialize();
 60   }
 61 }
 62 
 63 ShenandoahBarrierSetAssembler* ShenandoahBarrierSet::assembler() {
 64   BarrierSetAssembler* const bsa = BarrierSet::barrier_set()->barrier_set_assembler();
 65   return reinterpret_cast<ShenandoahBarrierSetAssembler*>(bsa);
 66 }
 67 
 68 void ShenandoahBarrierSet::print_on(outputStream* st) const {
 69   st->print("ShenandoahBarrierSet");
 70 }
 71 
 72 bool ShenandoahBarrierSet::need_load_reference_barrier(DecoratorSet decorators, BasicType type) {
 73   if (!ShenandoahLoadRefBarrier) return false;
 74   // Only needed for references
 75   return is_reference_type(type);
 76 }
 77 
 78 bool ShenandoahBarrierSet::need_keep_alive_barrier(DecoratorSet decorators, BasicType type) {
 79   if (!ShenandoahSATBBarrier) return false;
 80   // Only needed for references

113       thread->set_nmethod_disarmed_guard_value(bs_nm->disarmed_guard_value());
114     }
115 
116     if (ShenandoahStackWatermarkBarrier) {
117       JavaThread* const jt = JavaThread::cast(thread);
118       StackWatermark* const watermark = new ShenandoahStackWatermark(jt);
119       StackWatermarkSet::add_watermark(jt, watermark);
120     }
121   }
122 }
123 
124 void ShenandoahBarrierSet::on_thread_detach(Thread *thread) {
125   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
126   _satb_mark_queue_set.flush_queue(queue);
127   if (thread->is_Java_thread()) {
128     PLAB* gclab = ShenandoahThreadLocalData::gclab(thread);
129     if (gclab != nullptr) {
130       gclab->retire();
131     }
132 
133     PLAB* plab = ShenandoahThreadLocalData::plab(thread);
134     // CAUTION: retire_plab may register the remnant filler object with the remembered set scanner without a lock.
135     // This is safe iff it is assured that each PLAB is a whole-number multiple of card-mark memory size and each
136     // PLAB is aligned with the start of each card's memory range.
137     // TODO: Assert this in retire_plab?
138     if (plab != nullptr) {
139       ShenandoahGenerationalHeap::heap()->retire_plab(plab);
140     }
141 
142     // SATB protocol requires to keep alive reachable oops from roots at the beginning of GC
143     if (ShenandoahStackWatermarkBarrier) {
144       if (_heap->is_concurrent_mark_in_progress()) {
145         ShenandoahKeepAliveClosure oops;
146         StackWatermarkSet::finish_processing(JavaThread::cast(thread), &oops, StackWatermarkKind::gc);
147       } else if (_heap->is_concurrent_weak_root_in_progress() && _heap->is_evacuation_in_progress()) {
148         ShenandoahContextEvacuateUpdateRootsClosure oops;
149         StackWatermarkSet::finish_processing(JavaThread::cast(thread), &oops, StackWatermarkKind::gc);
150       }
151     }
152   }
153 }
154 
155 void ShenandoahBarrierSet::clone_barrier_runtime(oop src) {
156   if (_heap->has_forwarded_objects() || (ShenandoahIUBarrier && _heap->is_concurrent_mark_in_progress())) {
157     clone_barrier(src);
158   }
159 }
160 
161 void ShenandoahBarrierSet::write_ref_array(HeapWord* start, size_t count) {
162   assert(ShenandoahCardBarrier, "Did you mean to enable ShenandoahCardBarrier?");
163 
164   HeapWord* end = (HeapWord*)((char*) start + (count * heapOopSize));
165   // In the case of compressed oops, start and end may potentially be misaligned;
166   // so we need to conservatively align the first downward (this is not
167   // strictly necessary for current uses, but a case of good hygiene and,
168   // if you will, aesthetics) and the second upward (this is essential for
169   // current uses) to a HeapWord boundary, so we mark all cards overlapping
170   // this write.
171   HeapWord* aligned_start = align_down(start, HeapWordSize);
172   HeapWord* aligned_end   = align_up  (end,   HeapWordSize);
173   // If compressed oops were not being used, these should already be aligned
174   assert(UseCompressedOops || (aligned_start == start && aligned_end == end),
175          "Expected heap word alignment of start and end");
176   _heap->card_scan()->mark_range_as_dirty(aligned_start, (aligned_end - aligned_start));
177 }
178 
< prev index next >