< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2013, 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/g1/g1BarrierSet.hpp"
  26 #include "gc/shenandoah/shenandoahAsserts.hpp"
  27 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  28 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
  29 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  31 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  32 #include "gc/shenandoah/shenandoahTraversalGC.hpp"
  33 #include "memory/iterator.inline.hpp"
  34 #include "runtime/interfaceSupport.inline.hpp"
  35 #ifdef COMPILER1
  36 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
  37 #endif
  38 #ifdef COMPILER2
  39 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  40 #endif
  41 
  42 class ShenandoahBarrierSetC1;
  43 class ShenandoahBarrierSetC2;
  44 
  45 template <bool STOREVAL_WRITE_BARRIER>


 191   if (!ShenandoahCloneBarrier) return;
 192   if (! need_update_refs_barrier()) return;
 193 
 194   // This is called for cloning an object (see jvm.cpp) after the clone
 195   // has been made. We are not interested in any 'previous value' because
 196   // it would be NULL in any case. But we *are* interested in any oop*
 197   // that potentially need to be updated.
 198 
 199   oop obj = oop(mr.start());
 200   shenandoah_assert_correct(NULL, obj);
 201   if (_heap->is_concurrent_traversal_in_progress()) {
 202     ShenandoahEvacOOMScope oom_evac_scope;
 203     ShenandoahUpdateRefsForOopClosure</* wb = */ true> cl;
 204     obj->oop_iterate(&cl);
 205   } else {
 206     ShenandoahUpdateRefsForOopClosure</* wb = */ false> cl;
 207     obj->oop_iterate(&cl);
 208   }
 209 }
 210 
 211 oop ShenandoahBarrierSet::read_barrier(oop src) {
 212   // Check for forwarded objects, because on Full GC path we might deal with
 213   // non-trivial fwdptrs that contain Full GC specific metadata. We could check
 214   // for is_full_gc_in_progress(), but this also covers the case of stable heap,
 215   // which provides a bit of performance improvement.
 216   if (ShenandoahReadBarrier && _heap->has_forwarded_objects()) {
 217     return ShenandoahBarrierSet::resolve_forwarded(src);
 218   } else {
 219     return src;
 220   }
 221 }
 222 
 223 bool ShenandoahBarrierSet::obj_equals(oop obj1, oop obj2) {
 224   bool eq = oopDesc::equals_raw(obj1, obj2);
 225   if (! eq && ShenandoahAcmpBarrier) {
 226     OrderAccess::loadload();
 227     obj1 = resolve_forwarded(obj1);
 228     obj2 = resolve_forwarded(obj2);
 229     eq = oopDesc::equals_raw(obj1, obj2);
 230   }
 231   return eq;
 232 }
 233 
 234 oop ShenandoahBarrierSet::write_barrier_mutator(oop obj) {
 235   assert(UseShenandoahGC && ShenandoahWriteBarrier, "should be enabled");

 236   assert(_heap->is_gc_in_progress_mask(ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL), "evac should be in progress");
 237   shenandoah_assert_in_cset(NULL, obj);
 238 
 239   oop fwd = resolve_forwarded_not_null(obj);
 240   if (oopDesc::equals_raw(obj, fwd)) {
 241     ShenandoahEvacOOMScope oom_evac_scope;
 242 
 243     Thread* thread = Thread::current();
 244     oop res_oop = _heap->evacuate_object(obj, thread);
 245 
 246     // Since we are already here and paid the price of getting through runtime call adapters
 247     // and acquiring oom-scope, it makes sense to try and evacuate more adjacent objects,
 248     // thus amortizing the overhead. For sparsely live heaps, scan costs easily dominate
 249     // total assist costs, and can introduce a lot of evacuation latency. This is why we
 250     // only scan for _nearest_ N objects, regardless if they are eligible for evac or not.
 251     // The scan itself should also avoid touching the non-marked objects below TAMS, because
 252     // their metadata (notably, klasses) may be incorrect already.
 253 
 254     size_t max = ShenandoahEvacAssist;
 255     if (max > 0) {


 261       ShenandoahHeapRegion* r = _heap->heap_region_containing(obj);
 262       assert(r->is_cset(), "sanity");
 263 
 264       HeapWord* cur = (HeapWord*)obj + obj->size() + ShenandoahBrooksPointer::word_size();
 265 
 266       size_t count = 0;
 267       while ((cur < r->top()) && ctx->is_marked(oop(cur)) && (count++ < max)) {
 268         oop cur_oop = oop(cur);
 269         if (oopDesc::equals_raw(cur_oop, resolve_forwarded_not_null(cur_oop))) {
 270           _heap->evacuate_object(cur_oop, thread);
 271         }
 272         cur = cur + cur_oop->size() + ShenandoahBrooksPointer::word_size();
 273       }
 274     }
 275 
 276     return res_oop;
 277   }
 278   return fwd;
 279 }
 280 
 281 oop ShenandoahBarrierSet::write_barrier_impl(oop obj) {
 282   assert(UseShenandoahGC && ShenandoahWriteBarrier, "should be enabled");
 283   if (!CompressedOops::is_null(obj)) {
 284     bool evac_in_progress = _heap->is_gc_in_progress_mask(ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL);
 285     oop fwd = resolve_forwarded_not_null(obj);
 286     if (evac_in_progress &&
 287         _heap->in_collection_set(obj) &&
 288         oopDesc::equals_raw(obj, fwd)) {
 289       Thread *t = Thread::current();
 290       if (t->is_GC_task_thread()) {
 291         return _heap->evacuate_object(obj, t);
 292       } else {
 293         ShenandoahEvacOOMScope oom_evac_scope;
 294         return _heap->evacuate_object(obj, t);
 295       }
 296     } else {
 297       return fwd;
 298     }
 299   } else {
 300     return obj;
 301   }
 302 }
 303 
 304 oop ShenandoahBarrierSet::write_barrier(oop obj) {
 305   if (ShenandoahWriteBarrier && _heap->has_forwarded_objects()) {
 306     return write_barrier_impl(obj);
 307   } else {
 308     return obj;
 309   }
 310 }
 311 
 312 oop ShenandoahBarrierSet::storeval_barrier(oop obj) {
 313   if (ShenandoahStoreValEnqueueBarrier) {
 314     if (!CompressedOops::is_null(obj)) {
 315       obj = write_barrier(obj);
 316       enqueue(obj);
 317     }
 318   }
 319   if (ShenandoahStoreValReadBarrier) {
 320     obj = resolve_forwarded(obj);
 321   }
 322   return obj;
 323 }
 324 
 325 void ShenandoahBarrierSet::keep_alive_barrier(oop obj) {
 326   if (ShenandoahKeepAliveBarrier && _heap->is_concurrent_mark_in_progress()) {
 327     enqueue(obj);
 328   }
 329 }
 330 
 331 void ShenandoahBarrierSet::enqueue(oop obj) {
 332   shenandoah_assert_not_forwarded_if(NULL, obj, _heap->is_concurrent_traversal_in_progress());
 333   if (!_satb_mark_queue_set.is_active()) return;
 334 
 335   // Filter marked objects before hitting the SATB queues. The same predicate would
 336   // be used by SATBMQ::filter to eliminate already marked objects downstream, but
 337   // filtering here helps to avoid wasteful SATB queueing work to begin with.
 338   if (!_heap->requires_marking(obj)) return;
 339 
 340   Thread* thr = Thread::current();
 341   if (thr->is_Java_thread()) {
 342     ShenandoahThreadLocalData::satb_mark_queue(thr).enqueue(obj);
 343   } else {
 344     MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
 345     _satb_mark_queue_set.shared_satb_queue()->enqueue(obj);
 346   }
 347 }
 348 
 349 void ShenandoahBarrierSet::on_thread_create(Thread* thread) {
 350   // Create thread local data
 351   ShenandoahThreadLocalData::create(thread);
 352 }
 353 
 354 void ShenandoahBarrierSet::on_thread_destroy(Thread* thread) {
 355   // Destroy thread local data
 356   ShenandoahThreadLocalData::destroy(thread);
 357 }
 358 
 359 void ShenandoahBarrierSet::on_thread_attach(JavaThread* thread) {
 360   assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
 361   assert(!ShenandoahThreadLocalData::satb_mark_queue(thread).is_active(), "SATB queue should not be active");
 362   assert(ShenandoahThreadLocalData::satb_mark_queue(thread).is_empty(), "SATB queue should be empty");
 363   if (ShenandoahBarrierSet::satb_mark_queue_set().is_active()) {
 364     ShenandoahThreadLocalData::satb_mark_queue(thread).set_active(true);
 365   }
 366   ShenandoahThreadLocalData::set_gc_state(thread, _heap->gc_state());
 367   ShenandoahThreadLocalData::initialize_gclab(thread);
 368 }
 369 
 370 void ShenandoahBarrierSet::on_thread_detach(JavaThread* thread) {
 371   ShenandoahThreadLocalData::satb_mark_queue(thread).flush();
 372   PLAB* gclab = ShenandoahThreadLocalData::gclab(thread);
 373   if (gclab != NULL) {
 374     gclab->retire();





 375   }
 376 }
   1 /*
   2  * Copyright (c) 2013, 2019, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"

  25 #include "gc/shenandoah/shenandoahAsserts.hpp"
  26 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  27 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
  28 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  31 #include "gc/shenandoah/shenandoahTraversalGC.hpp"
  32 #include "memory/iterator.inline.hpp"
  33 #include "runtime/interfaceSupport.inline.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 template <bool STOREVAL_WRITE_BARRIER>


 190   if (!ShenandoahCloneBarrier) return;
 191   if (! need_update_refs_barrier()) return;
 192 
 193   // This is called for cloning an object (see jvm.cpp) after the clone
 194   // has been made. We are not interested in any 'previous value' because
 195   // it would be NULL in any case. But we *are* interested in any oop*
 196   // that potentially need to be updated.
 197 
 198   oop obj = oop(mr.start());
 199   shenandoah_assert_correct(NULL, obj);
 200   if (_heap->is_concurrent_traversal_in_progress()) {
 201     ShenandoahEvacOOMScope oom_evac_scope;
 202     ShenandoahUpdateRefsForOopClosure</* wb = */ true> cl;
 203     obj->oop_iterate(&cl);
 204   } else {
 205     ShenandoahUpdateRefsForOopClosure</* wb = */ false> cl;
 206     obj->oop_iterate(&cl);
 207   }
 208 }
 209 
 210 oop ShenandoahBarrierSet::load_reference_barrier_not_null(oop obj) {
 211   if (ShenandoahLoadRefBarrier && _heap->has_forwarded_objects()) {
 212     return load_reference_barrier_impl(obj);




 213   } else {
 214     return obj;
 215   }
 216 }
 217 
 218 oop ShenandoahBarrierSet::load_reference_barrier(oop obj) {
 219   if (obj != NULL) {
 220     return load_reference_barrier_not_null(obj);
 221   } else {
 222     return obj;


 223   }

 224 }
 225 
 226 
 227 oop ShenandoahBarrierSet::load_reference_barrier_mutator(oop obj) {
 228   assert(ShenandoahLoadRefBarrier, "should be enabled");
 229   assert(_heap->is_gc_in_progress_mask(ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL), "evac should be in progress");
 230   shenandoah_assert_in_cset(NULL, obj);
 231 
 232   oop fwd = resolve_forwarded_not_null(obj);
 233   if (oopDesc::equals_raw(obj, fwd)) {
 234     ShenandoahEvacOOMScope oom_evac_scope;
 235 
 236     Thread* thread = Thread::current();
 237     oop res_oop = _heap->evacuate_object(obj, thread);
 238 
 239     // Since we are already here and paid the price of getting through runtime call adapters
 240     // and acquiring oom-scope, it makes sense to try and evacuate more adjacent objects,
 241     // thus amortizing the overhead. For sparsely live heaps, scan costs easily dominate
 242     // total assist costs, and can introduce a lot of evacuation latency. This is why we
 243     // only scan for _nearest_ N objects, regardless if they are eligible for evac or not.
 244     // The scan itself should also avoid touching the non-marked objects below TAMS, because
 245     // their metadata (notably, klasses) may be incorrect already.
 246 
 247     size_t max = ShenandoahEvacAssist;
 248     if (max > 0) {


 254       ShenandoahHeapRegion* r = _heap->heap_region_containing(obj);
 255       assert(r->is_cset(), "sanity");
 256 
 257       HeapWord* cur = (HeapWord*)obj + obj->size() + ShenandoahBrooksPointer::word_size();
 258 
 259       size_t count = 0;
 260       while ((cur < r->top()) && ctx->is_marked(oop(cur)) && (count++ < max)) {
 261         oop cur_oop = oop(cur);
 262         if (oopDesc::equals_raw(cur_oop, resolve_forwarded_not_null(cur_oop))) {
 263           _heap->evacuate_object(cur_oop, thread);
 264         }
 265         cur = cur + cur_oop->size() + ShenandoahBrooksPointer::word_size();
 266       }
 267     }
 268 
 269     return res_oop;
 270   }
 271   return fwd;
 272 }
 273 
 274 oop ShenandoahBarrierSet::load_reference_barrier_impl(oop obj) {
 275   assert(ShenandoahLoadRefBarrier, "should be enabled");
 276   if (!CompressedOops::is_null(obj)) {
 277     bool evac_in_progress = _heap->is_gc_in_progress_mask(ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL);
 278     oop fwd = resolve_forwarded_not_null(obj);
 279     if (evac_in_progress &&
 280         _heap->in_collection_set(obj) &&
 281         oopDesc::equals_raw(obj, fwd)) {
 282       Thread *t = Thread::current();
 283       if (t->is_GC_task_thread()) {
 284         return _heap->evacuate_object(obj, t);
 285       } else {
 286         ShenandoahEvacOOMScope oom_evac_scope;
 287         return _heap->evacuate_object(obj, t);
 288       }
 289     } else {
 290       return fwd;
 291     }
 292   } else {
 293     return obj;
 294   }
 295 }
 296 
 297 void ShenandoahBarrierSet::storeval_barrier(oop obj) {
 298   if (ShenandoahStoreValEnqueueBarrier && !CompressedOops::is_null(obj)) {
 299     enqueue(obj);














 300   }

 301 }
 302 
 303 void ShenandoahBarrierSet::keep_alive_barrier(oop obj) {
 304   if (ShenandoahKeepAliveBarrier && _heap->is_concurrent_mark_in_progress()) {
 305     enqueue(obj);
 306   }
 307 }
 308 
 309 void ShenandoahBarrierSet::enqueue(oop obj) {
 310   shenandoah_assert_not_forwarded_if(NULL, obj, _heap->is_concurrent_traversal_in_progress());
 311   if (!_satb_mark_queue_set.is_active()) return;
 312 
 313   // Filter marked objects before hitting the SATB queues. The same predicate would
 314   // be used by SATBMQ::filter to eliminate already marked objects downstream, but
 315   // filtering here helps to avoid wasteful SATB queueing work to begin with.
 316   if (!_heap->requires_marking<false>(obj)) return;
 317 
 318   ShenandoahThreadLocalData::satb_mark_queue(Thread::current()).enqueue(obj);






 319 }
 320 
 321 void ShenandoahBarrierSet::on_thread_create(Thread* thread) {
 322   // Create thread local data
 323   ShenandoahThreadLocalData::create(thread);
 324 }
 325 
 326 void ShenandoahBarrierSet::on_thread_destroy(Thread* thread) {
 327   // Destroy thread local data
 328   ShenandoahThreadLocalData::destroy(thread);
 329 }
 330 
 331 void ShenandoahBarrierSet::on_thread_attach(Thread *thread) {
 332   assert(!thread->is_Java_thread() || !SafepointSynchronize::is_at_safepoint(),
 333          "We should not be at a safepoint");
 334   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
 335   assert(!queue.is_active(), "SATB queue should not be active");
 336   assert( queue.is_empty(),  "SATB queue should be empty");
 337   queue.set_active(_satb_mark_queue_set.is_active());
 338   if (thread->is_Java_thread()) {
 339     ShenandoahThreadLocalData::set_gc_state(thread, _heap->gc_state());
 340     ShenandoahThreadLocalData::initialize_gclab(thread);
 341   }
 342 }
 343 
 344 void ShenandoahBarrierSet::on_thread_detach(Thread *thread) {
 345   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
 346   queue.flush();
 347   if (thread->is_Java_thread()) {
 348     PLAB* gclab = ShenandoahThreadLocalData::gclab(thread);
 349     if (gclab != NULL) {
 350       gclab->retire();
 351     }
 352   }
 353 }
< prev index next >