1 /* 2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 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 "ci/ciConstant.hpp" 27 #include "ci/ciEnv.hpp" 28 #include "ci/ciField.hpp" 29 #include "ci/ciInstance.hpp" 30 #include "ci/ciInstanceKlass.hpp" 31 #include "ci/ciMethod.hpp" 32 #include "ci/ciNullObject.hpp" 33 #include "ci/ciReplay.hpp" 34 #include "ci/ciUtilities.hpp" 35 #include "classfile/systemDictionary.hpp" 36 #include "classfile/vmSymbols.hpp" 37 #include "code/codeCache.hpp" 38 #include "code/scopeDesc.hpp" 39 #include "compiler/compileBroker.hpp" 40 #include "compiler/compileLog.hpp" 41 #include "compiler/disassembler.hpp" 42 #include "gc/shared/collectedHeap.inline.hpp" 43 #include "interpreter/linkResolver.hpp" 44 #include "memory/allocation.inline.hpp" 45 #include "memory/oopFactory.hpp" 46 #include "memory/resourceArea.hpp" 47 #include "memory/universe.inline.hpp" 48 #include "oops/methodData.hpp" 49 #include "oops/objArrayKlass.hpp" 50 #include "oops/objArrayOop.inline.hpp" 51 #include "oops/oop.inline.hpp" 52 #include "prims/jvmtiExport.hpp" 53 #include "runtime/init.hpp" 54 #include "runtime/reflection.hpp" 55 #include "runtime/sharedRuntime.hpp" 56 #include "runtime/thread.inline.hpp" 57 #include "trace/tracing.hpp" 58 #include "utilities/dtrace.hpp" 59 #include "utilities/macros.hpp" 60 #ifdef COMPILER1 61 #include "c1/c1_Runtime1.hpp" 62 #endif 63 #ifdef COMPILER2 64 #include "opto/runtime.hpp" 65 #endif 66 67 // ciEnv 68 // 69 // This class is the top level broker for requests from the compiler 70 // to the VM. 71 72 ciObject* ciEnv::_null_object_instance; 73 74 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL; 75 WK_KLASSES_DO(WK_KLASS_DEFN) 76 #undef WK_KLASS_DEFN 77 78 ciSymbol* ciEnv::_unloaded_cisymbol = NULL; 79 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; 80 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; 81 82 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; 83 jobject ciEnv::_ArrayStoreException_handle = NULL; 84 jobject ciEnv::_ClassCastException_handle = NULL; 85 86 #ifndef PRODUCT 87 static bool firstEnv = true; 88 #endif /* PRODUCT */ 89 90 // ------------------------------------------------------------------ 91 // ciEnv::ciEnv 92 ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter) 93 : _ciEnv_arena(mtCompiler) { 94 VM_ENTRY_MARK; 95 96 // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. 97 thread->set_env(this); 98 assert(ciEnv::current() == this, "sanity"); 99 100 _oop_recorder = NULL; 101 _debug_info = NULL; 102 _dependencies = NULL; 103 _failure_reason = NULL; 104 _compilable = MethodCompilable; 105 _break_at_compile = false; 106 _compiler_data = NULL; 107 #ifndef PRODUCT 108 assert(!firstEnv, "not initialized properly"); 109 #endif /* !PRODUCT */ 110 111 _system_dictionary_modification_counter = system_dictionary_modification_counter; 112 _num_inlined_bytecodes = 0; 113 assert(task == NULL || thread->task() == task, "sanity"); 114 _task = task; 115 _log = NULL; 116 117 // Temporary buffer for creating symbols and such. 118 _name_buffer = NULL; 119 _name_buffer_len = 0; 120 121 _arena = &_ciEnv_arena; 122 _factory = new (_arena) ciObjectFactory(_arena, 128); 123 124 // Preload commonly referenced system ciObjects. 125 126 // During VM initialization, these instances have not yet been created. 127 // Assertions ensure that these instances are not accessed before 128 // their initialization. 129 130 assert(Universe::is_fully_initialized(), "should be complete"); 131 132 oop o = Universe::null_ptr_exception_instance(); 133 assert(o != NULL, "should have been initialized"); 134 _NullPointerException_instance = get_object(o)->as_instance(); 135 o = Universe::arithmetic_exception_instance(); 136 assert(o != NULL, "should have been initialized"); 137 _ArithmeticException_instance = get_object(o)->as_instance(); 138 139 _ArrayIndexOutOfBoundsException_instance = NULL; 140 _ArrayStoreException_instance = NULL; 141 _ClassCastException_instance = NULL; 142 _the_null_string = NULL; 143 _the_min_jint_string = NULL; 144 145 _jvmti_can_hotswap_or_post_breakpoint = false; 146 _jvmti_can_access_local_variables = false; 147 _jvmti_can_post_on_exceptions = false; 148 _jvmti_can_pop_frame = false; 149 } 150 151 ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) { 152 ASSERT_IN_VM; 153 154 // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. 155 CompilerThread* current_thread = CompilerThread::current(); 156 assert(current_thread->env() == NULL, "must be"); 157 current_thread->set_env(this); 158 assert(ciEnv::current() == this, "sanity"); 159 160 _oop_recorder = NULL; 161 _debug_info = NULL; 162 _dependencies = NULL; 163 _failure_reason = NULL; 164 _compilable = MethodCompilable_never; 165 _break_at_compile = false; 166 _compiler_data = NULL; 167 #ifndef PRODUCT 168 assert(firstEnv, "must be first"); 169 firstEnv = false; 170 #endif /* !PRODUCT */ 171 172 _system_dictionary_modification_counter = 0; 173 _num_inlined_bytecodes = 0; 174 _task = NULL; 175 _log = NULL; 176 177 // Temporary buffer for creating symbols and such. 178 _name_buffer = NULL; 179 _name_buffer_len = 0; 180 181 _arena = arena; 182 _factory = new (_arena) ciObjectFactory(_arena, 128); 183 184 // Preload commonly referenced system ciObjects. 185 186 // During VM initialization, these instances have not yet been created. 187 // Assertions ensure that these instances are not accessed before 188 // their initialization. 189 190 assert(Universe::is_fully_initialized(), "must be"); 191 192 _NullPointerException_instance = NULL; 193 _ArithmeticException_instance = NULL; 194 _ArrayIndexOutOfBoundsException_instance = NULL; 195 _ArrayStoreException_instance = NULL; 196 _ClassCastException_instance = NULL; 197 _the_null_string = NULL; 198 _the_min_jint_string = NULL; 199 200 _jvmti_can_hotswap_or_post_breakpoint = false; 201 _jvmti_can_access_local_variables = false; 202 _jvmti_can_post_on_exceptions = false; 203 _jvmti_can_pop_frame = false; 204 } 205 206 ciEnv::~ciEnv() { 207 CompilerThread* current_thread = CompilerThread::current(); 208 _factory->remove_symbols(); 209 // Need safepoint to clear the env on the thread. RedefineClasses might 210 // be reading it. 211 GUARDED_VM_ENTRY(current_thread->set_env(NULL);) 212 } 213 214 // ------------------------------------------------------------------ 215 // Cache Jvmti state 216 void ciEnv::cache_jvmti_state() { 217 VM_ENTRY_MARK; 218 // Get Jvmti capabilities under lock to get consistant values. 219 MutexLocker mu(JvmtiThreadState_lock); 220 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); 221 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); 222 _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); 223 _jvmti_can_pop_frame = JvmtiExport::can_pop_frame(); 224 } 225 226 bool ciEnv::should_retain_local_variables() const { 227 return _jvmti_can_access_local_variables || _jvmti_can_pop_frame; 228 } 229 230 bool ciEnv::jvmti_state_changed() const { 231 if (!_jvmti_can_access_local_variables && 232 JvmtiExport::can_access_local_variables()) { 233 return true; 234 } 235 if (!_jvmti_can_hotswap_or_post_breakpoint && 236 JvmtiExport::can_hotswap_or_post_breakpoint()) { 237 return true; 238 } 239 if (!_jvmti_can_post_on_exceptions && 240 JvmtiExport::can_post_on_exceptions()) { 241 return true; 242 } 243 if (!_jvmti_can_pop_frame && 244 JvmtiExport::can_pop_frame()) { 245 return true; 246 } 247 return false; 248 } 249 250 // ------------------------------------------------------------------ 251 // Cache DTrace flags 252 void ciEnv::cache_dtrace_flags() { 253 // Need lock? 254 _dtrace_extended_probes = ExtendedDTraceProbes; 255 if (_dtrace_extended_probes) { 256 _dtrace_monitor_probes = true; 257 _dtrace_method_probes = true; 258 _dtrace_alloc_probes = true; 259 } else { 260 _dtrace_monitor_probes = DTraceMonitorProbes; 261 _dtrace_method_probes = DTraceMethodProbes; 262 _dtrace_alloc_probes = DTraceAllocProbes; 263 } 264 } 265 266 // ------------------------------------------------------------------ 267 // helper for lazy exception creation 268 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) { 269 VM_ENTRY_MARK; 270 if (handle == NULL) { 271 // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. 272 Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD); 273 jobject objh = NULL; 274 if (!HAS_PENDING_EXCEPTION && k != NULL) { 275 oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD); 276 if (!HAS_PENDING_EXCEPTION) 277 objh = JNIHandles::make_global(obj); 278 } 279 if (HAS_PENDING_EXCEPTION) { 280 CLEAR_PENDING_EXCEPTION; 281 } else { 282 handle = objh; 283 } 284 } 285 oop obj = JNIHandles::resolve(handle); 286 return obj == NULL? NULL: get_object(obj)->as_instance(); 287 } 288 289 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { 290 if (_ArrayIndexOutOfBoundsException_instance == NULL) { 291 _ArrayIndexOutOfBoundsException_instance 292 = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, 293 vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); 294 } 295 return _ArrayIndexOutOfBoundsException_instance; 296 } 297 ciInstance* ciEnv::ArrayStoreException_instance() { 298 if (_ArrayStoreException_instance == NULL) { 299 _ArrayStoreException_instance 300 = get_or_create_exception(_ArrayStoreException_handle, 301 vmSymbols::java_lang_ArrayStoreException()); 302 } 303 return _ArrayStoreException_instance; 304 } 305 ciInstance* ciEnv::ClassCastException_instance() { 306 if (_ClassCastException_instance == NULL) { 307 _ClassCastException_instance 308 = get_or_create_exception(_ClassCastException_handle, 309 vmSymbols::java_lang_ClassCastException()); 310 } 311 return _ClassCastException_instance; 312 } 313 314 ciInstance* ciEnv::the_null_string() { 315 if (_the_null_string == NULL) { 316 VM_ENTRY_MARK; 317 _the_null_string = get_object(Universe::the_null_string())->as_instance(); 318 } 319 return _the_null_string; 320 } 321 322 ciInstance* ciEnv::the_min_jint_string() { 323 if (_the_min_jint_string == NULL) { 324 VM_ENTRY_MARK; 325 _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance(); 326 } 327 return _the_min_jint_string; 328 } 329 330 // ------------------------------------------------------------------ 331 // ciEnv::get_method_from_handle 332 ciMethod* ciEnv::get_method_from_handle(Method* method) { 333 VM_ENTRY_MARK; 334 return get_metadata(method)->as_method(); 335 } 336 337 // ------------------------------------------------------------------ 338 // ciEnv::array_element_offset_in_bytes 339 int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) { 340 VM_ENTRY_MARK; 341 objArrayOop a = (objArrayOop)a_h->get_oop(); 342 assert(a->is_objArray(), ""); 343 int length = a->length(); 344 oop o = o_h->get_oop(); 345 for (int i = 0; i < length; i++) { 346 if (a->obj_at(i) == o) return i; 347 } 348 return -1; 349 } 350 351 352 // ------------------------------------------------------------------ 353 // ciEnv::check_klass_accessiblity 354 // 355 // Note: the logic of this method should mirror the logic of 356 // ConstantPool::verify_constant_pool_resolve. 357 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, 358 Klass* resolved_klass) { 359 if (accessing_klass == NULL || !accessing_klass->is_loaded()) { 360 return true; 361 } 362 if (accessing_klass->is_obj_array_klass()) { 363 accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass(); 364 } 365 if (!accessing_klass->is_instance_klass()) { 366 return true; 367 } 368 369 if (resolved_klass->is_objArray_klass()) { 370 // Find the element klass, if this is an array. 371 resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); 372 } 373 if (resolved_klass->is_instance_klass()) { 374 return (Reflection::verify_class_access(accessing_klass->get_Klass(), 375 resolved_klass, 376 true) == Reflection::ACCESS_OK); 377 } 378 return true; 379 } 380 381 // ------------------------------------------------------------------ 382 // ciEnv::get_klass_by_name_impl 383 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass, 384 const constantPoolHandle& cpool, 385 ciSymbol* name, 386 bool require_local) { 387 ASSERT_IN_VM; 388 EXCEPTION_CONTEXT; 389 390 // Now we need to check the SystemDictionary 391 Symbol* sym = name->get_symbol(); 392 if (sym->byte_at(0) == 'L' && 393 sym->byte_at(sym->utf8_length()-1) == ';') { 394 // This is a name from a signature. Strip off the trimmings. 395 // Call recursive to keep scope of strippedsym. 396 TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, 397 sym->utf8_length()-2, 398 KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); 399 ciSymbol* strippedname = get_symbol(strippedsym); 400 return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local); 401 } 402 403 // Check for prior unloaded klass. The SystemDictionary's answers 404 // can vary over time but the compiler needs consistency. 405 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); 406 if (unloaded_klass != NULL) { 407 if (require_local) return NULL; 408 return unloaded_klass; 409 } 410 411 Handle loader(THREAD, (oop)NULL); 412 Handle domain(THREAD, (oop)NULL); 413 if (accessing_klass != NULL) { 414 loader = Handle(THREAD, accessing_klass->loader()); 415 domain = Handle(THREAD, accessing_klass->protection_domain()); 416 } 417 418 // setup up the proper type to return on OOM 419 ciKlass* fail_type; 420 if (sym->byte_at(0) == '[') { 421 fail_type = _unloaded_ciobjarrayklass; 422 } else { 423 fail_type = _unloaded_ciinstance_klass; 424 } 425 KlassHandle found_klass; 426 { 427 ttyUnlocker ttyul; // release tty lock to avoid ordering problems 428 MutexLocker ml(Compile_lock); 429 Klass* kls; 430 if (!require_local) { 431 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, 432 KILL_COMPILE_ON_FATAL_(fail_type)); 433 } else { 434 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, 435 KILL_COMPILE_ON_FATAL_(fail_type)); 436 } 437 found_klass = KlassHandle(THREAD, kls); 438 } 439 440 // If we fail to find an array klass, look again for its element type. 441 // The element type may be available either locally or via constraints. 442 // In either case, if we can find the element type in the system dictionary, 443 // we must build an array type around it. The CI requires array klasses 444 // to be loaded if their element klasses are loaded, except when memory 445 // is exhausted. 446 if (sym->byte_at(0) == '[' && 447 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 448 // We have an unloaded array. 449 // Build it on the fly if the element class exists. 450 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, 451 sym->utf8_length()-1, 452 KILL_COMPILE_ON_FATAL_(fail_type)); 453 454 // Get element ciKlass recursively. 455 ciKlass* elem_klass = 456 get_klass_by_name_impl(accessing_klass, 457 cpool, 458 get_symbol(elem_sym), 459 require_local); 460 if (elem_klass != NULL && elem_klass->is_loaded()) { 461 // Now make an array for it 462 return ciObjArrayKlass::make_impl(elem_klass); 463 } 464 } 465 466 if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) { 467 // Look inside the constant pool for pre-resolved class entries. 468 for (int i = cpool->length() - 1; i >= 1; i--) { 469 if (cpool->tag_at(i).is_klass()) { 470 Klass* kls = cpool->resolved_klass_at(i); 471 if (kls->name() == sym) { 472 found_klass = KlassHandle(THREAD, kls); 473 break; 474 } 475 } 476 } 477 } 478 479 if (found_klass() != NULL) { 480 // Found it. Build a CI handle. 481 return get_klass(found_klass()); 482 } 483 484 if (require_local) return NULL; 485 486 // Not yet loaded into the VM, or not governed by loader constraints. 487 // Make a CI representative for it. 488 return get_unloaded_klass(accessing_klass, name); 489 } 490 491 // ------------------------------------------------------------------ 492 // ciEnv::get_klass_by_name 493 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, 494 ciSymbol* klass_name, 495 bool require_local) { 496 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, 497 constantPoolHandle(), 498 klass_name, 499 require_local);) 500 } 501 502 // ------------------------------------------------------------------ 503 // ciEnv::get_klass_by_index_impl 504 // 505 // Implementation of get_klass_by_index. 506 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, 507 int index, 508 bool& is_accessible, 509 ciInstanceKlass* accessor) { 510 EXCEPTION_CONTEXT; 511 KlassHandle klass; // = NULL; 512 Symbol* klass_name = NULL; 513 514 if (cpool->tag_at(index).is_symbol()) { 515 klass_name = cpool->symbol_at(index); 516 } else { 517 // Check if it's resolved if it's not a symbol constant pool entry. 518 klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); 519 // Try to look it up by name. 520 if (klass.is_null()) { 521 klass_name = cpool->klass_name_at(index); 522 } 523 } 524 525 if (klass.is_null()) { 526 // Not found in constant pool. Use the name to do the lookup. 527 ciKlass* k = get_klass_by_name_impl(accessor, 528 cpool, 529 get_symbol(klass_name), 530 false); 531 // Calculate accessibility the hard way. 532 if (!k->is_loaded()) { 533 is_accessible = false; 534 } else if (k->loader() != accessor->loader() && 535 get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { 536 // Loaded only remotely. Not linked yet. 537 is_accessible = false; 538 } else { 539 // Linked locally, and we must also check public/private, etc. 540 is_accessible = check_klass_accessibility(accessor, k->get_Klass()); 541 } 542 return k; 543 } 544 545 // Check for prior unloaded klass. The SystemDictionary's answers 546 // can vary over time but the compiler needs consistency. 547 ciSymbol* name = get_symbol(klass()->name()); 548 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); 549 if (unloaded_klass != NULL) { 550 is_accessible = false; 551 return unloaded_klass; 552 } 553 554 // It is known to be accessible, since it was found in the constant pool. 555 is_accessible = true; 556 return get_klass(klass()); 557 } 558 559 // ------------------------------------------------------------------ 560 // ciEnv::get_klass_by_index 561 // 562 // Get a klass from the constant pool. 563 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool, 564 int index, 565 bool& is_accessible, 566 ciInstanceKlass* accessor) { 567 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) 568 } 569 570 // ------------------------------------------------------------------ 571 // ciEnv::get_constant_by_index_impl 572 // 573 // Implementation of get_constant_by_index(). 574 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool, 575 int pool_index, int cache_index, 576 ciInstanceKlass* accessor) { 577 bool ignore_will_link; 578 EXCEPTION_CONTEXT; 579 int index = pool_index; 580 if (cache_index >= 0) { 581 assert(index < 0, "only one kind of index at a time"); 582 oop obj = cpool->resolved_references()->obj_at(cache_index); 583 if (obj != NULL) { 584 ciObject* ciobj = get_object(obj); 585 if (ciobj->is_array()) { 586 return ciConstant(T_ARRAY, ciobj); 587 } else { 588 assert(ciobj->is_instance(), "should be an instance"); 589 return ciConstant(T_OBJECT, ciobj); 590 } 591 } 592 index = cpool->object_to_cp_index(cache_index); 593 } 594 constantTag tag = cpool->tag_at(index); 595 if (tag.is_int()) { 596 return ciConstant(T_INT, (jint)cpool->int_at(index)); 597 } else if (tag.is_long()) { 598 return ciConstant((jlong)cpool->long_at(index)); 599 } else if (tag.is_float()) { 600 return ciConstant((jfloat)cpool->float_at(index)); 601 } else if (tag.is_double()) { 602 return ciConstant((jdouble)cpool->double_at(index)); 603 } else if (tag.is_string()) { 604 oop string = NULL; 605 assert(cache_index >= 0, "should have a cache index"); 606 if (cpool->is_pseudo_string_at(index)) { 607 string = cpool->pseudo_string_at(index, cache_index); 608 } else { 609 string = cpool->string_at(index, cache_index, THREAD); 610 if (HAS_PENDING_EXCEPTION) { 611 CLEAR_PENDING_EXCEPTION; 612 record_out_of_memory_failure(); 613 return ciConstant(); 614 } 615 } 616 ciObject* constant = get_object(string); 617 if (constant->is_array()) { 618 return ciConstant(T_ARRAY, constant); 619 } else { 620 assert (constant->is_instance(), "must be an instance, or not? "); 621 return ciConstant(T_OBJECT, constant); 622 } 623 } else if (tag.is_klass() || tag.is_unresolved_klass()) { 624 // 4881222: allow ldc to take a class type 625 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); 626 if (HAS_PENDING_EXCEPTION) { 627 CLEAR_PENDING_EXCEPTION; 628 record_out_of_memory_failure(); 629 return ciConstant(); 630 } 631 assert (klass->is_instance_klass() || klass->is_array_klass(), 632 "must be an instance or array klass "); 633 return ciConstant(T_OBJECT, klass->java_mirror()); 634 } else if (tag.is_method_type()) { 635 // must execute Java code to link this CP entry into cache[i].f1 636 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index)); 637 ciObject* ciobj = get_unloaded_method_type_constant(signature); 638 return ciConstant(T_OBJECT, ciobj); 639 } else if (tag.is_method_handle()) { 640 // must execute Java code to link this CP entry into cache[i].f1 641 int ref_kind = cpool->method_handle_ref_kind_at(index); 642 int callee_index = cpool->method_handle_klass_index_at(index); 643 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); 644 ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index)); 645 ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index)); 646 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); 647 return ciConstant(T_OBJECT, ciobj); 648 } else { 649 ShouldNotReachHere(); 650 return ciConstant(); 651 } 652 } 653 654 // ------------------------------------------------------------------ 655 // ciEnv::get_constant_by_index 656 // 657 // Pull a constant out of the constant pool. How appropriate. 658 // 659 // Implementation note: this query is currently in no way cached. 660 ciConstant ciEnv::get_constant_by_index(const constantPoolHandle& cpool, 661 int pool_index, int cache_index, 662 ciInstanceKlass* accessor) { 663 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) 664 } 665 666 // ------------------------------------------------------------------ 667 // ciEnv::get_field_by_index_impl 668 // 669 // Implementation of get_field_by_index. 670 // 671 // Implementation note: the results of field lookups are cached 672 // in the accessor klass. 673 ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, 674 int index) { 675 ciConstantPoolCache* cache = accessor->field_cache(); 676 if (cache == NULL) { 677 ciField* field = new (arena()) ciField(accessor, index); 678 return field; 679 } else { 680 ciField* field = (ciField*)cache->get(index); 681 if (field == NULL) { 682 field = new (arena()) ciField(accessor, index); 683 cache->insert(index, field); 684 } 685 return field; 686 } 687 } 688 689 // ------------------------------------------------------------------ 690 // ciEnv::get_field_by_index 691 // 692 // Get a field by index from a klass's constant pool. 693 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, 694 int index) { 695 GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) 696 } 697 698 // ------------------------------------------------------------------ 699 // ciEnv::lookup_method 700 // 701 // Perform an appropriate method lookup based on accessor, holder, 702 // name, signature, and bytecode. 703 Method* ciEnv::lookup_method(InstanceKlass* accessor, 704 InstanceKlass* holder, 705 Symbol* name, 706 Symbol* sig, 707 Bytecodes::Code bc, 708 constantTag tag) { 709 EXCEPTION_CONTEXT; 710 KlassHandle h_accessor(THREAD, accessor); 711 KlassHandle h_holder(THREAD, holder); 712 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 713 methodHandle dest_method; 714 LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag); 715 switch (bc) { 716 case Bytecodes::_invokestatic: 717 dest_method = 718 LinkResolver::resolve_static_call_or_null(link_info); 719 break; 720 case Bytecodes::_invokespecial: 721 dest_method = 722 LinkResolver::resolve_special_call_or_null(link_info); 723 break; 724 case Bytecodes::_invokeinterface: 725 dest_method = 726 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 727 break; 728 case Bytecodes::_invokevirtual: 729 dest_method = 730 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 731 break; 732 default: ShouldNotReachHere(); 733 } 734 735 return dest_method(); 736 } 737 738 739 // ------------------------------------------------------------------ 740 // ciEnv::get_method_by_index_impl 741 ciMethod* ciEnv::get_method_by_index_impl(const constantPoolHandle& cpool, 742 int index, Bytecodes::Code bc, 743 ciInstanceKlass* accessor) { 744 if (bc == Bytecodes::_invokedynamic) { 745 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 746 bool is_resolved = !cpce->is_f1_null(); 747 // FIXME: code generation could allow for null (unlinked) call site 748 // The call site could be made patchable as follows: 749 // Load the appendix argument from the constant pool. 750 // Test the appendix argument and jump to a known deopt routine if it is null. 751 // Jump through a patchable call site, which is initially a deopt routine. 752 // Patch the call site to the nmethod entry point of the static compiled lambda form. 753 // As with other two-component call sites, both values must be independently verified. 754 755 if (is_resolved) { 756 // Get the invoker Method* from the constant pool. 757 // (The appendix argument, if any, will be noted in the method's signature.) 758 Method* adapter = cpce->f1_as_method(); 759 return get_method(adapter); 760 } 761 762 // Fake a method that is equivalent to a declared method. 763 ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass()); 764 ciSymbol* name = ciSymbol::invokeBasic_name(); 765 ciSymbol* signature = get_symbol(cpool->signature_ref_at(index)); 766 return get_unloaded_method(holder, name, signature, accessor); 767 } else { 768 const int holder_index = cpool->klass_ref_index_at(index); 769 bool holder_is_accessible; 770 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 771 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); 772 773 // Get the method's name and signature. 774 Symbol* name_sym = cpool->name_ref_at(index); 775 Symbol* sig_sym = cpool->signature_ref_at(index); 776 777 if (cpool->has_preresolution() 778 || ((holder == ciEnv::MethodHandle_klass() || holder == ciEnv::VarHandle_klass()) && 779 MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) { 780 // Short-circuit lookups for JSR 292-related call sites. 781 // That is, do not rely only on name-based lookups, because they may fail 782 // if the names are not resolvable in the boot class loader (7056328). 783 switch (bc) { 784 case Bytecodes::_invokevirtual: 785 case Bytecodes::_invokeinterface: 786 case Bytecodes::_invokespecial: 787 case Bytecodes::_invokestatic: 788 { 789 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 790 if (m != NULL) { 791 return get_method(m); 792 } 793 } 794 break; 795 } 796 } 797 798 if (holder_is_accessible) { // Our declared holder is loaded. 799 InstanceKlass* lookup = declared_holder->get_instanceKlass(); 800 constantTag tag = cpool->tag_ref_at(index); 801 assert(accessor->get_instanceKlass() == cpool->pool_holder(), "not the pool holder?"); 802 Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc, tag); 803 if (m != NULL && 804 (bc == Bytecodes::_invokestatic 805 ? m->method_holder()->is_not_initialized() 806 : !m->method_holder()->is_loaded())) { 807 m = NULL; 808 } 809 #ifdef ASSERT 810 if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) { 811 m = NULL; 812 } 813 #endif 814 if (m != NULL) { 815 // We found the method. 816 return get_method(m); 817 } 818 } 819 820 // Either the declared holder was not loaded, or the method could 821 // not be found. Create a dummy ciMethod to represent the failed 822 // lookup. 823 ciSymbol* name = get_symbol(name_sym); 824 ciSymbol* signature = get_symbol(sig_sym); 825 return get_unloaded_method(declared_holder, name, signature, accessor); 826 } 827 } 828 829 830 // ------------------------------------------------------------------ 831 // ciEnv::get_instance_klass_for_declared_method_holder 832 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) { 833 // For the case of <array>.clone(), the method holder can be a ciArrayKlass 834 // instead of a ciInstanceKlass. For that case simply pretend that the 835 // declared holder is Object.clone since that's where the call will bottom out. 836 // A more correct fix would trickle out through many interfaces in CI, 837 // requiring ciInstanceKlass* to become ciKlass* and many more places would 838 // require checks to make sure the expected type was found. Given that this 839 // only occurs for clone() the more extensive fix seems like overkill so 840 // instead we simply smear the array type into Object. 841 guarantee(method_holder != NULL, "no method holder"); 842 if (method_holder->is_instance_klass()) { 843 return method_holder->as_instance_klass(); 844 } else if (method_holder->is_array_klass()) { 845 return current()->Object_klass(); 846 } else { 847 ShouldNotReachHere(); 848 } 849 return NULL; 850 } 851 852 853 // ------------------------------------------------------------------ 854 // ciEnv::get_method_by_index 855 ciMethod* ciEnv::get_method_by_index(const constantPoolHandle& cpool, 856 int index, Bytecodes::Code bc, 857 ciInstanceKlass* accessor) { 858 GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);) 859 } 860 861 862 // ------------------------------------------------------------------ 863 // ciEnv::name_buffer 864 char *ciEnv::name_buffer(int req_len) { 865 if (_name_buffer_len < req_len) { 866 if (_name_buffer == NULL) { 867 _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len); 868 _name_buffer_len = req_len; 869 } else { 870 _name_buffer = 871 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len); 872 _name_buffer_len = req_len; 873 } 874 } 875 return _name_buffer; 876 } 877 878 // ------------------------------------------------------------------ 879 // ciEnv::is_in_vm 880 bool ciEnv::is_in_vm() { 881 return JavaThread::current()->thread_state() == _thread_in_vm; 882 } 883 884 bool ciEnv::system_dictionary_modification_counter_changed() { 885 return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); 886 } 887 888 // ------------------------------------------------------------------ 889 // ciEnv::validate_compile_task_dependencies 890 // 891 // Check for changes during compilation (e.g. class loads, evolution, 892 // breakpoints, call site invalidation). 893 void ciEnv::validate_compile_task_dependencies(ciMethod* target) { 894 if (failing()) return; // no need for further checks 895 896 // First, check non-klass dependencies as we might return early and 897 // not check klass dependencies if the system dictionary 898 // modification counter hasn't changed (see below). 899 for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { 900 if (deps.is_klass_type()) continue; // skip klass dependencies 901 Klass* witness = deps.check_dependency(); 902 if (witness != NULL) { 903 record_failure("invalid non-klass dependency"); 904 return; 905 } 906 } 907 908 // Klass dependencies must be checked when the system dictionary 909 // changes. If logging is enabled all violated dependences will be 910 // recorded in the log. In debug mode check dependencies even if 911 // the system dictionary hasn't changed to verify that no invalid 912 // dependencies were inserted. Any violated dependences in this 913 // case are dumped to the tty. 914 bool counter_changed = system_dictionary_modification_counter_changed(); 915 916 bool verify_deps = trueInDebug; 917 if (!counter_changed && !verify_deps) return; 918 919 int klass_violations = 0; 920 for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { 921 if (!deps.is_klass_type()) continue; // skip non-klass dependencies 922 Klass* witness = deps.check_dependency(); 923 if (witness != NULL) { 924 klass_violations++; 925 if (!counter_changed) { 926 // Dependence failed but counter didn't change. Log a message 927 // describing what failed and allow the assert at the end to 928 // trigger. 929 deps.print_dependency(witness); 930 } else if (xtty == NULL) { 931 // If we're not logging then a single violation is sufficient, 932 // otherwise we want to log all the dependences which were 933 // violated. 934 break; 935 } 936 } 937 } 938 939 if (klass_violations != 0) { 940 #ifdef ASSERT 941 if (!counter_changed && !PrintCompilation) { 942 // Print out the compile task that failed 943 _task->print_tty(); 944 } 945 #endif 946 assert(counter_changed, "failed dependencies, but counter didn't change"); 947 record_failure("concurrent class loading"); 948 } 949 } 950 951 // ------------------------------------------------------------------ 952 // ciEnv::register_method 953 void ciEnv::register_method(ciMethod* target, 954 int entry_bci, 955 CodeOffsets* offsets, 956 int orig_pc_offset, 957 CodeBuffer* code_buffer, 958 int frame_words, 959 OopMapSet* oop_map_set, 960 ExceptionHandlerTable* handler_table, 961 ImplicitExceptionTable* inc_table, 962 AbstractCompiler* compiler, 963 bool has_unsafe_access, 964 bool has_wide_vectors, 965 RTMState rtm_state) { 966 VM_ENTRY_MARK; 967 nmethod* nm = NULL; 968 { 969 // To prevent compile queue updates. 970 MutexLocker locker(MethodCompileQueue_lock, THREAD); 971 972 // Prevent SystemDictionary::add_to_hierarchy from running 973 // and invalidating our dependencies until we install this method. 974 // No safepoints are allowed. Otherwise, class redefinition can occur in between. 975 MutexLocker ml(Compile_lock); 976 NoSafepointVerifier nsv; 977 978 // Change in Jvmti state may invalidate compilation. 979 if (!failing() && jvmti_state_changed()) { 980 record_failure("Jvmti state change invalidated dependencies"); 981 } 982 983 // Change in DTrace flags may invalidate compilation. 984 if (!failing() && 985 ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || 986 (!dtrace_method_probes() && DTraceMethodProbes) || 987 (!dtrace_alloc_probes() && DTraceAllocProbes) )) { 988 record_failure("DTrace flags change invalidated dependencies"); 989 } 990 991 if (!failing()) { 992 if (log() != NULL) { 993 // Log the dependencies which this compilation declares. 994 dependencies()->log_all_dependencies(); 995 } 996 997 // Encode the dependencies now, so we can check them right away. 998 dependencies()->encode_content_bytes(); 999 1000 // Check for {class loads, evolution, breakpoints, ...} during compilation 1001 validate_compile_task_dependencies(target); 1002 } 1003 1004 methodHandle method(THREAD, target->get_Method()); 1005 1006 #if INCLUDE_RTM_OPT 1007 if (!failing() && (rtm_state != NoRTM) && 1008 (method()->method_data() != NULL) && 1009 (method()->method_data()->rtm_state() != rtm_state)) { 1010 // Preemptive decompile if rtm state was changed. 1011 record_failure("RTM state change invalidated rtm code"); 1012 } 1013 #endif 1014 1015 if (failing()) { 1016 // While not a true deoptimization, it is a preemptive decompile. 1017 MethodData* mdo = method()->method_data(); 1018 if (mdo != NULL) { 1019 mdo->inc_decompile_count(); 1020 } 1021 1022 // All buffers in the CodeBuffer are allocated in the CodeCache. 1023 // If the code buffer is created on each compile attempt 1024 // as in C2, then it must be freed. 1025 code_buffer->free_blob(); 1026 return; 1027 } 1028 1029 assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); 1030 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); 1031 1032 nm = nmethod::new_nmethod(method, 1033 compile_id(), 1034 entry_bci, 1035 offsets, 1036 orig_pc_offset, 1037 debug_info(), dependencies(), code_buffer, 1038 frame_words, oop_map_set, 1039 handler_table, inc_table, 1040 compiler, task()->comp_level()); 1041 1042 // Free codeBlobs 1043 code_buffer->free_blob(); 1044 1045 if (nm != NULL) { 1046 nm->set_has_unsafe_access(has_unsafe_access); 1047 nm->set_has_wide_vectors(has_wide_vectors); 1048 #if INCLUDE_RTM_OPT 1049 nm->set_rtm_state(rtm_state); 1050 #endif 1051 1052 // Record successful registration. 1053 // (Put nm into the task handle *before* publishing to the Java heap.) 1054 if (task() != NULL) { 1055 task()->set_code(nm); 1056 } 1057 1058 if (entry_bci == InvocationEntryBci) { 1059 if (TieredCompilation) { 1060 // If there is an old version we're done with it 1061 CompiledMethod* old = method->code(); 1062 if (TraceMethodReplacement && old != NULL) { 1063 ResourceMark rm; 1064 char *method_name = method->name_and_sig_as_C_string(); 1065 tty->print_cr("Replacing method %s", method_name); 1066 } 1067 if (old != NULL) { 1068 old->make_not_used(); 1069 } 1070 } 1071 if (TraceNMethodInstalls) { 1072 ResourceMark rm; 1073 char *method_name = method->name_and_sig_as_C_string(); 1074 ttyLocker ttyl; 1075 tty->print_cr("Installing method (%d) %s ", 1076 task()->comp_level(), 1077 method_name); 1078 } 1079 // Allow the code to be executed 1080 method->set_code(method, nm); 1081 } else { 1082 if (TraceNMethodInstalls) { 1083 ResourceMark rm; 1084 char *method_name = method->name_and_sig_as_C_string(); 1085 ttyLocker ttyl; 1086 tty->print_cr("Installing osr method (%d) %s @ %d", 1087 task()->comp_level(), 1088 method_name, 1089 entry_bci); 1090 } 1091 method->method_holder()->add_osr_nmethod(nm); 1092 } 1093 } 1094 } // safepoints are allowed again 1095 1096 if (nm != NULL) { 1097 // JVMTI -- compiled method notification (must be done outside lock) 1098 nm->post_compiled_method_load_event(); 1099 } else { 1100 // The CodeCache is full. 1101 record_failure("code cache is full"); 1102 } 1103 } 1104 1105 1106 // ------------------------------------------------------------------ 1107 // ciEnv::find_system_klass 1108 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { 1109 VM_ENTRY_MARK; 1110 return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false); 1111 } 1112 1113 // ------------------------------------------------------------------ 1114 // ciEnv::comp_level 1115 int ciEnv::comp_level() { 1116 if (task() == NULL) return CompLevel_highest_tier; 1117 return task()->comp_level(); 1118 } 1119 1120 // ------------------------------------------------------------------ 1121 // ciEnv::compile_id 1122 uint ciEnv::compile_id() { 1123 if (task() == NULL) return 0; 1124 return task()->compile_id(); 1125 } 1126 1127 // ------------------------------------------------------------------ 1128 // ciEnv::notice_inlined_method() 1129 void ciEnv::notice_inlined_method(ciMethod* method) { 1130 _num_inlined_bytecodes += method->code_size_for_inlining(); 1131 } 1132 1133 // ------------------------------------------------------------------ 1134 // ciEnv::num_inlined_bytecodes() 1135 int ciEnv::num_inlined_bytecodes() const { 1136 return _num_inlined_bytecodes; 1137 } 1138 1139 // ------------------------------------------------------------------ 1140 // ciEnv::record_failure() 1141 void ciEnv::record_failure(const char* reason) { 1142 if (_failure_reason == NULL) { 1143 // Record the first failure reason. 1144 _failure_reason = reason; 1145 } 1146 } 1147 1148 void ciEnv::report_failure(const char* reason) { 1149 // Create and fire JFR event 1150 EventCompilerFailure event; 1151 if (event.should_commit()) { 1152 event.set_compileID(compile_id()); 1153 event.set_failure(reason); 1154 event.commit(); 1155 } 1156 } 1157 1158 // ------------------------------------------------------------------ 1159 // ciEnv::record_method_not_compilable() 1160 void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { 1161 int new_compilable = 1162 all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; 1163 1164 // Only note transitions to a worse state 1165 if (new_compilable > _compilable) { 1166 if (log() != NULL) { 1167 if (all_tiers) { 1168 log()->elem("method_not_compilable"); 1169 } else { 1170 log()->elem("method_not_compilable_at_tier level='%d'", 1171 current()->task()->comp_level()); 1172 } 1173 } 1174 _compilable = new_compilable; 1175 1176 // Reset failure reason; this one is more important. 1177 _failure_reason = NULL; 1178 record_failure(reason); 1179 } 1180 } 1181 1182 // ------------------------------------------------------------------ 1183 // ciEnv::record_out_of_memory_failure() 1184 void ciEnv::record_out_of_memory_failure() { 1185 // If memory is low, we stop compiling methods. 1186 record_method_not_compilable("out of memory"); 1187 } 1188 1189 ciInstance* ciEnv::unloaded_ciinstance() { 1190 GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();) 1191 } 1192 1193 // ------------------------------------------------------------------ 1194 // ciEnv::dump_replay_data* 1195 1196 // Don't change thread state and acquire any locks. 1197 // Safe to call from VM error reporter. 1198 1199 void ciEnv::dump_compile_data(outputStream* out) { 1200 CompileTask* task = this->task(); 1201 Method* method = task->method(); 1202 int entry_bci = task->osr_bci(); 1203 int comp_level = task->comp_level(); 1204 out->print("compile %s %s %s %d %d", 1205 method->klass_name()->as_quoted_ascii(), 1206 method->name()->as_quoted_ascii(), 1207 method->signature()->as_quoted_ascii(), 1208 entry_bci, comp_level); 1209 if (compiler_data() != NULL) { 1210 if (is_c2_compile(comp_level)) { // C2 or Shark 1211 #ifdef COMPILER2 1212 // Dump C2 inlining data. 1213 ((Compile*)compiler_data())->dump_inline_data(out); 1214 #endif 1215 } else if (is_c1_compile(comp_level)) { // C1 1216 #ifdef COMPILER1 1217 // Dump C1 inlining data. 1218 ((Compilation*)compiler_data())->dump_inline_data(out); 1219 #endif 1220 } 1221 } 1222 out->cr(); 1223 } 1224 1225 void ciEnv::dump_replay_data_unsafe(outputStream* out) { 1226 ResourceMark rm; 1227 #if INCLUDE_JVMTI 1228 out->print_cr("JvmtiExport can_access_local_variables %d", _jvmti_can_access_local_variables); 1229 out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint); 1230 out->print_cr("JvmtiExport can_post_on_exceptions %d", _jvmti_can_post_on_exceptions); 1231 #endif // INCLUDE_JVMTI 1232 1233 GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata(); 1234 out->print_cr("# %d ciObject found", objects->length()); 1235 for (int i = 0; i < objects->length(); i++) { 1236 objects->at(i)->dump_replay_data(out); 1237 } 1238 dump_compile_data(out); 1239 out->flush(); 1240 } 1241 1242 void ciEnv::dump_replay_data(outputStream* out) { 1243 GUARDED_VM_ENTRY( 1244 MutexLocker ml(Compile_lock); 1245 dump_replay_data_unsafe(out); 1246 ) 1247 } 1248 1249 void ciEnv::dump_replay_data(int compile_id) { 1250 static char buffer[O_BUFLEN]; 1251 int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id); 1252 if (ret > 0) { 1253 int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); 1254 if (fd != -1) { 1255 FILE* replay_data_file = os::open(fd, "w"); 1256 if (replay_data_file != NULL) { 1257 fileStream replay_data_stream(replay_data_file, /*need_close=*/true); 1258 dump_replay_data(&replay_data_stream); 1259 tty->print_cr("# Compiler replay data is saved as: %s", buffer); 1260 } else { 1261 tty->print_cr("# Can't open file to dump replay data."); 1262 } 1263 } 1264 } 1265 } 1266 1267 void ciEnv::dump_inline_data(int compile_id) { 1268 static char buffer[O_BUFLEN]; 1269 int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id); 1270 if (ret > 0) { 1271 int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); 1272 if (fd != -1) { 1273 FILE* inline_data_file = os::open(fd, "w"); 1274 if (inline_data_file != NULL) { 1275 fileStream replay_data_stream(inline_data_file, /*need_close=*/true); 1276 GUARDED_VM_ENTRY( 1277 MutexLocker ml(Compile_lock); 1278 dump_compile_data(&replay_data_stream); 1279 ) 1280 replay_data_stream.flush(); 1281 tty->print("# Compiler inline data is saved as: "); 1282 tty->print_cr("%s", buffer); 1283 } else { 1284 tty->print_cr("# Can't open file to dump inline data."); 1285 } 1286 } 1287 } 1288 }