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