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