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
2133 RegisterMap::WalkContinuation::skip);
2134 frame stub_frame = thread->last_frame();
2135 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2136 frame caller_frame = stub_frame.sender(®_map);
2137 return caller_frame.is_deoptimized_frame();
2138 }
2139
2140 static const TypeFunc* make_register_finalizer_Type() {
2141 // create input type (domain)
2142 const Type **fields = TypeTuple::fields(1);
2143 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2144 // // The JavaThread* is passed to each routine as the last argument
2145 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2146 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2147
2148 // create result type (range)
2149 fields = TypeTuple::fields(0);
2150
2151 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2152
2153 return TypeFunc::make(domain,range);
2154 }
2155
2156 #if INCLUDE_JFR
2157 static const TypeFunc* make_class_id_load_barrier_Type() {
2158 // create input type (domain)
2159 const Type **fields = TypeTuple::fields(1);
2160 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2161 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2162
2163 // create result type (range)
2164 fields = TypeTuple::fields(0);
2165
2166 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2167
2168 return TypeFunc::make(domain,range);
2169 }
2170 #endif // INCLUDE_JFR
2171
2172 //-----------------------------------------------------------------------------
2173 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2174 // create input type (domain)
2175 const Type **fields = TypeTuple::fields(2);
2176 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2177 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2178 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2179
2180 // create result type (range)
2181 fields = TypeTuple::fields(0);
2182
2183 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2184
2185 return TypeFunc::make(domain,range);
2186 }
2187
2188 static const TypeFunc* make_dtrace_object_alloc_Type() {
2189 // create input type (domain)
2190 const Type **fields = TypeTuple::fields(2);
2191 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2192 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2193
2194 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2195
2196 // create result type (range)
2197 fields = TypeTuple::fields(0);
2198
2199 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2200
2201 return TypeFunc::make(domain,range);
2202 }
2203
2204 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2205 assert(oopDesc::is_oop(obj), "must be a valid oop");
2206 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2207 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2208 JRT_END
2209
2210 //-----------------------------------------------------------------------------
2211
2212 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2213
2214 //
2215 // dump the collected NamedCounters.
2216 //
2217 void OptoRuntime::print_named_counters() {
2218 int total_lock_count = 0;
2219 int eliminated_lock_count = 0;
2220
2221 NamedCounter* c = _named_counters;
2272 }
2273 st.print("@%d", bci);
2274 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2275 }
2276 NamedCounter* c = new NamedCounter(st.freeze(), tag);
2277
2278 // atomically add the new counter to the head of the list. We only
2279 // add counters so this is safe.
2280 NamedCounter* head;
2281 do {
2282 c->set_next(nullptr);
2283 head = _named_counters;
2284 c->set_next(head);
2285 } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2286 return c;
2287 }
2288
2289 void OptoRuntime::initialize_types() {
2290 _new_instance_Type = make_new_instance_Type();
2291 _new_array_Type = make_new_array_Type();
2292 _multianewarray2_Type = multianewarray_Type(2);
2293 _multianewarray3_Type = multianewarray_Type(3);
2294 _multianewarray4_Type = multianewarray_Type(4);
2295 _multianewarray5_Type = multianewarray_Type(5);
2296 _multianewarrayN_Type = make_multianewarrayN_Type();
2297 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2298 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2299 _monitor_notify_Type = make_monitor_notify_Type();
2300 _uncommon_trap_Type = make_uncommon_trap_Type();
2301 _athrow_Type = make_athrow_Type();
2302 _rethrow_Type = make_rethrow_Type();
2303 _Math_D_D_Type = make_Math_D_D_Type();
2304 _Math_DD_D_Type = make_Math_DD_D_Type();
2305 _modf_Type = make_modf_Type();
2306 _l2f_Type = make_l2f_Type();
2307 _void_long_Type = make_void_long_Type();
2308 _void_void_Type = make_void_void_Type();
2309 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2310 _flush_windows_Type = make_flush_windows_Type();
2311 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2371 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2372 trace_exception_counter++;
2373 stringStream tempst;
2374
2375 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2376 exception_oop->print_value_on(&tempst);
2377 tempst.print(" in ");
2378 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2379 if (blob->is_nmethod()) {
2380 blob->as_nmethod()->method()->print_value_on(&tempst);
2381 } else if (blob->is_runtime_stub()) {
2382 tempst.print("<runtime-stub>");
2383 } else {
2384 tempst.print("<unknown>");
2385 }
2386 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2387 tempst.print("]");
2388
2389 st->print_raw_cr(tempst.freeze());
2390 }
|
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
2163 RegisterMap::WalkContinuation::skip);
2164 frame stub_frame = thread->last_frame();
2165 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2166 frame caller_frame = stub_frame.sender(®_map);
2167 return caller_frame.is_deoptimized_frame();
2168 }
2169
2170 static const TypeFunc* make_register_finalizer_Type() {
2171 // create input type (domain)
2172 const Type **fields = TypeTuple::fields(1);
2173 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2174 // // The JavaThread* is passed to each routine as the last argument
2175 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2176 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2177
2178 // create result type (range)
2179 fields = TypeTuple::fields(0);
2180
2181 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2182
2183 return TypeFunc::make(domain, range);
2184 }
2185
2186 #if INCLUDE_JFR
2187 static const TypeFunc* make_class_id_load_barrier_Type() {
2188 // create input type (domain)
2189 const Type **fields = TypeTuple::fields(1);
2190 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2191 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2192
2193 // create result type (range)
2194 fields = TypeTuple::fields(0);
2195
2196 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2197
2198 return TypeFunc::make(domain,range);
2199 }
2200 #endif // INCLUDE_JFR
2201
2202 //-----------------------------------------------------------------------------
2203 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2204 // create input type (domain)
2205 const Type **fields = TypeTuple::fields(2);
2206 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2207 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2208 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2209
2210 // create result type (range)
2211 fields = TypeTuple::fields(0);
2212
2213 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2214
2215 return TypeFunc::make(domain, range);
2216 }
2217
2218 static const TypeFunc* make_dtrace_object_alloc_Type() {
2219 // create input type (domain)
2220 const Type **fields = TypeTuple::fields(2);
2221 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2222 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2223
2224 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2225
2226 // create result type (range)
2227 fields = TypeTuple::fields(0);
2228
2229 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2230
2231 return TypeFunc::make(domain, range);
2232 }
2233
2234 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2235 assert(oopDesc::is_oop(obj), "must be a valid oop");
2236 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2237 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2238 JRT_END
2239
2240 //-----------------------------------------------------------------------------
2241
2242 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2243
2244 //
2245 // dump the collected NamedCounters.
2246 //
2247 void OptoRuntime::print_named_counters() {
2248 int total_lock_count = 0;
2249 int eliminated_lock_count = 0;
2250
2251 NamedCounter* c = _named_counters;
2302 }
2303 st.print("@%d", bci);
2304 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
2305 }
2306 NamedCounter* c = new NamedCounter(st.freeze(), tag);
2307
2308 // atomically add the new counter to the head of the list. We only
2309 // add counters so this is safe.
2310 NamedCounter* head;
2311 do {
2312 c->set_next(nullptr);
2313 head = _named_counters;
2314 c->set_next(head);
2315 } while (AtomicAccess::cmpxchg(&_named_counters, head, c) != head);
2316 return c;
2317 }
2318
2319 void OptoRuntime::initialize_types() {
2320 _new_instance_Type = make_new_instance_Type();
2321 _new_array_Type = make_new_array_Type();
2322 _new_array_nozero_Type = make_new_array_nozero_Type();
2323 _multianewarray2_Type = multianewarray_Type(2);
2324 _multianewarray3_Type = multianewarray_Type(3);
2325 _multianewarray4_Type = multianewarray_Type(4);
2326 _multianewarray5_Type = multianewarray_Type(5);
2327 _multianewarrayN_Type = make_multianewarrayN_Type();
2328 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2329 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2330 _monitor_notify_Type = make_monitor_notify_Type();
2331 _uncommon_trap_Type = make_uncommon_trap_Type();
2332 _athrow_Type = make_athrow_Type();
2333 _rethrow_Type = make_rethrow_Type();
2334 _Math_D_D_Type = make_Math_D_D_Type();
2335 _Math_DD_D_Type = make_Math_DD_D_Type();
2336 _modf_Type = make_modf_Type();
2337 _l2f_Type = make_l2f_Type();
2338 _void_long_Type = make_void_long_Type();
2339 _void_void_Type = make_void_void_Type();
2340 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2341 _flush_windows_Type = make_flush_windows_Type();
2342 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2402 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2403 trace_exception_counter++;
2404 stringStream tempst;
2405
2406 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2407 exception_oop->print_value_on(&tempst);
2408 tempst.print(" in ");
2409 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2410 if (blob->is_nmethod()) {
2411 blob->as_nmethod()->method()->print_value_on(&tempst);
2412 } else if (blob->is_runtime_stub()) {
2413 tempst.print("<runtime-stub>");
2414 } else {
2415 tempst.print("<unknown>");
2416 }
2417 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2418 tempst.print("]");
2419
2420 st->print_raw_cr(tempst.freeze());
2421 }
2422
2423 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
2424 // create input type (domain)
2425 uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2426 const Type **fields = TypeTuple::fields(total);
2427 // We don't know the number of returned values and their
2428 // types. Assume all registers available to the return convention
2429 // are used.
2430 fields[TypeFunc::Parms] = TypePtr::BOTTOM;
2431 uint i = 1;
2432 for (; i < SharedRuntime::java_return_convention_max_int; i++) {
2433 fields[TypeFunc::Parms+i] = TypeInt::INT;
2434 }
2435 for (; i < total; i+=2) {
2436 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2437 fields[TypeFunc::Parms+i+1] = Type::HALF;
2438 }
2439 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2440
2441 // create result type (range)
2442 fields = TypeTuple::fields(1);
2443 fields[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM;
2444
2445 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2446
2447 return TypeFunc::make(domain, range);
2448 }
2449
2450 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
2451 // create input type (domain)
2452 uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2453 const Type **fields = TypeTuple::fields(total);
2454 // We don't know the number of returned values and their
2455 // types. Assume all registers available to the return convention
2456 // are used.
2457 fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
2458 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
2459 uint i = 2;
2460 for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
2461 fields[TypeFunc::Parms+i] = TypeInt::INT;
2462 }
2463 for (; i < total; i+=2) {
2464 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2465 fields[TypeFunc::Parms+i+1] = Type::HALF;
2466 }
2467 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2468
2469 // create result type (range)
2470 fields = TypeTuple::fields(1);
2471 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
2472
2473 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2474
2475 return TypeFunc::make(domain, range);
2476 }
2477
2478 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline_C(flatArrayOopDesc* array, int index, JavaThread* current))
2479 JRT_BLOCK;
2480 oop buffer = array->obj_at(index, THREAD);
2481 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
2482 current->set_vm_result_oop(buffer);
2483 JRT_BLOCK_END;
2484 JRT_END
2485
2486 const TypeFunc* OptoRuntime::load_unknown_inline_Type() {
2487 // create input type (domain)
2488 const Type** fields = TypeTuple::fields(2);
2489 fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
2490 fields[TypeFunc::Parms+1] = TypeInt::POS;
2491
2492 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
2493
2494 // create result type (range)
2495 fields = TypeTuple::fields(1);
2496 fields[TypeFunc::Parms] = TypeInstPtr::BOTTOM;
2497
2498 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
2499
2500 return TypeFunc::make(domain, range);
2501 }
2502
2503 JRT_BLOCK_ENTRY(void, OptoRuntime::store_unknown_inline_C(instanceOopDesc* buffer, flatArrayOopDesc* array, int index, JavaThread* current))
2504 JRT_BLOCK;
2505 array->obj_at_put(index, buffer, THREAD);
2506 if (HAS_PENDING_EXCEPTION) {
2507 fatal("This entry must be changed to be a non-leaf entry because writing to a flat array can now throw an exception");
2508 }
2509 JRT_BLOCK_END;
2510 JRT_END
2511
2512 const TypeFunc* OptoRuntime::store_unknown_inline_Type() {
2513 // create input type (domain)
2514 const Type** fields = TypeTuple::fields(3);
2515 fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2516 fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
2517 fields[TypeFunc::Parms+2] = TypeInt::POS;
2518
2519 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
2520
2521 // create result type (range)
2522 fields = TypeTuple::fields(0);
2523 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
2524
2525 return TypeFunc::make(domain, range);
2526 }
|