author | pliden |
Tue, 10 Sep 2019 11:11:31 +0200 | |
changeset 58066 | 8407928b9fe5 |
parent 54623 | 1126f0607c70 |
child 58063 | bdf136b8ae0e |
child 59040 | 1251d78fafbf |
permissions | -rw-r--r-- |
52939 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54567
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
52939 | 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 |
#include "precompiled.hpp" |
|
25 |
#include "classfile/classLoaderDataGraph.hpp" |
|
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "code/codeBehaviours.hpp" |
|
28 |
#include "code/codeCache.hpp" |
|
29 |
#include "code/dependencyContext.hpp" |
|
30 |
#include "gc/shared/gcBehaviours.hpp" |
|
31 |
#include "gc/shared/suspendibleThreadSet.hpp" |
|
32 |
#include "gc/z/zLock.inline.hpp" |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
33 |
#include "gc/z/zNMethod.hpp" |
52939 | 34 |
#include "gc/z/zOopClosures.hpp" |
35 |
#include "gc/z/zStat.hpp" |
|
36 |
#include "gc/z/zUnload.hpp" |
|
37 |
#include "oops/access.inline.hpp" |
|
38 |
||
39 |
static const ZStatSubPhase ZSubPhaseConcurrentClassesUnload("Concurrent Classes Unload"); |
|
40 |
||
41 |
class ZIsUnloadingOopClosure : public OopClosure { |
|
42 |
private: |
|
43 |
ZPhantomIsAliveObjectClosure _is_alive; |
|
44 |
bool _is_unloading; |
|
45 |
||
46 |
public: |
|
47 |
ZIsUnloadingOopClosure() : |
|
48 |
_is_alive(), |
|
49 |
_is_unloading(false) {} |
|
50 |
||
51 |
virtual void do_oop(oop* p) { |
|
52 |
const oop o = RawAccess<>::oop_load(p); |
|
53 |
if (o != NULL && !_is_alive.do_object_b(o)) { |
|
54 |
_is_unloading = true; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
virtual void do_oop(narrowOop* p) { |
|
59 |
ShouldNotReachHere(); |
|
60 |
} |
|
61 |
||
62 |
bool is_unloading() const { |
|
63 |
return _is_unloading; |
|
64 |
} |
|
65 |
}; |
|
66 |
||
67 |
class ZIsUnloadingBehaviour : public IsUnloadingBehaviour { |
|
68 |
public: |
|
69 |
virtual bool is_unloading(CompiledMethod* method) const { |
|
70 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
71 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
72 |
ZLocker<ZReentrantLock> locker(lock); |
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
73 |
ZIsUnloadingOopClosure cl; |
54567
224515275cf9
8219718: ZGC: Make nmethod entry barriers and nmethod::is_unloading use ZNMethodDataOops
eosterlund
parents:
53921
diff
changeset
|
74 |
ZNMethod::nmethod_oops_do(nm, &cl); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
75 |
return cl.is_unloading(); |
52939 | 76 |
} |
77 |
}; |
|
78 |
||
79 |
class ZCompiledICProtectionBehaviour : public CompiledICProtectionBehaviour { |
|
80 |
public: |
|
81 |
virtual bool lock(CompiledMethod* method) { |
|
82 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
83 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
84 |
lock->lock(); |
52939 | 85 |
return true; |
86 |
} |
|
87 |
||
88 |
virtual void unlock(CompiledMethod* method) { |
|
89 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
90 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
91 |
lock->unlock(); |
52939 | 92 |
} |
93 |
||
94 |
virtual bool is_safe(CompiledMethod* method) { |
|
95 |
if (SafepointSynchronize::is_at_safepoint()) { |
|
96 |
return true; |
|
97 |
} |
|
98 |
||
99 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
100 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
101 |
return lock->is_owned(); |
52939 | 102 |
} |
103 |
}; |
|
104 |
||
105 |
ZUnload::ZUnload(ZWorkers* workers) : |
|
106 |
_workers(workers) { |
|
107 |
||
108 |
if (!ClassUnloading) { |
|
109 |
return; |
|
110 |
} |
|
111 |
||
112 |
static ZIsUnloadingBehaviour is_unloading_behaviour; |
|
113 |
IsUnloadingBehaviour::set_current(&is_unloading_behaviour); |
|
114 |
||
115 |
static ZCompiledICProtectionBehaviour ic_protection_behaviour; |
|
116 |
CompiledICProtectionBehaviour::set_current(&ic_protection_behaviour); |
|
117 |
} |
|
118 |
||
119 |
void ZUnload::prepare() { |
|
120 |
if (!ClassUnloading) { |
|
121 |
return; |
|
122 |
} |
|
123 |
||
124 |
CodeCache::increment_unloading_cycle(); |
|
125 |
DependencyContext::cleaning_start(); |
|
126 |
} |
|
127 |
||
128 |
void ZUnload::unlink() { |
|
129 |
SuspendibleThreadSetJoiner sts; |
|
130 |
bool unloading_occurred; |
|
131 |
||
132 |
{ |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54567
diff
changeset
|
133 |
MutexLocker ml(ClassLoaderDataGraph_lock); |
52939 | 134 |
unloading_occurred = SystemDictionary::do_unloading(ZStatPhase::timer()); |
135 |
} |
|
136 |
||
137 |
Klass::clean_weak_klass_links(unloading_occurred); |
|
138 |
||
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
139 |
ZNMethod::unlink(_workers, unloading_occurred); |
52939 | 140 |
|
141 |
DependencyContext::cleaning_end(); |
|
142 |
} |
|
143 |
||
144 |
void ZUnload::purge() { |
|
145 |
{ |
|
146 |
SuspendibleThreadSetJoiner sts; |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
147 |
ZNMethod::purge(_workers); |
52939 | 148 |
} |
149 |
||
150 |
ClassLoaderDataGraph::purge(); |
|
151 |
CodeCache::purge_exception_caches(); |
|
152 |
} |
|
153 |
||
154 |
class ZUnloadRendezvousClosure : public ThreadClosure { |
|
155 |
public: |
|
156 |
void do_thread(Thread* thread) {} |
|
157 |
}; |
|
158 |
||
159 |
void ZUnload::unload() { |
|
160 |
if (!ClassUnloading) { |
|
161 |
return; |
|
162 |
} |
|
163 |
||
164 |
ZStatTimer timer(ZSubPhaseConcurrentClassesUnload); |
|
165 |
||
166 |
// Unlink stale metadata and nmethods |
|
167 |
unlink(); |
|
168 |
||
169 |
// Make sure stale metadata and nmethods are no longer observable |
|
170 |
ZUnloadRendezvousClosure cl; |
|
171 |
Handshake::execute(&cl); |
|
172 |
||
173 |
// Purge stale metadata and nmethods that were unlinked |
|
174 |
purge(); |
|
175 |
} |
|
176 |
||
177 |
void ZUnload::finish() { |
|
178 |
// Resize and verify metaspace |
|
179 |
MetaspaceGC::compute_new_size(); |
|
180 |
MetaspaceUtils::verify_metrics(); |
|
181 |
} |