< prev index next >

src/hotspot/share/opto/runtime.cpp

Print this page

   1 /*
   2  * Copyright (c) 1998, 2025, 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  *

  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/pcDesc.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "code/vtableStubs.hpp"
  33 #include "compiler/compilationMemoryStatistic.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "gc/g1/g1HeapRegion.hpp"
  37 #include "gc/shared/barrierSet.hpp"
  38 #include "gc/shared/collectedHeap.hpp"
  39 #include "gc/shared/gcLocker.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/resourceArea.hpp"



  47 #include "oops/klass.inline.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"

  51 #include "opto/ad.hpp"
  52 #include "opto/addnode.hpp"
  53 #include "opto/callnode.hpp"
  54 #include "opto/cfgnode.hpp"
  55 #include "opto/graphKit.hpp"
  56 #include "opto/machnode.hpp"
  57 #include "opto/matcher.hpp"
  58 #include "opto/memnode.hpp"
  59 #include "opto/mulnode.hpp"
  60 #include "opto/output.hpp"
  61 #include "opto/runtime.hpp"
  62 #include "opto/subnode.hpp"
  63 #include "prims/jvmtiExport.hpp"
  64 #include "runtime/atomicAccess.hpp"
  65 #include "runtime/frame.inline.hpp"
  66 #include "runtime/handles.inline.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/mountUnmountDisabler.hpp"
  70 #include "runtime/sharedRuntime.hpp"

 153 
 154 bool OptoRuntime::generate(ciEnv* env) {
 155 
 156   C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
 157 
 158   return true;
 159 }
 160 
 161 #undef GEN_C2_BLOB
 162 
 163 #undef C2_STUB_FIELD_NAME
 164 #undef C2_STUB_TYPEFUNC
 165 #undef C2_STUB_C_FUNC
 166 #undef C2_STUB_NAME
 167 #undef GEN_C2_STUB
 168 
 169 // #undef gen
 170 
 171 const TypeFunc* OptoRuntime::_new_instance_Type                   = nullptr;
 172 const TypeFunc* OptoRuntime::_new_array_Type                      = nullptr;

 173 const TypeFunc* OptoRuntime::_multianewarray2_Type                = nullptr;
 174 const TypeFunc* OptoRuntime::_multianewarray3_Type                = nullptr;
 175 const TypeFunc* OptoRuntime::_multianewarray4_Type                = nullptr;
 176 const TypeFunc* OptoRuntime::_multianewarray5_Type                = nullptr;
 177 const TypeFunc* OptoRuntime::_multianewarrayN_Type                = nullptr;
 178 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type         = nullptr;
 179 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type          = nullptr;
 180 const TypeFunc* OptoRuntime::_monitor_notify_Type                 = nullptr;
 181 const TypeFunc* OptoRuntime::_uncommon_trap_Type                  = nullptr;
 182 const TypeFunc* OptoRuntime::_athrow_Type                         = nullptr;
 183 const TypeFunc* OptoRuntime::_rethrow_Type                        = nullptr;
 184 const TypeFunc* OptoRuntime::_Math_D_D_Type                       = nullptr;
 185 const TypeFunc* OptoRuntime::_Math_DD_D_Type                      = nullptr;
 186 const TypeFunc* OptoRuntime::_modf_Type                           = nullptr;
 187 const TypeFunc* OptoRuntime::_l2f_Type                            = nullptr;
 188 const TypeFunc* OptoRuntime::_void_long_Type                      = nullptr;
 189 const TypeFunc* OptoRuntime::_void_void_Type                      = nullptr;
 190 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type           = nullptr;
 191 const TypeFunc* OptoRuntime::_flush_windows_Type                  = nullptr;
 192 const TypeFunc* OptoRuntime::_fast_arraycopy_Type                 = nullptr;

 281                                    oopDesc* dest, jint dest_pos,
 282                                    jint length, JavaThread* thread) {
 283   SharedRuntime::slow_arraycopy_C(src,  src_pos, dest, dest_pos, length, thread);
 284 }
 285 
 286 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
 287   SharedRuntime::complete_monitor_locking_C(obj, lock, current);
 288 }
 289 
 290 
 291 //=============================================================================
 292 // Opto compiler runtime routines
 293 //=============================================================================
 294 
 295 
 296 //=============================allocation======================================
 297 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 298 // and try allocation again.
 299 
 300 // object allocation
 301 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
 302   JRT_BLOCK;
 303 #ifndef PRODUCT
 304   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 305 #endif
 306   assert(check_compiled_frame(current), "incorrect caller");
 307 
 308   // These checks are cheap to make and support reflective allocation.
 309   int lh = klass->layout_helper();
 310   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 311     Handle holder(current, klass->klass_holder()); // keep the klass alive
 312     klass->check_valid_for_instantiation(false, THREAD);
 313     if (!HAS_PENDING_EXCEPTION) {
 314       InstanceKlass::cast(klass)->initialize(THREAD);
 315     }
 316   }
 317 
 318   if (!HAS_PENDING_EXCEPTION) {
 319     // Scavenge and allocate an instance.
 320     Handle holder(current, klass->klass_holder()); // keep the klass alive
 321     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);




 322     current->set_vm_result_oop(result);
 323 
 324     // Pass oops back through thread local storage.  Our apparent type to Java
 325     // is that we return an oop, but we can block on exit from this routine and
 326     // a GC can trash the oop in C's return register.  The generated stub will
 327     // fetch the oop from TLS after any possible GC.
 328   }
 329 
 330   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 331   JRT_BLOCK_END;
 332 
 333   // inform GC that we won't do card marks for initializing writes.
 334   SharedRuntime::on_slowpath_allocation_exit(current);
 335 JRT_END
 336 
 337 
 338 // array allocation
 339 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
 340   JRT_BLOCK;
 341 #ifndef PRODUCT
 342   SharedRuntime::_new_array_ctr++;            // new array requires GC
 343 #endif
 344   assert(check_compiled_frame(current), "incorrect caller");
 345 
 346   // Scavenge and allocate an instance.
 347   oop result;

 348 
 349   if (array_type->is_typeArray_klass()) {
 350     // The oopFactory likes to work with the element type.
 351     // (We could bypass the oopFactory, since it doesn't add much value.)
 352     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 353     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 354   } else {
 355     // Although the oopFactory likes to work with the elem_type,
 356     // the compiler prefers the array_type, since it must already have
 357     // that latter value in hand for the fast path.
 358     Handle holder(current, array_type->klass_holder()); // keep the array klass alive
 359     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
 360     result = oopFactory::new_objArray(elem_type, len, THREAD);










 361   }
 362 
 363   // Pass oops back through thread local storage.  Our apparent type to Java
 364   // is that we return an oop, but we can block on exit from this routine and
 365   // a GC can trash the oop in C's return register.  The generated stub will
 366   // fetch the oop from TLS after any possible GC.
 367   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 368   current->set_vm_result_oop(result);
 369   JRT_BLOCK_END;
 370 
 371   // inform GC that we won't do card marks for initializing writes.
 372   SharedRuntime::on_slowpath_allocation_exit(current);
 373 JRT_END
 374 
 375 // array allocation without zeroing
 376 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
 377   JRT_BLOCK;
 378 #ifndef PRODUCT
 379   SharedRuntime::_new_array_ctr++;            // new array requires GC
 380 #endif

 557 JRT_END
 558 
 559 JRT_ENTRY(void, OptoRuntime::vthread_start_final_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 560   java_lang_Thread::set_is_in_vthread_transition(vt, false);
 561   current->set_is_in_vthread_transition(false);
 562   MountUnmountDisabler::start_transition(current, vt, false /*is_mount */, true /*is_thread_end*/);
 563 JRT_END
 564 
 565 JRT_ENTRY(void, OptoRuntime::vthread_start_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 566   java_lang_Thread::set_is_in_vthread_transition(vt, false);
 567   current->set_is_in_vthread_transition(false);
 568   MountUnmountDisabler::start_transition(current, vt, is_mount, false /*is_thread_end*/);
 569 JRT_END
 570 
 571 JRT_ENTRY(void, OptoRuntime::vthread_end_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 572   MountUnmountDisabler::end_transition(current, vt, is_mount, false /*is_thread_start*/);
 573 JRT_END
 574 
 575 static const TypeFunc* make_new_instance_Type() {
 576   // create input type (domain)
 577   const Type **fields = TypeTuple::fields(1);
 578   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 579   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);

 580 
 581   // create result type (range)
 582   fields = TypeTuple::fields(1);
 583   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 584 
 585   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 586 
 587   return TypeFunc::make(domain, range);
 588 }
 589 
 590 static const TypeFunc* make_vthread_transition_Type() {
 591   // create input type (domain)
 592   const Type **fields = TypeTuple::fields(2);
 593   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
 594   fields[TypeFunc::Parms+1] = TypeInt::BOOL;        // jboolean
 595   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 596 
 597   // no result type needed
 598   fields = TypeTuple::fields(1);
 599   fields[TypeFunc::Parms+0] = nullptr; // void
 600   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 601 
 602   return TypeFunc::make(domain,range);
 603 }
 604 
 605 static const TypeFunc* make_athrow_Type() {
 606   // create input type (domain)
 607   const Type **fields = TypeTuple::fields(1);
 608   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 609   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 610 
 611   // create result type (range)
 612   fields = TypeTuple::fields(0);
 613 
 614   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 615 
 616   return TypeFunc::make(domain, range);
 617 }
 618 
 619 static const TypeFunc* make_new_array_Type() {

















 620   // create input type (domain)
 621   const Type **fields = TypeTuple::fields(2);
 622   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 623   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 624   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 625 
 626   // create result type (range)
 627   fields = TypeTuple::fields(1);
 628   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 629 
 630   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 631 
 632   return TypeFunc::make(domain, range);
 633 }
 634 
 635 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) {
 636   // create input type (domain)
 637   const int nargs = ndim + 1;
 638   const Type **fields = TypeTuple::fields(nargs);
 639   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass

 675   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 676 
 677   return TypeFunc::make(domain, range);
 678 }
 679 
 680 //-----------------------------------------------------------------------------
 681 // Monitor Handling
 682 
 683 static const TypeFunc* make_complete_monitor_enter_Type() {
 684   // create input type (domain)
 685   const Type **fields = TypeTuple::fields(2);
 686   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 687   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;   // Address of stack location for lock
 688   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 689 
 690   // create result type (range)
 691   fields = TypeTuple::fields(0);
 692 
 693   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
 694 
 695   return TypeFunc::make(domain,range);
 696 }
 697 
 698 //-----------------------------------------------------------------------------
 699 
 700 static const TypeFunc* make_complete_monitor_exit_Type() {
 701   // create input type (domain)
 702   const Type **fields = TypeTuple::fields(3);
 703   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 704   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;    // Address of stack location for lock - BasicLock
 705   fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM;    // Thread pointer (Self)
 706   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 707 
 708   // create result type (range)
 709   fields = TypeTuple::fields(0);
 710 
 711   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 712 
 713   return TypeFunc::make(domain, range);
 714 }
 715 

2111                       RegisterMap::WalkContinuation::skip);
2112   frame stub_frame = thread->last_frame();
2113   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2114   frame caller_frame = stub_frame.sender(&reg_map);
2115   return caller_frame.is_deoptimized_frame();
2116 }
2117 
2118 static const TypeFunc* make_register_finalizer_Type() {
2119   // create input type (domain)
2120   const Type **fields = TypeTuple::fields(1);
2121   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // oop;          Receiver
2122   // // The JavaThread* is passed to each routine as the last argument
2123   // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // JavaThread *; Executing thread
2124   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2125 
2126   // create result type (range)
2127   fields = TypeTuple::fields(0);
2128 
2129   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2130 
2131   return TypeFunc::make(domain,range);
2132 }
2133 
2134 #if INCLUDE_JFR
2135 static const TypeFunc* make_class_id_load_barrier_Type() {
2136   // create input type (domain)
2137   const Type **fields = TypeTuple::fields(1);
2138   fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2139   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2140 
2141   // create result type (range)
2142   fields = TypeTuple::fields(0);
2143 
2144   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2145 
2146   return TypeFunc::make(domain,range);
2147 }
2148 #endif // INCLUDE_JFR
2149 
2150 //-----------------------------------------------------------------------------
2151 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2152   // create input type (domain)
2153   const Type **fields = TypeTuple::fields(2);
2154   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2155   fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM;  // Method*;    Method we are entering
2156   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2157 
2158   // create result type (range)
2159   fields = TypeTuple::fields(0);
2160 
2161   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2162 
2163   return TypeFunc::make(domain,range);
2164 }
2165 
2166 static const TypeFunc* make_dtrace_object_alloc_Type() {
2167   // create input type (domain)
2168   const Type **fields = TypeTuple::fields(2);
2169   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2170   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;  // oop;    newly allocated object
2171 
2172   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2173 
2174   // create result type (range)
2175   fields = TypeTuple::fields(0);
2176 
2177   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2178 
2179   return TypeFunc::make(domain,range);
2180 }
2181 
2182 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2183   assert(oopDesc::is_oop(obj), "must be a valid oop");
2184   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2185   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2186 JRT_END
2187 
2188 //-----------------------------------------------------------------------------
2189 
2190 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2191 
2192 //
2193 // dump the collected NamedCounters.
2194 //
2195 void OptoRuntime::print_named_counters() {
2196   int total_lock_count = 0;
2197   int eliminated_lock_count = 0;
2198 
2199   NamedCounter* c = _named_counters;

2250     }
2251     st.print("@%d", bci);
2252     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2253   }
2254   NamedCounter* c = new NamedCounter(st.freeze(), tag);
2255 
2256   // atomically add the new counter to the head of the list.  We only
2257   // add counters so this is safe.
2258   NamedCounter* head;
2259   do {
2260     c->set_next(nullptr);
2261     head = _named_counters;
2262     c->set_next(head);
2263   } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2264   return c;
2265 }
2266 
2267 void OptoRuntime::initialize_types() {
2268   _new_instance_Type                  = make_new_instance_Type();
2269   _new_array_Type                     = make_new_array_Type();

2270   _multianewarray2_Type               = multianewarray_Type(2);
2271   _multianewarray3_Type               = multianewarray_Type(3);
2272   _multianewarray4_Type               = multianewarray_Type(4);
2273   _multianewarray5_Type               = multianewarray_Type(5);
2274   _multianewarrayN_Type               = make_multianewarrayN_Type();
2275   _complete_monitor_enter_Type        = make_complete_monitor_enter_Type();
2276   _complete_monitor_exit_Type         = make_complete_monitor_exit_Type();
2277   _monitor_notify_Type                = make_monitor_notify_Type();
2278   _uncommon_trap_Type                 = make_uncommon_trap_Type();
2279   _athrow_Type                        = make_athrow_Type();
2280   _rethrow_Type                       = make_rethrow_Type();
2281   _Math_D_D_Type                      = make_Math_D_D_Type();
2282   _Math_DD_D_Type                     = make_Math_DD_D_Type();
2283   _modf_Type                          = make_modf_Type();
2284   _l2f_Type                           = make_l2f_Type();
2285   _void_long_Type                     = make_void_long_Type();
2286   _void_void_Type                     = make_void_void_Type();
2287   _jfr_write_checkpoint_Type          = make_jfr_write_checkpoint_Type();
2288   _flush_windows_Type                 = make_flush_windows_Type();
2289   _fast_arraycopy_Type                = make_arraycopy_Type(ac_fast);

2348 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2349   trace_exception_counter++;
2350   stringStream tempst;
2351 
2352   tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2353   exception_oop->print_value_on(&tempst);
2354   tempst.print(" in ");
2355   CodeBlob* blob = CodeCache::find_blob(exception_pc);
2356   if (blob->is_nmethod()) {
2357     blob->as_nmethod()->method()->print_value_on(&tempst);
2358   } else if (blob->is_runtime_stub()) {
2359     tempst.print("<runtime-stub>");
2360   } else {
2361     tempst.print("<unknown>");
2362   }
2363   tempst.print(" at " INTPTR_FORMAT,  p2i(exception_pc));
2364   tempst.print("]");
2365 
2366   st->print_raw_cr(tempst.freeze());
2367 }










































































































   1 /*
   2  * Copyright (c) 1998, 2026, 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  *

  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/pcDesc.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "code/vtableStubs.hpp"
  33 #include "compiler/compilationMemoryStatistic.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "gc/g1/g1HeapRegion.hpp"
  37 #include "gc/shared/barrierSet.hpp"
  38 #include "gc/shared/collectedHeap.hpp"
  39 #include "gc/shared/gcLocker.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/flatArrayKlass.hpp"
  48 #include "oops/flatArrayOop.inline.hpp"
  49 #include "oops/inlineKlass.inline.hpp"
  50 #include "oops/klass.inline.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "oops/typeArrayOop.inline.hpp"
  54 #include "oops/valuePayload.inline.hpp"
  55 #include "opto/ad.hpp"
  56 #include "opto/addnode.hpp"
  57 #include "opto/callnode.hpp"
  58 #include "opto/cfgnode.hpp"
  59 #include "opto/graphKit.hpp"
  60 #include "opto/machnode.hpp"
  61 #include "opto/matcher.hpp"
  62 #include "opto/memnode.hpp"
  63 #include "opto/mulnode.hpp"
  64 #include "opto/output.hpp"
  65 #include "opto/runtime.hpp"
  66 #include "opto/subnode.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "runtime/atomicAccess.hpp"
  69 #include "runtime/frame.inline.hpp"
  70 #include "runtime/handles.inline.hpp"
  71 #include "runtime/interfaceSupport.inline.hpp"
  72 #include "runtime/javaCalls.hpp"
  73 #include "runtime/mountUnmountDisabler.hpp"
  74 #include "runtime/sharedRuntime.hpp"

 157 
 158 bool OptoRuntime::generate(ciEnv* env) {
 159 
 160   C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
 161 
 162   return true;
 163 }
 164 
 165 #undef GEN_C2_BLOB
 166 
 167 #undef C2_STUB_FIELD_NAME
 168 #undef C2_STUB_TYPEFUNC
 169 #undef C2_STUB_C_FUNC
 170 #undef C2_STUB_NAME
 171 #undef GEN_C2_STUB
 172 
 173 // #undef gen
 174 
 175 const TypeFunc* OptoRuntime::_new_instance_Type                   = nullptr;
 176 const TypeFunc* OptoRuntime::_new_array_Type                      = nullptr;
 177 const TypeFunc* OptoRuntime::_new_array_nozero_Type               = nullptr;
 178 const TypeFunc* OptoRuntime::_multianewarray2_Type                = nullptr;
 179 const TypeFunc* OptoRuntime::_multianewarray3_Type                = nullptr;
 180 const TypeFunc* OptoRuntime::_multianewarray4_Type                = nullptr;
 181 const TypeFunc* OptoRuntime::_multianewarray5_Type                = nullptr;
 182 const TypeFunc* OptoRuntime::_multianewarrayN_Type                = nullptr;
 183 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type         = nullptr;
 184 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type          = nullptr;
 185 const TypeFunc* OptoRuntime::_monitor_notify_Type                 = nullptr;
 186 const TypeFunc* OptoRuntime::_uncommon_trap_Type                  = nullptr;
 187 const TypeFunc* OptoRuntime::_athrow_Type                         = nullptr;
 188 const TypeFunc* OptoRuntime::_rethrow_Type                        = nullptr;
 189 const TypeFunc* OptoRuntime::_Math_D_D_Type                       = nullptr;
 190 const TypeFunc* OptoRuntime::_Math_DD_D_Type                      = nullptr;
 191 const TypeFunc* OptoRuntime::_modf_Type                           = nullptr;
 192 const TypeFunc* OptoRuntime::_l2f_Type                            = nullptr;
 193 const TypeFunc* OptoRuntime::_void_long_Type                      = nullptr;
 194 const TypeFunc* OptoRuntime::_void_void_Type                      = nullptr;
 195 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type           = nullptr;
 196 const TypeFunc* OptoRuntime::_flush_windows_Type                  = nullptr;
 197 const TypeFunc* OptoRuntime::_fast_arraycopy_Type                 = nullptr;

 286                                    oopDesc* dest, jint dest_pos,
 287                                    jint length, JavaThread* thread) {
 288   SharedRuntime::slow_arraycopy_C(src,  src_pos, dest, dest_pos, length, thread);
 289 }
 290 
 291 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
 292   SharedRuntime::complete_monitor_locking_C(obj, lock, current);
 293 }
 294 
 295 
 296 //=============================================================================
 297 // Opto compiler runtime routines
 298 //=============================================================================
 299 
 300 
 301 //=============================allocation======================================
 302 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 303 // and try allocation again.
 304 
 305 // object allocation
 306 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, bool is_larval, JavaThread* current))
 307   JRT_BLOCK;
 308 #ifndef PRODUCT
 309   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 310 #endif
 311   assert(check_compiled_frame(current), "incorrect caller");
 312 
 313   // These checks are cheap to make and support reflective allocation.
 314   int lh = klass->layout_helper();
 315   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 316     Handle holder(current, klass->klass_holder()); // keep the klass alive
 317     klass->check_valid_for_instantiation(false, THREAD);
 318     if (!HAS_PENDING_EXCEPTION) {
 319       InstanceKlass::cast(klass)->initialize(THREAD);
 320     }
 321   }
 322 
 323   if (!HAS_PENDING_EXCEPTION) {
 324     // Scavenge and allocate an instance.
 325     Handle holder(current, klass->klass_holder()); // keep the klass alive
 326     instanceOop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 327     if (is_larval) {
 328       // Check if this is a larval buffer allocation
 329       result->set_mark(result->mark().enter_larval_state());
 330     }
 331     current->set_vm_result_oop(result);
 332 
 333     // Pass oops back through thread local storage.  Our apparent type to Java
 334     // is that we return an oop, but we can block on exit from this routine and
 335     // a GC can trash the oop in C's return register.  The generated stub will
 336     // fetch the oop from TLS after any possible GC.
 337   }
 338 
 339   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 340   JRT_BLOCK_END;
 341 
 342   // inform GC that we won't do card marks for initializing writes.
 343   SharedRuntime::on_slowpath_allocation_exit(current);
 344 JRT_END
 345 
 346 
 347 // array allocation
 348 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, oopDesc* init_val, JavaThread* current))
 349   JRT_BLOCK;
 350 #ifndef PRODUCT
 351   SharedRuntime::_new_array_ctr++;            // new array requires GC
 352 #endif
 353   assert(check_compiled_frame(current), "incorrect caller");
 354 
 355   // Scavenge and allocate an instance.
 356   oop result;
 357   Handle h_init_val(current, init_val); // keep the init_val object alive
 358 
 359   if (array_type->is_typeArray_klass()) {
 360     // The oopFactory likes to work with the element type.
 361     // (We could bypass the oopFactory, since it doesn't add much value.)
 362     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 363     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 364   } else {



 365     Handle holder(current, array_type->klass_holder()); // keep the array klass alive
 366     ObjArrayKlass* oak = ObjArrayKlass::cast(array_type);
 367     result = oopFactory::new_objArray(oak->element_klass(), len, oak->properties(), THREAD);
 368     if (!HAS_PENDING_EXCEPTION && array_type->is_null_free_array_klass() && !h_init_val.is_null()) {
 369       // Null-free arrays need to be initialized
 370 #ifdef ASSERT
 371       ObjArrayKlass* result_oak = ObjArrayKlass::cast(result->klass());
 372       assert(result_oak->is_null_free_array_klass(), "Sanity check");
 373 #endif
 374       for (int i = 0; i < len; i++) {
 375         ((objArrayOop)result)->obj_at_put(i, h_init_val());
 376       }
 377     }
 378   }
 379 
 380   // Pass oops back through thread local storage.  Our apparent type to Java
 381   // is that we return an oop, but we can block on exit from this routine and
 382   // a GC can trash the oop in C's return register.  The generated stub will
 383   // fetch the oop from TLS after any possible GC.
 384   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 385   current->set_vm_result_oop(result);
 386   JRT_BLOCK_END;
 387 
 388   // inform GC that we won't do card marks for initializing writes.
 389   SharedRuntime::on_slowpath_allocation_exit(current);
 390 JRT_END
 391 
 392 // array allocation without zeroing
 393 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
 394   JRT_BLOCK;
 395 #ifndef PRODUCT
 396   SharedRuntime::_new_array_ctr++;            // new array requires GC
 397 #endif

 574 JRT_END
 575 
 576 JRT_ENTRY(void, OptoRuntime::vthread_start_final_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 577   java_lang_Thread::set_is_in_vthread_transition(vt, false);
 578   current->set_is_in_vthread_transition(false);
 579   MountUnmountDisabler::start_transition(current, vt, false /*is_mount */, true /*is_thread_end*/);
 580 JRT_END
 581 
 582 JRT_ENTRY(void, OptoRuntime::vthread_start_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 583   java_lang_Thread::set_is_in_vthread_transition(vt, false);
 584   current->set_is_in_vthread_transition(false);
 585   MountUnmountDisabler::start_transition(current, vt, is_mount, false /*is_thread_end*/);
 586 JRT_END
 587 
 588 JRT_ENTRY(void, OptoRuntime::vthread_end_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
 589   MountUnmountDisabler::end_transition(current, vt, is_mount, false /*is_thread_start*/);
 590 JRT_END
 591 
 592 static const TypeFunc* make_new_instance_Type() {
 593   // create input type (domain)
 594   const Type **fields = TypeTuple::fields(2);
 595   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 596   fields[TypeFunc::Parms+1] = TypeInt::BOOL;        // is_larval
 597   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 598 
 599   // create result type (range)
 600   fields = TypeTuple::fields(1);
 601   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 602 
 603   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 604 
 605   return TypeFunc::make(domain, range);
 606 }
 607 
 608 static const TypeFunc* make_vthread_transition_Type() {
 609   // create input type (domain)
 610   const Type **fields = TypeTuple::fields(2);
 611   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
 612   fields[TypeFunc::Parms+1] = TypeInt::BOOL;        // jboolean
 613   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 614 
 615   // no result type needed
 616   fields = TypeTuple::fields(1);
 617   fields[TypeFunc::Parms+0] = nullptr; // void
 618   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 619 
 620   return TypeFunc::make(domain,range);
 621 }
 622 
 623 static const TypeFunc* make_athrow_Type() {
 624   // create input type (domain)
 625   const Type **fields = TypeTuple::fields(1);
 626   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 627   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 628 
 629   // create result type (range)
 630   fields = TypeTuple::fields(0);
 631 
 632   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 633 
 634   return TypeFunc::make(domain, range);
 635 }
 636 
 637 static const TypeFunc* make_new_array_Type() {
 638   // create input type (domain)
 639   const Type **fields = TypeTuple::fields(3);
 640   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 641   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 642   fields[TypeFunc::Parms+2] = TypeInstPtr::NOTNULL;       // init value
 643   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 644 
 645   // create result type (range)
 646   fields = TypeTuple::fields(1);
 647   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 648 
 649   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 650 
 651   return TypeFunc::make(domain, range);
 652 }
 653 
 654 static const TypeFunc* make_new_array_nozero_Type() {
 655   // create input type (domain)
 656   const Type **fields = TypeTuple::fields(2);
 657   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 658   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 659   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 660 
 661   // create result type (range)
 662   fields = TypeTuple::fields(1);
 663   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 664 
 665   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 666 
 667   return TypeFunc::make(domain, range);
 668 }
 669 
 670 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) {
 671   // create input type (domain)
 672   const int nargs = ndim + 1;
 673   const Type **fields = TypeTuple::fields(nargs);
 674   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass

 710   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 711 
 712   return TypeFunc::make(domain, range);
 713 }
 714 
 715 //-----------------------------------------------------------------------------
 716 // Monitor Handling
 717 
 718 static const TypeFunc* make_complete_monitor_enter_Type() {
 719   // create input type (domain)
 720   const Type **fields = TypeTuple::fields(2);
 721   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 722   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;   // Address of stack location for lock
 723   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 724 
 725   // create result type (range)
 726   fields = TypeTuple::fields(0);
 727 
 728   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
 729 
 730   return TypeFunc::make(domain, range);
 731 }
 732 
 733 //-----------------------------------------------------------------------------
 734 
 735 static const TypeFunc* make_complete_monitor_exit_Type() {
 736   // create input type (domain)
 737   const Type **fields = TypeTuple::fields(3);
 738   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 739   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;    // Address of stack location for lock - BasicLock
 740   fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM;    // Thread pointer (Self)
 741   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 742 
 743   // create result type (range)
 744   fields = TypeTuple::fields(0);
 745 
 746   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 747 
 748   return TypeFunc::make(domain, range);
 749 }
 750 

2146                       RegisterMap::WalkContinuation::skip);
2147   frame stub_frame = thread->last_frame();
2148   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2149   frame caller_frame = stub_frame.sender(&reg_map);
2150   return caller_frame.is_deoptimized_frame();
2151 }
2152 
2153 static const TypeFunc* make_register_finalizer_Type() {
2154   // create input type (domain)
2155   const Type **fields = TypeTuple::fields(1);
2156   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // oop;          Receiver
2157   // // The JavaThread* is passed to each routine as the last argument
2158   // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // JavaThread *; Executing thread
2159   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2160 
2161   // create result type (range)
2162   fields = TypeTuple::fields(0);
2163 
2164   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2165 
2166   return TypeFunc::make(domain, range);
2167 }
2168 
2169 #if INCLUDE_JFR
2170 static const TypeFunc* make_class_id_load_barrier_Type() {
2171   // create input type (domain)
2172   const Type **fields = TypeTuple::fields(1);
2173   fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2174   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2175 
2176   // create result type (range)
2177   fields = TypeTuple::fields(0);
2178 
2179   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2180 
2181   return TypeFunc::make(domain,range);
2182 }
2183 #endif // INCLUDE_JFR
2184 
2185 //-----------------------------------------------------------------------------
2186 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2187   // create input type (domain)
2188   const Type **fields = TypeTuple::fields(2);
2189   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2190   fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM;  // Method*;    Method we are entering
2191   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2192 
2193   // create result type (range)
2194   fields = TypeTuple::fields(0);
2195 
2196   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2197 
2198   return TypeFunc::make(domain, range);
2199 }
2200 
2201 static const TypeFunc* make_dtrace_object_alloc_Type() {
2202   // create input type (domain)
2203   const Type **fields = TypeTuple::fields(2);
2204   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2205   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;  // oop;    newly allocated object
2206 
2207   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2208 
2209   // create result type (range)
2210   fields = TypeTuple::fields(0);
2211 
2212   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2213 
2214   return TypeFunc::make(domain, range);
2215 }
2216 
2217 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2218   assert(oopDesc::is_oop(obj), "must be a valid oop");
2219   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2220   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2221 JRT_END
2222 
2223 //-----------------------------------------------------------------------------
2224 
2225 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2226 
2227 //
2228 // dump the collected NamedCounters.
2229 //
2230 void OptoRuntime::print_named_counters() {
2231   int total_lock_count = 0;
2232   int eliminated_lock_count = 0;
2233 
2234   NamedCounter* c = _named_counters;

2285     }
2286     st.print("@%d", bci);
2287     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2288   }
2289   NamedCounter* c = new NamedCounter(st.freeze(), tag);
2290 
2291   // atomically add the new counter to the head of the list.  We only
2292   // add counters so this is safe.
2293   NamedCounter* head;
2294   do {
2295     c->set_next(nullptr);
2296     head = _named_counters;
2297     c->set_next(head);
2298   } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2299   return c;
2300 }
2301 
2302 void OptoRuntime::initialize_types() {
2303   _new_instance_Type                  = make_new_instance_Type();
2304   _new_array_Type                     = make_new_array_Type();
2305   _new_array_nozero_Type              = make_new_array_nozero_Type();
2306   _multianewarray2_Type               = multianewarray_Type(2);
2307   _multianewarray3_Type               = multianewarray_Type(3);
2308   _multianewarray4_Type               = multianewarray_Type(4);
2309   _multianewarray5_Type               = multianewarray_Type(5);
2310   _multianewarrayN_Type               = make_multianewarrayN_Type();
2311   _complete_monitor_enter_Type        = make_complete_monitor_enter_Type();
2312   _complete_monitor_exit_Type         = make_complete_monitor_exit_Type();
2313   _monitor_notify_Type                = make_monitor_notify_Type();
2314   _uncommon_trap_Type                 = make_uncommon_trap_Type();
2315   _athrow_Type                        = make_athrow_Type();
2316   _rethrow_Type                       = make_rethrow_Type();
2317   _Math_D_D_Type                      = make_Math_D_D_Type();
2318   _Math_DD_D_Type                     = make_Math_DD_D_Type();
2319   _modf_Type                          = make_modf_Type();
2320   _l2f_Type                           = make_l2f_Type();
2321   _void_long_Type                     = make_void_long_Type();
2322   _void_void_Type                     = make_void_void_Type();
2323   _jfr_write_checkpoint_Type          = make_jfr_write_checkpoint_Type();
2324   _flush_windows_Type                 = make_flush_windows_Type();
2325   _fast_arraycopy_Type                = make_arraycopy_Type(ac_fast);

2384 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2385   trace_exception_counter++;
2386   stringStream tempst;
2387 
2388   tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2389   exception_oop->print_value_on(&tempst);
2390   tempst.print(" in ");
2391   CodeBlob* blob = CodeCache::find_blob(exception_pc);
2392   if (blob->is_nmethod()) {
2393     blob->as_nmethod()->method()->print_value_on(&tempst);
2394   } else if (blob->is_runtime_stub()) {
2395     tempst.print("<runtime-stub>");
2396   } else {
2397     tempst.print("<unknown>");
2398   }
2399   tempst.print(" at " INTPTR_FORMAT,  p2i(exception_pc));
2400   tempst.print("]");
2401 
2402   st->print_raw_cr(tempst.freeze());
2403 }
2404 
2405 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
2406   // create input type (domain)
2407   uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2408   const Type **fields = TypeTuple::fields(total);
2409   // We don't know the number of returned values and their
2410   // types. Assume all registers available to the return convention
2411   // are used.
2412   fields[TypeFunc::Parms] = TypePtr::BOTTOM;
2413   uint i = 1;
2414   for (; i < SharedRuntime::java_return_convention_max_int; i++) {
2415     fields[TypeFunc::Parms+i] = TypeInt::INT;
2416   }
2417   for (; i < total; i+=2) {
2418     fields[TypeFunc::Parms+i] = Type::DOUBLE;
2419     fields[TypeFunc::Parms+i+1] = Type::HALF;
2420   }
2421   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2422 
2423   // create result type (range)
2424   fields = TypeTuple::fields(1);
2425   fields[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM;
2426 
2427   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2428 
2429   return TypeFunc::make(domain, range);
2430 }
2431 
2432 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
2433   // create input type (domain)
2434   uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2435   const Type **fields = TypeTuple::fields(total);
2436   // We don't know the number of returned values and their
2437   // types. Assume all registers available to the return convention
2438   // are used.
2439   fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
2440   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
2441   uint i = 2;
2442   for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
2443     fields[TypeFunc::Parms+i] = TypeInt::INT;
2444   }
2445   for (; i < total; i+=2) {
2446     fields[TypeFunc::Parms+i] = Type::DOUBLE;
2447     fields[TypeFunc::Parms+i+1] = Type::HALF;
2448   }
2449   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2450 
2451   // create result type (range)
2452   fields = TypeTuple::fields(1);
2453   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
2454 
2455   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2456 
2457   return TypeFunc::make(domain, range);
2458 }
2459 
2460 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline_C(flatArrayOopDesc* array, int index, JavaThread* current))
2461   JRT_BLOCK;
2462   oop buffer = array->obj_at(index, THREAD);
2463   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
2464   current->set_vm_result_oop(buffer);
2465   JRT_BLOCK_END;
2466 JRT_END
2467 
2468 const TypeFunc* OptoRuntime::load_unknown_inline_Type() {
2469   // create input type (domain)
2470   const Type** fields = TypeTuple::fields(2);
2471   fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
2472   fields[TypeFunc::Parms+1] = TypeInt::POS;
2473 
2474   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
2475 
2476   // create result type (range)
2477   fields = TypeTuple::fields(1);
2478   fields[TypeFunc::Parms] = TypeInstPtr::BOTTOM;
2479 
2480   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
2481 
2482   return TypeFunc::make(domain, range);
2483 }
2484 
2485 JRT_BLOCK_ENTRY(void, OptoRuntime::store_unknown_inline_C(instanceOopDesc* buffer, flatArrayOopDesc* array, int index, JavaThread* current))
2486   JRT_BLOCK;
2487   array->obj_at_put(index, buffer, THREAD);
2488   if (HAS_PENDING_EXCEPTION) {
2489       fatal("This entry must be changed to be a non-leaf entry because writing to a flat array can now throw an exception");
2490   }
2491   JRT_BLOCK_END;
2492 JRT_END
2493 
2494 const TypeFunc* OptoRuntime::store_unknown_inline_Type() {
2495   // create input type (domain)
2496   const Type** fields = TypeTuple::fields(3);
2497   fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2498   fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
2499   fields[TypeFunc::Parms+2] = TypeInt::POS;
2500 
2501   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
2502 
2503   // create result type (range)
2504   fields = TypeTuple::fields(0);
2505   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
2506 
2507   return TypeFunc::make(domain, range);
2508 }
< prev index next >