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