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