blob: 68d4a05bc7fe14127bfc5c3233e9781b99890c50 [file] [log] [blame]
Christian Thalinger16526e02015-10-08 12:49:30 -10001/*
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -04002 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
Christian Thalinger16526e02015-10-08 12:49:30 -10003 * 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
Tom Rodriguez87d68c22016-01-22 11:08:07 -080051JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter):
52 _task(task),
53 _system_dictionary_modification_counter(system_dictionary_modification_counter),
54 _failure_reason(NULL),
55 _retryable(true)
56{
57 // Get Jvmti capabilities under lock to get consistent values.
58 MutexLocker mu(JvmtiThreadState_lock);
59 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
60 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables();
61 _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions();
Christian Thalinger16526e02015-10-08 12:49:30 -100062}
63
64// ------------------------------------------------------------------
65// Note: the logic of this method should mirror the logic of
66// constantPoolOopDesc::verify_constant_pool_resolve.
67bool JVMCIEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass) {
Coleen Phillimorefc037192015-10-28 09:47:23 -040068 if (accessing_klass->is_objArray_klass()) {
Christian Thalinger16526e02015-10-08 12:49:30 -100069 accessing_klass = ObjArrayKlass::cast(accessing_klass())->bottom_klass();
70 }
Coleen Phillimorefc037192015-10-28 09:47:23 -040071 if (!accessing_klass->is_instance_klass()) {
Christian Thalinger16526e02015-10-08 12:49:30 -100072 return true;
73 }
74
Coleen Phillimorefc037192015-10-28 09:47:23 -040075 if (resolved_klass->is_objArray_klass()) {
Christian Thalinger16526e02015-10-08 12:49:30 -100076 // Find the element klass, if this is an array.
77 resolved_klass = ObjArrayKlass::cast(resolved_klass())->bottom_klass();
78 }
Coleen Phillimorefc037192015-10-28 09:47:23 -040079 if (resolved_klass->is_instance_klass()) {
Alan Batemanf30fc1c2016-03-17 19:04:01 +000080 Reflection::VerifyClassAccessResults result =
81 Reflection::verify_class_access(accessing_klass(), resolved_klass(), true);
82 return result == Reflection::ACCESS_OK;
Christian Thalinger16526e02015-10-08 12:49:30 -100083 }
84 return true;
85}
86
87// ------------------------------------------------------------------
88KlassHandle JVMCIEnv::get_klass_by_name_impl(KlassHandle& accessing_klass,
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -040089 const constantPoolHandle& cpool,
Christian Thalinger16526e02015-10-08 12:49:30 -100090 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// ------------------------------------------------------------------
Roland Schatz3d7459232015-11-10 10:34:39 -1000167KlassHandle JVMCIEnv::get_klass_by_name(KlassHandle accessing_klass,
Christian Thalinger16526e02015-10-08 12:49:30 -1000168 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.
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -0400180KlassHandle JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
Christian Thalinger16526e02015-10-08 12:49:30 -1000181 int index,
182 bool& is_accessible,
Roland Schatz3d7459232015-11-10 10:34:39 -1000183 KlassHandle accessor) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000184 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.
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -0400221KlassHandle JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool,
Christian Thalinger16526e02015-10-08 12:49:30 -1000222 int index,
223 bool& is_accessible,
Roland Schatz3d7459232015-11-10 10:34:39 -1000224 KlassHandle accessor) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000225 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.
Roland Schatz3d7459232015-11-10 10:34:39 -1000235void JVMCIEnv::get_field_by_index_impl(instanceKlassHandle klass, fieldDescriptor& field_desc,
Christian Thalinger16526e02015-10-08 12:49:30 -1000236 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.
Roland Schatz3d7459232015-11-10 10:34:39 -1000276void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000277 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.
Roland Schatz3d7459232015-11-10 10:34:39 -1000284methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor,
285 instanceKlassHandle h_holder,
Christian Thalinger16526e02015-10-08 12:49:30 -1000286 Symbol* name,
287 Symbol* sig,
Christian Tornqvistc02b26e2015-11-19 10:34:11 -0800288 Bytecodes::Code bc) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000289 JVMCI_EXCEPTION_CONTEXT;
290 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
291 methodHandle dest_method;
Christian Tornqvistc02b26e2015-11-19 10:34:11 -0800292 LinkInfo link_info(h_holder, name, sig, h_accessor, /*check_access*/true);
Christian Thalinger16526e02015-10-08 12:49:30 -1000293 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// ------------------------------------------------------------------
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -0400318methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
Christian Thalinger16526e02015-10-08 12:49:30 -1000319 int index, Bytecodes::Code bc,
Roland Schatz3d7459232015-11-10 10:34:39 -1000320 instanceKlassHandle accessor) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000321 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);
Christian Tornqvistc02b26e2015-11-19 10:34:11 -0800365 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc);
Christian Thalinger16526e02015-10-08 12:49:30 -1000366 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// ------------------------------------------------------------------
Roland Schatz3d7459232015-11-10 10:34:39 -1000385instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000386 // 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.
Coleen Phillimorefc037192015-10-28 09:47:23 -0400389 if (method_holder->is_instance_klass()) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000390 return instanceKlassHandle(method_holder());
Coleen Phillimorefc037192015-10-28 09:47:23 -0400391 } else if (method_holder->is_array_klass()) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000392 return instanceKlassHandle(SystemDictionary::Object_klass());
393 } else {
394 ShouldNotReachHere();
395 }
396 return NULL;
397}
398
399
400// ------------------------------------------------------------------
Coleen Phillimoref1e89ea2015-10-23 16:48:38 -0400401methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
Christian Thalinger16526e02015-10-08 12:49:30 -1000402 int index, Bytecodes::Code bc,
Roland Schatz3d7459232015-11-10 10:34:39 -1000403 instanceKlassHandle accessor) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000404 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
411JVMCIEnv::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// ------------------------------------------------------------------
457JVMCIEnv::CodeInstallResult JVMCIEnv::register_method(
Roland Schatz3d7459232015-11-10 10:34:39 -1000458 const methodHandle& method,
Christian Thalinger16526e02015-10-08 12:49:30 -1000459 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();
Christian Thalingera38ea492015-11-04 07:23:23 -1000500#ifdef ASSERT
Christian Thalinger16526e02015-10-08 12:49:30 -1000501 if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) {
Christian Thalinger16526e02015-10-08 12:49:30 -1000502 ResourceMark m;
503 tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string());
Christian Thalinger16526e02015-10-08 12:49:30 -1000504 }
Christian Thalingera38ea492015-11-04 07:23:23 -1000505#endif
Christian Thalinger16526e02015-10-08 12:49:30 -1000506 }
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();
Tom Rodriguez87d68c22016-01-22 11:08:07 -0800540 if (task != NULL) {
541 task->set_code(nm);
542 }
Christian Thalinger16526e02015-10-08 12:49:30 -1000543
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();
Tom Rodriguez05730d92016-02-16 09:49:58 -0800596
597 if (env == NULL) {
598 // This compile didn't come through the CompileBroker so perform the printing here
599 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
600 nm->maybe_print_nmethod(directive);
601 DirectivesStack::release(directive);
602 }
Christian Thalinger16526e02015-10-08 12:49:30 -1000603 }
604
605 return result;
606}
607