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