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