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 *
28 #include "code/codeCache.hpp"
29 #include "code/compiledIC.hpp"
30 #include "code/nmethod.hpp"
31 #include "code/pcDesc.hpp"
32 #include "code/scopeDesc.hpp"
33 #include "code/vtableStubs.hpp"
34 #include "compiler/compilationMemoryStatistic.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/oopMap.hpp"
37 #include "gc/g1/g1HeapRegion.hpp"
38 #include "gc/shared/barrierSet.hpp"
39 #include "gc/shared/collectedHeap.hpp"
40 #include "gc/shared/gcLocker.hpp"
41 #include "interpreter/bytecode.hpp"
42 #include "interpreter/interpreter.hpp"
43 #include "interpreter/linkResolver.hpp"
44 #include "logging/log.hpp"
45 #include "logging/logStream.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "oops/klass.inline.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "oops/typeArrayOop.inline.hpp"
52 #include "opto/ad.hpp"
53 #include "opto/addnode.hpp"
54 #include "opto/callnode.hpp"
55 #include "opto/cfgnode.hpp"
56 #include "opto/graphKit.hpp"
57 #include "opto/machnode.hpp"
58 #include "opto/matcher.hpp"
59 #include "opto/memnode.hpp"
60 #include "opto/mulnode.hpp"
61 #include "opto/output.hpp"
62 #include "opto/runtime.hpp"
63 #include "opto/subnode.hpp"
64 #include "prims/jvmtiExport.hpp"
65 #include "runtime/atomicAccess.hpp"
66 #include "runtime/frame.inline.hpp"
67 #include "runtime/handles.inline.hpp"
68 #include "runtime/interfaceSupport.inline.hpp"
69 #include "runtime/javaCalls.hpp"
70 #include "runtime/mountUnmountDisabler.hpp"
71 #include "runtime/sharedRuntime.hpp"
155 bool OptoRuntime::generate(ciEnv* env) {
156
157 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
158 // disallow any further c2 stub generation
159 AOTCodeCache::set_c2_stubs_complete();
160 return true;
161 }
162
163 #undef GEN_C2_BLOB
164
165 #undef C2_STUB_FIELD_NAME
166 #undef C2_STUB_TYPEFUNC
167 #undef C2_STUB_C_FUNC
168 #undef C2_STUB_NAME
169 #undef GEN_C2_STUB
170
171 // #undef gen
172
173 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
174 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
175 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr;
176 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr;
177 const TypeFunc* OptoRuntime::_multianewarray4_Type = nullptr;
178 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr;
179 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr;
180 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr;
181 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr;
182 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr;
183 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr;
184 const TypeFunc* OptoRuntime::_athrow_Type = nullptr;
185 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr;
186 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr;
187 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr;
188 const TypeFunc* OptoRuntime::_modf_Type = nullptr;
189 const TypeFunc* OptoRuntime::_l2f_Type = nullptr;
190 const TypeFunc* OptoRuntime::_void_long_Type = nullptr;
191 const TypeFunc* OptoRuntime::_void_void_Type = nullptr;
192 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr;
193 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr;
194 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr;
320 // Scavenge and allocate an instance.
321 Handle holder(current, klass->klass_holder()); // keep the klass alive
322 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
323 current->set_vm_result_oop(result);
324
325 // Pass oops back through thread local storage. Our apparent type to Java
326 // is that we return an oop, but we can block on exit from this routine and
327 // a GC can trash the oop in C's return register. The generated stub will
328 // fetch the oop from TLS after any possible GC.
329 }
330
331 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
332 JRT_BLOCK_END;
333
334 // inform GC that we won't do card marks for initializing writes.
335 SharedRuntime::on_slowpath_allocation_exit(current);
336 JRT_END
337
338
339 // array allocation
340 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
341 JRT_BLOCK;
342 #ifndef PRODUCT
343 SharedRuntime::_new_array_ctr++; // new array requires GC
344 #endif
345 assert(check_compiled_frame(current), "incorrect caller");
346
347 // Scavenge and allocate an instance.
348 oop result;
349
350 if (array_type->is_typeArray_klass()) {
351 // The oopFactory likes to work with the element type.
352 // (We could bypass the oopFactory, since it doesn't add much value.)
353 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
354 result = oopFactory::new_typeArray(elem_type, len, THREAD);
355 } else {
356 // Although the oopFactory likes to work with the elem_type,
357 // the compiler prefers the array_type, since it must already have
358 // that latter value in hand for the fast path.
359 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
360 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
361 result = oopFactory::new_objArray(elem_type, len, THREAD);
362 }
363
364 // Pass oops back through thread local storage. Our apparent type to Java
365 // is that we return an oop, but we can block on exit from this routine and
366 // a GC can trash the oop in C's return register. The generated stub will
367 // fetch the oop from TLS after any possible GC.
368 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
369 current->set_vm_result_oop(result);
370 JRT_BLOCK_END;
371
372 // inform GC that we won't do card marks for initializing writes.
373 SharedRuntime::on_slowpath_allocation_exit(current);
374 JRT_END
375
376 // array allocation without zeroing
377 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
378 JRT_BLOCK;
379 #ifndef PRODUCT
380 SharedRuntime::_new_array_ctr++; // new array requires GC
381 #endif
601 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
602
603 return TypeFunc::make(domain,range);
604 }
605
606 static const TypeFunc* make_athrow_Type() {
607 // create input type (domain)
608 const Type **fields = TypeTuple::fields(1);
609 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
610 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
611
612 // create result type (range)
613 fields = TypeTuple::fields(0);
614
615 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
616
617 return TypeFunc::make(domain, range);
618 }
619
620 static const TypeFunc* make_new_array_Type() {
621 // create input type (domain)
622 const Type **fields = TypeTuple::fields(2);
623 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
624 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
625 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
626
627 // create result type (range)
628 fields = TypeTuple::fields(1);
629 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
630
631 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
632
633 return TypeFunc::make(domain, range);
634 }
635
636 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) {
637 // create input type (domain)
638 const int nargs = ndim + 1;
639 const Type **fields = TypeTuple::fields(nargs);
640 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
676 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
677
678 return TypeFunc::make(domain, range);
679 }
680
681 //-----------------------------------------------------------------------------
682 // Monitor Handling
683
684 static const TypeFunc* make_complete_monitor_enter_Type() {
685 // create input type (domain)
686 const Type **fields = TypeTuple::fields(2);
687 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
688 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
689 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
690
691 // create result type (range)
692 fields = TypeTuple::fields(0);
693
694 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
695
696 return TypeFunc::make(domain,range);
697 }
698
699 //-----------------------------------------------------------------------------
700
701 static const TypeFunc* make_complete_monitor_exit_Type() {
702 // create input type (domain)
703 const Type **fields = TypeTuple::fields(3);
704 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
705 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
706 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
707 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
708
709 // create result type (range)
710 fields = TypeTuple::fields(0);
711
712 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
713
714 return TypeFunc::make(domain, range);
715 }
716
2112 RegisterMap::WalkContinuation::skip);
2113 frame stub_frame = thread->last_frame();
2114 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2115 frame caller_frame = stub_frame.sender(®_map);
2116 return caller_frame.is_deoptimized_frame();
2117 }
2118
2119 static const TypeFunc* make_register_finalizer_Type() {
2120 // create input type (domain)
2121 const Type **fields = TypeTuple::fields(1);
2122 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2123 // // The JavaThread* is passed to each routine as the last argument
2124 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2125 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2126
2127 // create result type (range)
2128 fields = TypeTuple::fields(0);
2129
2130 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2131
2132 return TypeFunc::make(domain,range);
2133 }
2134
2135 #if INCLUDE_JFR
2136 static const TypeFunc* make_class_id_load_barrier_Type() {
2137 // create input type (domain)
2138 const Type **fields = TypeTuple::fields(1);
2139 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2140 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2141
2142 // create result type (range)
2143 fields = TypeTuple::fields(0);
2144
2145 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2146
2147 return TypeFunc::make(domain,range);
2148 }
2149 #endif // INCLUDE_JFR
2150
2151 //-----------------------------------------------------------------------------
2152 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2153 // create input type (domain)
2154 const Type **fields = TypeTuple::fields(2);
2155 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2156 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2157 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2158
2159 // create result type (range)
2160 fields = TypeTuple::fields(0);
2161
2162 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2163
2164 return TypeFunc::make(domain,range);
2165 }
2166
2167 static const TypeFunc* make_dtrace_object_alloc_Type() {
2168 // create input type (domain)
2169 const Type **fields = TypeTuple::fields(2);
2170 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2171 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2172
2173 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2174
2175 // create result type (range)
2176 fields = TypeTuple::fields(0);
2177
2178 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2179
2180 return TypeFunc::make(domain,range);
2181 }
2182
2183 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2184 assert(oopDesc::is_oop(obj), "must be a valid oop");
2185 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2186 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2187 JRT_END
2188
2189 //-----------------------------------------------------------------------------
2190
2191 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2192
2193 //
2194 // dump the collected NamedCounters.
2195 //
2196 void OptoRuntime::print_named_counters() {
2197 int total_lock_count = 0;
2198 int eliminated_lock_count = 0;
2199
2200 NamedCounter* c = _named_counters;
2251 }
2252 st.print("@%d", bci);
2253 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2254 }
2255 NamedCounter* c = new NamedCounter(st.freeze(), tag);
2256
2257 // atomically add the new counter to the head of the list. We only
2258 // add counters so this is safe.
2259 NamedCounter* head;
2260 do {
2261 c->set_next(nullptr);
2262 head = _named_counters;
2263 c->set_next(head);
2264 } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2265 return c;
2266 }
2267
2268 void OptoRuntime::initialize_types() {
2269 _new_instance_Type = make_new_instance_Type();
2270 _new_array_Type = make_new_array_Type();
2271 _multianewarray2_Type = multianewarray_Type(2);
2272 _multianewarray3_Type = multianewarray_Type(3);
2273 _multianewarray4_Type = multianewarray_Type(4);
2274 _multianewarray5_Type = multianewarray_Type(5);
2275 _multianewarrayN_Type = make_multianewarrayN_Type();
2276 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2277 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2278 _monitor_notify_Type = make_monitor_notify_Type();
2279 _uncommon_trap_Type = make_uncommon_trap_Type();
2280 _athrow_Type = make_athrow_Type();
2281 _rethrow_Type = make_rethrow_Type();
2282 _Math_D_D_Type = make_Math_D_D_Type();
2283 _Math_DD_D_Type = make_Math_DD_D_Type();
2284 _modf_Type = make_modf_Type();
2285 _l2f_Type = make_l2f_Type();
2286 _void_long_Type = make_void_long_Type();
2287 _void_void_Type = make_void_void_Type();
2288 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2289 _flush_windows_Type = make_flush_windows_Type();
2290 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2349 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2350 trace_exception_counter++;
2351 stringStream tempst;
2352
2353 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2354 exception_oop->print_value_on(&tempst);
2355 tempst.print(" in ");
2356 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2357 if (blob->is_nmethod()) {
2358 blob->as_nmethod()->method()->print_value_on(&tempst);
2359 } else if (blob->is_runtime_stub()) {
2360 tempst.print("<runtime-stub>");
2361 } else {
2362 tempst.print("<unknown>");
2363 }
2364 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2365 tempst.print("]");
2366
2367 st->print_raw_cr(tempst.freeze());
2368 }
|
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 *
28 #include "code/codeCache.hpp"
29 #include "code/compiledIC.hpp"
30 #include "code/nmethod.hpp"
31 #include "code/pcDesc.hpp"
32 #include "code/scopeDesc.hpp"
33 #include "code/vtableStubs.hpp"
34 #include "compiler/compilationMemoryStatistic.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/oopMap.hpp"
37 #include "gc/g1/g1HeapRegion.hpp"
38 #include "gc/shared/barrierSet.hpp"
39 #include "gc/shared/collectedHeap.hpp"
40 #include "gc/shared/gcLocker.hpp"
41 #include "interpreter/bytecode.hpp"
42 #include "interpreter/interpreter.hpp"
43 #include "interpreter/linkResolver.hpp"
44 #include "logging/log.hpp"
45 #include "logging/logStream.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "oops/flatArrayKlass.hpp"
49 #include "oops/flatArrayOop.inline.hpp"
50 #include "oops/inlineKlass.inline.hpp"
51 #include "oops/klass.inline.hpp"
52 #include "oops/objArrayKlass.hpp"
53 #include "oops/oop.inline.hpp"
54 #include "oops/typeArrayOop.inline.hpp"
55 #include "oops/valuePayload.inline.hpp"
56 #include "opto/ad.hpp"
57 #include "opto/addnode.hpp"
58 #include "opto/callnode.hpp"
59 #include "opto/cfgnode.hpp"
60 #include "opto/graphKit.hpp"
61 #include "opto/machnode.hpp"
62 #include "opto/matcher.hpp"
63 #include "opto/memnode.hpp"
64 #include "opto/mulnode.hpp"
65 #include "opto/output.hpp"
66 #include "opto/runtime.hpp"
67 #include "opto/subnode.hpp"
68 #include "prims/jvmtiExport.hpp"
69 #include "runtime/atomicAccess.hpp"
70 #include "runtime/frame.inline.hpp"
71 #include "runtime/handles.inline.hpp"
72 #include "runtime/interfaceSupport.inline.hpp"
73 #include "runtime/javaCalls.hpp"
74 #include "runtime/mountUnmountDisabler.hpp"
75 #include "runtime/sharedRuntime.hpp"
159 bool OptoRuntime::generate(ciEnv* env) {
160
161 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
162 // disallow any further c2 stub generation
163 AOTCodeCache::set_c2_stubs_complete();
164 return true;
165 }
166
167 #undef GEN_C2_BLOB
168
169 #undef C2_STUB_FIELD_NAME
170 #undef C2_STUB_TYPEFUNC
171 #undef C2_STUB_C_FUNC
172 #undef C2_STUB_NAME
173 #undef GEN_C2_STUB
174
175 // #undef gen
176
177 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
178 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
179 const TypeFunc* OptoRuntime::_new_array_nozero_Type = nullptr;
180 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr;
181 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr;
182 const TypeFunc* OptoRuntime::_multianewarray4_Type = nullptr;
183 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr;
184 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr;
185 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr;
186 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr;
187 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr;
188 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr;
189 const TypeFunc* OptoRuntime::_athrow_Type = nullptr;
190 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr;
191 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr;
192 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr;
193 const TypeFunc* OptoRuntime::_modf_Type = nullptr;
194 const TypeFunc* OptoRuntime::_l2f_Type = nullptr;
195 const TypeFunc* OptoRuntime::_void_long_Type = nullptr;
196 const TypeFunc* OptoRuntime::_void_void_Type = nullptr;
197 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr;
198 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr;
199 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr;
325 // Scavenge and allocate an instance.
326 Handle holder(current, klass->klass_holder()); // keep the klass alive
327 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
328 current->set_vm_result_oop(result);
329
330 // Pass oops back through thread local storage. Our apparent type to Java
331 // is that we return an oop, but we can block on exit from this routine and
332 // a GC can trash the oop in C's return register. The generated stub will
333 // fetch the oop from TLS after any possible GC.
334 }
335
336 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
337 JRT_BLOCK_END;
338
339 // inform GC that we won't do card marks for initializing writes.
340 SharedRuntime::on_slowpath_allocation_exit(current);
341 JRT_END
342
343
344 // array allocation
345 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, oopDesc* init_val, JavaThread* current))
346 JRT_BLOCK;
347 #ifndef PRODUCT
348 SharedRuntime::_new_array_ctr++; // new array requires GC
349 #endif
350 assert(check_compiled_frame(current), "incorrect caller");
351
352 // Scavenge and allocate an instance.
353 oop result;
354 Handle h_init_val(current, init_val); // keep the init_val object alive
355
356 if (array_type->is_typeArray_klass()) {
357 // The oopFactory likes to work with the element type.
358 // (We could bypass the oopFactory, since it doesn't add much value.)
359 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
360 result = oopFactory::new_typeArray(elem_type, len, THREAD);
361 } else {
362 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
363 ObjArrayKlass* oak = ObjArrayKlass::cast(array_type);
364 result = oopFactory::new_objArray(oak->element_klass(), len, oak->properties(), THREAD);
365 if (!HAS_PENDING_EXCEPTION && array_type->is_null_free_array_klass() && !h_init_val.is_null()) {
366 // Null-free arrays need to be initialized
367 #ifdef ASSERT
368 ObjArrayKlass* result_oak = ObjArrayKlass::cast(result->klass());
369 assert(result_oak->is_null_free_array_klass(), "Sanity check");
370 #endif
371 for (int i = 0; i < len; i++) {
372 ((objArrayOop)result)->obj_at_put(i, h_init_val());
373 }
374 }
375 }
376
377 // Pass oops back through thread local storage. Our apparent type to Java
378 // is that we return an oop, but we can block on exit from this routine and
379 // a GC can trash the oop in C's return register. The generated stub will
380 // fetch the oop from TLS after any possible GC.
381 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
382 current->set_vm_result_oop(result);
383 JRT_BLOCK_END;
384
385 // inform GC that we won't do card marks for initializing writes.
386 SharedRuntime::on_slowpath_allocation_exit(current);
387 JRT_END
388
389 // array allocation without zeroing
390 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
391 JRT_BLOCK;
392 #ifndef PRODUCT
393 SharedRuntime::_new_array_ctr++; // new array requires GC
394 #endif
614 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
615
616 return TypeFunc::make(domain,range);
617 }
618
619 static const TypeFunc* make_athrow_Type() {
620 // create input type (domain)
621 const Type **fields = TypeTuple::fields(1);
622 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
623 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
624
625 // create result type (range)
626 fields = TypeTuple::fields(0);
627
628 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
629
630 return TypeFunc::make(domain, range);
631 }
632
633 static const TypeFunc* make_new_array_Type() {
634 // create input type (domain)
635 const Type **fields = TypeTuple::fields(3);
636 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
637 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
638 fields[TypeFunc::Parms+2] = TypeInstPtr::NOTNULL; // init value
639 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
640
641 // create result type (range)
642 fields = TypeTuple::fields(1);
643 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
644
645 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
646
647 return TypeFunc::make(domain, range);
648 }
649
650 static const TypeFunc* make_new_array_nozero_Type() {
651 // create input type (domain)
652 const Type **fields = TypeTuple::fields(2);
653 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
654 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
655 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
656
657 // create result type (range)
658 fields = TypeTuple::fields(1);
659 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
660
661 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
662
663 return TypeFunc::make(domain, range);
664 }
665
666 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) {
667 // create input type (domain)
668 const int nargs = ndim + 1;
669 const Type **fields = TypeTuple::fields(nargs);
670 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
706 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
707
708 return TypeFunc::make(domain, range);
709 }
710
711 //-----------------------------------------------------------------------------
712 // Monitor Handling
713
714 static const TypeFunc* make_complete_monitor_enter_Type() {
715 // create input type (domain)
716 const Type **fields = TypeTuple::fields(2);
717 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
718 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
719 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
720
721 // create result type (range)
722 fields = TypeTuple::fields(0);
723
724 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
725
726 return TypeFunc::make(domain, range);
727 }
728
729 //-----------------------------------------------------------------------------
730
731 static const TypeFunc* make_complete_monitor_exit_Type() {
732 // create input type (domain)
733 const Type **fields = TypeTuple::fields(3);
734 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
735 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
736 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
737 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
738
739 // create result type (range)
740 fields = TypeTuple::fields(0);
741
742 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
743
744 return TypeFunc::make(domain, range);
745 }
746
2142 RegisterMap::WalkContinuation::skip);
2143 frame stub_frame = thread->last_frame();
2144 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2145 frame caller_frame = stub_frame.sender(®_map);
2146 return caller_frame.is_deoptimized_frame();
2147 }
2148
2149 static const TypeFunc* make_register_finalizer_Type() {
2150 // create input type (domain)
2151 const Type **fields = TypeTuple::fields(1);
2152 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2153 // // The JavaThread* is passed to each routine as the last argument
2154 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2155 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2156
2157 // create result type (range)
2158 fields = TypeTuple::fields(0);
2159
2160 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2161
2162 return TypeFunc::make(domain, range);
2163 }
2164
2165 #if INCLUDE_JFR
2166 static const TypeFunc* make_class_id_load_barrier_Type() {
2167 // create input type (domain)
2168 const Type **fields = TypeTuple::fields(1);
2169 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2170 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2171
2172 // create result type (range)
2173 fields = TypeTuple::fields(0);
2174
2175 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2176
2177 return TypeFunc::make(domain,range);
2178 }
2179 #endif // INCLUDE_JFR
2180
2181 //-----------------------------------------------------------------------------
2182 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2183 // create input type (domain)
2184 const Type **fields = TypeTuple::fields(2);
2185 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2186 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2187 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2188
2189 // create result type (range)
2190 fields = TypeTuple::fields(0);
2191
2192 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2193
2194 return TypeFunc::make(domain, range);
2195 }
2196
2197 static const TypeFunc* make_dtrace_object_alloc_Type() {
2198 // create input type (domain)
2199 const Type **fields = TypeTuple::fields(2);
2200 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2201 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2202
2203 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2204
2205 // create result type (range)
2206 fields = TypeTuple::fields(0);
2207
2208 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2209
2210 return TypeFunc::make(domain, range);
2211 }
2212
2213 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2214 assert(oopDesc::is_oop(obj), "must be a valid oop");
2215 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2216 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2217 JRT_END
2218
2219 //-----------------------------------------------------------------------------
2220
2221 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2222
2223 //
2224 // dump the collected NamedCounters.
2225 //
2226 void OptoRuntime::print_named_counters() {
2227 int total_lock_count = 0;
2228 int eliminated_lock_count = 0;
2229
2230 NamedCounter* c = _named_counters;
2281 }
2282 st.print("@%d", bci);
2283 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2284 }
2285 NamedCounter* c = new NamedCounter(st.freeze(), tag);
2286
2287 // atomically add the new counter to the head of the list. We only
2288 // add counters so this is safe.
2289 NamedCounter* head;
2290 do {
2291 c->set_next(nullptr);
2292 head = _named_counters;
2293 c->set_next(head);
2294 } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2295 return c;
2296 }
2297
2298 void OptoRuntime::initialize_types() {
2299 _new_instance_Type = make_new_instance_Type();
2300 _new_array_Type = make_new_array_Type();
2301 _new_array_nozero_Type = make_new_array_nozero_Type();
2302 _multianewarray2_Type = multianewarray_Type(2);
2303 _multianewarray3_Type = multianewarray_Type(3);
2304 _multianewarray4_Type = multianewarray_Type(4);
2305 _multianewarray5_Type = multianewarray_Type(5);
2306 _multianewarrayN_Type = make_multianewarrayN_Type();
2307 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2308 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2309 _monitor_notify_Type = make_monitor_notify_Type();
2310 _uncommon_trap_Type = make_uncommon_trap_Type();
2311 _athrow_Type = make_athrow_Type();
2312 _rethrow_Type = make_rethrow_Type();
2313 _Math_D_D_Type = make_Math_D_D_Type();
2314 _Math_DD_D_Type = make_Math_DD_D_Type();
2315 _modf_Type = make_modf_Type();
2316 _l2f_Type = make_l2f_Type();
2317 _void_long_Type = make_void_long_Type();
2318 _void_void_Type = make_void_void_Type();
2319 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2320 _flush_windows_Type = make_flush_windows_Type();
2321 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2380 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2381 trace_exception_counter++;
2382 stringStream tempst;
2383
2384 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2385 exception_oop->print_value_on(&tempst);
2386 tempst.print(" in ");
2387 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2388 if (blob->is_nmethod()) {
2389 blob->as_nmethod()->method()->print_value_on(&tempst);
2390 } else if (blob->is_runtime_stub()) {
2391 tempst.print("<runtime-stub>");
2392 } else {
2393 tempst.print("<unknown>");
2394 }
2395 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2396 tempst.print("]");
2397
2398 st->print_raw_cr(tempst.freeze());
2399 }
2400
2401 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
2402 // create input type (domain)
2403 uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2404 const Type **fields = TypeTuple::fields(total);
2405 // We don't know the number of returned values and their
2406 // types. Assume all registers available to the return convention
2407 // are used.
2408 fields[TypeFunc::Parms] = TypePtr::BOTTOM;
2409 uint i = 1;
2410 for (; i < SharedRuntime::java_return_convention_max_int; i++) {
2411 fields[TypeFunc::Parms+i] = TypeInt::INT;
2412 }
2413 for (; i < total; i+=2) {
2414 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2415 fields[TypeFunc::Parms+i+1] = Type::HALF;
2416 }
2417 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2418
2419 // create result type (range)
2420 fields = TypeTuple::fields(1);
2421 fields[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM;
2422
2423 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2424
2425 return TypeFunc::make(domain, range);
2426 }
2427
2428 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
2429 // create input type (domain)
2430 uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2431 const Type **fields = TypeTuple::fields(total);
2432 // We don't know the number of returned values and their
2433 // types. Assume all registers available to the return convention
2434 // are used.
2435 fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
2436 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
2437 uint i = 2;
2438 for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
2439 fields[TypeFunc::Parms+i] = TypeInt::INT;
2440 }
2441 for (; i < total; i+=2) {
2442 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2443 fields[TypeFunc::Parms+i+1] = Type::HALF;
2444 }
2445 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2446
2447 // create result type (range)
2448 fields = TypeTuple::fields(1);
2449 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
2450
2451 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2452
2453 return TypeFunc::make(domain, range);
2454 }
2455
2456 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline_C(flatArrayOopDesc* array, int index, JavaThread* current))
2457 JRT_BLOCK;
2458 oop buffer = array->obj_at(index, THREAD);
2459 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
2460 current->set_vm_result_oop(buffer);
2461 JRT_BLOCK_END;
2462 JRT_END
2463
2464 const TypeFunc* OptoRuntime::load_unknown_inline_Type() {
2465 // create input type (domain)
2466 const Type** fields = TypeTuple::fields(2);
2467 fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
2468 fields[TypeFunc::Parms+1] = TypeInt::POS;
2469
2470 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
2471
2472 // create result type (range)
2473 fields = TypeTuple::fields(1);
2474 fields[TypeFunc::Parms] = TypeInstPtr::BOTTOM;
2475
2476 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
2477
2478 return TypeFunc::make(domain, range);
2479 }
2480
2481 JRT_BLOCK_ENTRY(void, OptoRuntime::store_unknown_inline_C(instanceOopDesc* buffer, flatArrayOopDesc* array, int index, JavaThread* current))
2482 JRT_BLOCK;
2483 array->obj_at_put(index, buffer, THREAD);
2484 if (HAS_PENDING_EXCEPTION) {
2485 fatal("This entry must be changed to be a non-leaf entry because writing to a flat array can now throw an exception");
2486 }
2487 JRT_BLOCK_END;
2488 JRT_END
2489
2490 const TypeFunc* OptoRuntime::store_unknown_inline_Type() {
2491 // create input type (domain)
2492 const Type** fields = TypeTuple::fields(3);
2493 fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2494 fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
2495 fields[TypeFunc::Parms+2] = TypeInt::POS;
2496
2497 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
2498
2499 // create result type (range)
2500 fields = TypeTuple::fields(0);
2501 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
2502
2503 return TypeFunc::make(domain, range);
2504 }
|