1 /*
   2  * Copyright (c) 1999, 2022, 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/ciSymbols.hpp"
  36 #include "ci/ciUtilities.inline.hpp"
  37 #include "classfile/javaClasses.hpp"
  38 #include "classfile/javaClasses.inline.hpp"
  39 #include "classfile/symbolTable.hpp"
  40 #include "classfile/systemDictionary.hpp"
  41 #include "classfile/vmClasses.hpp"
  42 #include "classfile/vmSymbols.hpp"
  43 #include "code/codeCache.hpp"
  44 #include "code/scopeDesc.hpp"
  45 #include "compiler/compilationPolicy.hpp"
  46 #include "compiler/compileBroker.hpp"
  47 #include "compiler/compilerEvent.hpp"
  48 #include "compiler/compileLog.hpp"
  49 #include "compiler/compileTask.hpp"
  50 #include "compiler/disassembler.hpp"
  51 #include "gc/shared/collectedHeap.inline.hpp"
  52 #include "interpreter/bytecodeStream.hpp"
  53 #include "interpreter/linkResolver.hpp"
  54 #include "jfr/jfrEvents.hpp"
  55 #include "logging/log.hpp"
  56 #include "memory/allocation.inline.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "memory/universe.hpp"
  60 #include "oops/constantPool.inline.hpp"
  61 #include "oops/cpCache.inline.hpp"
  62 #include "oops/method.inline.hpp"
  63 #include "oops/methodData.hpp"
  64 #include "oops/objArrayKlass.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/oop.inline.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/methodHandles.hpp"
  69 #include "runtime/fieldDescriptor.inline.hpp"
  70 #include "runtime/handles.inline.hpp"
  71 #include "runtime/init.hpp"
  72 #include "runtime/reflection.hpp"
  73 #include "runtime/jniHandles.inline.hpp"
  74 #include "runtime/safepointVerifiers.hpp"
  75 #include "runtime/sharedRuntime.hpp"
  76 #include "runtime/thread.inline.hpp"
  77 #include "utilities/dtrace.hpp"
  78 #include "utilities/macros.hpp"
  79 #ifdef COMPILER1
  80 #include "c1/c1_Runtime1.hpp"
  81 #endif
  82 #ifdef COMPILER2
  83 #include "opto/runtime.hpp"
  84 #endif
  85 
  86 // ciEnv
  87 //
  88 // This class is the top level broker for requests from the compiler
  89 // to the VM.
  90 
  91 ciObject*              ciEnv::_null_object_instance;
  92 
  93 #define VM_CLASS_DEFN(name, ignore_s) ciInstanceKlass* ciEnv::_##name = NULL;
  94 VM_CLASSES_DO(VM_CLASS_DEFN)
  95 #undef VM_CLASS_DEFN
  96 
  97 ciSymbol*        ciEnv::_unloaded_cisymbol = NULL;
  98 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL;
  99 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL;
 100 
 101 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL;
 102 jobject ciEnv::_ArrayStoreException_handle = NULL;
 103 jobject ciEnv::_ClassCastException_handle = NULL;
 104 
 105 #ifndef PRODUCT
 106 static bool firstEnv = true;
 107 #endif /* PRODUCT */
 108 
 109 // ------------------------------------------------------------------
 110 // ciEnv::ciEnv
 111 ciEnv::ciEnv(CompileTask* task)
 112   : _ciEnv_arena(mtCompiler) {
 113   VM_ENTRY_MARK;
 114 
 115   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
 116   thread->set_env(this);
 117   assert(ciEnv::current() == this, "sanity");
 118 
 119   _oop_recorder = NULL;
 120   _debug_info = NULL;
 121   _dependencies = NULL;
 122   _failure_reason = NULL;
 123   _inc_decompile_count_on_failure = true;
 124   _compilable = MethodCompilable;
 125   _break_at_compile = false;
 126   _compiler_data = NULL;
 127 #ifndef PRODUCT
 128   assert(!firstEnv, "not initialized properly");
 129 #endif /* !PRODUCT */
 130 
 131   _num_inlined_bytecodes = 0;
 132   assert(task == NULL || thread->task() == task, "sanity");
 133   if (task != NULL) {
 134     task->mark_started(os::elapsed_counter());
 135   }
 136   _task = task;
 137   _log = NULL;
 138 
 139   // Temporary buffer for creating symbols and such.
 140   _name_buffer = NULL;
 141   _name_buffer_len = 0;
 142 
 143   _arena   = &_ciEnv_arena;
 144   _factory = new (_arena) ciObjectFactory(_arena, 128);
 145 
 146   // Preload commonly referenced system ciObjects.
 147 
 148   // During VM initialization, these instances have not yet been created.
 149   // Assertions ensure that these instances are not accessed before
 150   // their initialization.
 151 
 152   assert(Universe::is_fully_initialized(), "should be complete");
 153 
 154   oop o = Universe::null_ptr_exception_instance();
 155   assert(o != NULL, "should have been initialized");
 156   _NullPointerException_instance = get_object(o)->as_instance();
 157   o = Universe::arithmetic_exception_instance();
 158   assert(o != NULL, "should have been initialized");
 159   _ArithmeticException_instance = get_object(o)->as_instance();
 160 
 161   _ArrayIndexOutOfBoundsException_instance = NULL;
 162   _ArrayStoreException_instance = NULL;
 163   _ClassCastException_instance = NULL;
 164   _the_null_string = NULL;
 165   _the_min_jint_string = NULL;
 166 
 167   _jvmti_redefinition_count = 0;
 168   _jvmti_can_hotswap_or_post_breakpoint = false;
 169   _jvmti_can_access_local_variables = false;
 170   _jvmti_can_post_on_exceptions = false;
 171   _jvmti_can_pop_frame = false;
 172 
 173   _dyno_klasses = NULL;
 174   _dyno_locs = NULL;
 175   _dyno_name[0] = '\0';
 176 }
 177 
 178 // Record components of a location descriptor string.  Components are appended by the constructor and
 179 // removed by the destructor, like a stack, so scope matters.  These location descriptors are used to
 180 // locate dynamic classes, and terminate at a Method* or oop field associated with dynamic/hidden class.
 181 //
 182 // Example use:
 183 //
 184 // {
 185 //   RecordLocation fp(this, "field1");
 186 //   // location: "field1"
 187 //   { RecordLocation fp(this, " field2"); // location: "field1 field2" }
 188 //   // location: "field1"
 189 //   { RecordLocation fp(this, " field3"); // location: "field1 field3" }
 190 //   // location: "field1"
 191 // }
 192 // // location: ""
 193 //
 194 // Examples of actual locations
 195 // @bci compiler/ciReplay/CiReplayBase$TestMain test (I)V 1 <appendix> argL0 ;
 196 // // resolve invokedynamic at bci 1 of TestMain.test, then read field "argL0" from appendix
 197 // @bci compiler/ciReplay/CiReplayBase$TestMain main ([Ljava/lang/String;)V 0 <appendix> form vmentry <vmtarget> ;
 198 // // resolve invokedynamic at bci 0 of TestMain.main, then read field "form.vmentry.method.vmtarget" from appendix
 199 // @cpi compiler/ciReplay/CiReplayBase$TestMain 56 form vmentry <vmtarget> ;
 200 // // resolve MethodHandle at cpi 56 of TestMain, then read field "vmentry.method.vmtarget" from resolved MethodHandle
 201 class RecordLocation {
 202 private:
 203   char* end;
 204 
 205   ATTRIBUTE_PRINTF(3, 4)
 206   void push(ciEnv* ci, const char* fmt, ...) {
 207     va_list args;
 208     va_start(args, fmt);
 209     push_va(ci, fmt, args);
 210     va_end(args);
 211   }
 212 
 213 public:
 214   ATTRIBUTE_PRINTF(3, 0)
 215   void push_va(ciEnv* ci, const char* fmt, va_list args) {
 216     char *e = ci->_dyno_name + strlen(ci->_dyno_name);
 217     char *m = ci->_dyno_name + ARRAY_SIZE(ci->_dyno_name) - 1;
 218     os::vsnprintf(e, m - e, fmt, args);
 219     assert(strlen(ci->_dyno_name) < (ARRAY_SIZE(ci->_dyno_name) - 1), "overflow");
 220   }
 221 
 222   // append a new component
 223   ATTRIBUTE_PRINTF(3, 4)
 224   RecordLocation(ciEnv* ci, const char* fmt, ...) {
 225     end = ci->_dyno_name + strlen(ci->_dyno_name);
 226     va_list args;
 227     va_start(args, fmt);
 228     push(ci, " ");
 229     push_va(ci, fmt, args);
 230     va_end(args);
 231   }
 232 
 233   // reset to previous state
 234   ~RecordLocation() {
 235     *end = '\0';
 236   }
 237 };
 238 
 239 ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) {
 240   ASSERT_IN_VM;
 241 
 242   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
 243   CompilerThread* current_thread = CompilerThread::current();
 244   assert(current_thread->env() == NULL, "must be");
 245   current_thread->set_env(this);
 246   assert(ciEnv::current() == this, "sanity");
 247 
 248   _oop_recorder = NULL;
 249   _debug_info = NULL;
 250   _dependencies = NULL;
 251   _failure_reason = NULL;
 252   _inc_decompile_count_on_failure = true;
 253   _compilable = MethodCompilable_never;
 254   _break_at_compile = false;
 255   _compiler_data = NULL;
 256 #ifndef PRODUCT
 257   assert(firstEnv, "must be first");
 258   firstEnv = false;
 259 #endif /* !PRODUCT */
 260 
 261   _num_inlined_bytecodes = 0;
 262   _task = NULL;
 263   _log = NULL;
 264 
 265   // Temporary buffer for creating symbols and such.
 266   _name_buffer = NULL;
 267   _name_buffer_len = 0;
 268 
 269   _arena   = arena;
 270   _factory = new (_arena) ciObjectFactory(_arena, 128);
 271 
 272   // Preload commonly referenced system ciObjects.
 273 
 274   // During VM initialization, these instances have not yet been created.
 275   // Assertions ensure that these instances are not accessed before
 276   // their initialization.
 277 
 278   assert(Universe::is_fully_initialized(), "must be");
 279 
 280   _NullPointerException_instance = NULL;
 281   _ArithmeticException_instance = NULL;
 282   _ArrayIndexOutOfBoundsException_instance = NULL;
 283   _ArrayStoreException_instance = NULL;
 284   _ClassCastException_instance = NULL;
 285   _the_null_string = NULL;
 286   _the_min_jint_string = NULL;
 287 
 288   _jvmti_redefinition_count = 0;
 289   _jvmti_can_hotswap_or_post_breakpoint = false;
 290   _jvmti_can_access_local_variables = false;
 291   _jvmti_can_post_on_exceptions = false;
 292   _jvmti_can_pop_frame = false;
 293 
 294   _dyno_klasses = NULL;
 295   _dyno_locs = NULL;
 296 }
 297 
 298 ciEnv::~ciEnv() {
 299   GUARDED_VM_ENTRY(
 300       CompilerThread* current_thread = CompilerThread::current();
 301       _factory->remove_symbols();
 302       // Need safepoint to clear the env on the thread.  RedefineClasses might
 303       // be reading it.
 304       current_thread->set_env(NULL);
 305   )
 306 }
 307 
 308 // ------------------------------------------------------------------
 309 // Cache Jvmti state
 310 bool ciEnv::cache_jvmti_state() {
 311   VM_ENTRY_MARK;
 312   // Get Jvmti capabilities under lock to get consistent values.
 313   MutexLocker mu(JvmtiThreadState_lock);
 314   _jvmti_redefinition_count             = JvmtiExport::redefinition_count();
 315   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
 316   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables();
 317   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions();
 318   _jvmti_can_pop_frame                  = JvmtiExport::can_pop_frame();
 319   _jvmti_can_get_owned_monitor_info     = JvmtiExport::can_get_owned_monitor_info();
 320   _jvmti_can_walk_any_space             = JvmtiExport::can_walk_any_space();
 321   return _task != NULL && _task->method()->is_old();
 322 }
 323 
 324 bool ciEnv::jvmti_state_changed() const {
 325   // Some classes were redefined
 326   if (_jvmti_redefinition_count != JvmtiExport::redefinition_count()) {
 327     return true;
 328   }
 329 
 330   if (!_jvmti_can_access_local_variables &&
 331       JvmtiExport::can_access_local_variables()) {
 332     return true;
 333   }
 334   if (!_jvmti_can_hotswap_or_post_breakpoint &&
 335       JvmtiExport::can_hotswap_or_post_breakpoint()) {
 336     return true;
 337   }
 338   if (!_jvmti_can_post_on_exceptions &&
 339       JvmtiExport::can_post_on_exceptions()) {
 340     return true;
 341   }
 342   if (!_jvmti_can_pop_frame &&
 343       JvmtiExport::can_pop_frame()) {
 344     return true;
 345   }
 346   if (!_jvmti_can_get_owned_monitor_info &&
 347       JvmtiExport::can_get_owned_monitor_info()) {
 348     return true;
 349   }
 350   if (!_jvmti_can_walk_any_space &&
 351       JvmtiExport::can_walk_any_space()) {
 352     return true;
 353   }
 354 
 355   return false;
 356 }
 357 
 358 // ------------------------------------------------------------------
 359 // Cache DTrace flags
 360 void ciEnv::cache_dtrace_flags() {
 361   // Need lock?
 362   _dtrace_extended_probes = ExtendedDTraceProbes;
 363   if (_dtrace_extended_probes) {
 364     _dtrace_method_probes   = true;
 365     _dtrace_alloc_probes    = true;
 366   } else {
 367     _dtrace_method_probes   = DTraceMethodProbes;
 368     _dtrace_alloc_probes    = DTraceAllocProbes;
 369   }
 370 }
 371 
 372 // ------------------------------------------------------------------
 373 // helper for lazy exception creation
 374 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
 375   VM_ENTRY_MARK;
 376   if (handle == NULL) {
 377     // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
 378     InstanceKlass* ik = SystemDictionary::find_instance_klass(name, Handle(), Handle());
 379     jobject objh = NULL;
 380     if (ik != NULL) {
 381       oop obj = ik->allocate_instance(THREAD);
 382       if (!HAS_PENDING_EXCEPTION)
 383         objh = JNIHandles::make_global(Handle(THREAD, obj));
 384     }
 385     if (HAS_PENDING_EXCEPTION) {
 386       CLEAR_PENDING_EXCEPTION;
 387     } else {
 388       handle = objh;
 389     }
 390   }
 391   oop obj = JNIHandles::resolve(handle);
 392   return obj == NULL? NULL: get_object(obj)->as_instance();
 393 }
 394 
 395 ciInstanceKlass* ciEnv::get_box_klass_for_primitive_type(BasicType type) {
 396   switch (type) {
 397     case T_BOOLEAN: return Boolean_klass();
 398     case T_BYTE   : return Byte_klass();
 399     case T_CHAR   : return Character_klass();
 400     case T_SHORT  : return Short_klass();
 401     case T_INT    : return Integer_klass();
 402     case T_LONG   : return Long_klass();
 403     case T_FLOAT  : return Float_klass();
 404     case T_DOUBLE : return Double_klass();
 405 
 406     default:
 407       assert(false, "not a primitive: %s", type2name(type));
 408       return NULL;
 409   }
 410 }
 411 
 412 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
 413   if (_ArrayIndexOutOfBoundsException_instance == NULL) {
 414     _ArrayIndexOutOfBoundsException_instance
 415           = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
 416           vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
 417   }
 418   return _ArrayIndexOutOfBoundsException_instance;
 419 }
 420 ciInstance* ciEnv::ArrayStoreException_instance() {
 421   if (_ArrayStoreException_instance == NULL) {
 422     _ArrayStoreException_instance
 423           = get_or_create_exception(_ArrayStoreException_handle,
 424           vmSymbols::java_lang_ArrayStoreException());
 425   }
 426   return _ArrayStoreException_instance;
 427 }
 428 ciInstance* ciEnv::ClassCastException_instance() {
 429   if (_ClassCastException_instance == NULL) {
 430     _ClassCastException_instance
 431           = get_or_create_exception(_ClassCastException_handle,
 432           vmSymbols::java_lang_ClassCastException());
 433   }
 434   return _ClassCastException_instance;
 435 }
 436 
 437 ciInstance* ciEnv::the_null_string() {
 438   if (_the_null_string == NULL) {
 439     VM_ENTRY_MARK;
 440     _the_null_string = get_object(Universe::the_null_string())->as_instance();
 441   }
 442   return _the_null_string;
 443 }
 444 
 445 ciInstance* ciEnv::the_min_jint_string() {
 446   if (_the_min_jint_string == NULL) {
 447     VM_ENTRY_MARK;
 448     _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
 449   }
 450   return _the_min_jint_string;
 451 }
 452 
 453 // ------------------------------------------------------------------
 454 // ciEnv::get_method_from_handle
 455 ciMethod* ciEnv::get_method_from_handle(Method* method) {
 456   VM_ENTRY_MARK;
 457   return get_metadata(method)->as_method();
 458 }
 459 
 460 // ------------------------------------------------------------------
 461 // ciEnv::check_klass_accessiblity
 462 //
 463 // Note: the logic of this method should mirror the logic of
 464 // ConstantPool::verify_constant_pool_resolve.
 465 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass,
 466                                       Klass* resolved_klass) {
 467   if (accessing_klass == NULL || !accessing_klass->is_loaded()) {
 468     return true;
 469   }
 470   if (accessing_klass->is_obj_array_klass()) {
 471     accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass();
 472   }
 473   if (!accessing_klass->is_instance_klass()) {
 474     return true;
 475   }
 476 
 477   if (resolved_klass->is_objArray_klass()) {
 478     // Find the element klass, if this is an array.
 479     resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
 480   }
 481   if (resolved_klass->is_instance_klass()) {
 482     return (Reflection::verify_class_access(accessing_klass->get_Klass(),
 483                                             InstanceKlass::cast(resolved_klass),
 484                                             true) == Reflection::ACCESS_OK);
 485   }
 486   return true;
 487 }
 488 
 489 // ------------------------------------------------------------------
 490 // ciEnv::get_klass_by_name_impl
 491 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
 492                                        const constantPoolHandle& cpool,
 493                                        ciSymbol* name,
 494                                        bool require_local) {
 495   ASSERT_IN_VM;
 496   Thread* current = Thread::current();
 497 
 498   // Now we need to check the SystemDictionary
 499   Symbol* sym = name->get_symbol();
 500   if (Signature::has_envelope(sym)) {
 501     // This is a name from a signature.  Strip off the trimmings.
 502     // Call recursive to keep scope of strippedsym.
 503     TempNewSymbol strippedsym = Signature::strip_envelope(sym);
 504     ciSymbol* strippedname = get_symbol(strippedsym);
 505     return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
 506   }
 507 
 508   // Check for prior unloaded klass.  The SystemDictionary's answers
 509   // can vary over time but the compiler needs consistency.
 510   ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
 511   if (unloaded_klass != NULL) {
 512     if (require_local)  return NULL;
 513     return unloaded_klass;
 514   }
 515 
 516   Handle loader;
 517   Handle domain;
 518   if (accessing_klass != NULL) {
 519     loader = Handle(current, accessing_klass->loader());
 520     domain = Handle(current, accessing_klass->protection_domain());
 521   }
 522 
 523   Klass* found_klass;
 524   {
 525     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 526     MutexLocker ml(current, Compile_lock);
 527     Klass* kls;
 528     if (!require_local) {
 529       kls = SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
 530     } else {
 531       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
 532     }
 533     found_klass = kls;
 534   }
 535 
 536   // If we fail to find an array klass, look again for its element type.
 537   // The element type may be available either locally or via constraints.
 538   // In either case, if we can find the element type in the system dictionary,
 539   // we must build an array type around it.  The CI requires array klasses
 540   // to be loaded if their element klasses are loaded, except when memory
 541   // is exhausted.
 542   if (Signature::is_array(sym) &&
 543       (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
 544     // We have an unloaded array.
 545     // Build it on the fly if the element class exists.
 546     SignatureStream ss(sym, false);
 547     ss.skip_array_prefix(1);
 548     // Get element ciKlass recursively.
 549     ciKlass* elem_klass =
 550       get_klass_by_name_impl(accessing_klass,
 551                              cpool,
 552                              get_symbol(ss.as_symbol()),
 553                              require_local);
 554     if (elem_klass != NULL && elem_klass->is_loaded()) {
 555       // Now make an array for it
 556       return ciObjArrayKlass::make_impl(elem_klass);
 557     }
 558   }
 559 
 560   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 561     // Look inside the constant pool for pre-resolved class entries.
 562     for (int i = cpool->length() - 1; i >= 1; i--) {
 563       if (cpool->tag_at(i).is_klass()) {
 564         Klass* kls = cpool->resolved_klass_at(i);
 565         if (kls->name() == sym) {
 566           found_klass = kls;
 567           break;
 568         }
 569       }
 570     }
 571   }
 572 
 573   if (found_klass != NULL) {
 574     // Found it.  Build a CI handle.
 575     return get_klass(found_klass);
 576   }
 577 
 578   if (require_local)  return NULL;
 579 
 580   // Not yet loaded into the VM, or not governed by loader constraints.
 581   // Make a CI representative for it.
 582   return get_unloaded_klass(accessing_klass, name);
 583 }
 584 
 585 // ------------------------------------------------------------------
 586 // ciEnv::get_klass_by_name
 587 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 588                                   ciSymbol* klass_name,
 589                                   bool require_local) {
 590   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 591                                                  constantPoolHandle(),
 592                                                  klass_name,
 593                                                  require_local);)
 594 }
 595 
 596 // ------------------------------------------------------------------
 597 // ciEnv::get_klass_by_index_impl
 598 //
 599 // Implementation of get_klass_by_index.
 600 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 601                                         int index,
 602                                         bool& is_accessible,
 603                                         ciInstanceKlass* accessor) {
 604   Klass* klass = NULL;
 605   Symbol* klass_name = NULL;
 606 
 607   if (cpool->tag_at(index).is_symbol()) {
 608     klass_name = cpool->symbol_at(index);
 609   } else {
 610     // Check if it's resolved if it's not a symbol constant pool entry.
 611     klass = ConstantPool::klass_at_if_loaded(cpool, index);
 612     // Try to look it up by name.
 613     if (klass == NULL) {
 614       klass_name = cpool->klass_name_at(index);
 615     }
 616   }
 617 
 618   if (klass == NULL) {
 619     // Not found in constant pool.  Use the name to do the lookup.
 620     ciKlass* k = get_klass_by_name_impl(accessor,
 621                                         cpool,
 622                                         get_symbol(klass_name),
 623                                         false);
 624     // Calculate accessibility the hard way.
 625     if (!k->is_loaded()) {
 626       is_accessible = false;
 627     } else if (k->loader() != accessor->loader() &&
 628                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
 629       // Loaded only remotely.  Not linked yet.
 630       is_accessible = false;
 631     } else {
 632       // Linked locally, and we must also check public/private, etc.
 633       is_accessible = check_klass_accessibility(accessor, k->get_Klass());
 634     }
 635     return k;
 636   }
 637 
 638   // Check for prior unloaded klass.  The SystemDictionary's answers
 639   // can vary over time but the compiler needs consistency.
 640   ciSymbol* name = get_symbol(klass->name());
 641   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
 642   if (unloaded_klass != NULL) {
 643     is_accessible = false;
 644     return unloaded_klass;
 645   }
 646 
 647   // It is known to be accessible, since it was found in the constant pool.
 648   ciKlass* ciKlass = get_klass(klass);
 649   is_accessible = true;
 650 #ifndef PRODUCT
 651   if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
 652     // Klass was unresolved at replay dump time and therefore not accessible.
 653     is_accessible = false;
 654   }
 655 #endif
 656   return ciKlass;
 657 }
 658 
 659 // ------------------------------------------------------------------
 660 // ciEnv::get_klass_by_index
 661 //
 662 // Get a klass from the constant pool.
 663 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 664                                    int index,
 665                                    bool& is_accessible,
 666                                    ciInstanceKlass* accessor) {
 667   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 668 }
 669 
 670 // ------------------------------------------------------------------
 671 // ciEnv::unbox_primitive_value
 672 //
 673 // Unbox a primitive and return it as a ciConstant.
 674 ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt) {
 675   jvalue value;
 676   BasicType bt = java_lang_boxing_object::get_value(cibox->get_oop(), &value);
 677   if (bt != expected_bt && expected_bt != T_ILLEGAL) {
 678     assert(false, "type mismatch: %s vs %s", type2name(expected_bt), cibox->klass()->name()->as_klass_external_name());
 679     return ciConstant();
 680   }
 681   switch (bt) {
 682     case T_BOOLEAN: return ciConstant(bt, value.z);
 683     case T_BYTE:    return ciConstant(bt, value.b);
 684     case T_SHORT:   return ciConstant(bt, value.s);
 685     case T_CHAR:    return ciConstant(bt, value.c);
 686     case T_INT:     return ciConstant(bt, value.i);
 687     case T_LONG:    return ciConstant(value.j);
 688     case T_FLOAT:   return ciConstant(value.f);
 689     case T_DOUBLE:  return ciConstant(value.d);
 690 
 691     default:
 692       assert(false, "not a primitive type: %s", type2name(bt));
 693       return ciConstant();
 694   }
 695 }
 696 
 697 // ------------------------------------------------------------------
 698 // ciEnv::get_resolved_constant
 699 //
 700 ciConstant ciEnv::get_resolved_constant(const constantPoolHandle& cpool, int obj_index) {
 701   assert(obj_index >= 0, "");
 702   oop obj = cpool->resolved_references()->obj_at(obj_index);
 703   if (obj == NULL) {
 704     // Unresolved constant. It is resolved when the corresponding slot contains a non-null reference.
 705     // Null constant is represented as a sentinel (non-null) value.
 706     return ciConstant();
 707   } else if (obj == Universe::the_null_sentinel()) {
 708     return ciConstant(T_OBJECT, get_object(NULL));
 709   } else {
 710     ciObject* ciobj = get_object(obj);
 711     if (ciobj->is_array()) {
 712       return ciConstant(T_ARRAY, ciobj);
 713     } else {
 714       int cp_index = cpool->object_to_cp_index(obj_index);
 715       BasicType bt = cpool->basic_type_for_constant_at(cp_index);
 716       if (is_java_primitive(bt)) {
 717         assert(cpool->tag_at(cp_index).is_dynamic_constant(), "sanity");
 718         return unbox_primitive_value(ciobj, bt);
 719       } else {
 720         assert(ciobj->is_instance(), "should be an instance");
 721         return ciConstant(T_OBJECT, ciobj);
 722       }
 723     }
 724   }
 725 }
 726 
 727 // ------------------------------------------------------------------
 728 // ciEnv::get_constant_by_index_impl
 729 //
 730 // Implementation of get_constant_by_index().
 731 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
 732                                              int index, int obj_index,
 733                                              ciInstanceKlass* accessor) {
 734   bool ignore_will_link;
 735   if (obj_index >= 0) {
 736     ciConstant con = get_resolved_constant(cpool, obj_index);
 737     if (con.is_valid()) {
 738       return con;
 739     }
 740   }
 741   constantTag tag = cpool->tag_at(index);
 742   if (tag.is_int()) {
 743     return ciConstant(T_INT, (jint)cpool->int_at(index));
 744   } else if (tag.is_long()) {
 745     return ciConstant((jlong)cpool->long_at(index));
 746   } else if (tag.is_float()) {
 747     return ciConstant((jfloat)cpool->float_at(index));
 748   } else if (tag.is_double()) {
 749     return ciConstant((jdouble)cpool->double_at(index));
 750   } else if (tag.is_string()) {
 751     EXCEPTION_CONTEXT;
 752     assert(obj_index >= 0, "should have an object index");
 753     oop string = cpool->string_at(index, obj_index, THREAD);
 754     if (HAS_PENDING_EXCEPTION) {
 755       CLEAR_PENDING_EXCEPTION;
 756       record_out_of_memory_failure();
 757       return ciConstant();
 758     }
 759     ciInstance* constant = get_object(string)->as_instance();
 760     return ciConstant(T_OBJECT, constant);
 761   } else if (tag.is_unresolved_klass_in_error()) {
 762     return ciConstant(T_OBJECT, get_unloaded_klass_mirror(NULL));
 763   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 764     ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
 765     return ciConstant(T_OBJECT, klass->java_mirror());
 766   } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
 767     // must execute Java code to link this CP entry into cache[i].f1
 768     assert(obj_index >= 0, "should have an object index");
 769     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 770     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 771     return ciConstant(T_OBJECT, ciobj);
 772   } else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
 773     // must execute Java code to link this CP entry into cache[i].f1
 774     assert(obj_index >= 0, "should have an object index");
 775     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 776     int callee_index    = cpool->method_handle_klass_index_at(index);
 777     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 778     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 779     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 780     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 781     return ciConstant(T_OBJECT, ciobj);
 782   } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 783     assert(obj_index >= 0, "should have an object index");
 784     return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant
 785   } else {
 786     assert(false, "unknown tag: %d (%s)", tag.value(), tag.internal_name());
 787     return ciConstant();
 788   }
 789 }
 790 
 791 // ------------------------------------------------------------------
 792 // ciEnv::get_constant_by_index
 793 //
 794 // Pull a constant out of the constant pool.  How appropriate.
 795 //
 796 // Implementation note: this query is currently in no way cached.
 797 ciConstant ciEnv::get_constant_by_index(const constantPoolHandle& cpool,
 798                                         int pool_index, int cache_index,
 799                                         ciInstanceKlass* accessor) {
 800   GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);)
 801 }
 802 
 803 // ------------------------------------------------------------------
 804 // ciEnv::get_field_by_index_impl
 805 //
 806 // Implementation of get_field_by_index.
 807 //
 808 // Implementation note: the results of field lookups are cached
 809 // in the accessor klass.
 810 ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor,
 811                                         int index) {
 812   ciConstantPoolCache* cache = accessor->field_cache();
 813   if (cache == NULL) {
 814     ciField* field = new (arena()) ciField(accessor, index);
 815     return field;
 816   } else {
 817     ciField* field = (ciField*)cache->get(index);
 818     if (field == NULL) {
 819       field = new (arena()) ciField(accessor, index);
 820       cache->insert(index, field);
 821     }
 822     return field;
 823   }
 824 }
 825 
 826 // ------------------------------------------------------------------
 827 // ciEnv::get_field_by_index
 828 //
 829 // Get a field by index from a klass's constant pool.
 830 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor,
 831                                    int index) {
 832   GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);)
 833 }
 834 
 835 // ------------------------------------------------------------------
 836 // ciEnv::lookup_method
 837 //
 838 // Perform an appropriate method lookup based on accessor, holder,
 839 // name, signature, and bytecode.
 840 Method* ciEnv::lookup_method(ciInstanceKlass* accessor,
 841                              ciKlass*         holder,
 842                              Symbol*          name,
 843                              Symbol*          sig,
 844                              Bytecodes::Code  bc,
 845                              constantTag      tag) {
 846   InstanceKlass* accessor_klass = accessor->get_instanceKlass();
 847   Klass* holder_klass = holder->get_Klass();
 848 
 849   // Accessibility checks are performed in ciEnv::get_method_by_index_impl.
 850   assert(check_klass_accessibility(accessor, holder_klass), "holder not accessible");
 851 
 852   LinkInfo link_info(holder_klass, name, sig, accessor_klass,
 853                      LinkInfo::AccessCheck::required,
 854                      LinkInfo::LoaderConstraintCheck::required,
 855                      tag);
 856   switch (bc) {
 857     case Bytecodes::_invokestatic:
 858       return LinkResolver::resolve_static_call_or_null(link_info);
 859     case Bytecodes::_invokespecial:
 860       return LinkResolver::resolve_special_call_or_null(link_info);
 861     case Bytecodes::_invokeinterface:
 862       return LinkResolver::linktime_resolve_interface_method_or_null(link_info);
 863     case Bytecodes::_invokevirtual:
 864       return LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
 865     default:
 866       fatal("Unhandled bytecode: %s", Bytecodes::name(bc));
 867       return NULL; // silence compiler warnings
 868   }
 869 }
 870 
 871 
 872 // ------------------------------------------------------------------
 873 // ciEnv::get_method_by_index_impl
 874 ciMethod* ciEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
 875                                           int index, Bytecodes::Code bc,
 876                                           ciInstanceKlass* accessor) {
 877   assert(cpool.not_null(), "need constant pool");
 878   assert(accessor != NULL, "need origin of access");
 879   if (bc == Bytecodes::_invokedynamic) {
 880     ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
 881     bool is_resolved = !cpce->is_f1_null();
 882     // FIXME: code generation could allow for null (unlinked) call site
 883     // The call site could be made patchable as follows:
 884     // Load the appendix argument from the constant pool.
 885     // Test the appendix argument and jump to a known deopt routine if it is null.
 886     // Jump through a patchable call site, which is initially a deopt routine.
 887     // Patch the call site to the nmethod entry point of the static compiled lambda form.
 888     // As with other two-component call sites, both values must be independently verified.
 889 
 890     if (is_resolved) {
 891       // Get the invoker Method* from the constant pool.
 892       // (The appendix argument, if any, will be noted in the method's signature.)
 893       Method* adapter = cpce->f1_as_method();
 894       return get_method(adapter);
 895     }
 896 
 897     // Fake a method that is equivalent to a declared method.
 898     ciInstanceKlass* holder    = get_instance_klass(vmClasses::MethodHandle_klass());
 899     ciSymbol*        name      = ciSymbols::invokeBasic_name();
 900     ciSymbol*        signature = get_symbol(cpool->signature_ref_at(index));
 901     return get_unloaded_method(holder, name, signature, accessor);
 902   } else {
 903     const int holder_index = cpool->klass_ref_index_at(index);
 904     bool holder_is_accessible;
 905     ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
 906 
 907     // Get the method's name and signature.
 908     Symbol* name_sym = cpool->name_ref_at(index);
 909     Symbol* sig_sym  = cpool->signature_ref_at(index);
 910 
 911     if (cpool->has_preresolution()
 912         || ((holder == ciEnv::MethodHandle_klass() || holder == ciEnv::VarHandle_klass()) &&
 913             MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) {
 914       // Short-circuit lookups for JSR 292-related call sites.
 915       // That is, do not rely only on name-based lookups, because they may fail
 916       // if the names are not resolvable in the boot class loader (7056328).
 917       switch (bc) {
 918       case Bytecodes::_invokevirtual:
 919       case Bytecodes::_invokeinterface:
 920       case Bytecodes::_invokespecial:
 921       case Bytecodes::_invokestatic:
 922         {
 923           Method* m = ConstantPool::method_at_if_loaded(cpool, index);
 924           if (m != NULL) {
 925             return get_method(m);
 926           }
 927         }
 928         break;
 929       default:
 930         break;
 931       }
 932     }
 933 
 934     if (holder_is_accessible) {  // Our declared holder is loaded.
 935       constantTag tag = cpool->tag_ref_at(index);
 936       assert(accessor->get_instanceKlass() == cpool->pool_holder(), "not the pool holder?");
 937       Method* m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
 938       if (m != NULL &&
 939           (bc == Bytecodes::_invokestatic
 940            ?  m->method_holder()->is_not_initialized()
 941            : !m->method_holder()->is_loaded())) {
 942         m = NULL;
 943       }
 944 #ifdef ASSERT
 945       if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) {
 946         m = NULL;
 947       }
 948 #endif
 949       if (m != NULL) {
 950         // We found the method.
 951         return get_method(m);
 952       }
 953     }
 954 
 955     // Either the declared holder was not loaded, or the method could
 956     // not be found.  Create a dummy ciMethod to represent the failed
 957     // lookup.
 958     ciSymbol* name      = get_symbol(name_sym);
 959     ciSymbol* signature = get_symbol(sig_sym);
 960     return get_unloaded_method(holder, name, signature, accessor);
 961   }
 962 }
 963 
 964 
 965 // ------------------------------------------------------------------
 966 // ciEnv::get_instance_klass_for_declared_method_holder
 967 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) {
 968   // For the case of <array>.clone(), the method holder can be a ciArrayKlass
 969   // instead of a ciInstanceKlass.  For that case simply pretend that the
 970   // declared holder is Object.clone since that's where the call will bottom out.
 971   // A more correct fix would trickle out through many interfaces in CI,
 972   // requiring ciInstanceKlass* to become ciKlass* and many more places would
 973   // require checks to make sure the expected type was found.  Given that this
 974   // only occurs for clone() the more extensive fix seems like overkill so
 975   // instead we simply smear the array type into Object.
 976   guarantee(method_holder != NULL, "no method holder");
 977   if (method_holder->is_instance_klass()) {
 978     return method_holder->as_instance_klass();
 979   } else if (method_holder->is_array_klass()) {
 980     return current()->Object_klass();
 981   } else {
 982     ShouldNotReachHere();
 983   }
 984   return NULL;
 985 }
 986 
 987 
 988 // ------------------------------------------------------------------
 989 // ciEnv::get_method_by_index
 990 ciMethod* ciEnv::get_method_by_index(const constantPoolHandle& cpool,
 991                                      int index, Bytecodes::Code bc,
 992                                      ciInstanceKlass* accessor) {
 993   GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
 994 }
 995 
 996 
 997 // ------------------------------------------------------------------
 998 // ciEnv::name_buffer
 999 char *ciEnv::name_buffer(int req_len) {
1000   if (_name_buffer_len < req_len) {
1001     if (_name_buffer == NULL) {
1002       _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len);
1003       _name_buffer_len = req_len;
1004     } else {
1005       _name_buffer =
1006         (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
1007       _name_buffer_len = req_len;
1008     }
1009   }
1010   return _name_buffer;
1011 }
1012 
1013 // ------------------------------------------------------------------
1014 // ciEnv::is_in_vm
1015 bool ciEnv::is_in_vm() {
1016   return JavaThread::current()->thread_state() == _thread_in_vm;
1017 }
1018 
1019 // ------------------------------------------------------------------
1020 // ciEnv::validate_compile_task_dependencies
1021 //
1022 // Check for changes during compilation (e.g. class loads, evolution,
1023 // breakpoints, call site invalidation).
1024 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
1025   if (failing())  return;  // no need for further checks
1026 
1027   Dependencies::DepType result = dependencies()->validate_dependencies(_task);
1028   if (result != Dependencies::end_marker) {
1029     if (result == Dependencies::call_site_target_value) {
1030       _inc_decompile_count_on_failure = false;
1031       record_failure("call site target change");
1032     } else if (Dependencies::is_klass_type(result)) {
1033       record_failure("concurrent class loading");
1034     } else {
1035       record_failure("invalid non-klass dependency");
1036     }
1037   }
1038 }
1039 
1040 // ------------------------------------------------------------------
1041 // ciEnv::register_method
1042 void ciEnv::register_method(ciMethod* target,
1043                             int entry_bci,
1044                             CodeOffsets* offsets,
1045                             int orig_pc_offset,
1046                             CodeBuffer* code_buffer,
1047                             int frame_words,
1048                             OopMapSet* oop_map_set,
1049                             ExceptionHandlerTable* handler_table,
1050                             ImplicitExceptionTable* inc_table,
1051                             AbstractCompiler* compiler,
1052                             bool has_unsafe_access,
1053                             bool has_wide_vectors,
1054                             RTMState  rtm_state,
1055                             const GrowableArrayView<RuntimeStub*>& native_invokers) {
1056   VM_ENTRY_MARK;
1057   nmethod* nm = NULL;
1058   {
1059     methodHandle method(THREAD, target->get_Method());
1060 
1061     // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1062     if (method->get_method_counters(THREAD) == NULL) {
1063       record_failure("can't create method counters");
1064       // All buffers in the CodeBuffer are allocated in the CodeCache.
1065       // If the code buffer is created on each compile attempt
1066       // as in C2, then it must be freed.
1067       code_buffer->free_blob();
1068       return;
1069     }
1070 
1071     // To prevent compile queue updates.
1072     MutexLocker locker(THREAD, MethodCompileQueue_lock);
1073 
1074     // Prevent SystemDictionary::add_to_hierarchy from running
1075     // and invalidating our dependencies until we install this method.
1076     // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1077     MutexLocker ml(Compile_lock);
1078     NoSafepointVerifier nsv;
1079 
1080     // Change in Jvmti state may invalidate compilation.
1081     if (!failing() && jvmti_state_changed()) {
1082       record_failure("Jvmti state change invalidated dependencies");
1083     }
1084 
1085     // Change in DTrace flags may invalidate compilation.
1086     if (!failing() &&
1087         ( (!dtrace_extended_probes() && ExtendedDTraceProbes) ||
1088           (!dtrace_method_probes() && DTraceMethodProbes) ||
1089           (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
1090       record_failure("DTrace flags change invalidated dependencies");
1091     }
1092 
1093     if (!failing() && target->needs_clinit_barrier() &&
1094         target->holder()->is_in_error_state()) {
1095       record_failure("method holder is in error state");
1096     }
1097 
1098     if (!failing()) {
1099       if (log() != NULL) {
1100         // Log the dependencies which this compilation declares.
1101         dependencies()->log_all_dependencies();
1102       }
1103 
1104       // Encode the dependencies now, so we can check them right away.
1105       dependencies()->encode_content_bytes();
1106 
1107       // Check for {class loads, evolution, breakpoints, ...} during compilation
1108       validate_compile_task_dependencies(target);
1109     }
1110 #if INCLUDE_RTM_OPT
1111     if (!failing() && (rtm_state != NoRTM) &&
1112         (method()->method_data() != NULL) &&
1113         (method()->method_data()->rtm_state() != rtm_state)) {
1114       // Preemptive decompile if rtm state was changed.
1115       record_failure("RTM state change invalidated rtm code");
1116     }
1117 #endif
1118 
1119     if (failing()) {
1120       // While not a true deoptimization, it is a preemptive decompile.
1121       MethodData* mdo = method()->method_data();
1122       if (mdo != NULL && _inc_decompile_count_on_failure) {
1123         mdo->inc_decompile_count();
1124       }
1125 
1126       // All buffers in the CodeBuffer are allocated in the CodeCache.
1127       // If the code buffer is created on each compile attempt
1128       // as in C2, then it must be freed.
1129       code_buffer->free_blob();
1130       return;
1131     }
1132 
1133     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1134     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1135 
1136     nm =  nmethod::new_nmethod(method,
1137                                compile_id(),
1138                                entry_bci,
1139                                offsets,
1140                                orig_pc_offset,
1141                                debug_info(), dependencies(), code_buffer,
1142                                frame_words, oop_map_set,
1143                                handler_table, inc_table,
1144                                compiler, task()->comp_level(),
1145                                native_invokers);
1146 
1147     // Free codeBlobs
1148     code_buffer->free_blob();
1149 
1150     if (nm != NULL) {
1151       nm->set_has_unsafe_access(has_unsafe_access);
1152       nm->set_has_wide_vectors(has_wide_vectors);
1153 #if INCLUDE_RTM_OPT
1154       nm->set_rtm_state(rtm_state);
1155 #endif
1156 
1157       // Record successful registration.
1158       // (Put nm into the task handle *before* publishing to the Java heap.)
1159       if (task() != NULL) {
1160         task()->set_code(nm);
1161       }
1162 
1163       if (entry_bci == InvocationEntryBci) {
1164         if (TieredCompilation) {
1165           // If there is an old version we're done with it
1166           CompiledMethod* old = method->code();
1167           if (TraceMethodReplacement && old != NULL) {
1168             ResourceMark rm;
1169             char *method_name = method->name_and_sig_as_C_string();
1170             tty->print_cr("Replacing method %s", method_name);
1171           }
1172           if (old != NULL) {
1173             old->make_not_used();
1174           }
1175         }
1176 
1177         LogTarget(Info, nmethod, install) lt;
1178         if (lt.is_enabled()) {
1179           ResourceMark rm;
1180           char *method_name = method->name_and_sig_as_C_string();
1181           lt.print("Installing method (%d) %s ",
1182                     task()->comp_level(), method_name);
1183         }
1184         // Allow the code to be executed
1185         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1186         if (nm->make_in_use()) {
1187           method->set_code(method, nm);
1188         }
1189       } else {
1190         LogTarget(Info, nmethod, install) lt;
1191         if (lt.is_enabled()) {
1192           ResourceMark rm;
1193           char *method_name = method->name_and_sig_as_C_string();
1194           lt.print("Installing osr method (%d) %s @ %d",
1195                     task()->comp_level(), method_name, entry_bci);
1196         }
1197         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1198         if (nm->make_in_use()) {
1199           method->method_holder()->add_osr_nmethod(nm);
1200         }
1201       }
1202     }
1203   }  // safepoints are allowed again
1204 
1205   if (nm != NULL) {
1206     // JVMTI -- compiled method notification (must be done outside lock)
1207     nm->post_compiled_method_load_event();
1208   } else {
1209     // The CodeCache is full.
1210     record_failure("code cache is full");
1211   }
1212 }
1213 
1214 // ------------------------------------------------------------------
1215 // ciEnv::comp_level
1216 int ciEnv::comp_level() {
1217   if (task() == NULL)  return CompilationPolicy::highest_compile_level();
1218   return task()->comp_level();
1219 }
1220 
1221 // ------------------------------------------------------------------
1222 // ciEnv::compile_id
1223 uint ciEnv::compile_id() {
1224   if (task() == NULL)  return 0;
1225   return task()->compile_id();
1226 }
1227 
1228 // ------------------------------------------------------------------
1229 // ciEnv::notice_inlined_method()
1230 void ciEnv::notice_inlined_method(ciMethod* method) {
1231   _num_inlined_bytecodes += method->code_size_for_inlining();
1232 }
1233 
1234 // ------------------------------------------------------------------
1235 // ciEnv::num_inlined_bytecodes()
1236 int ciEnv::num_inlined_bytecodes() const {
1237   return _num_inlined_bytecodes;
1238 }
1239 
1240 // ------------------------------------------------------------------
1241 // ciEnv::record_failure()
1242 void ciEnv::record_failure(const char* reason) {
1243   if (_failure_reason == NULL) {
1244     // Record the first failure reason.
1245     _failure_reason = reason;
1246   }
1247 }
1248 
1249 void ciEnv::report_failure(const char* reason) {
1250   EventCompilationFailure event;
1251   if (event.should_commit()) {
1252     CompilerEvent::CompilationFailureEvent::post(event, compile_id(), reason);
1253   }
1254 }
1255 
1256 // ------------------------------------------------------------------
1257 // ciEnv::record_method_not_compilable()
1258 void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) {
1259   int new_compilable =
1260     all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ;
1261 
1262   // Only note transitions to a worse state
1263   if (new_compilable > _compilable) {
1264     if (log() != NULL) {
1265       if (all_tiers) {
1266         log()->elem("method_not_compilable");
1267       } else {
1268         log()->elem("method_not_compilable_at_tier level='%d'",
1269                     current()->task()->comp_level());
1270       }
1271     }
1272     _compilable = new_compilable;
1273 
1274     // Reset failure reason; this one is more important.
1275     _failure_reason = NULL;
1276     record_failure(reason);
1277   }
1278 }
1279 
1280 // ------------------------------------------------------------------
1281 // ciEnv::record_out_of_memory_failure()
1282 void ciEnv::record_out_of_memory_failure() {
1283   // If memory is low, we stop compiling methods.
1284   record_method_not_compilable("out of memory");
1285 }
1286 
1287 ciInstance* ciEnv::unloaded_ciinstance() {
1288   GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();)
1289 }
1290 
1291 // ------------------------------------------------------------------
1292 // Replay support
1293 
1294 
1295 // Lookup location descriptor for the class, if any.
1296 // Returns false if not found.
1297 bool ciEnv::dyno_loc(const InstanceKlass* ik, const char *&loc) const {
1298   bool found = false;
1299   int pos = _dyno_klasses->find_sorted<const InstanceKlass*, klass_compare>(ik, found);
1300   if (!found) {
1301     return false;
1302   }
1303   loc = _dyno_locs->at(pos);
1304   return found;
1305 }
1306 
1307 // Associate the current location descriptor with the given class and record for later lookup.
1308 void ciEnv::set_dyno_loc(const InstanceKlass* ik) {
1309   const char *loc = os::strdup(_dyno_name);
1310   bool found = false;
1311   int pos = _dyno_klasses->find_sorted<const InstanceKlass*, klass_compare>(ik, found);
1312   if (found) {
1313     _dyno_locs->at_put(pos, loc);
1314   } else {
1315     _dyno_klasses->insert_before(pos, ik);
1316     _dyno_locs->insert_before(pos, loc);
1317   }
1318 }
1319 
1320 // Associate the current location descriptor with the given class and record for later lookup.
1321 // If it turns out that there are multiple locations for the given class, that conflict should
1322 // be handled here.  Currently we choose the first location found.
1323 void ciEnv::record_best_dyno_loc(const InstanceKlass* ik) {
1324   if (!ik->is_hidden()) {
1325     return;
1326   }
1327   const char *loc0;
1328   if (dyno_loc(ik, loc0)) {
1329     // TODO: found multiple references, see if we can improve
1330     if (Verbose) {
1331       tty->print_cr("existing call site @ %s for %s",
1332                      loc0, ik->external_name());
1333     }
1334   } else {
1335     set_dyno_loc(ik);
1336   }
1337 }
1338 
1339 // Look up the location descriptor for the given class and print it to the output stream.
1340 bool ciEnv::print_dyno_loc(outputStream* out, const InstanceKlass* ik) const {
1341   const char *loc;
1342   if (dyno_loc(ik, loc)) {
1343     out->print("%s", loc);
1344     return true;
1345   } else {
1346     return false;
1347   }
1348 }
1349 
1350 // Look up the location descriptor for the given class and return it as a string.
1351 // Returns NULL if no location is found.
1352 const char *ciEnv::dyno_name(const InstanceKlass* ik) const {
1353   if (ik->is_hidden()) {
1354     stringStream ss;
1355     if (print_dyno_loc(&ss, ik)) {
1356       ss.print(" ;"); // add terminator
1357       const char* call_site = ss.as_string();
1358       return call_site;
1359     }
1360   }
1361   return NULL;
1362 }
1363 
1364 // Look up the location descriptor for the given class and return it as a string.
1365 // Returns the class name as a fallback if no location is found.
1366 const char *ciEnv::replay_name(ciKlass* k) const {
1367   if (k->is_instance_klass()) {
1368     return replay_name(k->as_instance_klass()->get_instanceKlass());
1369   }
1370   return k->name()->as_quoted_ascii();
1371 }
1372 
1373 // Look up the location descriptor for the given class and return it as a string.
1374 // Returns the class name as a fallback if no location is found.
1375 const char *ciEnv::replay_name(const InstanceKlass* ik) const {
1376   const char* name = dyno_name(ik);
1377   if (name != NULL) {
1378       return name;
1379   }
1380   return ik->name()->as_quoted_ascii();
1381 }
1382 
1383 // Process a java.lang.invoke.MemberName object and record any dynamic locations.
1384 void ciEnv::record_member(Thread* thread, oop member) {
1385   assert(java_lang_invoke_MemberName::is_instance(member), "!");
1386   // Check MemberName.clazz field
1387   oop clazz = java_lang_invoke_MemberName::clazz(member);
1388   if (clazz->klass()->is_instance_klass()) {
1389     RecordLocation fp(this, "clazz");
1390     InstanceKlass* ik = InstanceKlass::cast(clazz->klass());
1391     record_best_dyno_loc(ik);
1392   }
1393   // Check MemberName.method.vmtarget field
1394   Method* vmtarget = java_lang_invoke_MemberName::vmtarget(member);
1395   if (vmtarget != NULL) {
1396     RecordLocation fp2(this, "<vmtarget>");
1397     InstanceKlass* ik = vmtarget->method_holder();
1398     record_best_dyno_loc(ik);
1399   }
1400 }
1401 
1402 // Read an object field.  Lookup is done by name only.
1403 static inline oop obj_field(oop obj, const char* name) {
1404     return ciReplay::obj_field(obj, name);
1405 }
1406 
1407 // Process a java.lang.invoke.LambdaForm object and record any dynamic locations.
1408 void ciEnv::record_lambdaform(Thread* thread, oop form) {
1409   assert(java_lang_invoke_LambdaForm::is_instance(form), "!");
1410 
1411   {
1412     // Check LambdaForm.vmentry field
1413     oop member = java_lang_invoke_LambdaForm::vmentry(form);
1414     RecordLocation fp0(this, "vmentry");
1415     record_member(thread, member);
1416   }
1417 
1418   // Check LambdaForm.names array
1419   objArrayOop names = (objArrayOop)obj_field(form, "names");
1420   if (names != NULL) {
1421     RecordLocation lp0(this, "names");
1422     int len = names->length();
1423     for (int i = 0; i < len; ++i) {
1424       oop name = names->obj_at(i);
1425       RecordLocation lp1(this, "%d", i);
1426      // Check LambdaForm.names[i].function field
1427       RecordLocation lp2(this, "function");
1428       oop function = obj_field(name, "function");
1429       if (function != NULL) {
1430         // Check LambdaForm.names[i].function.member field
1431         oop member = obj_field(function, "member");
1432         if (member != NULL) {
1433           RecordLocation lp3(this, "member");
1434           record_member(thread, member);
1435         }
1436         // Check LambdaForm.names[i].function.resolvedHandle field
1437         oop mh = obj_field(function, "resolvedHandle");
1438         if (mh != NULL) {
1439           RecordLocation lp3(this, "resolvedHandle");
1440           record_mh(thread, mh);
1441         }
1442         // Check LambdaForm.names[i].function.invoker field
1443         oop invoker = obj_field(function, "invoker");
1444         if (invoker != NULL) {
1445           RecordLocation lp3(this, "invoker");
1446           record_mh(thread, invoker);
1447         }
1448       }
1449     }
1450   }
1451 }
1452 
1453 // Process a java.lang.invoke.MethodHandle object and record any dynamic locations.
1454 void ciEnv::record_mh(Thread* thread, oop mh) {
1455   {
1456     // Check MethodHandle.form field
1457     oop form = java_lang_invoke_MethodHandle::form(mh);
1458     RecordLocation fp(this, "form");
1459     record_lambdaform(thread, form);
1460   }
1461   // Check DirectMethodHandle.member field
1462   if (java_lang_invoke_DirectMethodHandle::is_instance(mh)) {
1463     oop member = java_lang_invoke_DirectMethodHandle::member(mh);
1464     RecordLocation fp(this, "member");
1465     record_member(thread, member);
1466   } else {
1467     // Check <MethodHandle subclass>.argL<n> fields
1468     // Probably BoundMethodHandle.Species_L*, but we only care if the field exists
1469     char arg_name[] = "argLXX";
1470     int max_arg = 99;
1471     for (int index = 0; index <= max_arg; ++index) {
1472       jio_snprintf(arg_name, sizeof (arg_name), "argL%d", index);
1473       oop arg = obj_field(mh, arg_name);
1474       if (arg != NULL) {
1475         RecordLocation fp(this, "%s", arg_name);
1476         if (arg->klass()->is_instance_klass()) {
1477           InstanceKlass* ik2 = InstanceKlass::cast(arg->klass());
1478           record_best_dyno_loc(ik2);
1479           record_call_site_obj(thread, arg);
1480         }
1481       } else {
1482         break;
1483       }
1484     }
1485   }
1486 }
1487 
1488 // Process an object found at an invokedynamic/invokehandle call site and record any dynamic locations.
1489 // Types currently supported are MethodHandle and CallSite.
1490 // The object is typically the "appendix" object, or Bootstrap Method (BSM) object.
1491 void ciEnv::record_call_site_obj(Thread* thread, oop obj)
1492 {
1493   if (obj != NULL) {
1494     if (java_lang_invoke_MethodHandle::is_instance(obj)) {
1495         record_mh(thread, obj);
1496     } else if (java_lang_invoke_ConstantCallSite::is_instance(obj)) {
1497       oop target = java_lang_invoke_CallSite::target(obj);
1498       if (target->klass()->is_instance_klass()) {
1499         RecordLocation fp(this, "target");
1500         InstanceKlass* ik = InstanceKlass::cast(target->klass());
1501         record_best_dyno_loc(ik);
1502       }
1503     }
1504   }
1505 }
1506 
1507 // Process an adapter Method* found at an invokedynamic/invokehandle call site and record any dynamic locations.
1508 void ciEnv::record_call_site_method(Thread* thread, Method* adapter) {
1509   InstanceKlass* holder = adapter->method_holder();
1510   if (!holder->is_hidden()) {
1511     return;
1512   }
1513   RecordLocation fp(this, "<adapter>");
1514   record_best_dyno_loc(holder);
1515 }
1516 
1517 // Process an invokedynamic call site and record any dynamic locations.
1518 void ciEnv::process_invokedynamic(const constantPoolHandle &cp, int indy_index, JavaThread* thread) {
1519   ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(indy_index);
1520   if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
1521     // process the adapter
1522     Method* adapter = cp_cache_entry->f1_as_method();
1523     record_call_site_method(thread, adapter);
1524     // process the appendix
1525     oop appendix = cp_cache_entry->appendix_if_resolved(cp);
1526     {
1527       RecordLocation fp(this, "<appendix>");
1528       record_call_site_obj(thread, appendix);
1529     }
1530     // process the BSM
1531     int pool_index = cp_cache_entry->constant_pool_index();
1532     BootstrapInfo bootstrap_specifier(cp, pool_index, indy_index);
1533     oop bsm = cp->resolve_possibly_cached_constant_at(bootstrap_specifier.bsm_index(), thread);
1534     {
1535       RecordLocation fp(this, "<bsm>");
1536       record_call_site_obj(thread, bsm);
1537     }
1538   }
1539 }
1540 
1541 // Process an invokehandle call site and record any dynamic locations.
1542 void ciEnv::process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread) {
1543   const int holder_index = cp->klass_ref_index_at(index);
1544   if (!cp->tag_at(holder_index).is_klass()) {
1545     return;  // not resolved
1546   }
1547   Klass* holder = ConstantPool::klass_at_if_loaded(cp, holder_index);
1548   Symbol* name = cp->name_ref_at(index);
1549   if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
1550     ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1551     if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
1552       // process the adapter
1553       Method* adapter = cp_cache_entry->f1_as_method();
1554       oop appendix = cp_cache_entry->appendix_if_resolved(cp);
1555       record_call_site_method(thread, adapter);
1556       // process the appendix
1557       {
1558         RecordLocation fp(this, "<appendix>");
1559         record_call_site_obj(thread, appendix);
1560       }
1561     }
1562   }
1563 }
1564 
1565 // Search the class hierarchy for dynamic classes reachable through dynamic call sites or
1566 // constant pool entries and record for future lookup.
1567 void ciEnv::find_dynamic_call_sites() {
1568   _dyno_klasses = new (arena()) GrowableArray<const InstanceKlass*>(arena(), 100, 0, NULL);
1569   _dyno_locs    = new (arena()) GrowableArray<const char *>(arena(), 100, 0, NULL);
1570 
1571   // Iterate over the class hierarchy
1572   for (ClassHierarchyIterator iter(vmClasses::Object_klass()); !iter.done(); iter.next()) {
1573     Klass* sub = iter.klass();
1574     if (sub->is_instance_klass()) {
1575       InstanceKlass *isub = InstanceKlass::cast(sub);
1576       InstanceKlass* ik = isub;
1577       if (!ik->is_linked()) {
1578         continue;
1579       }
1580       if (ik->is_hidden()) {
1581         continue;
1582       }
1583       JavaThread* thread = JavaThread::current();
1584       const constantPoolHandle pool(thread, ik->constants());
1585 
1586       // Look for invokedynamic/invokehandle call sites
1587       for (int i = 0; i < ik->methods()->length(); ++i) {
1588         Method* m = ik->methods()->at(i);
1589 
1590         BytecodeStream bcs(methodHandle(thread, m));
1591         while (!bcs.is_last_bytecode()) {
1592           Bytecodes::Code opcode = bcs.next();
1593           opcode = bcs.raw_code();
1594           switch (opcode) {
1595           case Bytecodes::_invokedynamic:
1596           case Bytecodes::_invokehandle: {
1597             RecordLocation fp(this, "@bci %s %s %s %d",
1598                          ik->name()->as_quoted_ascii(),
1599                          m->name()->as_quoted_ascii(), m->signature()->as_quoted_ascii(),
1600                          bcs.bci());
1601             if (opcode == Bytecodes::_invokedynamic) {
1602               int index = bcs.get_index_u4();
1603               process_invokedynamic(pool, index, thread);
1604             } else {
1605               assert(opcode == Bytecodes::_invokehandle, "new switch label added?");
1606               int cp_cache_index = bcs.get_index_u2_cpcache();
1607               process_invokehandle(pool, cp_cache_index, thread);
1608             }
1609             break;
1610           }
1611           default:
1612             break;
1613           }
1614         }
1615       }
1616 
1617       // Look for MethodHandle constant pool entries
1618       RecordLocation fp(this, "@cpi %s", ik->name()->as_quoted_ascii());
1619       int len = pool->length();
1620       for (int i = 0; i < len; ++i) {
1621         if (pool->tag_at(i).is_method_handle()) {
1622           bool found_it;
1623           oop mh = pool->find_cached_constant_at(i, found_it, thread);
1624           if (mh != NULL) {
1625             RecordLocation fp(this, "%d", i);
1626             record_mh(thread, mh);
1627           }
1628         }
1629       }
1630     }
1631   }
1632 }
1633 
1634 void ciEnv::dump_compile_data(outputStream* out) {
1635   CompileTask* task = this->task();
1636   if (task) {
1637     Method* method = task->method();
1638     int entry_bci = task->osr_bci();
1639     int comp_level = task->comp_level();
1640     out->print("compile ");
1641     get_method(method)->dump_name_as_ascii(out);
1642     out->print(" %d %d", entry_bci, comp_level);
1643     if (compiler_data() != NULL) {
1644       if (is_c2_compile(comp_level)) {
1645 #ifdef COMPILER2
1646         // Dump C2 inlining data.
1647         ((Compile*)compiler_data())->dump_inline_data(out);
1648 #endif
1649       } else if (is_c1_compile(comp_level)) {
1650 #ifdef COMPILER1
1651         // Dump C1 inlining data.
1652         ((Compilation*)compiler_data())->dump_inline_data(out);
1653 #endif
1654       }
1655     }
1656     out->cr();
1657   }
1658 }
1659 
1660 // Called from VM error reporter, so be careful.
1661 // Don't safepoint or acquire any locks.
1662 //
1663 void ciEnv::dump_replay_data_helper(outputStream* out) {
1664   NoSafepointVerifier no_safepoint;
1665   ResourceMark rm;
1666 
1667   out->print_cr("version %d", REPLAY_VERSION);
1668 #if INCLUDE_JVMTI
1669   out->print_cr("JvmtiExport can_access_local_variables %d",     _jvmti_can_access_local_variables);
1670   out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint);
1671   out->print_cr("JvmtiExport can_post_on_exceptions %d",         _jvmti_can_post_on_exceptions);
1672 #endif // INCLUDE_JVMTI
1673 
1674   find_dynamic_call_sites();
1675 
1676   GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata();
1677   out->print_cr("# %d ciObject found", objects->length());
1678 
1679   // The very first entry is the InstanceKlass of the root method of the current compilation in order to get the right
1680   // protection domain to load subsequent classes during replay compilation.
1681   ciInstanceKlass::dump_replay_instanceKlass(out, task()->method()->method_holder());
1682 
1683   for (int i = 0; i < objects->length(); i++) {
1684     objects->at(i)->dump_replay_data(out);
1685   }
1686   dump_compile_data(out);
1687   out->flush();
1688 }
1689 
1690 // Called from VM error reporter, so be careful.
1691 // Don't safepoint or acquire any locks.
1692 //
1693 void ciEnv::dump_replay_data_unsafe(outputStream* out) {
1694   GUARDED_VM_ENTRY(
1695     dump_replay_data_helper(out);
1696   )
1697 }
1698 
1699 void ciEnv::dump_replay_data(outputStream* out) {
1700   GUARDED_VM_ENTRY(
1701     MutexLocker ml(Compile_lock);
1702     dump_replay_data_helper(out);
1703   )
1704 }
1705 
1706 void ciEnv::dump_replay_data(int compile_id) {
1707   char buffer[64];
1708   int ret = jio_snprintf(buffer, sizeof(buffer), "replay_pid%d_compid%d.log", os::current_process_id(), compile_id);
1709   if (ret > 0) {
1710     int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
1711     if (fd != -1) {
1712       FILE* replay_data_file = os::fdopen(fd, "w");
1713       if (replay_data_file != NULL) {
1714         fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
1715         dump_replay_data(&replay_data_stream);
1716         tty->print_cr("# Compiler replay data is saved as: %s", buffer);
1717       } else {
1718         tty->print_cr("# Can't open file to dump replay data.");
1719       }
1720     }
1721   }
1722 }
1723 
1724 void ciEnv::dump_inline_data(int compile_id) {
1725   char buffer[64];
1726   int ret = jio_snprintf(buffer, sizeof(buffer), "inline_pid%d_compid%d.log", os::current_process_id(), compile_id);
1727   if (ret > 0) {
1728     int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
1729     if (fd != -1) {
1730       FILE* inline_data_file = os::fdopen(fd, "w");
1731       if (inline_data_file != NULL) {
1732         fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1733         GUARDED_VM_ENTRY(
1734           MutexLocker ml(Compile_lock);
1735           dump_compile_data(&replay_data_stream);
1736         )
1737         replay_data_stream.flush();
1738         tty->print("# Compiler inline data is saved as: ");
1739         tty->print_cr("%s", buffer);
1740       } else {
1741         tty->print_cr("# Can't open file to dump inline data.");
1742       }
1743     }
1744   }
1745 }