author | eosterlund |
Mon, 05 Nov 2018 12:36:23 +0100 | |
changeset 52410 | 9d3abb1b7b1f |
parent 52405 | c0c6cdea32f1 |
child 52453 | 6e99148dbf33 |
permissions | -rw-r--r-- |
38133 | 1 |
/* |
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48557
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
38133 | 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 "code/compiledIC.hpp" |
|
46623
261b9d05b79d
8183299: Improve inlining of CompiledMethod methods into frame::sender
redestad
parents:
42650
diff
changeset
|
27 |
#include "code/compiledMethod.inline.hpp" |
38133 | 28 |
#include "code/scopeDesc.hpp" |
29 |
#include "code/codeCache.hpp" |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
30 |
#include "gc/shared/barrierSet.hpp" |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
31 |
#include "gc/shared/gcBehaviours.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48955
diff
changeset
|
32 |
#include "interpreter/bytecode.inline.hpp" |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
33 |
#include "logging/log.hpp" |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
34 |
#include "logging/logTag.hpp" |
38133 | 35 |
#include "memory/resourceArea.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
36 |
#include "oops/methodData.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48955
diff
changeset
|
37 |
#include "oops/method.inline.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
38 |
#include "prims/methodHandles.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49340
diff
changeset
|
39 |
#include "runtime/handles.inline.hpp" |
38133 | 40 |
#include "runtime/mutexLocker.hpp" |
41 |
||
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
42 |
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
43 |
int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
44 |
bool caller_must_gc_arguments) |
42040
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
39430
diff
changeset
|
45 |
: CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments), |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
46 |
_mark_for_deoptimization_status(not_marked), |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
47 |
_is_unloading_state(0), |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
48 |
_method(method) |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
49 |
{ |
38133 | 50 |
init_defaults(); |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
51 |
clear_unloading_state(); |
38133 | 52 |
} |
53 |
||
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
54 |
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
55 |
int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
56 |
OopMapSet* oop_maps, bool caller_must_gc_arguments) |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
57 |
: CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
58 |
frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments), |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
59 |
_mark_for_deoptimization_status(not_marked), |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
60 |
_is_unloading_state(0), |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
61 |
_method(method) |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
62 |
{ |
38133 | 63 |
init_defaults(); |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
64 |
clear_unloading_state(); |
38133 | 65 |
} |
66 |
||
67 |
void CompiledMethod::init_defaults() { |
|
68 |
_has_unsafe_access = 0; |
|
69 |
_has_method_handle_invokes = 0; |
|
70 |
_lazy_critical_native = 0; |
|
71 |
_has_wide_vectors = 0; |
|
72 |
} |
|
73 |
||
74 |
bool CompiledMethod::is_method_handle_return(address return_pc) { |
|
75 |
if (!has_method_handle_invokes()) return false; |
|
76 |
PcDesc* pd = pc_desc_at(return_pc); |
|
77 |
if (pd == NULL) |
|
78 |
return false; |
|
79 |
return pd->is_method_handle_invoke(); |
|
80 |
} |
|
81 |
||
82 |
// Returns a string version of the method state. |
|
83 |
const char* CompiledMethod::state() const { |
|
84 |
int state = get_state(); |
|
85 |
switch (state) { |
|
48007
ab3959df2115
8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents:
47687
diff
changeset
|
86 |
case not_installed: |
ab3959df2115
8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents:
47687
diff
changeset
|
87 |
return "not installed"; |
38133 | 88 |
case in_use: |
89 |
return "in use"; |
|
90 |
case not_used: |
|
91 |
return "not_used"; |
|
92 |
case not_entrant: |
|
93 |
return "not_entrant"; |
|
94 |
case zombie: |
|
95 |
return "zombie"; |
|
96 |
case unloaded: |
|
97 |
return "unloaded"; |
|
98 |
default: |
|
99 |
fatal("unexpected method state: %d", state); |
|
100 |
return NULL; |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
//----------------------------------------------------------------------------- |
|
105 |
||
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
106 |
ExceptionCache* CompiledMethod::exception_cache_acquire() const { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
107 |
return OrderAccess::load_acquire(&_exception_cache); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
108 |
} |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
109 |
|
38133 | 110 |
void CompiledMethod::add_exception_cache_entry(ExceptionCache* new_entry) { |
111 |
assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock"); |
|
112 |
assert(new_entry != NULL,"Must be non null"); |
|
113 |
assert(new_entry->next() == NULL, "Must be null"); |
|
114 |
||
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
115 |
for (;;) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
116 |
ExceptionCache *ec = exception_cache(); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
117 |
if (ec != NULL) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
118 |
Klass* ex_klass = ec->exception_type(); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
119 |
if (!ex_klass->is_loader_alive()) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
120 |
// We must guarantee that entries are not inserted with new next pointer |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
121 |
// edges to ExceptionCache entries with dead klasses, due to bad interactions |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
122 |
// with concurrent ExceptionCache cleanup. Therefore, the inserts roll |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
123 |
// the head pointer forward to the first live ExceptionCache, so that the new |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
124 |
// next pointers always point at live ExceptionCaches, that are not removed due |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
125 |
// to concurrent ExceptionCache cleanup. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
126 |
ExceptionCache* next = ec->next(); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
127 |
if (Atomic::cmpxchg(next, &_exception_cache, ec) == ec) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
128 |
CodeCache::release_exception_cache(ec); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
129 |
} |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
130 |
continue; |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
131 |
} |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
132 |
ec = exception_cache(); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
133 |
if (ec != NULL) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
134 |
new_entry->set_next(ec); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
135 |
} |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
136 |
} |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
137 |
if (Atomic::cmpxchg(new_entry, &_exception_cache, ec) == ec) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
138 |
return; |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
139 |
} |
38133 | 140 |
} |
141 |
} |
|
142 |
||
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
143 |
void CompiledMethod::clean_exception_cache() { |
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
144 |
// For each nmethod, only a single thread may call this cleanup function |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
145 |
// at the same time, whether called in STW cleanup or concurrent cleanup. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
146 |
// Note that if the GC is processing exception cache cleaning in a concurrent phase, |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
147 |
// then a single writer may contend with cleaning up the head pointer to the |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
148 |
// first ExceptionCache node that has a Klass* that is alive. That is fine, |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
149 |
// as long as there is no concurrent cleanup of next pointers from concurrent writers. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
150 |
// And the concurrent writers do not clean up next pointers, only the head. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
151 |
// Also note that concurent readers will walk through Klass* pointers that are not |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
152 |
// alive. That does not cause ABA problems, because Klass* is deleted after |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
153 |
// a handshake with all threads, after all stale ExceptionCaches have been |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
154 |
// unlinked. That is also when the CodeCache::exception_cache_purge_list() |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
155 |
// is deleted, with all ExceptionCache entries that were cleaned concurrently. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
156 |
// That similarly implies that CAS operations on ExceptionCache entries do not |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
157 |
// suffer from ABA problems as unlinking and deletion is separated by a global |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
158 |
// handshake operation. |
38133 | 159 |
ExceptionCache* prev = NULL; |
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
160 |
ExceptionCache* curr = exception_cache_acquire(); |
38133 | 161 |
|
162 |
while (curr != NULL) { |
|
163 |
ExceptionCache* next = curr->next(); |
|
164 |
||
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
165 |
if (!curr->exception_type()->is_loader_alive()) { |
38133 | 166 |
if (prev == NULL) { |
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
167 |
// Try to clean head; this is contended by concurrent inserts, that |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
168 |
// both lazily clean the head, and insert entries at the head. If |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
169 |
// the CAS fails, the operation is restarted. |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
170 |
if (Atomic::cmpxchg(next, &_exception_cache, curr) != curr) { |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
171 |
prev = NULL; |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
172 |
curr = exception_cache_acquire(); |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
173 |
continue; |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
174 |
} |
38133 | 175 |
} else { |
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
176 |
// It is impossible to during cleanup connect the next pointer to |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
177 |
// an ExceptionCache that has not been published before a safepoint |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
178 |
// prior to the cleanup. Therefore, release is not required. |
38133 | 179 |
prev->set_next(next); |
180 |
} |
|
181 |
// prev stays the same. |
|
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
182 |
|
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
183 |
CodeCache::release_exception_cache(curr); |
38133 | 184 |
} else { |
185 |
prev = curr; |
|
186 |
} |
|
187 |
||
188 |
curr = next; |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
// public method for accessing the exception cache |
|
193 |
// These are the public access methods. |
|
194 |
address CompiledMethod::handler_for_exception_and_pc(Handle exception, address pc) { |
|
195 |
// We never grab a lock to read the exception cache, so we may |
|
196 |
// have false negatives. This is okay, as it can only happen during |
|
197 |
// the first few exception lookups for a given nmethod. |
|
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
198 |
ExceptionCache* ec = exception_cache_acquire(); |
38133 | 199 |
while (ec != NULL) { |
200 |
address ret_val; |
|
201 |
if ((ret_val = ec->match(exception,pc)) != NULL) { |
|
202 |
return ret_val; |
|
203 |
} |
|
204 |
ec = ec->next(); |
|
205 |
} |
|
206 |
return NULL; |
|
207 |
} |
|
208 |
||
209 |
void CompiledMethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) { |
|
210 |
// There are potential race conditions during exception cache updates, so we |
|
211 |
// must own the ExceptionCache_lock before doing ANY modifications. Because |
|
212 |
// we don't lock during reads, it is possible to have several threads attempt |
|
213 |
// to update the cache with the same data. We need to check for already inserted |
|
214 |
// copies of the current data before adding it. |
|
215 |
||
216 |
MutexLocker ml(ExceptionCache_lock); |
|
217 |
ExceptionCache* target_entry = exception_cache_entry_for_exception(exception); |
|
218 |
||
219 |
if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) { |
|
220 |
target_entry = new ExceptionCache(exception,pc,handler); |
|
221 |
add_exception_cache_entry(target_entry); |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
// private method for handling exception cache |
|
226 |
// These methods are private, and used to manipulate the exception cache |
|
227 |
// directly. |
|
228 |
ExceptionCache* CompiledMethod::exception_cache_entry_for_exception(Handle exception) { |
|
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
229 |
ExceptionCache* ec = exception_cache_acquire(); |
38133 | 230 |
while (ec != NULL) { |
231 |
if (ec->match_exception_with_space(exception)) { |
|
232 |
return ec; |
|
233 |
} |
|
234 |
ec = ec->next(); |
|
235 |
} |
|
236 |
return NULL; |
|
237 |
} |
|
238 |
||
52405
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
239 |
//-------------end of code for ExceptionCache-------------- |
c0c6cdea32f1
8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents:
52385
diff
changeset
|
240 |
|
38133 | 241 |
bool CompiledMethod::is_at_poll_return(address pc) { |
242 |
RelocIterator iter(this, pc, pc+1); |
|
243 |
while (iter.next()) { |
|
244 |
if (iter.type() == relocInfo::poll_return_type) |
|
245 |
return true; |
|
246 |
} |
|
247 |
return false; |
|
248 |
} |
|
249 |
||
250 |
||
251 |
bool CompiledMethod::is_at_poll_or_poll_return(address pc) { |
|
252 |
RelocIterator iter(this, pc, pc+1); |
|
253 |
while (iter.next()) { |
|
254 |
relocInfo::relocType t = iter.type(); |
|
255 |
if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) |
|
256 |
return true; |
|
257 |
} |
|
258 |
return false; |
|
259 |
} |
|
260 |
||
261 |
void CompiledMethod::verify_oop_relocations() { |
|
262 |
// Ensure sure that the code matches the current oop values |
|
263 |
RelocIterator iter(this, NULL, NULL); |
|
264 |
while (iter.next()) { |
|
265 |
if (iter.type() == relocInfo::oop_type) { |
|
266 |
oop_Relocation* reloc = iter.oop_reloc(); |
|
267 |
if (!reloc->oop_is_immediate()) { |
|
268 |
reloc->verify_oop_relocation(); |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
||
275 |
ScopeDesc* CompiledMethod::scope_desc_at(address pc) { |
|
276 |
PcDesc* pd = pc_desc_at(pc); |
|
277 |
guarantee(pd != NULL, "scope must be present"); |
|
278 |
return new ScopeDesc(this, pd->scope_decode_offset(), |
|
279 |
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
|
280 |
pd->return_oop()); |
|
281 |
} |
|
282 |
||
46796 | 283 |
ScopeDesc* CompiledMethod::scope_desc_near(address pc) { |
284 |
PcDesc* pd = pc_desc_near(pc); |
|
285 |
guarantee(pd != NULL, "scope must be present"); |
|
286 |
return new ScopeDesc(this, pd->scope_decode_offset(), |
|
287 |
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
|
288 |
pd->return_oop()); |
|
289 |
} |
|
290 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
291 |
address CompiledMethod::oops_reloc_begin() const { |
38133 | 292 |
// If the method is not entrant or zombie then a JMP is plastered over the |
293 |
// first few bytes. If an oop in the old code was there, that oop |
|
294 |
// should not get GC'd. Skip the first few bytes of oops on |
|
295 |
// not-entrant methods. |
|
52410
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
296 |
if (frame_complete_offset() != CodeOffsets::frame_never_safe && |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
297 |
code_begin() + frame_complete_offset() > |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
298 |
verified_entry_point() + NativeJump::instruction_size) |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
299 |
{ |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
300 |
// If we have a frame_complete_offset after the native jump, then there |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
301 |
// is no point trying to look for oops before that. This is a requirement |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
302 |
// for being allowed to scan oops concurrently. |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
303 |
return code_begin() + frame_complete_offset(); |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
304 |
} |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
305 |
|
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
306 |
// It is not safe to read oops concurrently using entry barriers, if their |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
307 |
// location depend on whether the nmethod is entrant or not. |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
308 |
assert(BarrierSet::barrier_set()->barrier_set_nmethod() == NULL, "Not safe oop scan"); |
9d3abb1b7b1f
8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents:
52405
diff
changeset
|
309 |
|
38133 | 310 |
address low_boundary = verified_entry_point(); |
311 |
if (!is_in_use() && is_nmethod()) { |
|
312 |
low_boundary += NativeJump::instruction_size; |
|
313 |
// %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. |
|
314 |
// This means that the low_boundary is going to be a little too high. |
|
315 |
// This shouldn't matter, since oops of non-entrant methods are never used. |
|
316 |
// In fact, why are we bothering to look at oops in a non-entrant method?? |
|
317 |
} |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
318 |
return low_boundary; |
38133 | 319 |
} |
320 |
||
321 |
int CompiledMethod::verify_icholder_relocations() { |
|
322 |
ResourceMark rm; |
|
323 |
int count = 0; |
|
324 |
||
325 |
RelocIterator iter(this); |
|
326 |
while(iter.next()) { |
|
327 |
if (iter.type() == relocInfo::virtual_call_type) { |
|
42650 | 328 |
if (CompiledIC::is_icholder_call_site(iter.virtual_call_reloc(), this)) { |
38133 | 329 |
CompiledIC *ic = CompiledIC_at(&iter); |
330 |
if (TraceCompiledIC) { |
|
331 |
tty->print("noticed icholder " INTPTR_FORMAT " ", p2i(ic->cached_icholder())); |
|
332 |
ic->print(); |
|
333 |
} |
|
334 |
assert(ic->cached_icholder() != NULL, "must be non-NULL"); |
|
335 |
count++; |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
return count; |
|
341 |
} |
|
342 |
||
343 |
// Method that knows how to preserve outgoing arguments at call. This method must be |
|
344 |
// called with a frame corresponding to a Java invoke |
|
345 |
void CompiledMethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
|
346 |
if (method() != NULL && !method()->is_native()) { |
|
347 |
address pc = fr.pc(); |
|
348 |
SimpleScopeDesc ssd(this, pc); |
|
349 |
Bytecode_invoke call(ssd.method(), ssd.bci()); |
|
350 |
bool has_receiver = call.has_receiver(); |
|
351 |
bool has_appendix = call.has_appendix(); |
|
352 |
Symbol* signature = call.signature(); |
|
353 |
||
354 |
// The method attached by JIT-compilers should be used, if present. |
|
355 |
// Bytecode can be inaccurate in such case. |
|
356 |
Method* callee = attached_method_before_pc(pc); |
|
357 |
if (callee != NULL) { |
|
358 |
has_receiver = !(callee->access_flags().is_static()); |
|
359 |
has_appendix = false; |
|
360 |
signature = callee->signature(); |
|
361 |
} |
|
362 |
||
363 |
fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f); |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
Method* CompiledMethod::attached_method(address call_instr) { |
|
368 |
assert(code_contains(call_instr), "not part of the nmethod"); |
|
369 |
RelocIterator iter(this, call_instr, call_instr + 1); |
|
370 |
while (iter.next()) { |
|
371 |
if (iter.addr() == call_instr) { |
|
372 |
switch(iter.type()) { |
|
373 |
case relocInfo::static_call_type: return iter.static_call_reloc()->method_value(); |
|
374 |
case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value(); |
|
375 |
case relocInfo::virtual_call_type: return iter.virtual_call_reloc()->method_value(); |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
376 |
default: break; |
38133 | 377 |
} |
378 |
} |
|
379 |
} |
|
380 |
return NULL; // not found |
|
381 |
} |
|
382 |
||
383 |
Method* CompiledMethod::attached_method_before_pc(address pc) { |
|
384 |
if (NativeCall::is_call_before(pc)) { |
|
385 |
NativeCall* ncall = nativeCall_before(pc); |
|
386 |
return attached_method(ncall->instruction_address()); |
|
387 |
} |
|
388 |
return NULL; // not a call |
|
389 |
} |
|
390 |
||
391 |
void CompiledMethod::clear_inline_caches() { |
|
392 |
assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint"); |
|
393 |
if (is_zombie()) { |
|
394 |
return; |
|
395 |
} |
|
396 |
||
397 |
RelocIterator iter(this); |
|
398 |
while (iter.next()) { |
|
399 |
iter.reloc()->clear_inline_cache(); |
|
400 |
} |
|
401 |
} |
|
402 |
||
403 |
// Clear ICStubs of all compiled ICs |
|
404 |
void CompiledMethod::clear_ic_stubs() { |
|
52384
d6dc479bcdd3
8212681: Refactor IC locking to use a fine grained CompiledICLocker
eosterlund
parents:
51591
diff
changeset
|
405 |
assert(CompiledICLocker::is_safe(this), "mt unsafe call"); |
50995
3c59afe1afc9
8206394: missing ResourceMark in AOTCompiledMethod::metadata_do, AOTCompiledMethod::clear_inline_caches , CompiledMethod::clear_ic_stubs , CompiledMethod::cleanup_inline_caches_impl
mbaesken
parents:
50416
diff
changeset
|
406 |
ResourceMark rm; |
38133 | 407 |
RelocIterator iter(this); |
408 |
while(iter.next()) { |
|
409 |
if (iter.type() == relocInfo::virtual_call_type) { |
|
410 |
CompiledIC* ic = CompiledIC_at(&iter); |
|
411 |
ic->clear_ic_stub(); |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
#ifdef ASSERT |
|
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
417 |
// Check class_loader is alive for this bit of metadata. |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
418 |
static void check_class(Metadata* md) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
419 |
Klass* klass = NULL; |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
420 |
if (md->is_klass()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
421 |
klass = ((Klass*)md); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
422 |
} else if (md->is_method()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
423 |
klass = ((Method*)md)->method_holder(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
424 |
} else if (md->is_methodData()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
425 |
klass = ((MethodData*)md)->method()->method_holder(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
426 |
} else { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
427 |
md->print(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
428 |
ShouldNotReachHere(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
429 |
} |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
430 |
assert(klass->is_loader_alive(), "must be alive"); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
431 |
} |
38133 | 432 |
#endif // ASSERT |
433 |
||
42650 | 434 |
|
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
435 |
void CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic) { |
38133 | 436 |
if (ic->is_icholder_call()) { |
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
437 |
// The only exception is compiledICHolder metdata which may |
38133 | 438 |
// yet be marked below. (We check this further below). |
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
439 |
CompiledICHolder* cichk_metdata = ic->cached_icholder(); |
38133 | 440 |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
441 |
if (cichk_metdata->is_loader_alive()) { |
38133 | 442 |
return; |
443 |
} |
|
444 |
} else { |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
445 |
Metadata* ic_metdata = ic->cached_metadata(); |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
446 |
if (ic_metdata != NULL) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
447 |
if (ic_metdata->is_klass()) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
448 |
if (((Klass*)ic_metdata)->is_loader_alive()) { |
38133 | 449 |
return; |
450 |
} |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
451 |
} else if (ic_metdata->is_method()) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
452 |
Method* method = (Method*)ic_metdata; |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
453 |
assert(!method->is_old(), "old method should have been cleaned"); |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
454 |
if (method->method_holder()->is_loader_alive()) { |
38133 | 455 |
return; |
456 |
} |
|
457 |
} else { |
|
458 |
ShouldNotReachHere(); |
|
459 |
} |
|
460 |
} |
|
461 |
} |
|
462 |
||
463 |
ic->set_to_clean(); |
|
464 |
} |
|
465 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
466 |
// static_stub_Relocations may have dangling references to |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
467 |
// nmethods so trim them out here. Otherwise it looks like |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
468 |
// compiled code is maintaining a link to dead metadata. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
469 |
void CompiledMethod::clean_ic_stubs() { |
38133 | 470 |
#ifdef ASSERT |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
471 |
address low_boundary = oops_reloc_begin(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
472 |
RelocIterator iter(this, low_boundary); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
473 |
while (iter.next()) { |
38133 | 474 |
address static_call_addr = NULL; |
475 |
if (iter.type() == relocInfo::opt_virtual_call_type) { |
|
476 |
CompiledIC* cic = CompiledIC_at(&iter); |
|
477 |
if (!cic->is_call_to_interpreted()) { |
|
478 |
static_call_addr = iter.addr(); |
|
479 |
} |
|
480 |
} else if (iter.type() == relocInfo::static_call_type) { |
|
481 |
CompiledStaticCall* csc = compiledStaticCall_at(iter.reloc()); |
|
482 |
if (!csc->is_call_to_interpreted()) { |
|
483 |
static_call_addr = iter.addr(); |
|
484 |
} |
|
485 |
} |
|
486 |
if (static_call_addr != NULL) { |
|
487 |
RelocIterator sciter(this, low_boundary); |
|
488 |
while (sciter.next()) { |
|
489 |
if (sciter.type() == relocInfo::static_stub_type && |
|
490 |
sciter.static_stub_reloc()->static_call() == static_call_addr) { |
|
491 |
sciter.static_stub_reloc()->clear_inline_cache(); |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
#endif |
|
497 |
} |
|
498 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
499 |
// Clean references to unloaded nmethods at addr from this one, which is not unloaded. |
38133 | 500 |
template <class CompiledICorStaticCall> |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
501 |
static void clean_if_nmethod_is_unloaded(CompiledICorStaticCall *ic, address addr, CompiledMethod* from, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
502 |
bool clean_all) { |
38133 | 503 |
// Ok, to lookup references to zombies here |
504 |
CodeBlob *cb = CodeCache::find_blob_unsafe(addr); |
|
505 |
CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; |
|
506 |
if (nm != NULL) { |
|
507 |
// Clean inline caches pointing to both zombie and not_entrant methods |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
508 |
if (clean_all || !nm->is_in_use() || nm->is_unloading() || (nm->method()->code() != nm)) { |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
509 |
ic->set_to_clean(from->is_alive()); |
38133 | 510 |
assert(ic->is_clean(), "nmethod " PTR_FORMAT "not clean %s", p2i(from), from->method()->name_and_sig_as_C_string()); |
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
||
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
515 |
static void clean_if_nmethod_is_unloaded(CompiledIC *ic, CompiledMethod* from, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
516 |
bool clean_all) { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
517 |
clean_if_nmethod_is_unloaded(ic, ic->ic_destination(), from, clean_all); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
518 |
} |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
519 |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
520 |
static void clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, CompiledMethod* from, |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
521 |
bool clean_all) { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
522 |
clean_if_nmethod_is_unloaded(csc, csc->destination(), from, clean_all); |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
523 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
524 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
525 |
// Cleans caches in nmethods that point to either classes that are unloaded |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
526 |
// or nmethods that are unloaded. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
527 |
// |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
528 |
// Can be called either in parallel by G1 currently or after all |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
529 |
// nmethods are unloaded. Return postponed=true in the parallel case for |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
530 |
// inline caches found that point to nmethods that are not yet visited during |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
531 |
// the do_unloading walk. |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
532 |
void CompiledMethod::unload_nmethod_caches(bool unloading_occurred) { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
533 |
ResourceMark rm; |
38133 | 534 |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
535 |
// Exception cache only needs to be called if unloading occurred |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
536 |
if (unloading_occurred) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
537 |
clean_exception_cache(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
538 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
539 |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
540 |
cleanup_inline_caches_impl(unloading_occurred, false); |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
541 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
542 |
// All static stubs need to be cleaned. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
543 |
clean_ic_stubs(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
544 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
545 |
// Check that the metadata embedded in the nmethod is alive |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
546 |
DEBUG_ONLY(metadata_do(check_class)); |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
547 |
} |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
548 |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
549 |
// The IsUnloadingStruct represents a tuple comprising a result of |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
550 |
// IsUnloadingBehaviour::is_unloading() for a given unloading cycle. |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
551 |
struct IsUnloadingStruct { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
552 |
unsigned int _is_unloading:1; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
553 |
unsigned int _unloading_cycle:2; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
554 |
}; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
555 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
556 |
// The IsUnloadingUnion allows treating the tuple of the IsUnloadingStruct |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
557 |
// like a uint8_t, making it possible to read and write the tuple atomically. |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
558 |
union IsUnloadingUnion { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
559 |
IsUnloadingStruct _inflated; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
560 |
uint8_t _value; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
561 |
}; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
562 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
563 |
bool CompiledMethod::is_unloading() { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
564 |
IsUnloadingUnion state; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
565 |
state._value = RawAccess<MO_RELAXED>::load(&_is_unloading_state); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
566 |
if (state._inflated._is_unloading == 1) { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
567 |
return true; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
568 |
} |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
569 |
if (state._inflated._unloading_cycle == CodeCache::unloading_cycle()) { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
570 |
return state._inflated._is_unloading == 1; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
571 |
} |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
572 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
573 |
// The IsUnloadingBehaviour is responsible for checking if there are any dead |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
574 |
// oops in the CompiledMethod, by calling oops_do on it. |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
575 |
bool result = IsUnloadingBehaviour::current()->is_unloading(this); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
576 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
577 |
state._inflated._unloading_cycle = CodeCache::unloading_cycle(); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
578 |
state._inflated._is_unloading = result ? 1 : 0; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
579 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
580 |
RawAccess<MO_RELAXED>::store(&_is_unloading_state, state._value); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
581 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
582 |
return result; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
583 |
} |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
584 |
|
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
585 |
void CompiledMethod::clear_unloading_state() { |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
586 |
IsUnloadingUnion state; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
587 |
state._inflated._unloading_cycle = CodeCache::unloading_cycle(); |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
588 |
state._inflated._is_unloading = 0; |
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
589 |
RawAccess<MO_RELAXED>::store(&_is_unloading_state, state._value); |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
590 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
591 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
592 |
// Called to clean up after class unloading for live nmethods and from the sweeper |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
593 |
// for all methods. |
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
594 |
void CompiledMethod::cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all) { |
52384
d6dc479bcdd3
8212681: Refactor IC locking to use a fine grained CompiledICLocker
eosterlund
parents:
51591
diff
changeset
|
595 |
assert(CompiledICLocker::is_safe(this), "mt unsafe call"); |
50995
3c59afe1afc9
8206394: missing ResourceMark in AOTCompiledMethod::metadata_do, AOTCompiledMethod::clear_inline_caches , CompiledMethod::clear_ic_stubs , CompiledMethod::cleanup_inline_caches_impl
mbaesken
parents:
50416
diff
changeset
|
596 |
ResourceMark rm; |
38133 | 597 |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
598 |
// Find all calls in an nmethod and clear the ones that point to non-entrant, |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
599 |
// zombie and unloaded nmethods. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
600 |
RelocIterator iter(this, oops_reloc_begin()); |
38133 | 601 |
while(iter.next()) { |
602 |
||
603 |
switch (iter.type()) { |
|
604 |
||
605 |
case relocInfo::virtual_call_type: |
|
606 |
if (unloading_occurred) { |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
607 |
// If class unloading occurred we first clear ICs where the cached metadata |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
608 |
// is referring to an unloaded klass or method. |
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
609 |
clean_ic_if_metadata_is_dead(CompiledIC_at(&iter)); |
38133 | 610 |
} |
611 |
||
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
612 |
clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all); |
38133 | 613 |
break; |
614 |
||
615 |
case relocInfo::opt_virtual_call_type: |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
616 |
clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all); |
38133 | 617 |
break; |
618 |
||
619 |
case relocInfo::static_call_type: |
|
52385
5c679ec60888
8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents:
52384
diff
changeset
|
620 |
clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, clean_all); |
38133 | 621 |
break; |
622 |
||
623 |
case relocInfo::oop_type: |
|
624 |
break; |
|
625 |
||
626 |
case relocInfo::metadata_type: |
|
627 |
break; // nothing to do. |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
628 |
|
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
629 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
630 |
break; |
38133 | 631 |
} |
632 |
} |
|
633 |
} |
|
51591 | 634 |
|
635 |
// Iterating over all nmethods, e.g. with the help of CodeCache::nmethods_do(fun) was found |
|
636 |
// to not be inherently safe. There is a chance that fields are seen which are not properly |
|
637 |
// initialized. This happens despite the fact that nmethods_do() asserts the CodeCache_lock |
|
638 |
// to be held. |
|
639 |
// To bundle knowledge about necessary checks in one place, this function was introduced. |
|
640 |
// It is not claimed that these checks are sufficient, but they were found to be necessary. |
|
641 |
bool CompiledMethod::nmethod_access_is_safe(nmethod* nm) { |
|
642 |
Method* method = (nm == NULL) ? NULL : nm->method(); // nm->method() may be uninitialized, i.e. != NULL, but invalid |
|
643 |
return (nm != NULL) && (method != NULL) && (method->signature() != NULL) && |
|
644 |
!nm->is_zombie() && !nm->is_not_installed() && |
|
645 |
os::is_readable_pointer(method) && |
|
646 |
os::is_readable_pointer(method->constants()) && |
|
647 |
os::is_readable_pointer(method->signature()); |
|
648 |
} |