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