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