src/share/vm/ci/ciEnv.cpp

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 7535
7ae4e26cb1e0
parent 9858
b985cbb00e68
child 10015
eb7ce841ccec
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1999, 2014, 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  */
    25 #include "precompiled.hpp"
    26 #include "ci/ciConstant.hpp"
    27 #include "ci/ciEnv.hpp"
    28 #include "ci/ciField.hpp"
    29 #include "ci/ciInstance.hpp"
    30 #include "ci/ciInstanceKlass.hpp"
    31 #include "ci/ciMethod.hpp"
    32 #include "ci/ciNullObject.hpp"
    33 #include "ci/ciReplay.hpp"
    34 #include "ci/ciUtilities.hpp"
    35 #include "classfile/systemDictionary.hpp"
    36 #include "classfile/vmSymbols.hpp"
    37 #include "code/scopeDesc.hpp"
    38 #include "compiler/compileBroker.hpp"
    39 #include "compiler/compileLog.hpp"
    40 #include "compiler/compilerOracle.hpp"
    41 #include "gc_interface/collectedHeap.inline.hpp"
    42 #include "interpreter/linkResolver.hpp"
    43 #include "jfr/jfrEvents.hpp"
    44 #include "memory/allocation.inline.hpp"
    45 #include "memory/oopFactory.hpp"
    46 #include "memory/universe.inline.hpp"
    47 #include "oops/methodData.hpp"
    48 #include "oops/objArrayKlass.hpp"
    49 #include "oops/oop.inline.hpp"
    50 #include "oops/oop.inline2.hpp"
    51 #include "prims/jvmtiExport.hpp"
    52 #include "runtime/init.hpp"
    53 #include "runtime/reflection.hpp"
    54 #include "runtime/sharedRuntime.hpp"
    55 #include "runtime/thread.inline.hpp"
    56 #include "utilities/dtrace.hpp"
    57 #include "utilities/macros.hpp"
    58 #ifdef COMPILER1
    59 #include "c1/c1_Runtime1.hpp"
    60 #endif
    61 #ifdef COMPILER2
    62 #include "opto/runtime.hpp"
    63 #endif
    65 // ciEnv
    66 //
    67 // This class is the top level broker for requests from the compiler
    68 // to the VM.
    70 ciObject*              ciEnv::_null_object_instance;
    72 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
    73 WK_KLASSES_DO(WK_KLASS_DEFN)
    74 #undef WK_KLASS_DEFN
    76 ciSymbol*        ciEnv::_unloaded_cisymbol = NULL;
    77 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL;
    78 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL;
    80 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL;
    81 jobject ciEnv::_ArrayStoreException_handle = NULL;
    82 jobject ciEnv::_ClassCastException_handle = NULL;
    84 #ifndef PRODUCT
    85 static bool firstEnv = true;
    86 #endif /* PRODUCT */
    88 // ------------------------------------------------------------------
    89 // ciEnv::ciEnv
    90 ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter)
    91   : _ciEnv_arena(mtCompiler) {
    92   VM_ENTRY_MARK;
    94   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
    95   thread->set_env(this);
    96   assert(ciEnv::current() == this, "sanity");
    98   _oop_recorder = NULL;
    99   _debug_info = NULL;
   100   _dependencies = NULL;
   101   _failure_reason = NULL;
   102   _compilable = MethodCompilable;
   103   _break_at_compile = false;
   104   _compiler_data = NULL;
   105 #ifndef PRODUCT
   106   assert(!firstEnv, "not initialized properly");
   107 #endif /* !PRODUCT */
   109   _system_dictionary_modification_counter = system_dictionary_modification_counter;
   110   _num_inlined_bytecodes = 0;
   111   assert(task == NULL || thread->task() == task, "sanity");
   112   _task = task;
   113   _log = NULL;
   115   // Temporary buffer for creating symbols and such.
   116   _name_buffer = NULL;
   117   _name_buffer_len = 0;
   119   _arena   = &_ciEnv_arena;
   120   _factory = new (_arena) ciObjectFactory(_arena, 128);
   122   // Preload commonly referenced system ciObjects.
   124   // During VM initialization, these instances have not yet been created.
   125   // Assertions ensure that these instances are not accessed before
   126   // their initialization.
   128   assert(Universe::is_fully_initialized(), "should be complete");
   130   oop o = Universe::null_ptr_exception_instance();
   131   assert(o != NULL, "should have been initialized");
   132   _NullPointerException_instance = get_object(o)->as_instance();
   133   o = Universe::arithmetic_exception_instance();
   134   assert(o != NULL, "should have been initialized");
   135   _ArithmeticException_instance = get_object(o)->as_instance();
   137   _ArrayIndexOutOfBoundsException_instance = NULL;
   138   _ArrayStoreException_instance = NULL;
   139   _ClassCastException_instance = NULL;
   140   _the_null_string = NULL;
   141   _the_min_jint_string = NULL;
   142 }
   144 ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) {
   145   ASSERT_IN_VM;
   147   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
   148   CompilerThread* current_thread = CompilerThread::current();
   149   assert(current_thread->env() == NULL, "must be");
   150   current_thread->set_env(this);
   151   assert(ciEnv::current() == this, "sanity");
   153   _oop_recorder = NULL;
   154   _debug_info = NULL;
   155   _dependencies = NULL;
   156   _failure_reason = NULL;
   157   _compilable = MethodCompilable_never;
   158   _break_at_compile = false;
   159   _compiler_data = NULL;
   160 #ifndef PRODUCT
   161   assert(firstEnv, "must be first");
   162   firstEnv = false;
   163 #endif /* !PRODUCT */
   165   _system_dictionary_modification_counter = 0;
   166   _num_inlined_bytecodes = 0;
   167   _task = NULL;
   168   _log = NULL;
   170   // Temporary buffer for creating symbols and such.
   171   _name_buffer = NULL;
   172   _name_buffer_len = 0;
   174   _arena   = arena;
   175   _factory = new (_arena) ciObjectFactory(_arena, 128);
   177   // Preload commonly referenced system ciObjects.
   179   // During VM initialization, these instances have not yet been created.
   180   // Assertions ensure that these instances are not accessed before
   181   // their initialization.
   183   assert(Universe::is_fully_initialized(), "must be");
   185   _NullPointerException_instance = NULL;
   186   _ArithmeticException_instance = NULL;
   187   _ArrayIndexOutOfBoundsException_instance = NULL;
   188   _ArrayStoreException_instance = NULL;
   189   _ClassCastException_instance = NULL;
   190   _the_null_string = NULL;
   191   _the_min_jint_string = NULL;
   192 }
   194 ciEnv::~ciEnv() {
   195   CompilerThread* current_thread = CompilerThread::current();
   196   _factory->remove_symbols();
   197   // Need safepoint to clear the env on the thread.  RedefineClasses might
   198   // be reading it.
   199   GUARDED_VM_ENTRY(current_thread->set_env(NULL);)
   200 }
   202 // ------------------------------------------------------------------
   203 // Cache Jvmti state
   204 void ciEnv::cache_jvmti_state() {
   205   VM_ENTRY_MARK;
   206   // Get Jvmti capabilities under lock to get consistant values.
   207   MutexLocker mu(JvmtiThreadState_lock);
   208   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
   209   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables();
   210   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions();
   211 }
   213 // ------------------------------------------------------------------
   214 // Cache DTrace flags
   215 void ciEnv::cache_dtrace_flags() {
   216   // Need lock?
   217   _dtrace_extended_probes = ExtendedDTraceProbes;
   218   if (_dtrace_extended_probes) {
   219     _dtrace_monitor_probes  = true;
   220     _dtrace_method_probes   = true;
   221     _dtrace_alloc_probes    = true;
   222   } else {
   223     _dtrace_monitor_probes  = DTraceMonitorProbes;
   224     _dtrace_method_probes   = DTraceMethodProbes;
   225     _dtrace_alloc_probes    = DTraceAllocProbes;
   226   }
   227 }
   229 // ------------------------------------------------------------------
   230 // helper for lazy exception creation
   231 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
   232   VM_ENTRY_MARK;
   233   if (handle == NULL) {
   234     // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
   235     Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD);
   236     jobject objh = NULL;
   237     if (!HAS_PENDING_EXCEPTION && k != NULL) {
   238       oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD);
   239       if (!HAS_PENDING_EXCEPTION)
   240         objh = JNIHandles::make_global(obj);
   241     }
   242     if (HAS_PENDING_EXCEPTION) {
   243       CLEAR_PENDING_EXCEPTION;
   244     } else {
   245       handle = objh;
   246     }
   247   }
   248   oop obj = JNIHandles::resolve(handle);
   249   return obj == NULL? NULL: get_object(obj)->as_instance();
   250 }
   252 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
   253   if (_ArrayIndexOutOfBoundsException_instance == NULL) {
   254     _ArrayIndexOutOfBoundsException_instance
   255           = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
   256           vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
   257   }
   258   return _ArrayIndexOutOfBoundsException_instance;
   259 }
   260 ciInstance* ciEnv::ArrayStoreException_instance() {
   261   if (_ArrayStoreException_instance == NULL) {
   262     _ArrayStoreException_instance
   263           = get_or_create_exception(_ArrayStoreException_handle,
   264           vmSymbols::java_lang_ArrayStoreException());
   265   }
   266   return _ArrayStoreException_instance;
   267 }
   268 ciInstance* ciEnv::ClassCastException_instance() {
   269   if (_ClassCastException_instance == NULL) {
   270     _ClassCastException_instance
   271           = get_or_create_exception(_ClassCastException_handle,
   272           vmSymbols::java_lang_ClassCastException());
   273   }
   274   return _ClassCastException_instance;
   275 }
   277 ciInstance* ciEnv::the_null_string() {
   278   if (_the_null_string == NULL) {
   279     VM_ENTRY_MARK;
   280     _the_null_string = get_object(Universe::the_null_string())->as_instance();
   281   }
   282   return _the_null_string;
   283 }
   285 ciInstance* ciEnv::the_min_jint_string() {
   286   if (_the_min_jint_string == NULL) {
   287     VM_ENTRY_MARK;
   288     _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
   289   }
   290   return _the_min_jint_string;
   291 }
   293 // ------------------------------------------------------------------
   294 // ciEnv::get_method_from_handle
   295 ciMethod* ciEnv::get_method_from_handle(Method* method) {
   296   VM_ENTRY_MARK;
   297   return get_metadata(method)->as_method();
   298 }
   300 // ------------------------------------------------------------------
   301 // ciEnv::array_element_offset_in_bytes
   302 int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) {
   303   VM_ENTRY_MARK;
   304   objArrayOop a = (objArrayOop)a_h->get_oop();
   305   assert(a->is_objArray(), "");
   306   int length = a->length();
   307   oop o = o_h->get_oop();
   308   for (int i = 0; i < length; i++) {
   309     if (a->obj_at(i) == o)  return i;
   310   }
   311   return -1;
   312 }
   315 // ------------------------------------------------------------------
   316 // ciEnv::check_klass_accessiblity
   317 //
   318 // Note: the logic of this method should mirror the logic of
   319 // ConstantPool::verify_constant_pool_resolve.
   320 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass,
   321                                       Klass* resolved_klass) {
   322   if (accessing_klass == NULL || !accessing_klass->is_loaded()) {
   323     return true;
   324   }
   325   if (accessing_klass->is_obj_array_klass()) {
   326     accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass();
   327   }
   328   if (!accessing_klass->is_instance_klass()) {
   329     return true;
   330   }
   332   if (resolved_klass->oop_is_objArray()) {
   333     // Find the element klass, if this is an array.
   334     resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
   335   }
   336   if (resolved_klass->oop_is_instance()) {
   337     return Reflection::verify_class_access(accessing_klass->get_Klass(),
   338                                            resolved_klass,
   339                                            true);
   340   }
   341   return true;
   342 }
   344 // ------------------------------------------------------------------
   345 // ciEnv::get_klass_by_name_impl
   346 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
   347                                        constantPoolHandle cpool,
   348                                        ciSymbol* name,
   349                                        bool require_local) {
   350   ASSERT_IN_VM;
   351   EXCEPTION_CONTEXT;
   353   // Now we need to check the SystemDictionary
   354   Symbol* sym = name->get_symbol();
   355   if (sym->byte_at(0) == 'L' &&
   356     sym->byte_at(sym->utf8_length()-1) == ';') {
   357     // This is a name from a signature.  Strip off the trimmings.
   358     // Call recursive to keep scope of strippedsym.
   359     TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
   360                     sym->utf8_length()-2,
   361                     KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass));
   362     ciSymbol* strippedname = get_symbol(strippedsym);
   363     return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
   364   }
   366   // Check for prior unloaded klass.  The SystemDictionary's answers
   367   // can vary over time but the compiler needs consistency.
   368   ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
   369   if (unloaded_klass != NULL) {
   370     if (require_local)  return NULL;
   371     return unloaded_klass;
   372   }
   374   Handle loader(THREAD, (oop)NULL);
   375   Handle domain(THREAD, (oop)NULL);
   376   if (accessing_klass != NULL) {
   377     loader = Handle(THREAD, accessing_klass->loader());
   378     domain = Handle(THREAD, accessing_klass->protection_domain());
   379   }
   381   // setup up the proper type to return on OOM
   382   ciKlass* fail_type;
   383   if (sym->byte_at(0) == '[') {
   384     fail_type = _unloaded_ciobjarrayklass;
   385   } else {
   386     fail_type = _unloaded_ciinstance_klass;
   387   }
   388   KlassHandle found_klass;
   389   {
   390     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
   391     MutexLocker ml(Compile_lock);
   392     Klass* kls;
   393     if (!require_local) {
   394       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
   395                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
   396     } else {
   397       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
   398                                                            KILL_COMPILE_ON_FATAL_(fail_type));
   399     }
   400     found_klass = KlassHandle(THREAD, kls);
   401   }
   403   // If we fail to find an array klass, look again for its element type.
   404   // The element type may be available either locally or via constraints.
   405   // In either case, if we can find the element type in the system dictionary,
   406   // we must build an array type around it.  The CI requires array klasses
   407   // to be loaded if their element klasses are loaded, except when memory
   408   // is exhausted.
   409   if (sym->byte_at(0) == '[' &&
   410       (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) {
   411     // We have an unloaded array.
   412     // Build it on the fly if the element class exists.
   413     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
   414                                                  sym->utf8_length()-1,
   415                                                  KILL_COMPILE_ON_FATAL_(fail_type));
   417     // Get element ciKlass recursively.
   418     ciKlass* elem_klass =
   419       get_klass_by_name_impl(accessing_klass,
   420                              cpool,
   421                              get_symbol(elem_sym),
   422                              require_local);
   423     if (elem_klass != NULL && elem_klass->is_loaded()) {
   424       // Now make an array for it
   425       return ciObjArrayKlass::make_impl(elem_klass);
   426     }
   427   }
   429   if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
   430     // Look inside the constant pool for pre-resolved class entries.
   431     for (int i = cpool->length() - 1; i >= 1; i--) {
   432       if (cpool->tag_at(i).is_klass()) {
   433         Klass* kls = cpool->resolved_klass_at(i);
   434         if (kls->name() == sym) {
   435           found_klass = KlassHandle(THREAD, kls);
   436           break;
   437         }
   438       }
   439     }
   440   }
   442   if (found_klass() != NULL) {
   443     // Found it.  Build a CI handle.
   444     return get_klass(found_klass());
   445   }
   447   if (require_local)  return NULL;
   449   // Not yet loaded into the VM, or not governed by loader constraints.
   450   // Make a CI representative for it.
   451   return get_unloaded_klass(accessing_klass, name);
   452 }
   454 // ------------------------------------------------------------------
   455 // ciEnv::get_klass_by_name
   456 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
   457                                   ciSymbol* klass_name,
   458                                   bool require_local) {
   459   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
   460                                                  constantPoolHandle(),
   461                                                  klass_name,
   462                                                  require_local);)
   463 }
   465 // ------------------------------------------------------------------
   466 // ciEnv::get_klass_by_index_impl
   467 //
   468 // Implementation of get_klass_by_index.
   469 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
   470                                         int index,
   471                                         bool& is_accessible,
   472                                         ciInstanceKlass* accessor) {
   473   EXCEPTION_CONTEXT;
   474   KlassHandle klass; // = NULL;
   475   Symbol* klass_name = NULL;
   477   if (cpool->tag_at(index).is_symbol()) {
   478     klass_name = cpool->symbol_at(index);
   479   } else {
   480     // Check if it's resolved if it's not a symbol constant pool entry.
   481     klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index));
   483   if (klass.is_null()) {
   484     // The klass has not been inserted into the constant pool.
   485     // Try to look it up by name.
   486     {
   487       // We have to lock the cpool to keep the oop from being resolved
   488       // while we are accessing it.
   489         MonitorLockerEx ml(cpool->lock());
   490       constantTag tag = cpool->tag_at(index);
   491       if (tag.is_klass()) {
   492         // The klass has been inserted into the constant pool
   493         // very recently.
   494         klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
   495       } else {
   496         assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
   497         klass_name = cpool->unresolved_klass_at(index);
   498       }
   499     }
   500   }
   501   }
   503   if (klass.is_null()) {
   504     // Not found in constant pool.  Use the name to do the lookup.
   505     ciKlass* k = get_klass_by_name_impl(accessor,
   506                                         cpool,
   507                                         get_symbol(klass_name),
   508                                         false);
   509     // Calculate accessibility the hard way.
   510     if (!k->is_loaded()) {
   511       is_accessible = false;
   512     } else if (k->loader() != accessor->loader() &&
   513                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
   514       // Loaded only remotely.  Not linked yet.
   515       is_accessible = false;
   516     } else {
   517       // Linked locally, and we must also check public/private, etc.
   518       is_accessible = check_klass_accessibility(accessor, k->get_Klass());
   519     }
   520     return k;
   521   }
   523   // Check for prior unloaded klass.  The SystemDictionary's answers
   524   // can vary over time but the compiler needs consistency.
   525   ciSymbol* name = get_symbol(klass()->name());
   526   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
   527   if (unloaded_klass != NULL) {
   528     is_accessible = false;
   529     return unloaded_klass;
   530   }
   532   // It is known to be accessible, since it was found in the constant pool.
   533   is_accessible = true;
   534   return get_klass(klass());
   535 }
   537 // ------------------------------------------------------------------
   538 // ciEnv::get_klass_by_index
   539 //
   540 // Get a klass from the constant pool.
   541 ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool,
   542                                    int index,
   543                                    bool& is_accessible,
   544                                    ciInstanceKlass* accessor) {
   545   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
   546 }
   548 // ------------------------------------------------------------------
   549 // ciEnv::get_constant_by_index_impl
   550 //
   551 // Implementation of get_constant_by_index().
   552 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool,
   553                                              int pool_index, int cache_index,
   554                                              ciInstanceKlass* accessor) {
   555   bool ignore_will_link;
   556   EXCEPTION_CONTEXT;
   557   int index = pool_index;
   558   if (cache_index >= 0) {
   559     assert(index < 0, "only one kind of index at a time");
   560     oop obj = cpool->resolved_references()->obj_at(cache_index);
   561     if (obj != NULL) {
   562       ciObject* ciobj = get_object(obj);
   563       if (ciobj->is_array()) {
   564         return ciConstant(T_ARRAY, ciobj);
   565       } else {
   566         assert(ciobj->is_instance(), "should be an instance");
   567         return ciConstant(T_OBJECT, ciobj);
   568       }
   569     }
   570     index = cpool->object_to_cp_index(cache_index);
   571   }
   572   constantTag tag = cpool->tag_at(index);
   573   if (tag.is_int()) {
   574     return ciConstant(T_INT, (jint)cpool->int_at(index));
   575   } else if (tag.is_long()) {
   576     return ciConstant((jlong)cpool->long_at(index));
   577   } else if (tag.is_float()) {
   578     return ciConstant((jfloat)cpool->float_at(index));
   579   } else if (tag.is_double()) {
   580     return ciConstant((jdouble)cpool->double_at(index));
   581   } else if (tag.is_string()) {
   582     oop string = NULL;
   583     assert(cache_index >= 0, "should have a cache index");
   584     if (cpool->is_pseudo_string_at(index)) {
   585       string = cpool->pseudo_string_at(index, cache_index);
   586     } else {
   587       string = cpool->string_at(index, cache_index, THREAD);
   588       if (HAS_PENDING_EXCEPTION) {
   589         CLEAR_PENDING_EXCEPTION;
   590         record_out_of_memory_failure();
   591         return ciConstant();
   592       }
   593     }
   594     ciObject* constant = get_object(string);
   595     if (constant->is_array()) {
   596       return ciConstant(T_ARRAY, constant);
   597     } else {
   598       assert (constant->is_instance(), "must be an instance, or not? ");
   599       return ciConstant(T_OBJECT, constant);
   600     }
   601   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
   602     // 4881222: allow ldc to take a class type
   603     ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
   604     if (HAS_PENDING_EXCEPTION) {
   605       CLEAR_PENDING_EXCEPTION;
   606       record_out_of_memory_failure();
   607       return ciConstant();
   608     }
   609     assert (klass->is_instance_klass() || klass->is_array_klass(),
   610             "must be an instance or array klass ");
   611     return ciConstant(T_OBJECT, klass->java_mirror());
   612   } else if (tag.is_method_type()) {
   613     // must execute Java code to link this CP entry into cache[i].f1
   614     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
   615     ciObject* ciobj = get_unloaded_method_type_constant(signature);
   616     return ciConstant(T_OBJECT, ciobj);
   617   } else if (tag.is_method_handle()) {
   618     // must execute Java code to link this CP entry into cache[i].f1
   619     int ref_kind        = cpool->method_handle_ref_kind_at(index);
   620     int callee_index    = cpool->method_handle_klass_index_at(index);
   621     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
   622     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
   623     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
   624     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
   625     return ciConstant(T_OBJECT, ciobj);
   626   } else {
   627     ShouldNotReachHere();
   628     return ciConstant();
   629   }
   630 }
   632 // ------------------------------------------------------------------
   633 // ciEnv::get_constant_by_index
   634 //
   635 // Pull a constant out of the constant pool.  How appropriate.
   636 //
   637 // Implementation note: this query is currently in no way cached.
   638 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool,
   639                                         int pool_index, int cache_index,
   640                                         ciInstanceKlass* accessor) {
   641   GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);)
   642 }
   644 // ------------------------------------------------------------------
   645 // ciEnv::get_field_by_index_impl
   646 //
   647 // Implementation of get_field_by_index.
   648 //
   649 // Implementation note: the results of field lookups are cached
   650 // in the accessor klass.
   651 ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor,
   652                                         int index) {
   653   ciConstantPoolCache* cache = accessor->field_cache();
   654   if (cache == NULL) {
   655     ciField* field = new (arena()) ciField(accessor, index);
   656     return field;
   657   } else {
   658     ciField* field = (ciField*)cache->get(index);
   659     if (field == NULL) {
   660       field = new (arena()) ciField(accessor, index);
   661       cache->insert(index, field);
   662     }
   663     return field;
   664   }
   665 }
   667 // ------------------------------------------------------------------
   668 // ciEnv::get_field_by_index
   669 //
   670 // Get a field by index from a klass's constant pool.
   671 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor,
   672                                    int index) {
   673   GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);)
   674 }
   676 // ------------------------------------------------------------------
   677 // ciEnv::lookup_method
   678 //
   679 // Perform an appropriate method lookup based on accessor, holder,
   680 // name, signature, and bytecode.
   681 Method* ciEnv::lookup_method(InstanceKlass*  accessor,
   682                                InstanceKlass*  holder,
   683                                Symbol*       name,
   684                                Symbol*       sig,
   685                                Bytecodes::Code bc) {
   686   EXCEPTION_CONTEXT;
   687   KlassHandle h_accessor(THREAD, accessor);
   688   KlassHandle h_holder(THREAD, holder);
   689   LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
   690   methodHandle dest_method;
   691   switch (bc) {
   692   case Bytecodes::_invokestatic:
   693     dest_method =
   694       LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor);
   695     break;
   696   case Bytecodes::_invokespecial:
   697     dest_method =
   698       LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor);
   699     break;
   700   case Bytecodes::_invokeinterface:
   701     dest_method =
   702       LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig,
   703                                                               h_accessor, true);
   704     break;
   705   case Bytecodes::_invokevirtual:
   706     dest_method =
   707       LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig,
   708                                                             h_accessor, true);
   709     break;
   710   default: ShouldNotReachHere();
   711   }
   713   return dest_method();
   714 }
   717 // ------------------------------------------------------------------
   718 // ciEnv::get_method_by_index_impl
   719 ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool,
   720                                           int index, Bytecodes::Code bc,
   721                                           ciInstanceKlass* accessor) {
   722   if (bc == Bytecodes::_invokedynamic) {
   723     ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
   724     bool is_resolved = !cpce->is_f1_null();
   725     // FIXME: code generation could allow for null (unlinked) call site
   726     // The call site could be made patchable as follows:
   727     // Load the appendix argument from the constant pool.
   728     // Test the appendix argument and jump to a known deopt routine if it is null.
   729     // Jump through a patchable call site, which is initially a deopt routine.
   730     // Patch the call site to the nmethod entry point of the static compiled lambda form.
   731     // As with other two-component call sites, both values must be independently verified.
   733     if (is_resolved) {
   734       // Get the invoker Method* from the constant pool.
   735       // (The appendix argument, if any, will be noted in the method's signature.)
   736       Method* adapter = cpce->f1_as_method();
   737       return get_method(adapter);
   738     }
   740     // Fake a method that is equivalent to a declared method.
   741     ciInstanceKlass* holder    = get_instance_klass(SystemDictionary::MethodHandle_klass());
   742     ciSymbol*        name      = ciSymbol::invokeBasic_name();
   743     ciSymbol*        signature = get_symbol(cpool->signature_ref_at(index));
   744     return get_unloaded_method(holder, name, signature, accessor);
   745   } else {
   746     const int holder_index = cpool->klass_ref_index_at(index);
   747     bool holder_is_accessible;
   748     ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
   749     ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);
   751     // Get the method's name and signature.
   752     Symbol* name_sym = cpool->name_ref_at(index);
   753     Symbol* sig_sym  = cpool->signature_ref_at(index);
   755     if (cpool->has_preresolution()
   756         || (holder == ciEnv::MethodHandle_klass() &&
   757             MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) {
   758       // Short-circuit lookups for JSR 292-related call sites.
   759       // That is, do not rely only on name-based lookups, because they may fail
   760       // if the names are not resolvable in the boot class loader (7056328).
   761       switch (bc) {
   762       case Bytecodes::_invokevirtual:
   763       case Bytecodes::_invokeinterface:
   764       case Bytecodes::_invokespecial:
   765       case Bytecodes::_invokestatic:
   766         {
   767           Method* m = ConstantPool::method_at_if_loaded(cpool, index);
   768           if (m != NULL) {
   769             return get_method(m);
   770           }
   771         }
   772         break;
   773       }
   774     }
   776     if (holder_is_accessible) {  // Our declared holder is loaded.
   777       InstanceKlass* lookup = declared_holder->get_instanceKlass();
   778       Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
   779       if (m != NULL &&
   780           (bc == Bytecodes::_invokestatic
   781            ?  m->method_holder()->is_not_initialized()
   782            : !m->method_holder()->is_loaded())) {
   783         m = NULL;
   784       }
   785 #ifdef ASSERT
   786       if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) {
   787         m = NULL;
   788       }
   789 #endif
   790       if (m != NULL) {
   791         // We found the method.
   792         return get_method(m);
   793       }
   794     }
   796     // Either the declared holder was not loaded, or the method could
   797     // not be found.  Create a dummy ciMethod to represent the failed
   798     // lookup.
   799     ciSymbol* name      = get_symbol(name_sym);
   800     ciSymbol* signature = get_symbol(sig_sym);
   801     return get_unloaded_method(declared_holder, name, signature, accessor);
   802   }
   803 }
   806 // ------------------------------------------------------------------
   807 // ciEnv::get_instance_klass_for_declared_method_holder
   808 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) {
   809   // For the case of <array>.clone(), the method holder can be a ciArrayKlass
   810   // instead of a ciInstanceKlass.  For that case simply pretend that the
   811   // declared holder is Object.clone since that's where the call will bottom out.
   812   // A more correct fix would trickle out through many interfaces in CI,
   813   // requiring ciInstanceKlass* to become ciKlass* and many more places would
   814   // require checks to make sure the expected type was found.  Given that this
   815   // only occurs for clone() the more extensive fix seems like overkill so
   816   // instead we simply smear the array type into Object.
   817   guarantee(method_holder != NULL, "no method holder");
   818   if (method_holder->is_instance_klass()) {
   819     return method_holder->as_instance_klass();
   820   } else if (method_holder->is_array_klass()) {
   821     return current()->Object_klass();
   822   } else {
   823     ShouldNotReachHere();
   824   }
   825   return NULL;
   826 }
   829 // ------------------------------------------------------------------
   830 // ciEnv::get_method_by_index
   831 ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool,
   832                                      int index, Bytecodes::Code bc,
   833                                      ciInstanceKlass* accessor) {
   834   GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
   835 }
   838 // ------------------------------------------------------------------
   839 // ciEnv::name_buffer
   840 char *ciEnv::name_buffer(int req_len) {
   841   if (_name_buffer_len < req_len) {
   842     if (_name_buffer == NULL) {
   843       _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len);
   844       _name_buffer_len = req_len;
   845     } else {
   846       _name_buffer =
   847         (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
   848       _name_buffer_len = req_len;
   849     }
   850   }
   851   return _name_buffer;
   852 }
   854 // ------------------------------------------------------------------
   855 // ciEnv::is_in_vm
   856 bool ciEnv::is_in_vm() {
   857   return JavaThread::current()->thread_state() == _thread_in_vm;
   858 }
   860 bool ciEnv::system_dictionary_modification_counter_changed() {
   861   return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
   862 }
   864 // ------------------------------------------------------------------
   865 // ciEnv::validate_compile_task_dependencies
   866 //
   867 // Check for changes during compilation (e.g. class loads, evolution,
   868 // breakpoints, call site invalidation).
   869 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
   870   if (failing())  return;  // no need for further checks
   872   // First, check non-klass dependencies as we might return early and
   873   // not check klass dependencies if the system dictionary
   874   // modification counter hasn't changed (see below).
   875   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   876     if (deps.is_klass_type())  continue;  // skip klass dependencies
   877     Klass* witness = deps.check_dependency();
   878     if (witness != NULL) {
   879       record_failure("invalid non-klass dependency");
   880       return;
   881     }
   882   }
   884   // Klass dependencies must be checked when the system dictionary
   885   // changes.  If logging is enabled all violated dependences will be
   886   // recorded in the log.  In debug mode check dependencies even if
   887   // the system dictionary hasn't changed to verify that no invalid
   888   // dependencies were inserted.  Any violated dependences in this
   889   // case are dumped to the tty.
   890   bool counter_changed = system_dictionary_modification_counter_changed();
   892   bool verify_deps = trueInDebug;
   893   if (!counter_changed && !verify_deps)  return;
   895   int klass_violations = 0;
   896   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   897     if (!deps.is_klass_type())  continue;  // skip non-klass dependencies
   898     Klass* witness = deps.check_dependency();
   899     if (witness != NULL) {
   900       klass_violations++;
   901       if (!counter_changed) {
   902         // Dependence failed but counter didn't change.  Log a message
   903         // describing what failed and allow the assert at the end to
   904         // trigger.
   905         deps.print_dependency(witness);
   906       } else if (xtty == NULL) {
   907         // If we're not logging then a single violation is sufficient,
   908         // otherwise we want to log all the dependences which were
   909         // violated.
   910         break;
   911       }
   912     }
   913   }
   915   if (klass_violations != 0) {
   916 #ifdef ASSERT
   917     if (!counter_changed && !PrintCompilation) {
   918       // Print out the compile task that failed
   919       _task->print_line();
   920     }
   921 #endif
   922     assert(counter_changed, "failed dependencies, but counter didn't change");
   923     record_failure("concurrent class loading");
   924   }
   925 }
   927 // ------------------------------------------------------------------
   928 // ciEnv::register_method
   929 void ciEnv::register_method(ciMethod* target,
   930                             int entry_bci,
   931                             CodeOffsets* offsets,
   932                             int orig_pc_offset,
   933                             CodeBuffer* code_buffer,
   934                             int frame_words,
   935                             OopMapSet* oop_map_set,
   936                             ExceptionHandlerTable* handler_table,
   937                             ImplicitExceptionTable* inc_table,
   938                             AbstractCompiler* compiler,
   939                             int comp_level,
   940                             bool has_unsafe_access,
   941                             bool has_wide_vectors,
   942                             RTMState  rtm_state) {
   943   VM_ENTRY_MARK;
   944   nmethod* nm = NULL;
   945   {
   946     // To prevent compile queue updates.
   947     MutexLocker locker(MethodCompileQueue_lock, THREAD);
   949     // Prevent SystemDictionary::add_to_hierarchy from running
   950     // and invalidating our dependencies until we install this method.
   951     // No safepoints are allowed. Otherwise, class redefinition can occur in between.
   952     MutexLocker ml(Compile_lock);
   953     No_Safepoint_Verifier nsv;
   955     // Change in Jvmti state may invalidate compilation.
   956     if (!failing() &&
   957         ( (!jvmti_can_hotswap_or_post_breakpoint() &&
   958            JvmtiExport::can_hotswap_or_post_breakpoint()) ||
   959           (!jvmti_can_access_local_variables() &&
   960            JvmtiExport::can_access_local_variables()) ||
   961           (!jvmti_can_post_on_exceptions() &&
   962            JvmtiExport::can_post_on_exceptions()) )) {
   963       record_failure("Jvmti state change invalidated dependencies");
   964     }
   966     // Change in DTrace flags may invalidate compilation.
   967     if (!failing() &&
   968         ( (!dtrace_extended_probes() && ExtendedDTraceProbes) ||
   969           (!dtrace_method_probes() && DTraceMethodProbes) ||
   970           (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
   971       record_failure("DTrace flags change invalidated dependencies");
   972     }
   974     if (!failing()) {
   975       if (log() != NULL) {
   976         // Log the dependencies which this compilation declares.
   977         dependencies()->log_all_dependencies();
   978       }
   980       // Encode the dependencies now, so we can check them right away.
   981       dependencies()->encode_content_bytes();
   983       // Check for {class loads, evolution, breakpoints, ...} during compilation
   984       validate_compile_task_dependencies(target);
   985     }
   987     methodHandle method(THREAD, target->get_Method());
   989 #if INCLUDE_RTM_OPT
   990     if (!failing() && (rtm_state != NoRTM) &&
   991         (method()->method_data() != NULL) &&
   992         (method()->method_data()->rtm_state() != rtm_state)) {
   993       // Preemptive decompile if rtm state was changed.
   994       record_failure("RTM state change invalidated rtm code");
   995     }
   996 #endif
   998     if (failing()) {
   999       // While not a true deoptimization, it is a preemptive decompile.
  1000       MethodData* mdo = method()->method_data();
  1001       if (mdo != NULL) {
  1002         mdo->inc_decompile_count();
  1005       // All buffers in the CodeBuffer are allocated in the CodeCache.
  1006       // If the code buffer is created on each compile attempt
  1007       // as in C2, then it must be freed.
  1008       code_buffer->free_blob();
  1009       return;
  1012     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
  1013     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
  1015     nm =  nmethod::new_nmethod(method,
  1016                                compile_id(),
  1017                                entry_bci,
  1018                                offsets,
  1019                                orig_pc_offset,
  1020                                debug_info(), dependencies(), code_buffer,
  1021                                frame_words, oop_map_set,
  1022                                handler_table, inc_table,
  1023                                compiler, comp_level);
  1024     // Free codeBlobs
  1025     code_buffer->free_blob();
  1027     if (nm != NULL) {
  1028       nm->set_has_unsafe_access(has_unsafe_access);
  1029       nm->set_has_wide_vectors(has_wide_vectors);
  1030 #if INCLUDE_RTM_OPT
  1031       nm->set_rtm_state(rtm_state);
  1032 #endif
  1034       // Record successful registration.
  1035       // (Put nm into the task handle *before* publishing to the Java heap.)
  1036       if (task() != NULL) {
  1037         task()->set_code(nm);
  1040       if (entry_bci == InvocationEntryBci) {
  1041         if (TieredCompilation) {
  1042           // If there is an old version we're done with it
  1043           nmethod* old = method->code();
  1044           if (TraceMethodReplacement && old != NULL) {
  1045             ResourceMark rm;
  1046             char *method_name = method->name_and_sig_as_C_string();
  1047             tty->print_cr("Replacing method %s", method_name);
  1049           if (old != NULL) {
  1050             old->make_not_entrant();
  1053         if (TraceNMethodInstalls) {
  1054           ResourceMark rm;
  1055           char *method_name = method->name_and_sig_as_C_string();
  1056           ttyLocker ttyl;
  1057           tty->print_cr("Installing method (%d) %s ",
  1058                         comp_level,
  1059                         method_name);
  1061         // Allow the code to be executed
  1062         method->set_code(method, nm);
  1063       } else {
  1064         if (TraceNMethodInstalls) {
  1065           ResourceMark rm;
  1066           char *method_name = method->name_and_sig_as_C_string();
  1067           ttyLocker ttyl;
  1068           tty->print_cr("Installing osr method (%d) %s @ %d",
  1069                         comp_level,
  1070                         method_name,
  1071                         entry_bci);
  1073         method->method_holder()->add_osr_nmethod(nm);
  1076   }  // safepoints are allowed again
  1078   if (nm != NULL) {
  1079     // JVMTI -- compiled method notification (must be done outside lock)
  1080     nm->post_compiled_method_load_event();
  1081   } else {
  1082     // The CodeCache is full. Print out warning and disable compilation.
  1083     record_failure("code cache is full");
  1084     CompileBroker::handle_full_code_cache();
  1089 // ------------------------------------------------------------------
  1090 // ciEnv::find_system_klass
  1091 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) {
  1092   VM_ENTRY_MARK;
  1093   return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false);
  1096 // ------------------------------------------------------------------
  1097 // ciEnv::comp_level
  1098 int ciEnv::comp_level() {
  1099   if (task() == NULL)  return CompLevel_highest_tier;
  1100   return task()->comp_level();
  1103 // ------------------------------------------------------------------
  1104 // ciEnv::compile_id
  1105 uint ciEnv::compile_id() {
  1106   if (task() == NULL)  return 0;
  1107   return task()->compile_id();
  1110 // ------------------------------------------------------------------
  1111 // ciEnv::notice_inlined_method()
  1112 void ciEnv::notice_inlined_method(ciMethod* method) {
  1113   _num_inlined_bytecodes += method->code_size_for_inlining();
  1116 // ------------------------------------------------------------------
  1117 // ciEnv::num_inlined_bytecodes()
  1118 int ciEnv::num_inlined_bytecodes() const {
  1119   return _num_inlined_bytecodes;
  1122 // ------------------------------------------------------------------
  1123 // ciEnv::record_failure()
  1124 void ciEnv::record_failure(const char* reason) {
  1125   if (_failure_reason == NULL) {
  1126     // Record the first failure reason.
  1127     _failure_reason = reason;
  1131 // ------------------------------------------------------------------
  1132 // ciEnv::record_method_not_compilable()
  1133 void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) {
  1134   int new_compilable =
  1135     all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ;
  1137   // Only note transitions to a worse state
  1138   if (new_compilable > _compilable) {
  1139     if (log() != NULL) {
  1140       if (all_tiers) {
  1141         log()->elem("method_not_compilable");
  1142       } else {
  1143         log()->elem("method_not_compilable_at_tier level='%d'",
  1144                     current()->task()->comp_level());
  1147     _compilable = new_compilable;
  1149     // Reset failure reason; this one is more important.
  1150     _failure_reason = NULL;
  1151     record_failure(reason);
  1155 // ------------------------------------------------------------------
  1156 // ciEnv::record_out_of_memory_failure()
  1157 void ciEnv::record_out_of_memory_failure() {
  1158   // If memory is low, we stop compiling methods.
  1159   record_method_not_compilable("out of memory");
  1162 ciInstance* ciEnv::unloaded_ciinstance() {
  1163   GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();)
  1166 // ------------------------------------------------------------------
  1167 // ciEnv::dump_replay_data*
  1169 // Don't change thread state and acquire any locks.
  1170 // Safe to call from VM error reporter.
  1172 void ciEnv::dump_compile_data(outputStream* out) {
  1173   CompileTask* task = this->task();
  1174   Method* method = task->method();
  1175   int entry_bci = task->osr_bci();
  1176   int comp_level = task->comp_level();
  1177   out->print("compile %s %s %s %d %d",
  1178                 method->klass_name()->as_quoted_ascii(),
  1179                 method->name()->as_quoted_ascii(),
  1180                 method->signature()->as_quoted_ascii(),
  1181                 entry_bci, comp_level);
  1182   if (compiler_data() != NULL) {
  1183     if (is_c2_compile(comp_level)) { // C2 or Shark
  1184 #ifdef COMPILER2
  1185       // Dump C2 inlining data.
  1186       ((Compile*)compiler_data())->dump_inline_data(out);
  1187 #endif
  1188     } else if (is_c1_compile(comp_level)) { // C1
  1189 #ifdef COMPILER1
  1190       // Dump C1 inlining data.
  1191       ((Compilation*)compiler_data())->dump_inline_data(out);
  1192 #endif
  1195   out->cr();
  1198 void ciEnv::dump_replay_data_unsafe(outputStream* out) {
  1199   ResourceMark rm;
  1200 #if INCLUDE_JVMTI
  1201   out->print_cr("JvmtiExport can_access_local_variables %d",     _jvmti_can_access_local_variables);
  1202   out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint);
  1203   out->print_cr("JvmtiExport can_post_on_exceptions %d",         _jvmti_can_post_on_exceptions);
  1204 #endif // INCLUDE_JVMTI
  1206   GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata();
  1207   out->print_cr("# %d ciObject found", objects->length());
  1208   for (int i = 0; i < objects->length(); i++) {
  1209     objects->at(i)->dump_replay_data(out);
  1211   dump_compile_data(out);
  1212   out->flush();
  1215 void ciEnv::dump_replay_data(outputStream* out) {
  1216   GUARDED_VM_ENTRY(
  1217     MutexLocker ml(Compile_lock);
  1218     dump_replay_data_unsafe(out);
  1222 void ciEnv::dump_replay_data(int compile_id) {
  1223   static char buffer[O_BUFLEN];
  1224   int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id);
  1225   if (ret > 0) {
  1226     int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
  1227     if (fd != -1) {
  1228       FILE* replay_data_file = os::open(fd, "w");
  1229       if (replay_data_file != NULL) {
  1230         fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
  1231         dump_replay_data(&replay_data_stream);
  1232         tty->print_cr("# Compiler replay data is saved as: %s", buffer);
  1233       } else {
  1234         tty->print_cr("# Can't open file to dump replay data.");
  1240 void ciEnv::dump_inline_data(int compile_id) {
  1241   static char buffer[O_BUFLEN];
  1242   int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id);
  1243   if (ret > 0) {
  1244     int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
  1245     if (fd != -1) {
  1246       FILE* inline_data_file = os::open(fd, "w");
  1247       if (inline_data_file != NULL) {
  1248         fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
  1249         GUARDED_VM_ENTRY(
  1250           MutexLocker ml(Compile_lock);
  1251           dump_compile_data(&replay_data_stream);
  1253         replay_data_stream.flush();
  1254         tty->print("# Compiler inline data is saved as: ");
  1255         tty->print_cr("%s", buffer);
  1256       } else {
  1257         tty->print_cr("# Can't open file to dump inline data.");

mercurial