Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/gc/parallel/psClosure.inline.hpp
66644 views
1
/*
2
* Copyright (c) 2018, 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
#ifndef SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP
26
#define SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP
27
28
// No psClosure.hpp
29
30
#include "gc/parallel/psPromotionManager.inline.hpp"
31
#include "gc/parallel/psScavenge.inline.hpp"
32
#include "memory/iterator.hpp"
33
#include "oops/access.inline.hpp"
34
#include "oops/oop.inline.hpp"
35
#include "utilities/globalDefinitions.hpp"
36
37
class PSAdjustWeakRootsClosure final: public OopClosure {
38
public:
39
virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
40
41
virtual void do_oop(oop* p) {
42
if (PSScavenge::should_scavenge(p)) {
43
oop o = RawAccess<IS_NOT_NULL>::oop_load(p);
44
assert(o->is_forwarded(), "Objects are already forwarded before weak processing");
45
oop new_obj = o->forwardee();
46
if (log_develop_is_enabled(Trace, gc, scavenge)) {
47
ResourceMark rm; // required by internal_name()
48
log_develop_trace(gc, scavenge)("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
49
"forwarding",
50
new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
51
}
52
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
53
}
54
}
55
};
56
57
template <bool promote_immediately>
58
class PSRootsClosure: public OopClosure {
59
private:
60
PSPromotionManager* _promotion_manager;
61
62
template <class T> void do_oop_work(T *p) {
63
if (PSScavenge::should_scavenge(p)) {
64
// We never card mark roots, maybe call a func without test?
65
_promotion_manager->copy_and_push_safe_barrier<promote_immediately>(p);
66
}
67
}
68
public:
69
PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
70
void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
71
void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
72
};
73
74
typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
75
typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
76
77
// Scavenges a single oop in a ClassLoaderData.
78
class PSScavengeFromCLDClosure: public OopClosure {
79
private:
80
PSPromotionManager* _pm;
81
// Used to redirty a scanned cld if it has oops
82
// pointing to the young generation after being scanned.
83
ClassLoaderData* _scanned_cld;
84
public:
85
PSScavengeFromCLDClosure(PSPromotionManager* pm) : _pm(pm), _scanned_cld(NULL) { }
86
void do_oop(narrowOop* p) { ShouldNotReachHere(); }
87
void do_oop(oop* p) {
88
ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
89
assert(!psh->is_in_reserved(p), "GC barrier needed");
90
if (PSScavenge::should_scavenge(p)) {
91
assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
92
93
oop o = RawAccess<IS_NOT_NULL>::oop_load(p);
94
oop new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
95
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
96
97
if (PSScavenge::is_obj_in_young(new_obj)) {
98
do_cld_barrier();
99
}
100
}
101
}
102
103
void set_scanned_cld(ClassLoaderData* cld) {
104
assert(_scanned_cld == NULL || cld == NULL, "Should always only handling one cld at a time");
105
_scanned_cld = cld;
106
}
107
108
private:
109
void do_cld_barrier() {
110
assert(_scanned_cld != NULL, "Should not be called without having a scanned cld");
111
_scanned_cld->record_modified_oops();
112
}
113
};
114
115
// Scavenges the oop in a ClassLoaderData.
116
class PSScavengeCLDClosure: public CLDClosure {
117
private:
118
PSScavengeFromCLDClosure _oop_closure;
119
public:
120
PSScavengeCLDClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
121
void do_cld(ClassLoaderData* cld) {
122
// If the cld has not been dirtied we know that there's
123
// no references into the young gen and we can skip it.
124
125
if (cld->has_modified_oops()) {
126
// Setup the promotion manager to redirty this cld
127
// if references are left in the young gen.
128
_oop_closure.set_scanned_cld(cld);
129
130
// Clean the cld since we're going to scavenge all the metadata.
131
cld->oops_do(&_oop_closure, false, /*clear_modified_oops*/true);
132
133
_oop_closure.set_scanned_cld(NULL);
134
}
135
}
136
};
137
138
#endif // SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP
139
140