1 /*
 2  * Copyright (c) 2018, 2019, 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 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_INLINE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_INLINE_HPP
27 
28 #include "gc/shenandoah/shenandoahMarkingContext.hpp"
29 
30 #include "gc/shenandoah/shenandoahMarkBitMap.inline.hpp"
31 
32 inline bool ShenandoahMarkingContext::mark_strong(oop obj, bool& was_upgraded) {
33   return !allocated_after_mark_start(obj) && _mark_bit_map.mark_strong(cast_from_oop<HeapWord*>(obj), was_upgraded);
34 }
35 
36 inline bool ShenandoahMarkingContext::mark_weak(oop obj) {
37   return !allocated_after_mark_start(obj) && _mark_bit_map.mark_weak(cast_from_oop<HeapWord *>(obj));
38 }
39 
40 inline bool ShenandoahMarkingContext::is_marked(oop obj) const {
41   return allocated_after_mark_start(obj) || _mark_bit_map.is_marked(cast_from_oop<HeapWord *>(obj));
42 }
43 
44 inline bool ShenandoahMarkingContext::is_marked_strong(oop obj) const {
45   return allocated_after_mark_start(obj) || _mark_bit_map.is_marked_strong(cast_from_oop<HeapWord*>(obj));
46 }
47 
48 inline bool ShenandoahMarkingContext::is_marked_weak(oop obj) const {
49   return allocated_after_mark_start(obj) || _mark_bit_map.is_marked_weak(cast_from_oop<HeapWord *>(obj));
50 }
51 
52 inline HeapWord* ShenandoahMarkingContext::get_next_marked_addr(HeapWord* start, HeapWord* limit) const {
53   return _mark_bit_map.get_next_marked_addr(start, limit);
54 }
55 
56 inline bool ShenandoahMarkingContext::allocated_after_mark_start(oop obj) const {
57   HeapWord* addr = cast_from_oop<HeapWord*>(obj);
58   return allocated_after_mark_start(addr);
59 }
60 
61 inline bool ShenandoahMarkingContext::allocated_after_mark_start(HeapWord* addr) const {
62   uintx index = ((uintx) addr) >> ShenandoahHeapRegion::region_size_bytes_shift();
63   HeapWord* top_at_mark_start = _top_at_mark_starts[index];
64   bool alloc_after_mark_start = addr >= top_at_mark_start;
65   return alloc_after_mark_start;
66 }
67 
68 inline void ShenandoahMarkingContext::capture_top_at_mark_start(ShenandoahHeapRegion *r) {
69   size_t idx = r->index();
70   HeapWord* old_tams = _top_at_mark_starts_base[idx];
71   HeapWord* new_tams = r->top();
72 
73   assert(new_tams >= old_tams,
74          "Region " SIZE_FORMAT", TAMS updates should be monotonic: " PTR_FORMAT " -> " PTR_FORMAT,
75          idx, p2i(old_tams), p2i(new_tams));
76   assert(is_bitmap_clear_range(old_tams, new_tams),
77          "Region " SIZE_FORMAT ", bitmap should be clear while adjusting TAMS: " PTR_FORMAT " -> " PTR_FORMAT,
78          idx, p2i(old_tams), p2i(new_tams));
79 
80   _top_at_mark_starts_base[idx] = new_tams;
81   _top_bitmaps[idx] = new_tams;
82 }
83 
84 inline void ShenandoahMarkingContext::reset_top_at_mark_start(ShenandoahHeapRegion* r) {
85   _top_at_mark_starts_base[r->index()] = r->bottom();
86 }
87 
88 inline HeapWord* ShenandoahMarkingContext::top_at_mark_start(ShenandoahHeapRegion* r) const {
89   return _top_at_mark_starts_base[r->index()];
90 }
91 
92 inline void ShenandoahMarkingContext::reset_top_bitmap(ShenandoahHeapRegion* r) {
93   assert(is_bitmap_clear_range(r->bottom(), r->end()),
94          "Region " SIZE_FORMAT " should have no marks in bitmap", r->index());
95   _top_bitmaps[r->index()] = r->bottom();
96 }
97 
98 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_INLINE_HPP