353 }
354
355 void HumongousRegionSetMtSafeChecker::check() {
356 // Humongous Set MT safety protocol:
357 // (a) If we're at a safepoint, operations on the master humongous
358 // set should be invoked by either the VM thread (which will
359 // serialize them) or by the GC workers while holding the
360 // OldSets_lock.
361 // (b) If we're not at a safepoint, operations on the master
362 // humongous set should be invoked while holding the Heap_lock.
363
364 if (SafepointSynchronize::is_at_safepoint()) {
365 guarantee(Thread::current()->is_VM_thread() ||
366 OldSets_lock->owned_by_self(),
367 "master humongous set MT safety protocol at a safepoint");
368 } else {
369 guarantee(Heap_lock->owned_by_self(),
370 "master humongous set MT safety protocol outside a safepoint");
371 }
372 }
373
374 void FreeRegionList_test() {
375 FreeRegionList l("test");
376
377 const uint num_regions_in_test = 5;
378 // Create a fake heap. It does not need to be valid, as the HeapRegion constructor
379 // does not access it.
380 MemRegion heap(NULL, num_regions_in_test * HeapRegion::GrainWords);
381 // Allocate a fake BOT because the HeapRegion constructor initializes
382 // the BOT.
383 size_t bot_size = G1BlockOffsetTable::compute_size(heap.word_size());
384 HeapWord* bot_data = NEW_C_HEAP_ARRAY(HeapWord, bot_size, mtGC);
385 ReservedSpace bot_rs(G1BlockOffsetTable::compute_size(heap.word_size()));
386 G1RegionToSpaceMapper* bot_storage =
387 G1RegionToSpaceMapper::create_mapper(bot_rs,
388 bot_rs.size(),
389 os::vm_page_size(),
390 HeapRegion::GrainBytes,
391 BOTConstants::N_bytes,
392 mtGC);
393 G1BlockOffsetTable bot(heap, bot_storage);
394 bot_storage->commit_regions(0, num_regions_in_test);
395
396 // Set up memory regions for the heap regions.
397 MemRegion mr0(heap.start(), HeapRegion::GrainWords);
398 MemRegion mr1(mr0.end(), HeapRegion::GrainWords);
399 MemRegion mr2(mr1.end(), HeapRegion::GrainWords);
400 MemRegion mr3(mr2.end(), HeapRegion::GrainWords);
401 MemRegion mr4(mr3.end(), HeapRegion::GrainWords);
402
403 HeapRegion hr0(0, &bot, mr0);
404 HeapRegion hr1(1, &bot, mr1);
405 HeapRegion hr2(2, &bot, mr2);
406 HeapRegion hr3(3, &bot, mr3);
407 HeapRegion hr4(4, &bot, mr4);
408 l.add_ordered(&hr1);
409 l.add_ordered(&hr0);
410 l.add_ordered(&hr3);
411 l.add_ordered(&hr4);
412 l.add_ordered(&hr2);
413 assert(l.length() == num_regions_in_test, "wrong length");
414 l.verify_list();
415
416 bot_storage->uncommit_regions(0, num_regions_in_test);
417 delete bot_storage;
418 FREE_C_HEAP_ARRAY(HeapWord, bot_data);
419 }
|
353 }
354
355 void HumongousRegionSetMtSafeChecker::check() {
356 // Humongous Set MT safety protocol:
357 // (a) If we're at a safepoint, operations on the master humongous
358 // set should be invoked by either the VM thread (which will
359 // serialize them) or by the GC workers while holding the
360 // OldSets_lock.
361 // (b) If we're not at a safepoint, operations on the master
362 // humongous set should be invoked while holding the Heap_lock.
363
364 if (SafepointSynchronize::is_at_safepoint()) {
365 guarantee(Thread::current()->is_VM_thread() ||
366 OldSets_lock->owned_by_self(),
367 "master humongous set MT safety protocol at a safepoint");
368 } else {
369 guarantee(Heap_lock->owned_by_self(),
370 "master humongous set MT safety protocol outside a safepoint");
371 }
372 }
|