< prev index next > src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp
Print this page
oop ShenandoahGenerationalHeap::try_evacuate_object(oop p, Thread* thread, ShenandoahHeapRegion* from_region,
ShenandoahAffiliation target_gen) {
bool alloc_from_lab = true;
bool has_plab = false;
HeapWord* copy = nullptr;
- size_t size = ShenandoahForwarding::size(p);
+
+ markWord mark = p->mark();
+ if (ShenandoahForwarding::is_forwarded(mark)) {
+ return ShenandoahForwarding::get_forwardee(p);
+ }
+ size_t old_size = ShenandoahForwarding::size(p);
+ size_t size = p->copy_size(old_size, mark);
+
bool is_promotion = (target_gen == OLD_GENERATION) && from_region->is_young();
#ifdef ASSERT
if (ShenandoahOOMDuringEvacALot &&
(os::random() & 1) == 0) { // Simulate OOM every ~2nd slow-path call
if (ShenandoahEvacTracking) {
evac_tracker()->begin_evacuation(thread, size * HeapWordSize, from_region->affiliation(), target_gen);
}
// Copy the object:
- Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(p), copy, size);
+ Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(p), copy, old_size);
oop copy_val = cast_to_oop(copy);
+ // Initialize the identity hash on the copy before installing the forwarding
+ // pointer, using the mark word we captured earlier. We must do this before
+ // the CAS so that the copy is fully initialized when it becomes visible to
+ // other threads. Using the captured mark (rather than re-reading the copy's
+ // mark) avoids races with other threads that may have evacuated p and
+ // installed a forwarding pointer in the meantime.
+ if (UseCompactObjectHeaders && mark.is_hashed_not_expanded()) {
+ copy_val->set_mark(copy_val->initialize_hash_if_necessary(p, mark.klass(), mark));
+ }
+
// Update the age of the evacuated object
if (target_gen == YOUNG_GENERATION && is_aging_cycle()) {
ShenandoahHeap::increase_object_age(copy_val, from_region->age() + 1);
}
< prev index next >