1 /*
2 * Copyright (c) 2016, 2021, Oracle and/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 #include "gc/shared/preservedMarks.inline.hpp"
27 #include "gc/shared/workerThread.hpp"
28 #include "gc/shared/workerUtils.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "memory/resourceArea.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "runtime/atomic.hpp"
33 #include "utilities/macros.hpp"
34
35 void PreservedMarks::restore() {
36 while (!_stack.is_empty()) {
37 const OopAndMarkWord elem = _stack.pop();
38 elem.set_mark();
39 }
40 assert_empty();
41 }
42
43 void PreservedMarks::adjust_during_full_gc() {
44 StackIterator<OopAndMarkWord, mtGC> iter(_stack);
45 while (!iter.is_empty()) {
46 OopAndMarkWord* elem = iter.next_addr();
47
48 oop obj = elem->get_oop();
49 if (obj->is_forwarded()) {
50 elem->set_oop(obj->forwardee());
51 }
52 }
53 }
54
55 void PreservedMarks::restore_and_increment(volatile size_t* const total_size_addr) {
56 const size_t stack_size = size();
57 restore();
58 // Only do the atomic add if the size is > 0.
59 if (stack_size > 0) {
60 Atomic::add(total_size_addr, stack_size);
61 }
62 }
63
64 #ifndef PRODUCT
65 void PreservedMarks::assert_empty() {
66 assert(_stack.is_empty(), "stack expected to be empty, size = " SIZE_FORMAT,
67 _stack.size());
68 assert(_stack.cache_size() == 0,
69 "stack expected to have no cached segments, cache size = " SIZE_FORMAT,
70 _stack.cache_size());
71 }
72 #endif // ndef PRODUCT
73
74 void PreservedMarksSet::init(uint num) {
|
1 /*
2 * Copyright (c) 2016, 2023, Oracle and/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 #include "gc/shared/preservedMarks.inline.hpp"
27 #include "gc/shared/slidingForwarding.inline.hpp"
28 #include "gc/shared/workerThread.hpp"
29 #include "gc/shared/workerUtils.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "runtime/atomic.hpp"
34 #include "utilities/macros.hpp"
35
36 void PreservedMarks::restore() {
37 while (!_stack.is_empty()) {
38 const OopAndMarkWord elem = _stack.pop();
39 elem.set_mark();
40 }
41 assert_empty();
42 }
43
44 template <bool ALT_FWD>
45 void PreservedMarks::adjust_during_full_gc_impl() {
46 StackIterator<OopAndMarkWord, mtGC> iter(_stack);
47 while (!iter.is_empty()) {
48 OopAndMarkWord* elem = iter.next_addr();
49
50 oop obj = elem->get_oop();
51 if (obj->is_forwarded()) {
52 elem->set_oop(SlidingForwarding::forwardee<ALT_FWD>(obj));
53 }
54 }
55 }
56
57 void PreservedMarks::adjust_during_full_gc() {
58 if (UseAltGCForwarding) {
59 adjust_during_full_gc_impl<true>();
60 } else {
61 adjust_during_full_gc_impl<false>();
62 }
63 }
64
65 void PreservedMarks::restore_and_increment(volatile size_t* const total_size_addr) {
66 const size_t stack_size = size();
67 restore();
68 // Only do the atomic add if the size is > 0.
69 if (stack_size > 0) {
70 Atomic::add(total_size_addr, stack_size);
71 }
72 }
73
74 #ifndef PRODUCT
75 void PreservedMarks::assert_empty() {
76 assert(_stack.is_empty(), "stack expected to be empty, size = " SIZE_FORMAT,
77 _stack.size());
78 assert(_stack.cache_size() == 0,
79 "stack expected to have no cached segments, cache size = " SIZE_FORMAT,
80 _stack.cache_size());
81 }
82 #endif // ndef PRODUCT
83
84 void PreservedMarksSet::init(uint num) {
|