1 /*
2 * Copyright Amazon.com Inc. or its affiliates. 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
27 #include "gc/shenandoah/shenandoahHeapRegionClosures.hpp"
28 #include "gc/shenandoah/shenandoahMarkingContext.hpp"
29 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
30
31 ShenandoahSynchronizePinnedRegionStates::ShenandoahSynchronizePinnedRegionStates() :
32 _lock(ShenandoahHeap::heap()->lock()) { }
33
34 void ShenandoahSynchronizePinnedRegionStates::heap_region_do(ShenandoahHeapRegion* r) {
35 // Drop "pinned" state from regions that no longer have a pinned count. Put
36 // regions with a pinned count into the "pinned" state.
37 if (r->is_active()) {
38 synchronize_pin_count(r);
39 }
40 }
41
42 void ShenandoahSynchronizePinnedRegionStates::synchronize_pin_count(ShenandoahHeapRegion* r) {
43 if (r->is_pinned()) {
44 if (r->pin_count() == 0) {
45 ShenandoahHeapLocker locker(_lock);
46 r->make_unpinned();
47 }
48 } else {
49 if (r->pin_count() > 0) {
50 ShenandoahHeapLocker locker(_lock);
51 r->make_pinned();
52 }
53 }
54 }
55
56 ShenandoahFinalMarkUpdateRegionStateClosure::ShenandoahFinalMarkUpdateRegionStateClosure(ShenandoahMarkingContext *ctx) :
57 _ctx(ctx) { }
58
59 void ShenandoahFinalMarkUpdateRegionStateClosure::heap_region_do(ShenandoahHeapRegion* r) {
60 if (r->is_active()) {
61 if (_ctx != nullptr) {
62 // _ctx may be null when this closure is used to sync only the pin status
63 // update the watermark of old regions. For old regions we cannot reset
64 // the TAMS because we rely on that to keep promoted objects alive after
65 // old marking is complete.
66
67 // All allocations past TAMS are implicitly live, adjust the region data.
68 // Bitmaps/TAMS are swapped at this point, so we need to poll complete bitmap.
69 HeapWord *tams = _ctx->top_at_mark_start(r);
70 HeapWord *top = r->top();
71 if (top > tams) {
72 r->increase_live_data_alloc_words(pointer_delta(top, tams));
73 }
74 }
75
76 // We are about to select the collection set, make sure it knows about
77 // current pinning status. Also, this allows trashing more regions that
78 // now have their pinning status dropped.
79 _pins.synchronize_pin_count(r);
80
81 // Remember limit for updating refs. It's guaranteed that we get no
82 // from-space-refs written from here on.
83 r->set_update_watermark_at_safepoint(r->top());
84 } else {
85 assert(!r->has_live(), "Region " SIZE_FORMAT " should have no live data", r->index());
86 assert(_ctx == nullptr || _ctx->top_at_mark_start(r) == r->top(),
87 "Region " SIZE_FORMAT " should have correct TAMS", r->index());
88 }
89 }