ciEnv.cpp revision 6402:2377269bd73d
1/* 2 * Copyright (c) 1999, 2013, 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 69ciObject* ciEnv::_null_object_instance; 70 71#define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL; 72WK_KLASSES_DO(WK_KLASS_DEFN) 73#undef WK_KLASS_DEFN 74 75ciSymbol* ciEnv::_unloaded_cisymbol = NULL; 76ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; 77ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; 78 79jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; 80jobject ciEnv::_ArrayStoreException_handle = NULL; 81jobject ciEnv::_ClassCastException_handle = NULL; 82 83#ifndef PRODUCT 84static bool firstEnv = true; 85#endif /* PRODUCT */ 86 87// ------------------------------------------------------------------ 88// ciEnv::ciEnv 89ciEnv::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 147ciEnv::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 202ciEnv::~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 212void 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 222bool ciEnv::should_retain_local_variables() const { 223 return _jvmti_can_access_local_variables || _jvmti_can_pop_frame; 224} 225 226bool 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 248void 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 264ciInstance* 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 285ciInstance* 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} 293ciInstance* 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} 301ciInstance* 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 310ciInstance* 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 318ciInstance* 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 328ciMethod* 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 335int 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. 353bool 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 379ciKlass* 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 489ciKlass* 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. 502ciKlass* 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 516 if (klass.is_null()) { 517 // The klass has not been inserted into the constant pool. 518 // Try to look it up by name. 519 { 520 // We have to lock the cpool to keep the oop from being resolved 521 // while we are accessing it. 522 MonitorLockerEx ml(cpool->lock()); 523 constantTag tag = cpool->tag_at(index); 524 if (tag.is_klass()) { 525 // The klass has been inserted into the constant pool 526 // very recently. 527 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); 528 } else { 529 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); 530 klass_name = cpool->unresolved_klass_at(index); 531 } 532 } 533 } 534 } 535 536 if (klass.is_null()) { 537 // Not found in constant pool. Use the name to do the lookup. 538 ciKlass* k = get_klass_by_name_impl(accessor, 539 cpool, 540 get_symbol(klass_name), 541 false); 542 // Calculate accessibility the hard way. 543 if (!k->is_loaded()) { 544 is_accessible = false; 545 } else if (k->loader() != accessor->loader() && 546 get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { 547 // Loaded only remotely. Not linked yet. 548 is_accessible = false; 549 } else { 550 // Linked locally, and we must also check public/private, etc. 551 is_accessible = check_klass_accessibility(accessor, k->get_Klass()); 552 } 553 return k; 554 } 555 556 // Check for prior unloaded klass. The SystemDictionary's answers 557 // can vary over time but the compiler needs consistency. 558 ciSymbol* name = get_symbol(klass()->name()); 559 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); 560 if (unloaded_klass != NULL) { 561 is_accessible = false; 562 return unloaded_klass; 563 } 564 565 // It is known to be accessible, since it was found in the constant pool. 566 is_accessible = true; 567 return get_klass(klass()); 568} 569 570// ------------------------------------------------------------------ 571// ciEnv::get_klass_by_index 572// 573// Get a klass from the constant pool. 574ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool, 575 int index, 576 bool& is_accessible, 577 ciInstanceKlass* accessor) { 578 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) 579} 580 581// ------------------------------------------------------------------ 582// ciEnv::get_constant_by_index_impl 583// 584// Implementation of get_constant_by_index(). 585ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, 586 int pool_index, int cache_index, 587 ciInstanceKlass* accessor) { 588 bool ignore_will_link; 589 EXCEPTION_CONTEXT; 590 int index = pool_index; 591 if (cache_index >= 0) { 592 assert(index < 0, "only one kind of index at a time"); 593 oop obj = cpool->resolved_references()->obj_at(cache_index); 594 if (obj != NULL) { 595 ciObject* ciobj = get_object(obj); 596 return ciConstant(T_OBJECT, ciobj); 597 } 598 index = cpool->object_to_cp_index(cache_index); 599 } 600 constantTag tag = cpool->tag_at(index); 601 if (tag.is_int()) { 602 return ciConstant(T_INT, (jint)cpool->int_at(index)); 603 } else if (tag.is_long()) { 604 return ciConstant((jlong)cpool->long_at(index)); 605 } else if (tag.is_float()) { 606 return ciConstant((jfloat)cpool->float_at(index)); 607 } else if (tag.is_double()) { 608 return ciConstant((jdouble)cpool->double_at(index)); 609 } else if (tag.is_string()) { 610 oop string = NULL; 611 assert(cache_index >= 0, "should have a cache index"); 612 if (cpool->is_pseudo_string_at(index)) { 613 string = cpool->pseudo_string_at(index, cache_index); 614 } else { 615 string = cpool->string_at(index, cache_index, THREAD); 616 if (HAS_PENDING_EXCEPTION) { 617 CLEAR_PENDING_EXCEPTION; 618 record_out_of_memory_failure(); 619 return ciConstant(); 620 } 621 } 622 ciObject* constant = get_object(string); 623 assert (constant->is_instance(), "must be an instance, or not? "); 624 return ciConstant(T_OBJECT, constant); 625 } else if (tag.is_klass() || tag.is_unresolved_klass()) { 626 // 4881222: allow ldc to take a class type 627 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); 628 if (HAS_PENDING_EXCEPTION) { 629 CLEAR_PENDING_EXCEPTION; 630 record_out_of_memory_failure(); 631 return ciConstant(); 632 } 633 assert (klass->is_instance_klass() || klass->is_array_klass(), 634 "must be an instance or array klass "); 635 return ciConstant(T_OBJECT, klass->java_mirror()); 636 } else if (tag.is_method_type()) { 637 // must execute Java code to link this CP entry into cache[i].f1 638 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index)); 639 ciObject* ciobj = get_unloaded_method_type_constant(signature); 640 return ciConstant(T_OBJECT, ciobj); 641 } else if (tag.is_method_handle()) { 642 // must execute Java code to link this CP entry into cache[i].f1 643 int ref_kind = cpool->method_handle_ref_kind_at(index); 644 int callee_index = cpool->method_handle_klass_index_at(index); 645 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); 646 ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index)); 647 ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index)); 648 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); 649 return ciConstant(T_OBJECT, ciobj); 650 } else { 651 ShouldNotReachHere(); 652 return ciConstant(); 653 } 654} 655 656// ------------------------------------------------------------------ 657// ciEnv::get_constant_by_index 658// 659// Pull a constant out of the constant pool. How appropriate. 660// 661// Implementation note: this query is currently in no way cached. 662ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, 663 int pool_index, int cache_index, 664 ciInstanceKlass* accessor) { 665 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) 666} 667 668// ------------------------------------------------------------------ 669// ciEnv::get_field_by_index_impl 670// 671// Implementation of get_field_by_index. 672// 673// Implementation note: the results of field lookups are cached 674// in the accessor klass. 675ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, 676 int index) { 677 ciConstantPoolCache* cache = accessor->field_cache(); 678 if (cache == NULL) { 679 ciField* field = new (arena()) ciField(accessor, index); 680 return field; 681 } else { 682 ciField* field = (ciField*)cache->get(index); 683 if (field == NULL) { 684 field = new (arena()) ciField(accessor, index); 685 cache->insert(index, field); 686 } 687 return field; 688 } 689} 690 691// ------------------------------------------------------------------ 692// ciEnv::get_field_by_index 693// 694// Get a field by index from a klass's constant pool. 695ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, 696 int index) { 697 GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) 698} 699 700// ------------------------------------------------------------------ 701// ciEnv::lookup_method 702// 703// Perform an appropriate method lookup based on accessor, holder, 704// name, signature, and bytecode. 705Method* ciEnv::lookup_method(InstanceKlass* accessor, 706 InstanceKlass* holder, 707 Symbol* name, 708 Symbol* sig, 709 Bytecodes::Code bc) { 710 EXCEPTION_CONTEXT; 711 KlassHandle h_accessor(THREAD, accessor); 712 KlassHandle h_holder(THREAD, holder); 713 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 714 methodHandle dest_method; 715 switch (bc) { 716 case Bytecodes::_invokestatic: 717 dest_method = 718 LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor); 719 break; 720 case Bytecodes::_invokespecial: 721 dest_method = 722 LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor); 723 break; 724 case Bytecodes::_invokeinterface: 725 dest_method = 726 LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig, 727 h_accessor, true); 728 break; 729 case Bytecodes::_invokevirtual: 730 dest_method = 731 LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig, 732 h_accessor, true); 733 break; 734 default: ShouldNotReachHere(); 735 } 736 737 return dest_method(); 738} 739 740 741// ------------------------------------------------------------------ 742// ciEnv::get_method_by_index_impl 743ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool, 744 int index, Bytecodes::Code bc, 745 ciInstanceKlass* accessor) { 746 if (bc == Bytecodes::_invokedynamic) { 747 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 748 bool is_resolved = !cpce->is_f1_null(); 749 // FIXME: code generation could allow for null (unlinked) call site 750 // The call site could be made patchable as follows: 751 // Load the appendix argument from the constant pool. 752 // Test the appendix argument and jump to a known deopt routine if it is null. 753 // Jump through a patchable call site, which is initially a deopt routine. 754 // Patch the call site to the nmethod entry point of the static compiled lambda form. 755 // As with other two-component call sites, both values must be independently verified. 756 757 if (is_resolved) { 758 // Get the invoker Method* from the constant pool. 759 // (The appendix argument, if any, will be noted in the method's signature.) 760 Method* adapter = cpce->f1_as_method(); 761 return get_method(adapter); 762 } 763 764 // Fake a method that is equivalent to a declared method. 765 ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass()); 766 ciSymbol* name = ciSymbol::invokeBasic_name(); 767 ciSymbol* signature = get_symbol(cpool->signature_ref_at(index)); 768 return get_unloaded_method(holder, name, signature, accessor); 769 } else { 770 const int holder_index = cpool->klass_ref_index_at(index); 771 bool holder_is_accessible; 772 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 773 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); 774 775 // Get the method's name and signature. 776 Symbol* name_sym = cpool->name_ref_at(index); 777 Symbol* sig_sym = cpool->signature_ref_at(index); 778 779 if (cpool->has_preresolution() 780 || (holder == ciEnv::MethodHandle_klass() && 781 MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) { 782 // Short-circuit lookups for JSR 292-related call sites. 783 // That is, do not rely only on name-based lookups, because they may fail 784 // if the names are not resolvable in the boot class loader (7056328). 785 switch (bc) { 786 case Bytecodes::_invokevirtual: 787 case Bytecodes::_invokeinterface: 788 case Bytecodes::_invokespecial: 789 case Bytecodes::_invokestatic: 790 { 791 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 792 if (m != NULL) { 793 return get_method(m); 794 } 795 } 796 break; 797 } 798 } 799 800 if (holder_is_accessible) { // Our declared holder is loaded. 801 InstanceKlass* lookup = declared_holder->get_instanceKlass(); 802 Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); 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 832ciInstanceKlass* 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 855ciMethod* ciEnv::get_method_by_index(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 864char *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 880bool ciEnv::is_in_vm() { 881 return JavaThread::current()->thread_state() == _thread_in_vm; 882} 883 884bool 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). 893void 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_line(); 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 953void 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 int comp_level, 964 bool has_unsafe_access, 965 bool has_wide_vectors, 966 RTMState rtm_state) { 967 VM_ENTRY_MARK; 968 nmethod* nm = NULL; 969 { 970 // To prevent compile queue updates. 971 MutexLocker locker(MethodCompileQueue_lock, THREAD); 972 973 // Prevent SystemDictionary::add_to_hierarchy from running 974 // and invalidating our dependencies until we install this method. 975 // No safepoints are allowed. Otherwise, class redefinition can occur in between. 976 MutexLocker ml(Compile_lock); 977 No_Safepoint_Verifier nsv; 978 979 // Change in Jvmti state may invalidate compilation. 980 if (!failing() && jvmti_state_changed()) { 981 record_failure("Jvmti state change invalidated dependencies"); 982 } 983 984 // Change in DTrace flags may invalidate compilation. 985 if (!failing() && 986 ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || 987 (!dtrace_method_probes() && DTraceMethodProbes) || 988 (!dtrace_alloc_probes() && DTraceAllocProbes) )) { 989 record_failure("DTrace flags change invalidated dependencies"); 990 } 991 992 if (!failing()) { 993 if (log() != NULL) { 994 // Log the dependencies which this compilation declares. 995 dependencies()->log_all_dependencies(); 996 } 997 998 // Encode the dependencies now, so we can check them right away. 999 dependencies()->encode_content_bytes(); 1000 1001 // Check for {class loads, evolution, breakpoints, ...} during compilation 1002 validate_compile_task_dependencies(target); 1003 } 1004 1005 methodHandle method(THREAD, target->get_Method()); 1006 1007#if INCLUDE_RTM_OPT 1008 if (!failing() && (rtm_state != NoRTM) && 1009 (method()->method_data() != NULL) && 1010 (method()->method_data()->rtm_state() != rtm_state)) { 1011 // Preemptive decompile if rtm state was changed. 1012 record_failure("RTM state change invalidated rtm code"); 1013 } 1014#endif 1015 1016 if (failing()) { 1017 // While not a true deoptimization, it is a preemptive decompile. 1018 MethodData* mdo = method()->method_data(); 1019 if (mdo != NULL) { 1020 mdo->inc_decompile_count(); 1021 } 1022 1023 // All buffers in the CodeBuffer are allocated in the CodeCache. 1024 // If the code buffer is created on each compile attempt 1025 // as in C2, then it must be freed. 1026 code_buffer->free_blob(); 1027 return; 1028 } 1029 1030 assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); 1031 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); 1032 1033 nm = nmethod::new_nmethod(method, 1034 compile_id(), 1035 entry_bci, 1036 offsets, 1037 orig_pc_offset, 1038 debug_info(), dependencies(), code_buffer, 1039 frame_words, oop_map_set, 1040 handler_table, inc_table, 1041 compiler, comp_level); 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 nmethod* 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_entrant(); 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 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 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. Print out warning and disable compilation. 1101 record_failure("code cache is full"); 1102 CompileBroker::handle_full_code_cache(); 1103 } 1104} 1105 1106 1107// ------------------------------------------------------------------ 1108// ciEnv::find_system_klass 1109ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { 1110 VM_ENTRY_MARK; 1111 return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false); 1112} 1113 1114// ------------------------------------------------------------------ 1115// ciEnv::comp_level 1116int ciEnv::comp_level() { 1117 if (task() == NULL) return CompLevel_highest_tier; 1118 return task()->comp_level(); 1119} 1120 1121// ------------------------------------------------------------------ 1122// ciEnv::compile_id 1123uint ciEnv::compile_id() { 1124 if (task() == NULL) return 0; 1125 return task()->compile_id(); 1126} 1127 1128// ------------------------------------------------------------------ 1129// ciEnv::notice_inlined_method() 1130void ciEnv::notice_inlined_method(ciMethod* method) { 1131 _num_inlined_bytecodes += method->code_size_for_inlining(); 1132} 1133 1134// ------------------------------------------------------------------ 1135// ciEnv::num_inlined_bytecodes() 1136int ciEnv::num_inlined_bytecodes() const { 1137 return _num_inlined_bytecodes; 1138} 1139 1140// ------------------------------------------------------------------ 1141// ciEnv::record_failure() 1142void ciEnv::record_failure(const char* reason) { 1143 if (log() != NULL) { 1144 log()->elem("failure reason='%s'", reason); 1145 } 1146 if (_failure_reason == NULL) { 1147 // Record the first failure reason. 1148 _failure_reason = reason; 1149 } 1150} 1151 1152// ------------------------------------------------------------------ 1153// ciEnv::record_method_not_compilable() 1154void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { 1155 int new_compilable = 1156 all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; 1157 1158 // Only note transitions to a worse state 1159 if (new_compilable > _compilable) { 1160 if (log() != NULL) { 1161 if (all_tiers) { 1162 log()->elem("method_not_compilable"); 1163 } else { 1164 log()->elem("method_not_compilable_at_tier level='%d'", 1165 current()->task()->comp_level()); 1166 } 1167 } 1168 _compilable = new_compilable; 1169 1170 // Reset failure reason; this one is more important. 1171 _failure_reason = NULL; 1172 record_failure(reason); 1173 } 1174} 1175 1176// ------------------------------------------------------------------ 1177// ciEnv::record_out_of_memory_failure() 1178void ciEnv::record_out_of_memory_failure() { 1179 // If memory is low, we stop compiling methods. 1180 record_method_not_compilable("out of memory"); 1181} 1182 1183ciInstance* ciEnv::unloaded_ciinstance() { 1184 GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();) 1185} 1186 1187// ------------------------------------------------------------------ 1188// ciEnv::dump_replay_data* 1189 1190// Don't change thread state and acquire any locks. 1191// Safe to call from VM error reporter. 1192 1193void ciEnv::dump_compile_data(outputStream* out) { 1194 CompileTask* task = this->task(); 1195 Method* method = task->method(); 1196 int entry_bci = task->osr_bci(); 1197 int comp_level = task->comp_level(); 1198 out->print("compile %s %s %s %d %d", 1199 method->klass_name()->as_quoted_ascii(), 1200 method->name()->as_quoted_ascii(), 1201 method->signature()->as_quoted_ascii(), 1202 entry_bci, comp_level); 1203 if (compiler_data() != NULL) { 1204 if (is_c2_compile(comp_level)) { // C2 or Shark 1205#ifdef COMPILER2 1206 // Dump C2 inlining data. 1207 ((Compile*)compiler_data())->dump_inline_data(out); 1208#endif 1209 } else if (is_c1_compile(comp_level)) { // C1 1210#ifdef COMPILER1 1211 // Dump C1 inlining data. 1212 ((Compilation*)compiler_data())->dump_inline_data(out); 1213#endif 1214 } 1215 } 1216 out->cr(); 1217} 1218 1219void ciEnv::dump_replay_data_unsafe(outputStream* out) { 1220 ResourceMark rm; 1221#if INCLUDE_JVMTI 1222 out->print_cr("JvmtiExport can_access_local_variables %d", _jvmti_can_access_local_variables); 1223 out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint); 1224 out->print_cr("JvmtiExport can_post_on_exceptions %d", _jvmti_can_post_on_exceptions); 1225#endif // INCLUDE_JVMTI 1226 1227 GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata(); 1228 out->print_cr("# %d ciObject found", objects->length()); 1229 for (int i = 0; i < objects->length(); i++) { 1230 objects->at(i)->dump_replay_data(out); 1231 } 1232 dump_compile_data(out); 1233 out->flush(); 1234} 1235 1236void ciEnv::dump_replay_data(outputStream* out) { 1237 GUARDED_VM_ENTRY( 1238 MutexLocker ml(Compile_lock); 1239 dump_replay_data_unsafe(out); 1240 ) 1241} 1242 1243void ciEnv::dump_replay_data(int compile_id) { 1244 static char buffer[O_BUFLEN]; 1245 int ret = jio_snprintf(buffer, O_BUFLEN, "replay_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* replay_data_file = os::open(fd, "w"); 1250 if (replay_data_file != NULL) { 1251 fileStream replay_data_stream(replay_data_file, /*need_close=*/true); 1252 dump_replay_data(&replay_data_stream); 1253 tty->print("# Compiler replay data is saved as: "); 1254 tty->print_cr(buffer); 1255 } else { 1256 tty->print_cr("# Can't open file to dump replay data."); 1257 } 1258 } 1259 } 1260} 1261 1262void ciEnv::dump_inline_data(int compile_id) { 1263 static char buffer[O_BUFLEN]; 1264 int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id); 1265 if (ret > 0) { 1266 int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); 1267 if (fd != -1) { 1268 FILE* inline_data_file = os::open(fd, "w"); 1269 if (inline_data_file != NULL) { 1270 fileStream replay_data_stream(inline_data_file, /*need_close=*/true); 1271 GUARDED_VM_ENTRY( 1272 MutexLocker ml(Compile_lock); 1273 dump_compile_data(&replay_data_stream); 1274 ) 1275 replay_data_stream.flush(); 1276 tty->print("# Compiler inline data is saved as: "); 1277 tty->print_cr(buffer); 1278 } else { 1279 tty->print_cr("# Can't open file to dump inline data."); 1280 } 1281 } 1282 } 1283} 1284