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   VM_ENTRY_MARK;
1056   nmethod* nm = NULL;
1057   {
1058     methodHandle method(THREAD, target->get_Method());
1059 
1060     // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1061     if (method->get_method_counters(THREAD) == NULL) {
1062       record_failure("can't create method counters");
1063       // All buffers in the CodeBuffer are allocated in the CodeCache.
1064       // If the code buffer is created on each compile attempt
1065       // as in C2, then it must be freed.
1066       code_buffer->free_blob();
1067       return;
1068     }
1069 
1070     // To prevent compile queue updates.
1071     MutexLocker locker(THREAD, MethodCompileQueue_lock);
1072 
1073     // Prevent SystemDictionary::add_to_hierarchy from running
1074     // and invalidating our dependencies until we install this method.
1075     // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1076     MutexLocker ml(Compile_lock);
1077     NoSafepointVerifier nsv;
1078 
1079     // Change in Jvmti state may invalidate compilation.
1080     if (!failing() && jvmti_state_changed()) {
1081       record_failure("Jvmti state change invalidated dependencies");
1082     }
1083 
1084     // Change in DTrace flags may invalidate compilation.
1085     if (!failing() &&
1086         ( (!dtrace_extended_probes() && ExtendedDTraceProbes) ||
1087           (!dtrace_method_probes() && DTraceMethodProbes) ||
1088           (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
1089       record_failure("DTrace flags change invalidated dependencies");
1090     }
1091 
1092     if (!failing() && target->needs_clinit_barrier() &&
1093         target->holder()->is_in_error_state()) {
1094       record_failure("method holder is in error state");
1095     }
1096 
1097     if (!failing()) {
1098       if (log() != NULL) {
1099         // Log the dependencies which this compilation declares.
1100         dependencies()->log_all_dependencies();
1101       }
1102 
1103       // Encode the dependencies now, so we can check them right away.
1104       dependencies()->encode_content_bytes();
1105 
1106       // Check for {class loads, evolution, breakpoints, ...} during compilation
1107       validate_compile_task_dependencies(target);
1108     }
1109 #if INCLUDE_RTM_OPT
1110     if (!failing() && (rtm_state != NoRTM) &&
1111         (method()->method_data() != NULL) &&
1112         (method()->method_data()->rtm_state() != rtm_state)) {
1113       // Preemptive decompile if rtm state was changed.
1114       record_failure("RTM state change invalidated rtm code");
1115     }
1116 #endif
1117 
1118     if (failing()) {
1119       // While not a true deoptimization, it is a preemptive decompile.
1120       MethodData* mdo = method()->method_data();
1121       if (mdo != NULL && _inc_decompile_count_on_failure) {
1122         mdo->inc_decompile_count();
1123       }
1124 
1125       // All buffers in the CodeBuffer are allocated in the CodeCache.
1126       // If the code buffer is created on each compile attempt
1127       // as in C2, then it must be freed.
1128       code_buffer->free_blob();
1129       return;
1130     }
1131 
1132     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1133     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1134 
1135     nm =  nmethod::new_nmethod(method,
1136                                compile_id(),
1137                                entry_bci,
1138                                offsets,
1139                                orig_pc_offset,
1140                                debug_info(), dependencies(), code_buffer,
1141                                frame_words, oop_map_set,
1142                                handler_table, inc_table,
1143                                compiler, task()->comp_level());
1144 
1145     // Free codeBlobs
1146     code_buffer->free_blob();
1147 
1148     if (nm != NULL) {
1149       nm->set_has_unsafe_access(has_unsafe_access);
1150       nm->set_has_wide_vectors(has_wide_vectors);
1151 #if INCLUDE_RTM_OPT
1152       nm->set_rtm_state(rtm_state);
1153 #endif
1154 
1155       // Record successful registration.
1156       // (Put nm into the task handle *before* publishing to the Java heap.)
1157       if (task() != NULL) {
1158         task()->set_code(nm);
1159       }
1160 
1161       if (entry_bci == InvocationEntryBci) {
1162         if (TieredCompilation) {
1163           // If there is an old version we're done with it
1164           CompiledMethod* old = method->code();
1165           if (TraceMethodReplacement && old != NULL) {
1166             ResourceMark rm;
1167             char *method_name = method->name_and_sig_as_C_string();
1168             tty->print_cr("Replacing method %s", method_name);
1169           }
1170           if (old != NULL) {
1171             old->make_not_used();
1172           }
1173         }
1174 
1175         LogTarget(Info, nmethod, install) lt;
1176         if (lt.is_enabled()) {
1177           ResourceMark rm;
1178           char *method_name = method->name_and_sig_as_C_string();
1179           lt.print("Installing method (%d) %s ",
1180                     task()->comp_level(), method_name);
1181         }
1182         // Allow the code to be executed
1183         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1184         if (nm->make_in_use()) {
1185           method->set_code(method, nm);
1186         }
1187       } else {
1188         LogTarget(Info, nmethod, install) lt;
1189         if (lt.is_enabled()) {
1190           ResourceMark rm;
1191           char *method_name = method->name_and_sig_as_C_string();
1192           lt.print("Installing osr method (%d) %s @ %d",
1193                     task()->comp_level(), method_name, entry_bci);
1194         }
1195         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1196         if (nm->make_in_use()) {
1197           method->method_holder()->add_osr_nmethod(nm);
1198         }
1199       }
1200     }
1201   }  // safepoints are allowed again
1202 
1203   if (nm != NULL) {
1204     // JVMTI -- compiled method notification (must be done outside lock)
1205     nm->post_compiled_method_load_event();
1206   } else {
1207     // The CodeCache is full.
1208     record_failure("code cache is full");
1209   }
1210 }
1211 
1212 // ------------------------------------------------------------------
1213 // ciEnv::comp_level
1214 int ciEnv::comp_level() {
1215   if (task() == NULL)  return CompilationPolicy::highest_compile_level();
1216   return task()->comp_level();
1217 }
1218 
1219 // ------------------------------------------------------------------
1220 // ciEnv::compile_id
1221 uint ciEnv::compile_id() {
1222   if (task() == NULL)  return 0;
1223   return task()->compile_id();
1224 }
1225 
1226 // ------------------------------------------------------------------
1227 // ciEnv::notice_inlined_method()
1228 void ciEnv::notice_inlined_method(ciMethod* method) {
1229   _num_inlined_bytecodes += method->code_size_for_inlining();
1230 }
1231 
1232 // ------------------------------------------------------------------
1233 // ciEnv::num_inlined_bytecodes()
1234 int ciEnv::num_inlined_bytecodes() const {
1235   return _num_inlined_bytecodes;
1236 }
1237 
1238 // ------------------------------------------------------------------
1239 // ciEnv::record_failure()
1240 void ciEnv::record_failure(const char* reason) {
1241   if (_failure_reason == NULL) {
1242     // Record the first failure reason.
1243     _failure_reason = reason;
1244   }
1245 }
1246 
1247 void ciEnv::report_failure(const char* reason) {
1248   EventCompilationFailure event;
1249   if (event.should_commit()) {
1250     CompilerEvent::CompilationFailureEvent::post(event, compile_id(), reason);
1251   }
1252 }
1253 
1254 // ------------------------------------------------------------------
1255 // ciEnv::record_method_not_compilable()
1256 void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) {
1257   int new_compilable =
1258     all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ;
1259 
1260   // Only note transitions to a worse state
1261   if (new_compilable > _compilable) {
1262     if (log() != NULL) {
1263       if (all_tiers) {
1264         log()->elem("method_not_compilable");
1265       } else {
1266         log()->elem("method_not_compilable_at_tier level='%d'",
1267                     current()->task()->comp_level());
1268       }
1269     }
1270     _compilable = new_compilable;
1271 
1272     // Reset failure reason; this one is more important.
1273     _failure_reason = NULL;
1274     record_failure(reason);
1275   }
1276 }
1277 
1278 // ------------------------------------------------------------------
1279 // ciEnv::record_out_of_memory_failure()
1280 void ciEnv::record_out_of_memory_failure() {
1281   // If memory is low, we stop compiling methods.
1282   record_method_not_compilable("out of memory");
1283 }
1284 
1285 ciInstance* ciEnv::unloaded_ciinstance() {
1286   GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();)
1287 }
1288 
1289 // ------------------------------------------------------------------
1290 // Replay support
1291 
1292 
1293 // Lookup location descriptor for the class, if any.
1294 // Returns false if not found.
1295 bool ciEnv::dyno_loc(const InstanceKlass* ik, const char *&loc) const {
1296   bool found = false;
1297   int pos = _dyno_klasses->find_sorted<const InstanceKlass*, klass_compare>(ik, found);
1298   if (!found) {
1299     return false;
1300   }
1301   loc = _dyno_locs->at(pos);
1302   return found;
1303 }
1304 
1305 // Associate the current location descriptor with the given class and record for later lookup.
1306 void ciEnv::set_dyno_loc(const InstanceKlass* ik) {
1307   const char *loc = os::strdup(_dyno_name);
1308   bool found = false;
1309   int pos = _dyno_klasses->find_sorted<const InstanceKlass*, klass_compare>(ik, found);
1310   if (found) {
1311     _dyno_locs->at_put(pos, loc);
1312   } else {
1313     _dyno_klasses->insert_before(pos, ik);
1314     _dyno_locs->insert_before(pos, loc);
1315   }
1316 }
1317 
1318 // Associate the current location descriptor with the given class and record for later lookup.
1319 // If it turns out that there are multiple locations for the given class, that conflict should
1320 // be handled here.  Currently we choose the first location found.
1321 void ciEnv::record_best_dyno_loc(const InstanceKlass* ik) {
1322   if (!ik->is_hidden()) {
1323     return;
1324   }
1325   const char *loc0;
1326   if (dyno_loc(ik, loc0)) {
1327     // TODO: found multiple references, see if we can improve
1328     if (Verbose) {
1329       tty->print_cr("existing call site @ %s for %s",
1330                      loc0, ik->external_name());
1331     }
1332   } else {
1333     set_dyno_loc(ik);
1334   }
1335 }
1336 
1337 // Look up the location descriptor for the given class and print it to the output stream.
1338 bool ciEnv::print_dyno_loc(outputStream* out, const InstanceKlass* ik) const {
1339   const char *loc;
1340   if (dyno_loc(ik, loc)) {
1341     out->print("%s", loc);
1342     return true;
1343   } else {
1344     return false;
1345   }
1346 }
1347 
1348 // Look up the location descriptor for the given class and return it as a string.
1349 // Returns NULL if no location is found.
1350 const char *ciEnv::dyno_name(const InstanceKlass* ik) const {
1351   if (ik->is_hidden()) {
1352     stringStream ss;
1353     if (print_dyno_loc(&ss, ik)) {
1354       ss.print(" ;"); // add terminator
1355       const char* call_site = ss.as_string();
1356       return call_site;
1357     }
1358   }
1359   return NULL;
1360 }
1361 
1362 // Look up the location descriptor for the given class and return it as a string.
1363 // Returns the class name as a fallback if no location is found.
1364 const char *ciEnv::replay_name(ciKlass* k) const {
1365   if (k->is_instance_klass()) {
1366     return replay_name(k->as_instance_klass()->get_instanceKlass());
1367   }
1368   return k->name()->as_quoted_ascii();
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(const InstanceKlass* ik) const {
1374   const char* name = dyno_name(ik);
1375   if (name != NULL) {
1376       return name;
1377   }
1378   return ik->name()->as_quoted_ascii();
1379 }
1380 
1381 // Process a java.lang.invoke.MemberName object and record any dynamic locations.
1382 void ciEnv::record_member(Thread* thread, oop member) {
1383   assert(java_lang_invoke_MemberName::is_instance(member), "!");
1384   // Check MemberName.clazz field
1385   oop clazz = java_lang_invoke_MemberName::clazz(member);
1386   if (clazz->klass()->is_instance_klass()) {
1387     RecordLocation fp(this, "clazz");
1388     InstanceKlass* ik = InstanceKlass::cast(clazz->klass());
1389     record_best_dyno_loc(ik);
1390   }
1391   // Check MemberName.method.vmtarget field
1392   Method* vmtarget = java_lang_invoke_MemberName::vmtarget(member);
1393   if (vmtarget != NULL) {
1394     RecordLocation fp2(this, "<vmtarget>");
1395     InstanceKlass* ik = vmtarget->method_holder();
1396     record_best_dyno_loc(ik);
1397   }
1398 }
1399 
1400 // Read an object field.  Lookup is done by name only.
1401 static inline oop obj_field(oop obj, const char* name) {
1402     return ciReplay::obj_field(obj, name);
1403 }
1404 
1405 // Process a java.lang.invoke.LambdaForm object and record any dynamic locations.
1406 void ciEnv::record_lambdaform(Thread* thread, oop form) {
1407   assert(java_lang_invoke_LambdaForm::is_instance(form), "!");
1408 
1409   {
1410     // Check LambdaForm.vmentry field
1411     oop member = java_lang_invoke_LambdaForm::vmentry(form);
1412     RecordLocation fp0(this, "vmentry");
1413     record_member(thread, member);
1414   }
1415 
1416   // Check LambdaForm.names array
1417   objArrayOop names = (objArrayOop)obj_field(form, "names");
1418   if (names != NULL) {
1419     RecordLocation lp0(this, "names");
1420     int len = names->length();
1421     for (int i = 0; i < len; ++i) {
1422       oop name = names->obj_at(i);
1423       RecordLocation lp1(this, "%d", i);
1424      // Check LambdaForm.names[i].function field
1425       RecordLocation lp2(this, "function");
1426       oop function = obj_field(name, "function");
1427       if (function != NULL) {
1428         // Check LambdaForm.names[i].function.member field
1429         oop member = obj_field(function, "member");
1430         if (member != NULL) {
1431           RecordLocation lp3(this, "member");
1432           record_member(thread, member);
1433         }
1434         // Check LambdaForm.names[i].function.resolvedHandle field
1435         oop mh = obj_field(function, "resolvedHandle");
1436         if (mh != NULL) {
1437           RecordLocation lp3(this, "resolvedHandle");
1438           record_mh(thread, mh);
1439         }
1440         // Check LambdaForm.names[i].function.invoker field
1441         oop invoker = obj_field(function, "invoker");
1442         if (invoker != NULL) {
1443           RecordLocation lp3(this, "invoker");
1444           record_mh(thread, invoker);
1445         }
1446       }
1447     }
1448   }
1449 }
1450 
1451 // Process a java.lang.invoke.MethodHandle object and record any dynamic locations.
1452 void ciEnv::record_mh(Thread* thread, oop mh) {
1453   {
1454     // Check MethodHandle.form field
1455     oop form = java_lang_invoke_MethodHandle::form(mh);
1456     RecordLocation fp(this, "form");
1457     record_lambdaform(thread, form);
1458   }
1459   // Check DirectMethodHandle.member field
1460   if (java_lang_invoke_DirectMethodHandle::is_instance(mh)) {
1461     oop member = java_lang_invoke_DirectMethodHandle::member(mh);
1462     RecordLocation fp(this, "member");
1463     record_member(thread, member);
1464   } else {
1465     // Check <MethodHandle subclass>.argL<n> fields
1466     // Probably BoundMethodHandle.Species_L*, but we only care if the field exists
1467     char arg_name[] = "argLXX";
1468     int max_arg = 99;
1469     for (int index = 0; index <= max_arg; ++index) {
1470       jio_snprintf(arg_name, sizeof (arg_name), "argL%d", index);
1471       oop arg = obj_field(mh, arg_name);
1472       if (arg != NULL) {
1473         RecordLocation fp(this, "%s", arg_name);
1474         if (arg->klass()->is_instance_klass()) {
1475           InstanceKlass* ik2 = InstanceKlass::cast(arg->klass());
1476           record_best_dyno_loc(ik2);
1477           record_call_site_obj(thread, arg);
1478         }
1479       } else {
1480         break;
1481       }
1482     }
1483   }
1484 }
1485 
1486 // Process an object found at an invokedynamic/invokehandle call site and record any dynamic locations.
1487 // Types currently supported are MethodHandle and CallSite.
1488 // The object is typically the "appendix" object, or Bootstrap Method (BSM) object.
1489 void ciEnv::record_call_site_obj(Thread* thread, oop obj)
1490 {
1491   if (obj != NULL) {
1492     if (java_lang_invoke_MethodHandle::is_instance(obj)) {
1493         record_mh(thread, obj);
1494     } else if (java_lang_invoke_ConstantCallSite::is_instance(obj)) {
1495       oop target = java_lang_invoke_CallSite::target(obj);
1496       if (target->klass()->is_instance_klass()) {
1497         RecordLocation fp(this, "target");
1498         InstanceKlass* ik = InstanceKlass::cast(target->klass());
1499         record_best_dyno_loc(ik);
1500       }
1501     }
1502   }
1503 }
1504 
1505 // Process an adapter Method* found at an invokedynamic/invokehandle call site and record any dynamic locations.
1506 void ciEnv::record_call_site_method(Thread* thread, Method* adapter) {
1507   InstanceKlass* holder = adapter->method_holder();
1508   if (!holder->is_hidden()) {
1509     return;
1510   }
1511   RecordLocation fp(this, "<adapter>");
1512   record_best_dyno_loc(holder);
1513 }
1514 
1515 // Process an invokedynamic call site and record any dynamic locations.
1516 void ciEnv::process_invokedynamic(const constantPoolHandle &cp, int indy_index, JavaThread* thread) {
1517   ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(indy_index);
1518   if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
1519     // process the adapter
1520     Method* adapter = cp_cache_entry->f1_as_method();
1521     record_call_site_method(thread, adapter);
1522     // process the appendix
1523     oop appendix = cp_cache_entry->appendix_if_resolved(cp);
1524     {
1525       RecordLocation fp(this, "<appendix>");
1526       record_call_site_obj(thread, appendix);
1527     }
1528     // process the BSM
1529     int pool_index = cp_cache_entry->constant_pool_index();
1530     BootstrapInfo bootstrap_specifier(cp, pool_index, indy_index);
1531     oop bsm = cp->resolve_possibly_cached_constant_at(bootstrap_specifier.bsm_index(), thread);
1532     {
1533       RecordLocation fp(this, "<bsm>");
1534       record_call_site_obj(thread, bsm);
1535     }
1536   }
1537 }
1538 
1539 // Process an invokehandle call site and record any dynamic locations.
1540 void ciEnv::process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread) {
1541   const int holder_index = cp->klass_ref_index_at(index);
1542   if (!cp->tag_at(holder_index).is_klass()) {
1543     return;  // not resolved
1544   }
1545   Klass* holder = ConstantPool::klass_at_if_loaded(cp, holder_index);
1546   Symbol* name = cp->name_ref_at(index);
1547   if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
1548     ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1549     if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
1550       // process the adapter
1551       Method* adapter = cp_cache_entry->f1_as_method();
1552       oop appendix = cp_cache_entry->appendix_if_resolved(cp);
1553       record_call_site_method(thread, adapter);
1554       // process the appendix
1555       {
1556         RecordLocation fp(this, "<appendix>");
1557         record_call_site_obj(thread, appendix);
1558       }
1559     }
1560   }
1561 }
1562 
1563 // Search the class hierarchy for dynamic classes reachable through dynamic call sites or
1564 // constant pool entries and record for future lookup.
1565 void ciEnv::find_dynamic_call_sites() {
1566   _dyno_klasses = new (arena()) GrowableArray<const InstanceKlass*>(arena(), 100, 0, NULL);
1567   _dyno_locs    = new (arena()) GrowableArray<const char *>(arena(), 100, 0, NULL);
1568 
1569   // Iterate over the class hierarchy
1570   for (ClassHierarchyIterator iter(vmClasses::Object_klass()); !iter.done(); iter.next()) {
1571     Klass* sub = iter.klass();
1572     if (sub->is_instance_klass()) {
1573       InstanceKlass *isub = InstanceKlass::cast(sub);
1574       InstanceKlass* ik = isub;
1575       if (!ik->is_linked()) {
1576         continue;
1577       }
1578       if (ik->is_hidden()) {
1579         continue;
1580       }
1581       JavaThread* thread = JavaThread::current();
1582       const constantPoolHandle pool(thread, ik->constants());
1583 
1584       // Look for invokedynamic/invokehandle call sites
1585       for (int i = 0; i < ik->methods()->length(); ++i) {
1586         Method* m = ik->methods()->at(i);
1587 
1588         BytecodeStream bcs(methodHandle(thread, m));
1589         while (!bcs.is_last_bytecode()) {
1590           Bytecodes::Code opcode = bcs.next();
1591           opcode = bcs.raw_code();
1592           switch (opcode) {
1593           case Bytecodes::_invokedynamic:
1594           case Bytecodes::_invokehandle: {
1595             RecordLocation fp(this, "@bci %s %s %s %d",
1596                          ik->name()->as_quoted_ascii(),
1597                          m->name()->as_quoted_ascii(), m->signature()->as_quoted_ascii(),
1598                          bcs.bci());
1599             if (opcode == Bytecodes::_invokedynamic) {
1600               int index = bcs.get_index_u4();
1601               process_invokedynamic(pool, index, thread);
1602             } else {
1603               assert(opcode == Bytecodes::_invokehandle, "new switch label added?");
1604               int cp_cache_index = bcs.get_index_u2_cpcache();
1605               process_invokehandle(pool, cp_cache_index, thread);
1606             }
1607             break;
1608           }
1609           default:
1610             break;
1611           }
1612         }
1613       }
1614 
1615       // Look for MethodHandle constant pool entries
1616       RecordLocation fp(this, "@cpi %s", ik->name()->as_quoted_ascii());
1617       int len = pool->length();
1618       for (int i = 0; i < len; ++i) {
1619         if (pool->tag_at(i).is_method_handle()) {
1620           bool found_it;
1621           oop mh = pool->find_cached_constant_at(i, found_it, thread);
1622           if (mh != NULL) {
1623             RecordLocation fp(this, "%d", i);
1624             record_mh(thread, mh);
1625           }
1626         }
1627       }
1628     }
1629   }
1630 }
1631 
1632 void ciEnv::dump_compile_data(outputStream* out) {
1633   CompileTask* task = this->task();
1634   if (task) {
1635     Method* method = task->method();
1636     int entry_bci = task->osr_bci();
1637     int comp_level = task->comp_level();
1638     out->print("compile ");
1639     get_method(method)->dump_name_as_ascii(out);
1640     out->print(" %d %d", entry_bci, comp_level);
1641     if (compiler_data() != NULL) {
1642       if (is_c2_compile(comp_level)) {
1643 #ifdef COMPILER2
1644         // Dump C2 inlining data.
1645         ((Compile*)compiler_data())->dump_inline_data(out);
1646 #endif
1647       } else if (is_c1_compile(comp_level)) {
1648 #ifdef COMPILER1
1649         // Dump C1 inlining data.
1650         ((Compilation*)compiler_data())->dump_inline_data(out);
1651 #endif
1652       }
1653     }
1654     out->cr();
1655   }
1656 }
1657 
1658 // Called from VM error reporter, so be careful.
1659 // Don't safepoint or acquire any locks.
1660 //
1661 void ciEnv::dump_replay_data_helper(outputStream* out) {
1662   NoSafepointVerifier no_safepoint;
1663   ResourceMark rm;
1664 
1665   out->print_cr("version %d", REPLAY_VERSION);
1666 #if INCLUDE_JVMTI
1667   out->print_cr("JvmtiExport can_access_local_variables %d",     _jvmti_can_access_local_variables);
1668   out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint);
1669   out->print_cr("JvmtiExport can_post_on_exceptions %d",         _jvmti_can_post_on_exceptions);
1670 #endif // INCLUDE_JVMTI
1671 
1672   find_dynamic_call_sites();
1673 
1674   GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata();
1675   out->print_cr("# %d ciObject found", objects->length());
1676 
1677   // The very first entry is the InstanceKlass of the root method of the current compilation in order to get the right
1678   // protection domain to load subsequent classes during replay compilation.
1679   ciInstanceKlass::dump_replay_instanceKlass(out, task()->method()->method_holder());
1680 
1681   for (int i = 0; i < objects->length(); i++) {
1682     objects->at(i)->dump_replay_data(out);
1683   }
1684   dump_compile_data(out);
1685   out->flush();
1686 }
1687 
1688 // Called from VM error reporter, so be careful.
1689 // Don't safepoint or acquire any locks.
1690 //
1691 void ciEnv::dump_replay_data_unsafe(outputStream* out) {
1692   GUARDED_VM_ENTRY(
1693     dump_replay_data_helper(out);
1694   )
1695 }
1696 
1697 void ciEnv::dump_replay_data(outputStream* out) {
1698   GUARDED_VM_ENTRY(
1699     MutexLocker ml(Compile_lock);
1700     dump_replay_data_helper(out);
1701   )
1702 }
1703 
1704 void ciEnv::dump_replay_data(int compile_id) {
1705   char buffer[64];
1706   int ret = jio_snprintf(buffer, sizeof(buffer), "replay_pid%d_compid%d.log", os::current_process_id(), compile_id);
1707   if (ret > 0) {
1708     int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
1709     if (fd != -1) {
1710       FILE* replay_data_file = os::fdopen(fd, "w");
1711       if (replay_data_file != NULL) {
1712         fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
1713         dump_replay_data(&replay_data_stream);
1714         tty->print_cr("# Compiler replay data is saved as: %s", buffer);
1715       } else {
1716         tty->print_cr("# Can't open file to dump replay data.");
1717       }
1718     }
1719   }
1720 }
1721 
1722 void ciEnv::dump_inline_data(int compile_id) {
1723   char buffer[64];
1724   int ret = jio_snprintf(buffer, sizeof(buffer), "inline_pid%d_compid%d.log", os::current_process_id(), compile_id);
1725   if (ret > 0) {
1726     int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
1727     if (fd != -1) {
1728       FILE* inline_data_file = os::fdopen(fd, "w");
1729       if (inline_data_file != NULL) {
1730         fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1731         GUARDED_VM_ENTRY(
1732           MutexLocker ml(Compile_lock);
1733           dump_compile_data(&replay_data_stream);
1734         )
1735         replay_data_stream.flush();
1736         tty->print("# Compiler inline data is saved as: ");
1737         tty->print_cr("%s", buffer);
1738       } else {
1739         tty->print_cr("# Can't open file to dump inline data.");
1740       }
1741     }
1742   }
1743 }