29 #include "code/compiledMethod.inline.hpp"
30 #include "code/compiledIC.hpp"
31 #include "code/icBuffer.hpp"
32 #include "code/nmethod.hpp"
33 #include "code/pcDesc.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "code/vtableStubs.hpp"
36 #include "compiler/compileBroker.hpp"
37 #include "compiler/oopMap.hpp"
38 #include "gc/g1/heapRegion.hpp"
39 #include "gc/shared/barrierSet.hpp"
40 #include "gc/shared/collectedHeap.hpp"
41 #include "gc/shared/gcLocker.hpp"
42 #include "interpreter/bytecode.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "logging/log.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/oopFactory.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/klass.inline.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "opto/ad.hpp"
54 #include "opto/addnode.hpp"
55 #include "opto/callnode.hpp"
56 #include "opto/cfgnode.hpp"
57 #include "opto/graphKit.hpp"
58 #include "opto/machnode.hpp"
59 #include "opto/matcher.hpp"
60 #include "opto/memnode.hpp"
61 #include "opto/mulnode.hpp"
62 #include "opto/output.hpp"
63 #include "opto/runtime.hpp"
64 #include "opto/subnode.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "runtime/atomic.hpp"
67 #include "runtime/frame.inline.hpp"
68 #include "runtime/handles.inline.hpp"
89 //
90 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
91
92
93
94
95 // Compiled code entry points
96 address OptoRuntime::_new_instance_Java = nullptr;
97 address OptoRuntime::_new_array_Java = nullptr;
98 address OptoRuntime::_new_array_nozero_Java = nullptr;
99 address OptoRuntime::_multianewarray2_Java = nullptr;
100 address OptoRuntime::_multianewarray3_Java = nullptr;
101 address OptoRuntime::_multianewarray4_Java = nullptr;
102 address OptoRuntime::_multianewarray5_Java = nullptr;
103 address OptoRuntime::_multianewarrayN_Java = nullptr;
104 address OptoRuntime::_vtable_must_compile_Java = nullptr;
105 address OptoRuntime::_complete_monitor_locking_Java = nullptr;
106 address OptoRuntime::_monitor_notify_Java = nullptr;
107 address OptoRuntime::_monitor_notifyAll_Java = nullptr;
108 address OptoRuntime::_rethrow_Java = nullptr;
109
110 address OptoRuntime::_slow_arraycopy_Java = nullptr;
111 address OptoRuntime::_register_finalizer_Java = nullptr;
112 #if INCLUDE_JVMTI
113 address OptoRuntime::_notify_jvmti_vthread_start = nullptr;
114 address OptoRuntime::_notify_jvmti_vthread_end = nullptr;
115 address OptoRuntime::_notify_jvmti_vthread_mount = nullptr;
116 address OptoRuntime::_notify_jvmti_vthread_unmount = nullptr;
117 #endif
118
119 ExceptionBlob* OptoRuntime::_exception_blob;
120
121 // This should be called in an assertion at the start of OptoRuntime routines
122 // which are entered from compiled code (all of them)
123 #ifdef ASSERT
124 static bool check_compiled_frame(JavaThread* thread) {
125 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
126 RegisterMap map(thread,
127 RegisterMap::UpdateMap::skip,
128 RegisterMap::ProcessFrames::include,
129 RegisterMap::WalkContinuation::skip);
130 frame caller = thread->last_frame().sender(&map);
131 assert(caller.is_compiled_frame(), "not being called from compiled like code");
147 // variable/name type-function-gen , runtime method ,fncy_jp, tls,retpc
148 // -------------------------------------------------------------------------------------------------------------------------------
149 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true, false);
150 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true, false);
151 gen(env, _new_array_nozero_Java , new_array_Type , new_array_nozero_C , 0 , true, false);
152 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true, false);
153 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true, false);
154 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true, false);
155 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true, false);
156 gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true, false);
157 #if INCLUDE_JVMTI
158 gen(env, _notify_jvmti_vthread_start , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_start, 0, true, false);
159 gen(env, _notify_jvmti_vthread_end , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_end, 0, true, false);
160 gen(env, _notify_jvmti_vthread_mount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_mount, 0, true, false);
161 gen(env, _notify_jvmti_vthread_unmount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_unmount, 0, true, false);
162 #endif
163 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C, 0, false, false);
164 gen(env, _monitor_notify_Java , monitor_notify_Type , monitor_notify_C , 0 , false, false);
165 gen(env, _monitor_notifyAll_Java , monitor_notify_Type , monitor_notifyAll_C , 0 , false, false);
166 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , true );
167
168 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false);
169 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false);
170
171 return true;
172 }
173
174 #undef gen
175
176
177 // Helper method to do generation of RunTimeStub's
178 address OptoRuntime::generate_stub(ciEnv* env,
179 TypeFunc_generator gen, address C_function,
180 const char *name, int is_fancy_jump,
181 bool pass_tls,
182 bool return_pc) {
183
184 // Matching the default directive, we currently have no method to match.
185 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
186 ResourceMark rm;
187 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
188 DirectivesStack::release(directive);
189 return C.stub_entry_point();
195 RuntimeStub* rs =(RuntimeStub *)cb;
196 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
197 return rs->name();
198 #else
199 // Fast implementation for product mode (maybe it should be inlined too)
200 return "runtime stub";
201 #endif
202 }
203
204
205 //=============================================================================
206 // Opto compiler runtime routines
207 //=============================================================================
208
209
210 //=============================allocation======================================
211 // We failed the fast-path allocation. Now we need to do a scavenge or GC
212 // and try allocation again.
213
214 // object allocation
215 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
216 JRT_BLOCK;
217 #ifndef PRODUCT
218 SharedRuntime::_new_instance_ctr++; // new instance requires GC
219 #endif
220 assert(check_compiled_frame(current), "incorrect caller");
221
222 // These checks are cheap to make and support reflective allocation.
223 int lh = klass->layout_helper();
224 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
225 Handle holder(current, klass->klass_holder()); // keep the klass alive
226 klass->check_valid_for_instantiation(false, THREAD);
227 if (!HAS_PENDING_EXCEPTION) {
228 InstanceKlass::cast(klass)->initialize(THREAD);
229 }
230 }
231
232 if (!HAS_PENDING_EXCEPTION) {
233 // Scavenge and allocate an instance.
234 Handle holder(current, klass->klass_holder()); // keep the klass alive
235 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
236 current->set_vm_result(result);
237
238 // Pass oops back through thread local storage. Our apparent type to Java
239 // is that we return an oop, but we can block on exit from this routine and
240 // a GC can trash the oop in C's return register. The generated stub will
241 // fetch the oop from TLS after any possible GC.
242 }
243
244 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
245 JRT_BLOCK_END;
246
247 // inform GC that we won't do card marks for initializing writes.
248 SharedRuntime::on_slowpath_allocation_exit(current);
249 JRT_END
250
251
252 // array allocation
253 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
254 JRT_BLOCK;
255 #ifndef PRODUCT
256 SharedRuntime::_new_array_ctr++; // new array requires GC
257 #endif
258 assert(check_compiled_frame(current), "incorrect caller");
259
260 // Scavenge and allocate an instance.
261 oop result;
262
263 if (array_type->is_typeArray_klass()) {
264 // The oopFactory likes to work with the element type.
265 // (We could bypass the oopFactory, since it doesn't add much value.)
266 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
267 result = oopFactory::new_typeArray(elem_type, len, THREAD);
268 } else {
269 // Although the oopFactory likes to work with the elem_type,
270 // the compiler prefers the array_type, since it must already have
271 // that latter value in hand for the fast path.
272 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
273 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
274 result = oopFactory::new_objArray(elem_type, len, THREAD);
275 }
276
277 // Pass oops back through thread local storage. Our apparent type to Java
278 // is that we return an oop, but we can block on exit from this routine and
279 // a GC can trash the oop in C's return register. The generated stub will
280 // fetch the oop from TLS after any possible GC.
281 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
282 current->set_vm_result(result);
283 JRT_BLOCK_END;
284
285 // inform GC that we won't do card marks for initializing writes.
286 SharedRuntime::on_slowpath_allocation_exit(current);
287 JRT_END
288
289 // array allocation without zeroing
290 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
291 JRT_BLOCK;
292 #ifndef PRODUCT
293 SharedRuntime::_new_array_ctr++; // new array requires GC
294 #endif
448 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
449
450 if (!SafepointSynchronize::is_synchronizing() ) {
451 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
452 return;
453 }
454 }
455
456 // This is the case the fast-path above isn't provisioned to handle.
457 // The fast-path is designed to handle frequently arising cases in an efficient manner.
458 // (The fast-path is just a degenerate variant of the slow-path).
459 // Perform the dreaded state transition and pass control into the slow-path.
460 JRT_BLOCK;
461 Handle h_obj(current, obj);
462 ObjectSynchronizer::notifyall(h_obj, CHECK);
463 JRT_BLOCK_END;
464 JRT_END
465
466 const TypeFunc *OptoRuntime::new_instance_Type() {
467 // create input type (domain)
468 const Type **fields = TypeTuple::fields(1);
469 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
470 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
471
472 // create result type (range)
473 fields = TypeTuple::fields(1);
474 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
475
476 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
477
478 return TypeFunc::make(domain, range);
479 }
480
481 #if INCLUDE_JVMTI
482 const TypeFunc *OptoRuntime::notify_jvmti_vthread_Type() {
483 // create input type (domain)
484 const Type **fields = TypeTuple::fields(2);
485 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
486 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean
487 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
488
489 // no result type needed
490 fields = TypeTuple::fields(1);
584 fields = TypeTuple::fields(0);
585 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
586
587 return TypeFunc::make(domain, range);
588 }
589
590 //-----------------------------------------------------------------------------
591 // Monitor Handling
592 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
593 // create input type (domain)
594 const Type **fields = TypeTuple::fields(2);
595 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
596 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
597 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
598
599 // create result type (range)
600 fields = TypeTuple::fields(0);
601
602 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
603
604 return TypeFunc::make(domain,range);
605 }
606
607
608 //-----------------------------------------------------------------------------
609 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
610 // create input type (domain)
611 const Type **fields = TypeTuple::fields(3);
612 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
613 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
614 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
615 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
616
617 // create result type (range)
618 fields = TypeTuple::fields(0);
619
620 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
621
622 return TypeFunc::make(domain, range);
623 }
624
1672 frame stub_frame = thread->last_frame();
1673 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1674 frame caller_frame = stub_frame.sender(®_map);
1675 return caller_frame.is_deoptimized_frame();
1676 }
1677
1678
1679 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1680 // create input type (domain)
1681 const Type **fields = TypeTuple::fields(1);
1682 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1683 // // The JavaThread* is passed to each routine as the last argument
1684 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1685 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1686
1687 // create result type (range)
1688 fields = TypeTuple::fields(0);
1689
1690 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1691
1692 return TypeFunc::make(domain,range);
1693 }
1694
1695 #if INCLUDE_JFR
1696 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1697 // create input type (domain)
1698 const Type **fields = TypeTuple::fields(1);
1699 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1700 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1701
1702 // create result type (range)
1703 fields = TypeTuple::fields(0);
1704
1705 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1706
1707 return TypeFunc::make(domain,range);
1708 }
1709 #endif
1710
1711 //-----------------------------------------------------------------------------
1712 // Dtrace support. entry and exit probes have the same signature
1713 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1714 // create input type (domain)
1715 const Type **fields = TypeTuple::fields(2);
1716 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1717 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
1718 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1719
1720 // create result type (range)
1721 fields = TypeTuple::fields(0);
1722
1723 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1724
1725 return TypeFunc::make(domain,range);
1726 }
1727
1728 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1729 // create input type (domain)
1730 const Type **fields = TypeTuple::fields(2);
1731 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1732 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1733
1734 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1735
1736 // create result type (range)
1737 fields = TypeTuple::fields(0);
1738
1739 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1740
1741 return TypeFunc::make(domain,range);
1742 }
1743
1744
1745 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* current))
1746 assert(oopDesc::is_oop(obj), "must be a valid oop");
1747 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1748 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1749 JRT_END
1750
1751 //-----------------------------------------------------------------------------
1752
1753 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1754
1755 //
1756 // dump the collected NamedCounters.
1757 //
1758 void OptoRuntime::print_named_counters() {
1759 int total_lock_count = 0;
1760 int eliminated_lock_count = 0;
1761
1845 trace_exception_counter++;
1846 stringStream tempst;
1847
1848 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1849 exception_oop->print_value_on(&tempst);
1850 tempst.print(" in ");
1851 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1852 if (blob->is_compiled()) {
1853 CompiledMethod* cm = blob->as_compiled_method_or_null();
1854 cm->method()->print_value_on(&tempst);
1855 } else if (blob->is_runtime_stub()) {
1856 tempst.print("<runtime-stub>");
1857 } else {
1858 tempst.print("<unknown>");
1859 }
1860 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
1861 tempst.print("]");
1862
1863 st->print_raw_cr(tempst.freeze());
1864 }
|
29 #include "code/compiledMethod.inline.hpp"
30 #include "code/compiledIC.hpp"
31 #include "code/icBuffer.hpp"
32 #include "code/nmethod.hpp"
33 #include "code/pcDesc.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "code/vtableStubs.hpp"
36 #include "compiler/compileBroker.hpp"
37 #include "compiler/oopMap.hpp"
38 #include "gc/g1/heapRegion.hpp"
39 #include "gc/shared/barrierSet.hpp"
40 #include "gc/shared/collectedHeap.hpp"
41 #include "gc/shared/gcLocker.hpp"
42 #include "interpreter/bytecode.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "logging/log.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/oopFactory.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "oops/flatArrayKlass.hpp"
50 #include "oops/flatArrayOop.inline.hpp"
51 #include "oops/objArrayKlass.hpp"
52 #include "oops/klass.inline.hpp"
53 #include "oops/oop.inline.hpp"
54 #include "oops/typeArrayOop.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/atomic.hpp"
69 #include "runtime/frame.inline.hpp"
70 #include "runtime/handles.inline.hpp"
91 //
92 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
93
94
95
96
97 // Compiled code entry points
98 address OptoRuntime::_new_instance_Java = nullptr;
99 address OptoRuntime::_new_array_Java = nullptr;
100 address OptoRuntime::_new_array_nozero_Java = nullptr;
101 address OptoRuntime::_multianewarray2_Java = nullptr;
102 address OptoRuntime::_multianewarray3_Java = nullptr;
103 address OptoRuntime::_multianewarray4_Java = nullptr;
104 address OptoRuntime::_multianewarray5_Java = nullptr;
105 address OptoRuntime::_multianewarrayN_Java = nullptr;
106 address OptoRuntime::_vtable_must_compile_Java = nullptr;
107 address OptoRuntime::_complete_monitor_locking_Java = nullptr;
108 address OptoRuntime::_monitor_notify_Java = nullptr;
109 address OptoRuntime::_monitor_notifyAll_Java = nullptr;
110 address OptoRuntime::_rethrow_Java = nullptr;
111 address OptoRuntime::_slow_arraycopy_Java = nullptr;
112 address OptoRuntime::_register_finalizer_Java = nullptr;
113 address OptoRuntime::_load_unknown_inline = nullptr;
114 #if INCLUDE_JVMTI
115 address OptoRuntime::_notify_jvmti_vthread_start = nullptr;
116 address OptoRuntime::_notify_jvmti_vthread_end = nullptr;
117 address OptoRuntime::_notify_jvmti_vthread_mount = nullptr;
118 address OptoRuntime::_notify_jvmti_vthread_unmount = nullptr;
119 #endif
120
121 ExceptionBlob* OptoRuntime::_exception_blob;
122
123 // This should be called in an assertion at the start of OptoRuntime routines
124 // which are entered from compiled code (all of them)
125 #ifdef ASSERT
126 static bool check_compiled_frame(JavaThread* thread) {
127 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
128 RegisterMap map(thread,
129 RegisterMap::UpdateMap::skip,
130 RegisterMap::ProcessFrames::include,
131 RegisterMap::WalkContinuation::skip);
132 frame caller = thread->last_frame().sender(&map);
133 assert(caller.is_compiled_frame(), "not being called from compiled like code");
149 // variable/name type-function-gen , runtime method ,fncy_jp, tls,retpc
150 // -------------------------------------------------------------------------------------------------------------------------------
151 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true, false);
152 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true, false);
153 gen(env, _new_array_nozero_Java , new_array_Type , new_array_nozero_C , 0 , true, false);
154 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true, false);
155 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true, false);
156 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true, false);
157 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true, false);
158 gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true, false);
159 #if INCLUDE_JVMTI
160 gen(env, _notify_jvmti_vthread_start , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_start, 0, true, false);
161 gen(env, _notify_jvmti_vthread_end , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_end, 0, true, false);
162 gen(env, _notify_jvmti_vthread_mount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_mount, 0, true, false);
163 gen(env, _notify_jvmti_vthread_unmount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_unmount, 0, true, false);
164 #endif
165 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C, 0, false, false);
166 gen(env, _monitor_notify_Java , monitor_notify_Type , monitor_notify_C , 0 , false, false);
167 gen(env, _monitor_notifyAll_Java , monitor_notify_Type , monitor_notifyAll_C , 0 , false, false);
168 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , true );
169 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false);
170 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false);
171 gen(env, _load_unknown_inline , load_unknown_inline_type , load_unknown_inline , 0 , true, false);
172
173 return true;
174 }
175
176 #undef gen
177
178
179 // Helper method to do generation of RunTimeStub's
180 address OptoRuntime::generate_stub(ciEnv* env,
181 TypeFunc_generator gen, address C_function,
182 const char *name, int is_fancy_jump,
183 bool pass_tls,
184 bool return_pc) {
185
186 // Matching the default directive, we currently have no method to match.
187 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
188 ResourceMark rm;
189 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
190 DirectivesStack::release(directive);
191 return C.stub_entry_point();
197 RuntimeStub* rs =(RuntimeStub *)cb;
198 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
199 return rs->name();
200 #else
201 // Fast implementation for product mode (maybe it should be inlined too)
202 return "runtime stub";
203 #endif
204 }
205
206
207 //=============================================================================
208 // Opto compiler runtime routines
209 //=============================================================================
210
211
212 //=============================allocation======================================
213 // We failed the fast-path allocation. Now we need to do a scavenge or GC
214 // and try allocation again.
215
216 // object allocation
217 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, bool is_larval, JavaThread* current))
218 JRT_BLOCK;
219 #ifndef PRODUCT
220 SharedRuntime::_new_instance_ctr++; // new instance requires GC
221 #endif
222 assert(check_compiled_frame(current), "incorrect caller");
223
224 // These checks are cheap to make and support reflective allocation.
225 int lh = klass->layout_helper();
226 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
227 Handle holder(current, klass->klass_holder()); // keep the klass alive
228 klass->check_valid_for_instantiation(false, THREAD);
229 if (!HAS_PENDING_EXCEPTION) {
230 InstanceKlass::cast(klass)->initialize(THREAD);
231 }
232 }
233
234 if (!HAS_PENDING_EXCEPTION) {
235 // Scavenge and allocate an instance.
236 Handle holder(current, klass->klass_holder()); // keep the klass alive
237 instanceOop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
238 if (is_larval) {
239 // Check if this is a larval buffer allocation
240 result->set_mark(result->mark().enter_larval_state());
241 }
242 current->set_vm_result(result);
243
244 // Pass oops back through thread local storage. Our apparent type to Java
245 // is that we return an oop, but we can block on exit from this routine and
246 // a GC can trash the oop in C's return register. The generated stub will
247 // fetch the oop from TLS after any possible GC.
248 }
249
250 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
251 JRT_BLOCK_END;
252
253 // inform GC that we won't do card marks for initializing writes.
254 SharedRuntime::on_slowpath_allocation_exit(current);
255 JRT_END
256
257
258 // array allocation
259 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
260 JRT_BLOCK;
261 #ifndef PRODUCT
262 SharedRuntime::_new_array_ctr++; // new array requires GC
263 #endif
264 assert(check_compiled_frame(current), "incorrect caller");
265
266 // Scavenge and allocate an instance.
267 oop result;
268
269 if (array_type->is_flatArray_klass()) {
270 Klass* elem_type = FlatArrayKlass::cast(array_type)->element_klass();
271 result = oopFactory::new_valueArray(elem_type, len, THREAD);
272 } else if (array_type->is_typeArray_klass()) {
273 // The oopFactory likes to work with the element type.
274 // (We could bypass the oopFactory, since it doesn't add much value.)
275 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
276 result = oopFactory::new_typeArray(elem_type, len, THREAD);
277 } else {
278 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
279 result = ObjArrayKlass::cast(array_type)->allocate(len, THREAD);
280 }
281
282 // Pass oops back through thread local storage. Our apparent type to Java
283 // is that we return an oop, but we can block on exit from this routine and
284 // a GC can trash the oop in C's return register. The generated stub will
285 // fetch the oop from TLS after any possible GC.
286 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
287 current->set_vm_result(result);
288 JRT_BLOCK_END;
289
290 // inform GC that we won't do card marks for initializing writes.
291 SharedRuntime::on_slowpath_allocation_exit(current);
292 JRT_END
293
294 // array allocation without zeroing
295 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
296 JRT_BLOCK;
297 #ifndef PRODUCT
298 SharedRuntime::_new_array_ctr++; // new array requires GC
299 #endif
453 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
454
455 if (!SafepointSynchronize::is_synchronizing() ) {
456 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
457 return;
458 }
459 }
460
461 // This is the case the fast-path above isn't provisioned to handle.
462 // The fast-path is designed to handle frequently arising cases in an efficient manner.
463 // (The fast-path is just a degenerate variant of the slow-path).
464 // Perform the dreaded state transition and pass control into the slow-path.
465 JRT_BLOCK;
466 Handle h_obj(current, obj);
467 ObjectSynchronizer::notifyall(h_obj, CHECK);
468 JRT_BLOCK_END;
469 JRT_END
470
471 const TypeFunc *OptoRuntime::new_instance_Type() {
472 // create input type (domain)
473 const Type **fields = TypeTuple::fields(2);
474 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
475 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // is_larval
476 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
477
478 // create result type (range)
479 fields = TypeTuple::fields(1);
480 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
481
482 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
483
484 return TypeFunc::make(domain, range);
485 }
486
487 #if INCLUDE_JVMTI
488 const TypeFunc *OptoRuntime::notify_jvmti_vthread_Type() {
489 // create input type (domain)
490 const Type **fields = TypeTuple::fields(2);
491 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
492 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean
493 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
494
495 // no result type needed
496 fields = TypeTuple::fields(1);
590 fields = TypeTuple::fields(0);
591 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
592
593 return TypeFunc::make(domain, range);
594 }
595
596 //-----------------------------------------------------------------------------
597 // Monitor Handling
598 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
599 // create input type (domain)
600 const Type **fields = TypeTuple::fields(2);
601 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
602 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
603 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
604
605 // create result type (range)
606 fields = TypeTuple::fields(0);
607
608 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
609
610 return TypeFunc::make(domain, range);
611 }
612
613
614 //-----------------------------------------------------------------------------
615 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
616 // create input type (domain)
617 const Type **fields = TypeTuple::fields(3);
618 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
619 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
620 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
621 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
622
623 // create result type (range)
624 fields = TypeTuple::fields(0);
625
626 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
627
628 return TypeFunc::make(domain, range);
629 }
630
1678 frame stub_frame = thread->last_frame();
1679 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1680 frame caller_frame = stub_frame.sender(®_map);
1681 return caller_frame.is_deoptimized_frame();
1682 }
1683
1684
1685 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1686 // create input type (domain)
1687 const Type **fields = TypeTuple::fields(1);
1688 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1689 // // The JavaThread* is passed to each routine as the last argument
1690 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1691 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1692
1693 // create result type (range)
1694 fields = TypeTuple::fields(0);
1695
1696 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1697
1698 return TypeFunc::make(domain, range);
1699 }
1700
1701 #if INCLUDE_JFR
1702 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1703 // create input type (domain)
1704 const Type **fields = TypeTuple::fields(1);
1705 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1706 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1707
1708 // create result type (range)
1709 fields = TypeTuple::fields(0);
1710
1711 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1712
1713 return TypeFunc::make(domain,range);
1714 }
1715 #endif
1716
1717 //-----------------------------------------------------------------------------
1718 // Dtrace support. entry and exit probes have the same signature
1719 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1720 // create input type (domain)
1721 const Type **fields = TypeTuple::fields(2);
1722 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1723 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
1724 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1725
1726 // create result type (range)
1727 fields = TypeTuple::fields(0);
1728
1729 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1730
1731 return TypeFunc::make(domain, range);
1732 }
1733
1734 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1735 // create input type (domain)
1736 const Type **fields = TypeTuple::fields(2);
1737 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1738 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1739
1740 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1741
1742 // create result type (range)
1743 fields = TypeTuple::fields(0);
1744
1745 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1746
1747 return TypeFunc::make(domain, range);
1748 }
1749
1750
1751 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* current))
1752 assert(oopDesc::is_oop(obj), "must be a valid oop");
1753 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1754 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1755 JRT_END
1756
1757 //-----------------------------------------------------------------------------
1758
1759 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1760
1761 //
1762 // dump the collected NamedCounters.
1763 //
1764 void OptoRuntime::print_named_counters() {
1765 int total_lock_count = 0;
1766 int eliminated_lock_count = 0;
1767
1851 trace_exception_counter++;
1852 stringStream tempst;
1853
1854 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1855 exception_oop->print_value_on(&tempst);
1856 tempst.print(" in ");
1857 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1858 if (blob->is_compiled()) {
1859 CompiledMethod* cm = blob->as_compiled_method_or_null();
1860 cm->method()->print_value_on(&tempst);
1861 } else if (blob->is_runtime_stub()) {
1862 tempst.print("<runtime-stub>");
1863 } else {
1864 tempst.print("<unknown>");
1865 }
1866 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
1867 tempst.print("]");
1868
1869 st->print_raw_cr(tempst.freeze());
1870 }
1871
1872 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
1873 // create input type (domain)
1874 uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
1875 const Type **fields = TypeTuple::fields(total);
1876 // We don't know the number of returned values and their
1877 // types. Assume all registers available to the return convention
1878 // are used.
1879 fields[TypeFunc::Parms] = TypePtr::BOTTOM;
1880 uint i = 1;
1881 for (; i < SharedRuntime::java_return_convention_max_int; i++) {
1882 fields[TypeFunc::Parms+i] = TypeInt::INT;
1883 }
1884 for (; i < total; i+=2) {
1885 fields[TypeFunc::Parms+i] = Type::DOUBLE;
1886 fields[TypeFunc::Parms+i+1] = Type::HALF;
1887 }
1888 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
1889
1890 // create result type (range)
1891 fields = TypeTuple::fields(1);
1892 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
1893
1894 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
1895
1896 return TypeFunc::make(domain, range);
1897 }
1898
1899 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
1900 // create input type (domain)
1901 uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
1902 const Type **fields = TypeTuple::fields(total);
1903 // We don't know the number of returned values and their
1904 // types. Assume all registers available to the return convention
1905 // are used.
1906 fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
1907 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
1908 uint i = 2;
1909 for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
1910 fields[TypeFunc::Parms+i] = TypeInt::INT;
1911 }
1912 for (; i < total; i+=2) {
1913 fields[TypeFunc::Parms+i] = Type::DOUBLE;
1914 fields[TypeFunc::Parms+i+1] = Type::HALF;
1915 }
1916 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
1917
1918 // create result type (range)
1919 fields = TypeTuple::fields(1);
1920 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
1921
1922 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
1923
1924 return TypeFunc::make(domain, range);
1925 }
1926
1927 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline(flatArrayOopDesc* array, int index, JavaThread* current))
1928 JRT_BLOCK;
1929 flatArrayHandle vah(current, array);
1930 oop buffer = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, THREAD);
1931 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
1932 current->set_vm_result(buffer);
1933 JRT_BLOCK_END;
1934 JRT_END
1935
1936 const TypeFunc* OptoRuntime::load_unknown_inline_type() {
1937 // create input type (domain)
1938 const Type** fields = TypeTuple::fields(2);
1939 fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
1940 fields[TypeFunc::Parms+1] = TypeInt::POS;
1941
1942 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
1943
1944 // create result type (range)
1945 fields = TypeTuple::fields(1);
1946 fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
1947
1948 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1949
1950 return TypeFunc::make(domain, range);
1951 }
1952
1953 JRT_LEAF(void, OptoRuntime::store_unknown_inline(instanceOopDesc* buffer, flatArrayOopDesc* array, int index))
1954 {
1955 assert(buffer != nullptr, "can't store null into flat array");
1956 array->value_copy_to_index(buffer, index);
1957 }
1958 JRT_END
1959
1960 const TypeFunc* OptoRuntime::store_unknown_inline_type() {
1961 // create input type (domain)
1962 const Type** fields = TypeTuple::fields(3);
1963 fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
1964 fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
1965 fields[TypeFunc::Parms+2] = TypeInt::POS;
1966
1967 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
1968
1969 // create result type (range)
1970 fields = TypeTuple::fields(0);
1971 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1972
1973 return TypeFunc::make(domain, range);
1974 }
|