author | stefank |
Fri, 04 May 2018 11:41:35 +0200 | |
changeset 49982 | 9042ffe5b7fe |
parent 49818 | e57e6addb978 |
child 51472 | eb97d1a319f9 |
permissions | -rw-r--r-- |
46505 | 1 |
/* |
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
48615
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
46505 | 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" |
|
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
48615
diff
changeset
|
26 |
#include "classfile/javaClasses.hpp" |
49982 | 27 |
#include "logging/log.hpp" |
46505 | 28 |
#include "memory/allocation.hpp" |
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
48615
diff
changeset
|
29 |
#include "memory/resourceArea.hpp" |
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
30 |
#include "oops/access.inline.hpp" |
46505 | 31 |
#include "oops/oop.inline.hpp" |
32 |
#include "oops/method.hpp" |
|
33 |
#include "oops/symbol.hpp" |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
34 |
#include "oops/weakHandle.inline.hpp" |
46505 | 35 |
#include "prims/resolvedMethodTable.hpp" |
36 |
#include "runtime/handles.inline.hpp" |
|
37 |
#include "runtime/mutexLocker.hpp" |
|
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49593
diff
changeset
|
38 |
#include "runtime/safepointVerifiers.hpp" |
46505 | 39 |
#include "utilities/hashtable.inline.hpp" |
40 |
#include "utilities/macros.hpp" |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
41 |
|
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
42 |
|
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
43 |
oop ResolvedMethodEntry::object() { |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
44 |
return literal().resolve(); |
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
45 |
} |
46505 | 46 |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
47 |
oop ResolvedMethodEntry::object_no_keepalive() { |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
48 |
// The AS_NO_KEEPALIVE peeks at the oop without keeping it alive. |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
49 |
// This is dangerous in general but is okay if the loaded oop does |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
50 |
// not leak out past a thread transition where a safepoint can happen. |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
51 |
// A subsequent oop_load without AS_NO_KEEPALIVE (the object() accessor) |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
52 |
// keeps the oop alive before doing so. |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
53 |
return literal().peek(); |
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
54 |
} |
46505 | 55 |
|
56 |
ResolvedMethodTable::ResolvedMethodTable() |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
57 |
: Hashtable<ClassLoaderWeakHandle, mtClass>(_table_size, sizeof(ResolvedMethodEntry)) { } |
46505 | 58 |
|
59 |
oop ResolvedMethodTable::lookup(int index, unsigned int hash, Method* method) { |
|
60 |
for (ResolvedMethodEntry* p = bucket(index); p != NULL; p = p->next()) { |
|
61 |
if (p->hash() == hash) { |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
62 |
|
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
63 |
// Peek the object to check if it is the right target. |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
64 |
oop target = p->object_no_keepalive(); |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
65 |
|
46505 | 66 |
// The method is in the table as a target already |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
67 |
if (target != NULL && java_lang_invoke_ResolvedMethodName::vmtarget(target) == method) { |
46505 | 68 |
ResourceMark rm; |
69 |
log_debug(membername, table) ("ResolvedMethod entry found for %s index %d", |
|
70 |
method->name_and_sig_as_C_string(), index); |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
71 |
// The object() accessor makes sure the target object is kept alive before |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
72 |
// leaking out. |
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
73 |
return p->object(); |
46505 | 74 |
} |
75 |
} |
|
76 |
} |
|
77 |
return NULL; |
|
78 |
} |
|
79 |
||
80 |
unsigned int ResolvedMethodTable::compute_hash(Method* method) { |
|
81 |
unsigned int name_hash = method->name()->identity_hash(); |
|
82 |
unsigned int signature_hash = method->signature()->identity_hash(); |
|
83 |
return name_hash ^ signature_hash; |
|
84 |
} |
|
85 |
||
86 |
||
87 |
oop ResolvedMethodTable::lookup(Method* method) { |
|
88 |
unsigned int hash = compute_hash(method); |
|
89 |
int index = hash_to_index(hash); |
|
90 |
return lookup(index, hash, method); |
|
91 |
} |
|
92 |
||
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
93 |
oop ResolvedMethodTable::basic_add(Method* method, Handle rmethod_name) { |
46505 | 94 |
assert_locked_or_safepoint(ResolvedMethodTable_lock); |
95 |
||
96 |
unsigned int hash = compute_hash(method); |
|
97 |
int index = hash_to_index(hash); |
|
98 |
||
99 |
// One was added while aquiring the lock |
|
100 |
oop entry = lookup(index, hash, method); |
|
101 |
if (entry != NULL) { |
|
102 |
return entry; |
|
103 |
} |
|
104 |
||
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
105 |
ClassLoaderWeakHandle w = ClassLoaderWeakHandle::create(rmethod_name); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
106 |
ResolvedMethodEntry* p = (ResolvedMethodEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::new_entry(hash, w); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
107 |
Hashtable<ClassLoaderWeakHandle, mtClass>::add_entry(index, p); |
46505 | 108 |
ResourceMark rm; |
109 |
log_debug(membername, table) ("ResolvedMethod entry added for %s index %d", |
|
110 |
method->name_and_sig_as_C_string(), index); |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
111 |
return rmethod_name(); |
46505 | 112 |
} |
113 |
||
114 |
ResolvedMethodTable* ResolvedMethodTable::_the_table = NULL; |
|
115 |
||
116 |
oop ResolvedMethodTable::find_method(Method* method) { |
|
117 |
oop entry = _the_table->lookup(method); |
|
118 |
return entry; |
|
119 |
} |
|
120 |
||
121 |
oop ResolvedMethodTable::add_method(Handle resolved_method_name) { |
|
122 |
MutexLocker ml(ResolvedMethodTable_lock); |
|
123 |
DEBUG_ONLY(NoSafepointVerifier nsv); |
|
124 |
||
125 |
// Check if method has been redefined while taking out ResolvedMethodTable_lock, if so |
|
126 |
// use new method. |
|
127 |
Method* method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(resolved_method_name()); |
|
128 |
assert(method->is_method(), "must be method"); |
|
129 |
if (method->is_old()) { |
|
130 |
// Replace method with redefined version |
|
131 |
InstanceKlass* holder = method->method_holder(); |
|
132 |
method = holder->method_with_idnum(method->method_idnum()); |
|
133 |
java_lang_invoke_ResolvedMethodName::set_vmtarget(resolved_method_name(), method); |
|
134 |
} |
|
135 |
// Set flag in class to indicate this InstanceKlass has entries in the table |
|
136 |
// to avoid walking table during redefinition if none of the redefined classes |
|
137 |
// have any membernames in the table. |
|
138 |
method->method_holder()->set_has_resolved_methods(); |
|
139 |
||
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
140 |
return _the_table->basic_add(method, resolved_method_name); |
46505 | 141 |
} |
142 |
||
143 |
// Removing entries |
|
144 |
int ResolvedMethodTable::_oops_removed = 0; |
|
145 |
int ResolvedMethodTable::_oops_counted = 0; |
|
146 |
||
147 |
// Serially invoke removed unused oops from the table. |
|
148 |
// This is done late during GC. |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
149 |
void ResolvedMethodTable::unlink() { |
46505 | 150 |
_oops_removed = 0; |
151 |
_oops_counted = 0; |
|
152 |
for (int i = 0; i < _the_table->table_size(); ++i) { |
|
153 |
ResolvedMethodEntry** p = _the_table->bucket_addr(i); |
|
154 |
ResolvedMethodEntry* entry = _the_table->bucket(i); |
|
155 |
while (entry != NULL) { |
|
156 |
_oops_counted++; |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
157 |
oop l = entry->object_no_keepalive(); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
158 |
if (l != NULL) { |
46505 | 159 |
p = entry->next_addr(); |
160 |
} else { |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
161 |
// Entry has been removed. |
46505 | 162 |
_oops_removed++; |
163 |
if (log_is_enabled(Debug, membername, table)) { |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
164 |
log_debug(membername, table) ("ResolvedMethod entry removed for index %d", i); |
46505 | 165 |
} |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
166 |
entry->literal().release(); |
46505 | 167 |
*p = entry->next(); |
168 |
_the_table->free_entry(entry); |
|
169 |
} |
|
170 |
// get next entry |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
171 |
entry = (ResolvedMethodEntry*)HashtableEntry<ClassLoaderWeakHandle, mtClass>::make_ptr(*p); |
46505 | 172 |
} |
173 |
} |
|
174 |
log_debug(membername, table) ("ResolvedMethod entries counted %d removed %d", |
|
175 |
_oops_counted, _oops_removed); |
|
176 |
} |
|
177 |
||
178 |
#ifndef PRODUCT |
|
179 |
void ResolvedMethodTable::print() { |
|
180 |
for (int i = 0; i < table_size(); ++i) { |
|
181 |
ResolvedMethodEntry* entry = bucket(i); |
|
182 |
while (entry != NULL) { |
|
183 |
tty->print("%d : ", i); |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
184 |
oop rmethod_name = entry->object_no_keepalive(); |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
185 |
if (rmethod_name != NULL) { |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
186 |
rmethod_name->print(); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
187 |
Method* m = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(rmethod_name); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
188 |
m->print(); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
189 |
} |
46505 | 190 |
entry = entry->next(); |
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
#endif // PRODUCT |
|
195 |
||
196 |
#if INCLUDE_JVMTI |
|
197 |
// It is called at safepoint only for RedefineClasses |
|
198 |
void ResolvedMethodTable::adjust_method_entries(bool * trace_name_printed) { |
|
199 |
assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint"); |
|
200 |
// For each entry in RMT, change to new method |
|
201 |
for (int i = 0; i < _the_table->table_size(); ++i) { |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
202 |
for (ResolvedMethodEntry* entry = _the_table->bucket(i); |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
203 |
entry != NULL; |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
204 |
entry = entry->next()) { |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
205 |
|
48615
31cd0c16f4d2
8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents:
47216
diff
changeset
|
206 |
oop mem_name = entry->object_no_keepalive(); |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
207 |
// except ones removed |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
208 |
if (mem_name == NULL) { |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
209 |
continue; |
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49594
diff
changeset
|
210 |
} |
46505 | 211 |
Method* old_method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(mem_name); |
212 |
||
213 |
if (old_method->is_old()) { |
|
214 |
||
215 |
if (old_method->is_deleted()) { |
|
216 |
// leave deleted method in ResolvedMethod for now (this is a bug that we don't mark |
|
217 |
// these on_stack) |
|
218 |
continue; |
|
219 |
} |
|
220 |
||
221 |
InstanceKlass* holder = old_method->method_holder(); |
|
222 |
Method* new_method = holder->method_with_idnum(old_method->orig_method_idnum()); |
|
223 |
assert(holder == new_method->method_holder(), "call after swapping redefined guts"); |
|
224 |
assert(new_method != NULL, "method_with_idnum() should not be NULL"); |
|
225 |
assert(old_method != new_method, "sanity check"); |
|
226 |
||
227 |
java_lang_invoke_ResolvedMethodName::set_vmtarget(mem_name, new_method); |
|
228 |
||
229 |
ResourceMark rm; |
|
230 |
if (!(*trace_name_printed)) { |
|
231 |
log_info(redefine, class, update)("adjust: name=%s", old_method->method_holder()->external_name()); |
|
232 |
*trace_name_printed = true; |
|
233 |
} |
|
234 |
log_debug(redefine, class, update, constantpool) |
|
235 |
("ResolvedMethod method update: %s(%s)", |
|
236 |
new_method->name()->as_C_string(), new_method->signature()->as_C_string()); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
#endif // INCLUDE_JVMTI |