author | dnsimon |
Mon, 06 Nov 2017 12:53:55 +0100 | |
changeset 47794 | e84aa2c71241 |
parent 47216 | 71c04702a3d5 |
child 48007 | ab3959df2115 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
40642
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 "jvmci/jvmciEnv.hpp" |
|
27 |
#include "classfile/javaAssertions.hpp" |
|
28 |
#include "classfile/systemDictionary.hpp" |
|
29 |
#include "classfile/vmSymbols.hpp" |
|
30 |
#include "code/codeCache.hpp" |
|
31 |
#include "code/scopeDesc.hpp" |
|
32 |
#include "runtime/sweeper.hpp" |
|
33 |
#include "compiler/compileBroker.hpp" |
|
34 |
#include "compiler/compileLog.hpp" |
|
35 |
#include "compiler/compilerOracle.hpp" |
|
36 |
#include "interpreter/linkResolver.hpp" |
|
37 |
#include "memory/allocation.inline.hpp" |
|
38 |
#include "memory/oopFactory.hpp" |
|
37248 | 39 |
#include "memory/resourceArea.hpp" |
33160 | 40 |
#include "memory/universe.inline.hpp" |
41 |
#include "oops/methodData.hpp" |
|
42 |
#include "oops/objArrayKlass.hpp" |
|
43 |
#include "oops/oop.inline.hpp" |
|
44 |
#include "prims/jvmtiExport.hpp" |
|
45 |
#include "runtime/init.hpp" |
|
46 |
#include "runtime/reflection.hpp" |
|
47 |
#include "runtime/sharedRuntime.hpp" |
|
48 |
#include "utilities/dtrace.hpp" |
|
49 |
#include "jvmci/jvmciRuntime.hpp" |
|
50 |
#include "jvmci/jvmciJavaClasses.hpp" |
|
51 |
||
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
52 |
JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter): |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
53 |
_task(task), |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
54 |
_system_dictionary_modification_counter(system_dictionary_modification_counter), |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
55 |
_failure_reason(NULL), |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
56 |
_retryable(true) |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
57 |
{ |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
58 |
// Get Jvmti capabilities under lock to get consistent values. |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
59 |
MutexLocker mu(JvmtiThreadState_lock); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
60 |
_jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
61 |
_jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
62 |
_jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); |
33160 | 63 |
} |
64 |
||
65 |
// ------------------------------------------------------------------ |
|
66 |
// Note: the logic of this method should mirror the logic of |
|
67 |
// constantPoolOopDesc::verify_constant_pool_resolve. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
68 |
bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) { |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
69 |
if (accessing_klass->is_objArray_klass()) { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
70 |
accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass(); |
33160 | 71 |
} |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
72 |
if (!accessing_klass->is_instance_klass()) { |
33160 | 73 |
return true; |
74 |
} |
|
75 |
||
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
76 |
if (resolved_klass->is_objArray_klass()) { |
33160 | 77 |
// Find the element klass, if this is an array. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
78 |
resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); |
33160 | 79 |
} |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
80 |
if (resolved_klass->is_instance_klass()) { |
36508 | 81 |
Reflection::VerifyClassAccessResults result = |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
82 |
Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true); |
36508 | 83 |
return result == Reflection::ACCESS_OK; |
33160 | 84 |
} |
85 |
return true; |
|
86 |
} |
|
87 |
||
88 |
// ------------------------------------------------------------------ |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
89 |
Klass* JVMCIEnv::get_klass_by_name_impl(Klass* accessing_klass, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
90 |
const constantPoolHandle& cpool, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
91 |
Symbol* sym, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
92 |
bool require_local) { |
33160 | 93 |
JVMCI_EXCEPTION_CONTEXT; |
94 |
||
95 |
// Now we need to check the SystemDictionary |
|
96 |
if (sym->byte_at(0) == 'L' && |
|
97 |
sym->byte_at(sym->utf8_length()-1) == ';') { |
|
98 |
// This is a name from a signature. Strip off the trimmings. |
|
99 |
// Call recursive to keep scope of strippedsym. |
|
100 |
TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, |
|
101 |
sym->utf8_length()-2, |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
102 |
CHECK_NULL); |
33160 | 103 |
return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local); |
104 |
} |
|
105 |
||
106 |
Handle loader(THREAD, (oop)NULL); |
|
107 |
Handle domain(THREAD, (oop)NULL); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
108 |
if (accessing_klass != NULL) { |
33160 | 109 |
loader = Handle(THREAD, accessing_klass->class_loader()); |
110 |
domain = Handle(THREAD, accessing_klass->protection_domain()); |
|
111 |
} |
|
112 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
113 |
Klass* found_klass = NULL; |
33160 | 114 |
{ |
115 |
ttyUnlocker ttyul; // release tty lock to avoid ordering problems |
|
116 |
MutexLocker ml(Compile_lock); |
|
117 |
if (!require_local) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
118 |
found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL); |
33160 | 119 |
} else { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
120 |
found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL); |
33160 | 121 |
} |
122 |
} |
|
123 |
||
124 |
// If we fail to find an array klass, look again for its element type. |
|
125 |
// The element type may be available either locally or via constraints. |
|
126 |
// In either case, if we can find the element type in the system dictionary, |
|
127 |
// we must build an array type around it. The CI requires array klasses |
|
128 |
// to be loaded if their element klasses are loaded, except when memory |
|
129 |
// is exhausted. |
|
130 |
if (sym->byte_at(0) == '[' && |
|
131 |
(sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { |
|
132 |
// We have an unloaded array. |
|
133 |
// Build it on the fly if the element class exists. |
|
134 |
TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, |
|
135 |
sym->utf8_length()-1, |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
136 |
CHECK_NULL); |
33160 | 137 |
|
138 |
// Get element Klass recursively. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
139 |
Klass* elem_klass = |
33160 | 140 |
get_klass_by_name_impl(accessing_klass, |
141 |
cpool, |
|
142 |
elem_sym, |
|
143 |
require_local); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
144 |
if (elem_klass != NULL) { |
33160 | 145 |
// Now make an array for it |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
146 |
return elem_klass->array_klass(CHECK_NULL); |
33160 | 147 |
} |
148 |
} |
|
149 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
150 |
if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) { |
33160 | 151 |
// Look inside the constant pool for pre-resolved class entries. |
152 |
for (int i = cpool->length() - 1; i >= 1; i--) { |
|
153 |
if (cpool->tag_at(i).is_klass()) { |
|
154 |
Klass* kls = cpool->resolved_klass_at(i); |
|
155 |
if (kls->name() == sym) { |
|
156 |
return kls; |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
162 |
return found_klass; |
33160 | 163 |
} |
164 |
||
165 |
// ------------------------------------------------------------------ |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
166 |
Klass* JVMCIEnv::get_klass_by_name(Klass* accessing_klass, |
33160 | 167 |
Symbol* klass_name, |
168 |
bool require_local) { |
|
169 |
ResourceMark rm; |
|
170 |
constantPoolHandle cpool; |
|
171 |
return get_klass_by_name_impl(accessing_klass, |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
172 |
cpool, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
173 |
klass_name, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
174 |
require_local); |
33160 | 175 |
} |
176 |
||
177 |
// ------------------------------------------------------------------ |
|
178 |
// Implementation of get_klass_by_index. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
179 |
Klass* JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, |
33160 | 180 |
int index, |
181 |
bool& is_accessible, |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
182 |
Klass* accessor) { |
33160 | 183 |
JVMCI_EXCEPTION_CONTEXT; |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
184 |
Klass* klass = ConstantPool::klass_at_if_loaded(cpool, index); |
33160 | 185 |
Symbol* klass_name = NULL; |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
186 |
if (klass == NULL) { |
33160 | 187 |
klass_name = cpool->klass_name_at(index); |
188 |
} |
|
189 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
190 |
if (klass == NULL) { |
33160 | 191 |
// Not found in constant pool. Use the name to do the lookup. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
192 |
Klass* k = get_klass_by_name_impl(accessor, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
193 |
cpool, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
194 |
klass_name, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
195 |
false); |
33160 | 196 |
// Calculate accessibility the hard way. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
197 |
if (k == NULL) { |
33160 | 198 |
is_accessible = false; |
199 |
} else if (k->class_loader() != accessor->class_loader() && |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
200 |
get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { |
33160 | 201 |
// Loaded only remotely. Not linked yet. |
202 |
is_accessible = false; |
|
203 |
} else { |
|
204 |
// Linked locally, and we must also check public/private, etc. |
|
205 |
is_accessible = check_klass_accessibility(accessor, k); |
|
206 |
} |
|
207 |
if (!is_accessible) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
208 |
return NULL; |
33160 | 209 |
} |
210 |
return k; |
|
211 |
} |
|
212 |
||
213 |
// It is known to be accessible, since it was found in the constant pool. |
|
214 |
is_accessible = true; |
|
215 |
return klass; |
|
216 |
} |
|
217 |
||
218 |
// ------------------------------------------------------------------ |
|
219 |
// Get a klass from the constant pool. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
220 |
Klass* JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
221 |
int index, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
222 |
bool& is_accessible, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
223 |
Klass* accessor) { |
33160 | 224 |
ResourceMark rm; |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
225 |
return get_klass_by_index_impl(cpool, index, is_accessible, accessor); |
33160 | 226 |
} |
227 |
||
228 |
// ------------------------------------------------------------------ |
|
229 |
// Implementation of get_field_by_index. |
|
230 |
// |
|
231 |
// Implementation note: the results of field lookups are cached |
|
232 |
// in the accessor klass. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
233 |
void JVMCIEnv::get_field_by_index_impl(InstanceKlass* klass, fieldDescriptor& field_desc, |
33160 | 234 |
int index) { |
235 |
JVMCI_EXCEPTION_CONTEXT; |
|
236 |
||
237 |
assert(klass->is_linked(), "must be linked before using its constant-pool"); |
|
238 |
||
239 |
constantPoolHandle cpool(thread, klass->constants()); |
|
240 |
||
241 |
// Get the field's name, signature, and type. |
|
242 |
Symbol* name = cpool->name_ref_at(index); |
|
243 |
||
244 |
int nt_index = cpool->name_and_type_ref_index_at(index); |
|
245 |
int sig_index = cpool->signature_ref_index_at(nt_index); |
|
246 |
Symbol* signature = cpool->symbol_at(sig_index); |
|
247 |
||
248 |
// Get the field's declared holder. |
|
249 |
int holder_index = cpool->klass_ref_index_at(index); |
|
250 |
bool holder_is_accessible; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
251 |
Klass* declared_holder = get_klass_by_index(cpool, holder_index, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
252 |
holder_is_accessible, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
253 |
klass); |
33160 | 254 |
|
255 |
// The declared holder of this field may not have been loaded. |
|
256 |
// Bail out with partial field information. |
|
257 |
if (!holder_is_accessible) { |
|
258 |
return; |
|
259 |
} |
|
260 |
||
261 |
||
262 |
// Perform the field lookup. |
|
263 |
Klass* canonical_holder = |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
264 |
InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc); |
33160 | 265 |
if (canonical_holder == NULL) { |
266 |
return; |
|
267 |
} |
|
268 |
||
269 |
assert(canonical_holder == field_desc.field_holder(), "just checking"); |
|
270 |
} |
|
271 |
||
272 |
// ------------------------------------------------------------------ |
|
273 |
// Get a field by index from a klass's constant pool. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
274 |
void JVMCIEnv::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) { |
33160 | 275 |
ResourceMark rm; |
276 |
return get_field_by_index_impl(accessor, fd, index); |
|
277 |
} |
|
278 |
||
279 |
// ------------------------------------------------------------------ |
|
280 |
// Perform an appropriate method lookup based on accessor, holder, |
|
281 |
// name, signature, and bytecode. |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
282 |
methodHandle JVMCIEnv::lookup_method(InstanceKlass* accessor, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
283 |
Klass* holder, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
284 |
Symbol* name, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
285 |
Symbol* sig, |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38133
diff
changeset
|
286 |
Bytecodes::Code bc, |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38133
diff
changeset
|
287 |
constantTag tag) { |
43938
f0e4bcc4d9f3
8170455: C2: Access to [].clone from interfaces fails
jcm
parents:
40642
diff
changeset
|
288 |
// Accessibility checks are performed in JVMCIEnv::get_method_by_index_impl(). |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
289 |
assert(check_klass_accessibility(accessor, holder), "holder not accessible"); |
43938
f0e4bcc4d9f3
8170455: C2: Access to [].clone from interfaces fails
jcm
parents:
40642
diff
changeset
|
290 |
|
33160 | 291 |
methodHandle dest_method; |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
292 |
LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag); |
33160 | 293 |
switch (bc) { |
294 |
case Bytecodes::_invokestatic: |
|
295 |
dest_method = |
|
296 |
LinkResolver::resolve_static_call_or_null(link_info); |
|
297 |
break; |
|
298 |
case Bytecodes::_invokespecial: |
|
299 |
dest_method = |
|
300 |
LinkResolver::resolve_special_call_or_null(link_info); |
|
301 |
break; |
|
302 |
case Bytecodes::_invokeinterface: |
|
303 |
dest_method = |
|
304 |
LinkResolver::linktime_resolve_interface_method_or_null(link_info); |
|
305 |
break; |
|
306 |
case Bytecodes::_invokevirtual: |
|
307 |
dest_method = |
|
308 |
LinkResolver::linktime_resolve_virtual_method_or_null(link_info); |
|
309 |
break; |
|
310 |
default: ShouldNotReachHere(); |
|
311 |
} |
|
312 |
||
313 |
return dest_method; |
|
314 |
} |
|
315 |
||
316 |
||
317 |
// ------------------------------------------------------------------ |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33160
diff
changeset
|
318 |
methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool, |
33160 | 319 |
int index, Bytecodes::Code bc, |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
320 |
InstanceKlass* accessor) { |
33160 | 321 |
if (bc == Bytecodes::_invokedynamic) { |
322 |
ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); |
|
323 |
bool is_resolved = !cpce->is_f1_null(); |
|
324 |
if (is_resolved) { |
|
325 |
// Get the invoker Method* from the constant pool. |
|
326 |
// (The appendix argument, if any, will be noted in the method's signature.) |
|
327 |
Method* adapter = cpce->f1_as_method(); |
|
328 |
return methodHandle(adapter); |
|
329 |
} |
|
330 |
||
331 |
return NULL; |
|
332 |
} |
|
333 |
||
334 |
int holder_index = cpool->klass_ref_index_at(index); |
|
335 |
bool holder_is_accessible; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
336 |
Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); |
33160 | 337 |
|
338 |
// Get the method's name and signature. |
|
339 |
Symbol* name_sym = cpool->name_ref_at(index); |
|
340 |
Symbol* sig_sym = cpool->signature_ref_at(index); |
|
341 |
||
342 |
if (cpool->has_preresolution() |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
343 |
|| ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) && |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
344 |
MethodHandles::is_signature_polymorphic_name(holder, name_sym))) { |
33160 | 345 |
// Short-circuit lookups for JSR 292-related call sites. |
346 |
// That is, do not rely only on name-based lookups, because they may fail |
|
347 |
// if the names are not resolvable in the boot class loader (7056328). |
|
348 |
switch (bc) { |
|
349 |
case Bytecodes::_invokevirtual: |
|
350 |
case Bytecodes::_invokeinterface: |
|
351 |
case Bytecodes::_invokespecial: |
|
352 |
case Bytecodes::_invokestatic: |
|
353 |
{ |
|
354 |
Method* m = ConstantPool::method_at_if_loaded(cpool, index); |
|
355 |
if (m != NULL) { |
|
356 |
return m; |
|
357 |
} |
|
358 |
} |
|
359 |
break; |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46329
diff
changeset
|
360 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46329
diff
changeset
|
361 |
break; |
33160 | 362 |
} |
363 |
} |
|
364 |
||
365 |
if (holder_is_accessible) { // Our declared holder is loaded. |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38133
diff
changeset
|
366 |
constantTag tag = cpool->tag_ref_at(index); |
43938
f0e4bcc4d9f3
8170455: C2: Access to [].clone from interfaces fails
jcm
parents:
40642
diff
changeset
|
367 |
methodHandle m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag); |
33160 | 368 |
if (!m.is_null() && |
369 |
(bc == Bytecodes::_invokestatic |
|
370 |
? InstanceKlass::cast(m->method_holder())->is_not_initialized() |
|
371 |
: !InstanceKlass::cast(m->method_holder())->is_loaded())) { |
|
372 |
m = NULL; |
|
373 |
} |
|
374 |
if (!m.is_null()) { |
|
375 |
// We found the method. |
|
376 |
return m; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
// Either the declared holder was not loaded, or the method could |
|
381 |
// not be found. |
|
382 |
||
383 |
return NULL; |
|
384 |
} |
|
385 |
||
386 |
// ------------------------------------------------------------------ |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
387 |
InstanceKlass* JVMCIEnv::get_instance_klass_for_declared_method_holder(Klass* method_holder) { |
33160 | 388 |
// For the case of <array>.clone(), the method holder can be an ArrayKlass* |
389 |
// instead of an InstanceKlass*. For that case simply pretend that the |
|
390 |
// declared holder is Object.clone since that's where the call will bottom out. |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
391 |
if (method_holder->is_instance_klass()) { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
392 |
return InstanceKlass::cast(method_holder); |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33593
diff
changeset
|
393 |
} else if (method_holder->is_array_klass()) { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
394 |
return SystemDictionary::Object_klass(); |
33160 | 395 |
} else { |
396 |
ShouldNotReachHere(); |
|
397 |
} |
|
398 |
return NULL; |
|
399 |
} |
|
400 |
||
401 |
||
402 |
// ------------------------------------------------------------------ |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33160
diff
changeset
|
403 |
methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool, |
33160 | 404 |
int index, Bytecodes::Code bc, |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
405 |
InstanceKlass* accessor) { |
33160 | 406 |
ResourceMark rm; |
407 |
return get_method_by_index_impl(cpool, index, bc, accessor); |
|
408 |
} |
|
409 |
||
410 |
// ------------------------------------------------------------------ |
|
411 |
// Check for changes to the system dictionary during compilation |
|
412 |
// class loads, evolution, breakpoints |
|
413 |
JVMCIEnv::CodeInstallResult JVMCIEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code, |
|
414 |
JVMCIEnv* env, char** failure_detail) { |
|
415 |
// If JVMTI capabilities were enabled during compile, the compilation is invalidated. |
|
416 |
if (env != NULL) { |
|
417 |
if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) { |
|
418 |
*failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation"; |
|
419 |
return JVMCIEnv::dependencies_failed; |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
// Dependencies must be checked when the system dictionary changes |
|
424 |
// or if we don't know whether it has changed (i.e., env == NULL). |
|
425 |
// In debug mode, always check dependencies. |
|
426 |
bool counter_changed = env != NULL && env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); |
|
427 |
bool verify_deps = env == NULL || trueInDebug || JavaAssertions::enabled(SystemDictionary::HotSpotInstalledCode_klass()->name()->as_C_string(), true); |
|
428 |
if (!counter_changed && !verify_deps) { |
|
429 |
return JVMCIEnv::ok; |
|
430 |
} |
|
431 |
||
432 |
for (Dependencies::DepStream deps(dependencies); deps.next(); ) { |
|
433 |
Klass* witness = deps.check_dependency(); |
|
434 |
if (witness != NULL) { |
|
435 |
// Use a fixed size buffer to prevent the string stream from |
|
436 |
// resizing in the context of an inner resource mark. |
|
437 |
char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN); |
|
438 |
stringStream st(buffer, O_BUFLEN); |
|
439 |
deps.print_dependency(witness, true, &st); |
|
440 |
*failure_detail = st.as_string(); |
|
37286
67b04a68b881
8153315: [JVMCI] evol_method dependencies failures should return dependencies_failed
never
parents:
36508
diff
changeset
|
441 |
if (env == NULL || counter_changed || deps.type() == Dependencies::evol_method) { |
33160 | 442 |
return JVMCIEnv::dependencies_failed; |
443 |
} else { |
|
444 |
// The dependencies were invalid at the time of installation |
|
445 |
// without any intervening modification of the system |
|
446 |
// dictionary. That means they were invalidly constructed. |
|
447 |
return JVMCIEnv::dependencies_invalid; |
|
448 |
} |
|
449 |
} |
|
450 |
if (LogCompilation) { |
|
451 |
deps.log_dependency(); |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
return JVMCIEnv::ok; |
|
456 |
} |
|
457 |
||
458 |
// ------------------------------------------------------------------ |
|
459 |
JVMCIEnv::CodeInstallResult JVMCIEnv::register_method( |
|
34165 | 460 |
const methodHandle& method, |
33160 | 461 |
nmethod*& nm, |
462 |
int entry_bci, |
|
463 |
CodeOffsets* offsets, |
|
464 |
int orig_pc_offset, |
|
465 |
CodeBuffer* code_buffer, |
|
466 |
int frame_words, |
|
467 |
OopMapSet* oop_map_set, |
|
468 |
ExceptionHandlerTable* handler_table, |
|
469 |
AbstractCompiler* compiler, |
|
470 |
DebugInformationRecorder* debug_info, |
|
471 |
Dependencies* dependencies, |
|
472 |
JVMCIEnv* env, |
|
473 |
int compile_id, |
|
474 |
bool has_unsafe_access, |
|
475 |
bool has_wide_vector, |
|
476 |
Handle installed_code, |
|
477 |
Handle compiled_code, |
|
478 |
Handle speculation_log) { |
|
479 |
JVMCI_EXCEPTION_CONTEXT; |
|
480 |
nm = NULL; |
|
481 |
int comp_level = CompLevel_full_optimization; |
|
482 |
char* failure_detail = NULL; |
|
483 |
JVMCIEnv::CodeInstallResult result; |
|
484 |
{ |
|
485 |
// To prevent compile queue updates. |
|
486 |
MutexLocker locker(MethodCompileQueue_lock, THREAD); |
|
487 |
||
488 |
// Prevent SystemDictionary::add_to_hierarchy from running |
|
489 |
// and invalidating our dependencies until we install this method. |
|
490 |
MutexLocker ml(Compile_lock); |
|
491 |
||
492 |
// Encode the dependencies now, so we can check them right away. |
|
493 |
dependencies->encode_content_bytes(); |
|
494 |
||
495 |
// Check for {class loads, evolution, breakpoints} during compilation |
|
496 |
result = check_for_system_dictionary_modification(dependencies, compiled_code, env, &failure_detail); |
|
497 |
if (result != JVMCIEnv::ok) { |
|
498 |
// While not a true deoptimization, it is a preemptive decompile. |
|
499 |
MethodData* mdp = method()->method_data(); |
|
500 |
if (mdp != NULL) { |
|
501 |
mdp->inc_decompile_count(); |
|
33632 | 502 |
#ifdef ASSERT |
33160 | 503 |
if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) { |
504 |
ResourceMark m; |
|
505 |
tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string()); |
|
506 |
} |
|
33632 | 507 |
#endif |
33160 | 508 |
} |
509 |
||
510 |
// All buffers in the CodeBuffer are allocated in the CodeCache. |
|
511 |
// If the code buffer is created on each compile attempt |
|
512 |
// as in C2, then it must be freed. |
|
513 |
//code_buffer->free_blob(); |
|
514 |
} else { |
|
515 |
ImplicitExceptionTable implicit_tbl; |
|
516 |
nm = nmethod::new_nmethod(method, |
|
517 |
compile_id, |
|
518 |
entry_bci, |
|
519 |
offsets, |
|
520 |
orig_pc_offset, |
|
521 |
debug_info, dependencies, code_buffer, |
|
522 |
frame_words, oop_map_set, |
|
523 |
handler_table, &implicit_tbl, |
|
47794
e84aa2c71241
8188102: [JVMCI] Convert special JVMCI oops in nmethod to jweak values
dnsimon
parents:
47216
diff
changeset
|
524 |
compiler, comp_level, |
e84aa2c71241
8188102: [JVMCI] Convert special JVMCI oops in nmethod to jweak values
dnsimon
parents:
47216
diff
changeset
|
525 |
JNIHandles::make_weak_global(installed_code), |
e84aa2c71241
8188102: [JVMCI] Convert special JVMCI oops in nmethod to jweak values
dnsimon
parents:
47216
diff
changeset
|
526 |
JNIHandles::make_weak_global(speculation_log)); |
33160 | 527 |
|
528 |
// Free codeBlobs |
|
529 |
//code_buffer->free_blob(); |
|
530 |
if (nm == NULL) { |
|
531 |
// The CodeCache is full. Print out warning and disable compilation. |
|
532 |
{ |
|
533 |
MutexUnlocker ml(Compile_lock); |
|
534 |
MutexUnlocker locker(MethodCompileQueue_lock); |
|
535 |
CompileBroker::handle_full_code_cache(CodeCache::get_code_blob_type(comp_level)); |
|
536 |
} |
|
537 |
} else { |
|
538 |
nm->set_has_unsafe_access(has_unsafe_access); |
|
539 |
nm->set_has_wide_vectors(has_wide_vector); |
|
540 |
||
541 |
// Record successful registration. |
|
542 |
// (Put nm into the task handle *before* publishing to the Java heap.) |
|
543 |
CompileTask* task = env == NULL ? NULL : env->task(); |
|
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
544 |
if (task != NULL) { |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
545 |
task->set_code(nm); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
34317
diff
changeset
|
546 |
} |
33160 | 547 |
|
548 |
if (installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(installed_code())) { |
|
549 |
if (entry_bci == InvocationEntryBci) { |
|
550 |
if (TieredCompilation) { |
|
551 |
// If there is an old version we're done with it |
|
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
37296
diff
changeset
|
552 |
CompiledMethod* old = method->code(); |
33160 | 553 |
if (TraceMethodReplacement && old != NULL) { |
554 |
ResourceMark rm; |
|
555 |
char *method_name = method->name_and_sig_as_C_string(); |
|
556 |
tty->print_cr("Replacing method %s", method_name); |
|
557 |
} |
|
558 |
if (old != NULL ) { |
|
559 |
old->make_not_entrant(); |
|
560 |
} |
|
561 |
} |
|
562 |
if (TraceNMethodInstalls) { |
|
563 |
ResourceMark rm; |
|
564 |
char *method_name = method->name_and_sig_as_C_string(); |
|
565 |
ttyLocker ttyl; |
|
566 |
tty->print_cr("Installing method (%d) %s [entry point: %p]", |
|
567 |
comp_level, |
|
568 |
method_name, nm->entry_point()); |
|
569 |
} |
|
570 |
// Allow the code to be executed |
|
571 |
method->set_code(method, nm); |
|
572 |
} else { |
|
573 |
if (TraceNMethodInstalls ) { |
|
574 |
ResourceMark rm; |
|
575 |
char *method_name = method->name_and_sig_as_C_string(); |
|
576 |
ttyLocker ttyl; |
|
577 |
tty->print_cr("Installing osr method (%d) %s @ %d", |
|
578 |
comp_level, |
|
579 |
method_name, |
|
580 |
entry_bci); |
|
581 |
} |
|
582 |
InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm); |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
result = nm != NULL ? JVMCIEnv::ok :JVMCIEnv::cache_full; |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
// String creation must be done outside lock |
|
591 |
if (failure_detail != NULL) { |
|
592 |
// A failure to allocate the string is silently ignored. |
|
593 |
Handle message = java_lang_String::create_from_str(failure_detail, THREAD); |
|
594 |
HotSpotCompiledNmethod::set_installationFailureMessage(compiled_code, message()); |
|
595 |
} |
|
596 |
||
597 |
// JVMTI -- compiled method notification (must be done outside lock) |
|
598 |
if (nm != NULL) { |
|
599 |
nm->post_compiled_method_load_event(); |
|
36078
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
600 |
|
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
601 |
if (env == NULL) { |
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
602 |
// This compile didn't come through the CompileBroker so perform the printing here |
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
603 |
DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler); |
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
604 |
nm->maybe_print_nmethod(directive); |
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
605 |
DirectivesStack::release(directive); |
954c49c0ba57
8149969: [JVMCI] PrintNMethods is ignored for CompilerToVM.installCode when not called from the broker
never
parents:
35592
diff
changeset
|
606 |
} |
33160 | 607 |
} |
608 |
||
609 |
return result; |
|
610 |
} |