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 *
23 */
24
25 #include "classfile/vmClasses.hpp"
26 #include "classfile/vmSymbols.hpp"
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/klass.inline.hpp"
50 #include "oops/objArrayKlass.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "opto/ad.hpp"
54 #include "opto/addnode.hpp"
55 #include "opto/callnode.hpp"
56 #include "opto/cfgnode.hpp"
57 #include "opto/graphKit.hpp"
58 #include "opto/machnode.hpp"
59 #include "opto/matcher.hpp"
60 #include "opto/memnode.hpp"
61 #include "opto/mulnode.hpp"
62 #include "opto/output.hpp"
63 #include "opto/runtime.hpp"
64 #include "opto/subnode.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "runtime/atomicAccess.hpp"
67 #include "runtime/frame.inline.hpp"
68 #include "runtime/handles.inline.hpp"
69 #include "runtime/interfaceSupport.inline.hpp"
70 #include "runtime/javaCalls.hpp"
71 #include "runtime/sharedRuntime.hpp"
72 #include "runtime/signature.hpp"
73 #include "runtime/stackWatermarkSet.hpp"
74 #include "runtime/synchronizer.hpp"
75 #include "runtime/threadWXSetters.inline.hpp"
76 #include "runtime/vframe.hpp"
77 #include "runtime/vframe_hp.hpp"
78 #include "runtime/vframeArray.hpp"
79 #include "utilities/copy.hpp"
80 #include "utilities/preserveException.hpp"
81
82
83 // For debugging purposes:
84 // To force FullGCALot inside a runtime function, add the following two lines
85 //
86 // Universe::release_fullgc_alot_dummy();
87 // Universe::heap()->collect();
88 //
89 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
90
91
92 #define C2_BLOB_FIELD_DEFINE(name, type) \
93 type* OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
94 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
95 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
96 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
97 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \
98 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr;
99 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE)
100 #undef C2_BLOB_FIELD_DEFINE
101 #undef C2_STUB_FIELD_DEFINE
102 #undef C2_JVMTI_STUB_FIELD_DEFINE
103
104 // This should be called in an assertion at the start of OptoRuntime routines
105 // which are entered from compiled code (all of them)
106 #ifdef ASSERT
107 static bool check_compiled_frame(JavaThread* thread) {
108 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
109 RegisterMap map(thread,
110 RegisterMap::UpdateMap::skip,
111 RegisterMap::ProcessFrames::include,
112 RegisterMap::WalkContinuation::skip);
113 frame caller = thread->last_frame().sender(&map);
114 assert(caller.is_compiled_frame(), "not being called from compiled like code");
115 return true;
116 }
117 #endif // ASSERT
118
119 /*
120 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
121 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
122 if (var == nullptr) { return false; }
123 */
124
125 #define GEN_C2_BLOB(name, type) \
126 BLOB_FIELD_NAME(name) = \
127 generate_ ## name ## _blob(); \
128 if (BLOB_FIELD_NAME(name) == nullptr) { return false; }
129
130 // a few helper macros to conjure up generate_stub call arguments
131 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
132 #define C2_STUB_TYPEFUNC(name) name ## _Type
133 #define C2_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, name ## _C)
134 #define C2_STUB_ID(name) StubId:: JOIN3(c2, name, id)
135 #define C2_STUB_NAME(name) stub_name(C2_STUB_ID(name))
136
137 // Almost all the C functions targeted from the generated stubs are
138 // implemented locally to OptoRuntime with names that can be generated
139 // from the stub name by appending suffix '_C'. However, in two cases
140 // a common target method also needs to be called from shared runtime
141 // stubs. In these two cases the opto stubs rely on method
142 // imlementations defined in class SharedRuntime. The following
143 // defines temporarily rebind the generated names to reference the
144 // relevant implementations.
145
146 #define GEN_C2_STUB(name, fancy_jump, pass_tls, pass_retpc ) \
147 C2_STUB_FIELD_NAME(name) = \
148 generate_stub(env, \
149 C2_STUB_TYPEFUNC(name), \
150 C2_STUB_C_FUNC(name), \
151 C2_STUB_NAME(name), \
152 C2_STUB_ID(name), \
153 fancy_jump, \
154 pass_tls, \
155 pass_retpc); \
156 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
157
158 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name)
159
160 #define GEN_C2_JVMTI_STUB(name) \
161 STUB_FIELD_NAME(name) = \
162 generate_stub(env, \
163 notify_jvmti_vthread_Type, \
164 C2_JVMTI_STUB_C_FUNC(name), \
165 C2_STUB_NAME(name), \
166 C2_STUB_ID(name), \
167 0, \
168 true, \
169 false); \
170 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \
171
172 bool OptoRuntime::generate(ciEnv* env) {
173
174 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB)
175
176 return true;
177 }
178
179 #undef GEN_C2_BLOB
180
181 #undef C2_STUB_FIELD_NAME
182 #undef C2_STUB_TYPEFUNC
183 #undef C2_STUB_C_FUNC
184 #undef C2_STUB_NAME
185 #undef GEN_C2_STUB
186
187 #undef C2_JVMTI_STUB_C_FUNC
188 #undef GEN_C2_JVMTI_STUB
189 // #undef gen
190
191 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
192 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
193 const TypeFunc* OptoRuntime::_new_array_nozero_Type = nullptr;
194 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr;
195 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr;
196 const TypeFunc* OptoRuntime::_multianewarray4_Type = nullptr;
197 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr;
198 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr;
199 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr;
200 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr;
201 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr;
202 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr;
203 const TypeFunc* OptoRuntime::_athrow_Type = nullptr;
204 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr;
205 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr;
206 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr;
207 const TypeFunc* OptoRuntime::_modf_Type = nullptr;
208 const TypeFunc* OptoRuntime::_l2f_Type = nullptr;
209 const TypeFunc* OptoRuntime::_void_long_Type = nullptr;
210 const TypeFunc* OptoRuntime::_void_void_Type = nullptr;
211 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr;
212 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr;
213 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr;
214 const TypeFunc* OptoRuntime::_checkcast_arraycopy_Type = nullptr;
215 const TypeFunc* OptoRuntime::_generic_arraycopy_Type = nullptr;
216 const TypeFunc* OptoRuntime::_slow_arraycopy_Type = nullptr;
217 const TypeFunc* OptoRuntime::_unsafe_setmemory_Type = nullptr;
218 const TypeFunc* OptoRuntime::_array_fill_Type = nullptr;
219 const TypeFunc* OptoRuntime::_array_sort_Type = nullptr;
220 const TypeFunc* OptoRuntime::_array_partition_Type = nullptr;
221 const TypeFunc* OptoRuntime::_aescrypt_block_Type = nullptr;
222 const TypeFunc* OptoRuntime::_cipherBlockChaining_aescrypt_Type = nullptr;
223 const TypeFunc* OptoRuntime::_electronicCodeBook_aescrypt_Type = nullptr;
224 const TypeFunc* OptoRuntime::_counterMode_aescrypt_Type = nullptr;
225 const TypeFunc* OptoRuntime::_galoisCounterMode_aescrypt_Type = nullptr;
226 const TypeFunc* OptoRuntime::_digestBase_implCompress_with_sha3_Type = nullptr;
227 const TypeFunc* OptoRuntime::_digestBase_implCompress_without_sha3_Type = nullptr;
228 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_with_sha3_Type = nullptr;
229 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_without_sha3_Type = nullptr;
230 const TypeFunc* OptoRuntime::_double_keccak_Type = nullptr;
231 const TypeFunc* OptoRuntime::_multiplyToLen_Type = nullptr;
232 const TypeFunc* OptoRuntime::_montgomeryMultiply_Type = nullptr;
233 const TypeFunc* OptoRuntime::_montgomerySquare_Type = nullptr;
234 const TypeFunc* OptoRuntime::_squareToLen_Type = nullptr;
235 const TypeFunc* OptoRuntime::_mulAdd_Type = nullptr;
236 const TypeFunc* OptoRuntime::_bigIntegerShift_Type = nullptr;
237 const TypeFunc* OptoRuntime::_vectorizedMismatch_Type = nullptr;
238 const TypeFunc* OptoRuntime::_ghash_processBlocks_Type = nullptr;
239 const TypeFunc* OptoRuntime::_chacha20Block_Type = nullptr;
240 const TypeFunc* OptoRuntime::_kyberNtt_Type = nullptr;
241 const TypeFunc* OptoRuntime::_kyberInverseNtt_Type = nullptr;
242 const TypeFunc* OptoRuntime::_kyberNttMult_Type = nullptr;
243 const TypeFunc* OptoRuntime::_kyberAddPoly_2_Type = nullptr;
244 const TypeFunc* OptoRuntime::_kyberAddPoly_3_Type = nullptr;
245 const TypeFunc* OptoRuntime::_kyber12To16_Type = nullptr;
246 const TypeFunc* OptoRuntime::_kyberBarrettReduce_Type = nullptr;
247 const TypeFunc* OptoRuntime::_dilithiumAlmostNtt_Type = nullptr;
248 const TypeFunc* OptoRuntime::_dilithiumAlmostInverseNtt_Type = nullptr;
249 const TypeFunc* OptoRuntime::_dilithiumNttMult_Type = nullptr;
250 const TypeFunc* OptoRuntime::_dilithiumMontMulByConstant_Type = nullptr;
251 const TypeFunc* OptoRuntime::_dilithiumDecomposePoly_Type = nullptr;
252 const TypeFunc* OptoRuntime::_base64_encodeBlock_Type = nullptr;
253 const TypeFunc* OptoRuntime::_base64_decodeBlock_Type = nullptr;
254 const TypeFunc* OptoRuntime::_string_IndexOf_Type = nullptr;
255 const TypeFunc* OptoRuntime::_poly1305_processBlocks_Type = nullptr;
256 const TypeFunc* OptoRuntime::_intpoly_montgomeryMult_P256_Type = nullptr;
257 const TypeFunc* OptoRuntime::_intpoly_assign_Type = nullptr;
258 const TypeFunc* OptoRuntime::_updateBytesCRC32_Type = nullptr;
259 const TypeFunc* OptoRuntime::_updateBytesCRC32C_Type = nullptr;
260 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr;
261 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr;
262 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr;
263 #if INCLUDE_JFR
264 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr;
265 #endif // INCLUDE_JFR
266 #if INCLUDE_JVMTI
267 const TypeFunc* OptoRuntime::_notify_jvmti_vthread_Type = nullptr;
268 #endif // INCLUDE_JVMTI
269 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr;
270 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr;
271
272 // Helper method to do generation of RunTimeStub's
273 address OptoRuntime::generate_stub(ciEnv* env,
274 TypeFunc_generator gen, address C_function,
275 const char *name, StubId stub_id,
276 int is_fancy_jump, bool pass_tls,
277 bool return_pc) {
278
279 // Matching the default directive, we currently have no method to match.
280 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
281 CompilationMemoryStatisticMark cmsm(directive);
282 ResourceMark rm;
283 Compile C(env, gen, C_function, name, stub_id, is_fancy_jump, pass_tls, return_pc, directive);
284 DirectivesStack::release(directive);
285 return C.stub_entry_point();
286 }
287
288 const char* OptoRuntime::stub_name(address entry) {
289 #ifndef PRODUCT
290 CodeBlob* cb = CodeCache::find_blob(entry);
291 RuntimeStub* rs =(RuntimeStub *)cb;
292 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
293 return rs->name();
294 #else
295 // Fast implementation for product mode (maybe it should be inlined too)
296 return "runtime stub";
297 #endif
298 }
299
300 // local methods passed as arguments to stub generator that forward
301 // control to corresponding JRT methods of SharedRuntime
302
303 void OptoRuntime::slow_arraycopy_C(oopDesc* src, jint src_pos,
304 oopDesc* dest, jint dest_pos,
305 jint length, JavaThread* thread) {
306 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
307 }
308
309 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
310 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
311 }
312
313
314 //=============================================================================
315 // Opto compiler runtime routines
316 //=============================================================================
317
318
319 //=============================allocation======================================
320 // We failed the fast-path allocation. Now we need to do a scavenge or GC
321 // and try allocation again.
322
323 // object allocation
324 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, bool is_larval, JavaThread* current))
325 JRT_BLOCK;
326 #ifndef PRODUCT
327 SharedRuntime::_new_instance_ctr++; // new instance requires GC
328 #endif
329 assert(check_compiled_frame(current), "incorrect caller");
330
331 // These checks are cheap to make and support reflective allocation.
332 int lh = klass->layout_helper();
333 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
334 Handle holder(current, klass->klass_holder()); // keep the klass alive
335 klass->check_valid_for_instantiation(false, THREAD);
336 if (!HAS_PENDING_EXCEPTION) {
337 InstanceKlass::cast(klass)->initialize(THREAD);
338 }
339 }
340
341 if (!HAS_PENDING_EXCEPTION) {
342 // Scavenge and allocate an instance.
343 Handle holder(current, klass->klass_holder()); // keep the klass alive
344 instanceOop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
345 if (is_larval) {
346 // Check if this is a larval buffer allocation
347 result->set_mark(result->mark().enter_larval_state());
348 }
349 current->set_vm_result_oop(result);
350
351 // Pass oops back through thread local storage. Our apparent type to Java
352 // is that we return an oop, but we can block on exit from this routine and
353 // a GC can trash the oop in C's return register. The generated stub will
354 // fetch the oop from TLS after any possible GC.
355 }
356
357 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
358 JRT_BLOCK_END;
359
360 // inform GC that we won't do card marks for initializing writes.
361 SharedRuntime::on_slowpath_allocation_exit(current);
362 JRT_END
363
364
365 // array allocation
366 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, oopDesc* init_val, JavaThread* current))
367 JRT_BLOCK;
368 #ifndef PRODUCT
369 SharedRuntime::_new_array_ctr++; // new array requires GC
370 #endif
371 assert(check_compiled_frame(current), "incorrect caller");
372
373 // Scavenge and allocate an instance.
374 oop result;
375 Handle h_init_val(current, init_val); // keep the init_val object alive
376
377 if (array_type->is_flatArray_klass()) {
378 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
379 FlatArrayKlass* fak = FlatArrayKlass::cast(array_type);
380 InlineKlass* vk = fak->element_klass();
381 ArrayKlass::ArrayProperties props = ArrayKlass::ArrayProperties::DEFAULT;
382 switch(fak->layout_kind()) {
383 case LayoutKind::ATOMIC_FLAT:
384 props = ArrayKlass::ArrayProperties::NULL_RESTRICTED;
385 break;
386 case LayoutKind::NON_ATOMIC_FLAT:
387 props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::NULL_RESTRICTED | ArrayKlass::ArrayProperties::NON_ATOMIC);
388 break;
389 case LayoutKind::NULLABLE_ATOMIC_FLAT:
390 props = ArrayKlass::ArrayProperties::NON_ATOMIC;
391 break;
392 default:
393 ShouldNotReachHere();
394 }
395 result = oopFactory::new_flatArray(vk, len, props, fak->layout_kind(), THREAD);
396 if (array_type->is_null_free_array_klass() && !h_init_val.is_null()) {
397 // Null-free arrays need to be initialized
398 for (int i = 0; i < len; i++) {
399 vk->write_value_to_addr(h_init_val(), ((flatArrayOop)result)->value_at_addr(i, fak->layout_helper()), fak->layout_kind(), true, CHECK);
400 }
401 }
402 } else if (array_type->is_typeArray_klass()) {
403 // The oopFactory likes to work with the element type.
404 // (We could bypass the oopFactory, since it doesn't add much value.)
405 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
406 result = oopFactory::new_typeArray(elem_type, len, THREAD);
407 } else {
408 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
409 result = oopFactory::new_refArray(array_type, len, THREAD);
410 if (array_type->is_null_free_array_klass() && !h_init_val.is_null()) {
411 // Null-free arrays need to be initialized
412 for (int i = 0; i < len; i++) {
413 ((objArrayOop)result)->obj_at_put(i, h_init_val());
414 }
415 }
416 }
417
418 // Pass oops back through thread local storage. Our apparent type to Java
419 // is that we return an oop, but we can block on exit from this routine and
420 // a GC can trash the oop in C's return register. The generated stub will
421 // fetch the oop from TLS after any possible GC.
422 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
423 current->set_vm_result_oop(result);
424 JRT_BLOCK_END;
425
426 // inform GC that we won't do card marks for initializing writes.
427 SharedRuntime::on_slowpath_allocation_exit(current);
428 JRT_END
429
430 // array allocation without zeroing
431 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
432 JRT_BLOCK;
433 #ifndef PRODUCT
434 SharedRuntime::_new_array_ctr++; // new array requires GC
435 #endif
436 assert(check_compiled_frame(current), "incorrect caller");
437
438 // Scavenge and allocate an instance.
439 oop result;
440
441 assert(array_type->is_typeArray_klass(), "should be called only for type array");
442 // The oopFactory likes to work with the element type.
443 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
444 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
445
446 // Pass oops back through thread local storage. Our apparent type to Java
447 // is that we return an oop, but we can block on exit from this routine and
448 // a GC can trash the oop in C's return register. The generated stub will
449 // fetch the oop from TLS after any possible GC.
450 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
451 current->set_vm_result_oop(result);
452 JRT_BLOCK_END;
453
454
455 // inform GC that we won't do card marks for initializing writes.
456 SharedRuntime::on_slowpath_allocation_exit(current);
457
458 oop result = current->vm_result_oop();
459 if ((len > 0) && (result != nullptr) &&
460 is_deoptimized_caller_frame(current)) {
461 // Zero array here if the caller is deoptimized.
462 const size_t size = TypeArrayKlass::cast(array_type)->oop_size(result);
463 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
464 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
465 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
466 HeapWord* obj = cast_from_oop<HeapWord*>(result);
467 if (!is_aligned(hs_bytes, BytesPerLong)) {
468 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
469 hs_bytes += BytesPerInt;
470 }
471
472 // Optimized zeroing.
473 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
474 const size_t aligned_hs = hs_bytes / BytesPerLong;
475 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
476 }
477
478 JRT_END
479
480 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
481
482 // multianewarray for 2 dimensions
483 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
484 #ifndef PRODUCT
485 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
486 #endif
487 assert(check_compiled_frame(current), "incorrect caller");
488 assert(elem_type->is_klass(), "not a class");
489 jint dims[2];
490 dims[0] = len1;
491 dims[1] = len2;
492 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
493 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
494 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
495 current->set_vm_result_oop(obj);
496 JRT_END
497
498 // multianewarray for 3 dimensions
499 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
500 #ifndef PRODUCT
501 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
502 #endif
503 assert(check_compiled_frame(current), "incorrect caller");
504 assert(elem_type->is_klass(), "not a class");
505 jint dims[3];
506 dims[0] = len1;
507 dims[1] = len2;
508 dims[2] = len3;
509 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
510 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
511 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
512 current->set_vm_result_oop(obj);
513 JRT_END
514
515 // multianewarray for 4 dimensions
516 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
517 #ifndef PRODUCT
518 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
519 #endif
520 assert(check_compiled_frame(current), "incorrect caller");
521 assert(elem_type->is_klass(), "not a class");
522 jint dims[4];
523 dims[0] = len1;
524 dims[1] = len2;
525 dims[2] = len3;
526 dims[3] = len4;
527 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
528 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
529 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
530 current->set_vm_result_oop(obj);
531 JRT_END
532
533 // multianewarray for 5 dimensions
534 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
535 #ifndef PRODUCT
536 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
537 #endif
538 assert(check_compiled_frame(current), "incorrect caller");
539 assert(elem_type->is_klass(), "not a class");
540 jint dims[5];
541 dims[0] = len1;
542 dims[1] = len2;
543 dims[2] = len3;
544 dims[3] = len4;
545 dims[4] = len5;
546 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
547 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
548 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
549 current->set_vm_result_oop(obj);
550 JRT_END
551
552 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
553 assert(check_compiled_frame(current), "incorrect caller");
554 assert(elem_type->is_klass(), "not a class");
555 assert(oop(dims)->is_typeArray(), "not an array");
556
557 ResourceMark rm;
558 jint len = dims->length();
559 assert(len > 0, "Dimensions array should contain data");
560 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
561 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
562 c_dims, len);
563
564 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
565 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
566 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
567 current->set_vm_result_oop(obj);
568 JRT_END
569
570 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
571
572 // Very few notify/notifyAll operations find any threads on the waitset, so
573 // the dominant fast-path is to simply return.
574 // Relatedly, it's critical that notify/notifyAll be fast in order to
575 // reduce lock hold times.
576 if (!SafepointSynchronize::is_synchronizing()) {
577 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
578 return;
579 }
580 }
581
582 // This is the case the fast-path above isn't provisioned to handle.
583 // The fast-path is designed to handle frequently arising cases in an efficient manner.
584 // (The fast-path is just a degenerate variant of the slow-path).
585 // Perform the dreaded state transition and pass control into the slow-path.
586 JRT_BLOCK;
587 Handle h_obj(current, obj);
588 ObjectSynchronizer::notify(h_obj, CHECK);
589 JRT_BLOCK_END;
590 JRT_END
591
592 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
593
594 if (!SafepointSynchronize::is_synchronizing() ) {
595 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
596 return;
597 }
598 }
599
600 // This is the case the fast-path above isn't provisioned to handle.
601 // The fast-path is designed to handle frequently arising cases in an efficient manner.
602 // (The fast-path is just a degenerate variant of the slow-path).
603 // Perform the dreaded state transition and pass control into the slow-path.
604 JRT_BLOCK;
605 Handle h_obj(current, obj);
606 ObjectSynchronizer::notifyall(h_obj, CHECK);
607 JRT_BLOCK_END;
608 JRT_END
609
610 static const TypeFunc* make_new_instance_Type() {
611 // create input type (domain)
612 const Type **fields = TypeTuple::fields(2);
613 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
614 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // is_larval
615 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
616
617 // create result type (range)
618 fields = TypeTuple::fields(1);
619 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
620
621 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
622
623 return TypeFunc::make(domain, range);
624 }
625
626 #if INCLUDE_JVMTI
627 static const TypeFunc* make_notify_jvmti_vthread_Type() {
628 // create input type (domain)
629 const Type **fields = TypeTuple::fields(2);
630 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
631 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean
632 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
633
634 // no result type needed
635 fields = TypeTuple::fields(1);
636 fields[TypeFunc::Parms+0] = nullptr; // void
637 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
638
639 return TypeFunc::make(domain,range);
640 }
641 #endif
642
643 static const TypeFunc* make_athrow_Type() {
644 // create input type (domain)
645 const Type **fields = TypeTuple::fields(1);
646 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
647 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
648
649 // create result type (range)
650 fields = TypeTuple::fields(0);
651
652 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
653
654 return TypeFunc::make(domain, range);
655 }
656
657 static const TypeFunc* make_new_array_Type() {
658 // create input type (domain)
659 const Type **fields = TypeTuple::fields(3);
660 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
661 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
662 fields[TypeFunc::Parms+2] = TypeInstPtr::NOTNULL; // init value
663 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
664
665 // create result type (range)
666 fields = TypeTuple::fields(1);
667 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
668
669 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
670
671 return TypeFunc::make(domain, range);
672 }
673
674 static const TypeFunc* make_new_array_nozero_Type() {
675 // create input type (domain)
676 const Type **fields = TypeTuple::fields(2);
677 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
678 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
679 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
680
681 // create result type (range)
682 fields = TypeTuple::fields(1);
683 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
684
685 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
686
687 return TypeFunc::make(domain, range);
688 }
689
690 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) {
691 // create input type (domain)
692 const int nargs = ndim + 1;
693 const Type **fields = TypeTuple::fields(nargs);
694 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
695 for( int i = 1; i < nargs; i++ )
696 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size
697 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
698
699 // create result type (range)
700 fields = TypeTuple::fields(1);
701 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
702 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
703
704 return TypeFunc::make(domain, range);
705 }
706
707 static const TypeFunc* make_multianewarrayN_Type() {
708 // create input type (domain)
709 const Type **fields = TypeTuple::fields(2);
710 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
711 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // array of dim sizes
712 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
713
714 // create result type (range)
715 fields = TypeTuple::fields(1);
716 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
717 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
718
719 return TypeFunc::make(domain, range);
720 }
721
722 static const TypeFunc* make_uncommon_trap_Type() {
723 // create input type (domain)
724 const Type **fields = TypeTuple::fields(1);
725 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
726 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
727
728 // create result type (range)
729 fields = TypeTuple::fields(0);
730 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
731
732 return TypeFunc::make(domain, range);
733 }
734
735 //-----------------------------------------------------------------------------
736 // Monitor Handling
737
738 static const TypeFunc* make_complete_monitor_enter_Type() {
739 // create input type (domain)
740 const Type **fields = TypeTuple::fields(2);
741 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
742 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
743 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
744
745 // create result type (range)
746 fields = TypeTuple::fields(0);
747
748 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
749
750 return TypeFunc::make(domain, range);
751 }
752
753 //-----------------------------------------------------------------------------
754
755 static const TypeFunc* make_complete_monitor_exit_Type() {
756 // create input type (domain)
757 const Type **fields = TypeTuple::fields(3);
758 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
759 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
760 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
761 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
762
763 // create result type (range)
764 fields = TypeTuple::fields(0);
765
766 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
767
768 return TypeFunc::make(domain, range);
769 }
770
771 static const TypeFunc* make_monitor_notify_Type() {
772 // create input type (domain)
773 const Type **fields = TypeTuple::fields(1);
774 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
775 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
776
777 // create result type (range)
778 fields = TypeTuple::fields(0);
779 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
780 return TypeFunc::make(domain, range);
781 }
782
783 static const TypeFunc* make_flush_windows_Type() {
784 // create input type (domain)
785 const Type** fields = TypeTuple::fields(1);
786 fields[TypeFunc::Parms+0] = nullptr; // void
787 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
788
789 // create result type
790 fields = TypeTuple::fields(1);
791 fields[TypeFunc::Parms+0] = nullptr; // void
792 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
793
794 return TypeFunc::make(domain, range);
795 }
796
797 static const TypeFunc* make_l2f_Type() {
798 // create input type (domain)
799 const Type **fields = TypeTuple::fields(2);
800 fields[TypeFunc::Parms+0] = TypeLong::LONG;
801 fields[TypeFunc::Parms+1] = Type::HALF;
802 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
803
804 // create result type (range)
805 fields = TypeTuple::fields(1);
806 fields[TypeFunc::Parms+0] = Type::FLOAT;
807 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
808
809 return TypeFunc::make(domain, range);
810 }
811
812 static const TypeFunc* make_modf_Type() {
813 const Type **fields = TypeTuple::fields(2);
814 fields[TypeFunc::Parms+0] = Type::FLOAT;
815 fields[TypeFunc::Parms+1] = Type::FLOAT;
816 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
817
818 // create result type (range)
819 fields = TypeTuple::fields(1);
820 fields[TypeFunc::Parms+0] = Type::FLOAT;
821
822 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
823
824 return TypeFunc::make(domain, range);
825 }
826
827 static const TypeFunc* make_Math_D_D_Type() {
828 // create input type (domain)
829 const Type **fields = TypeTuple::fields(2);
830 // Symbol* name of class to be loaded
831 fields[TypeFunc::Parms+0] = Type::DOUBLE;
832 fields[TypeFunc::Parms+1] = Type::HALF;
833 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
834
835 // create result type (range)
836 fields = TypeTuple::fields(2);
837 fields[TypeFunc::Parms+0] = Type::DOUBLE;
838 fields[TypeFunc::Parms+1] = Type::HALF;
839 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
840
841 return TypeFunc::make(domain, range);
842 }
843
844 const TypeFunc* OptoRuntime::Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type) {
845 // create input type (domain)
846 const Type **fields = TypeTuple::fields(num_arg);
847 // Symbol* name of class to be loaded
848 assert(num_arg > 0, "must have at least 1 input");
849 for (uint i = 0; i < num_arg; i++) {
850 fields[TypeFunc::Parms+i] = in_type;
851 }
852 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+num_arg, fields);
853
854 // create result type (range)
855 const uint num_ret = 1;
856 fields = TypeTuple::fields(num_ret);
857 fields[TypeFunc::Parms+0] = out_type;
858 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+num_ret, fields);
859
860 return TypeFunc::make(domain, range);
861 }
862
863 static const TypeFunc* make_Math_DD_D_Type() {
864 const Type **fields = TypeTuple::fields(4);
865 fields[TypeFunc::Parms+0] = Type::DOUBLE;
866 fields[TypeFunc::Parms+1] = Type::HALF;
867 fields[TypeFunc::Parms+2] = Type::DOUBLE;
868 fields[TypeFunc::Parms+3] = Type::HALF;
869 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
870
871 // create result type (range)
872 fields = TypeTuple::fields(2);
873 fields[TypeFunc::Parms+0] = Type::DOUBLE;
874 fields[TypeFunc::Parms+1] = Type::HALF;
875 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
876
877 return TypeFunc::make(domain, range);
878 }
879
880 //-------------- currentTimeMillis, currentTimeNanos, etc
881
882 static const TypeFunc* make_void_long_Type() {
883 // create input type (domain)
884 const Type **fields = TypeTuple::fields(0);
885 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
886
887 // create result type (range)
888 fields = TypeTuple::fields(2);
889 fields[TypeFunc::Parms+0] = TypeLong::LONG;
890 fields[TypeFunc::Parms+1] = Type::HALF;
891 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
892
893 return TypeFunc::make(domain, range);
894 }
895
896 static const TypeFunc* make_void_void_Type() {
897 // create input type (domain)
898 const Type **fields = TypeTuple::fields(0);
899 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
900
901 // create result type (range)
902 fields = TypeTuple::fields(0);
903 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
904 return TypeFunc::make(domain, range);
905 }
906
907 static const TypeFunc* make_jfr_write_checkpoint_Type() {
908 // create input type (domain)
909 const Type **fields = TypeTuple::fields(0);
910 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
911
912 // create result type (range)
913 fields = TypeTuple::fields(0);
914 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
915 return TypeFunc::make(domain, range);
916 }
917
918
919 // Takes as parameters:
920 // void *dest
921 // long size
922 // uchar byte
923
924 static const TypeFunc* make_setmemory_Type() {
925 // create input type (domain)
926 int argcnt = NOT_LP64(3) LP64_ONLY(4);
927 const Type** fields = TypeTuple::fields(argcnt);
928 int argp = TypeFunc::Parms;
929 fields[argp++] = TypePtr::NOTNULL; // dest
930 fields[argp++] = TypeX_X; // size
931 LP64_ONLY(fields[argp++] = Type::HALF); // size
932 fields[argp++] = TypeInt::UBYTE; // bytevalue
933 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
934 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
935
936 // no result type needed
937 fields = TypeTuple::fields(1);
938 fields[TypeFunc::Parms+0] = nullptr; // void
939 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
940 return TypeFunc::make(domain, range);
941 }
942
943 // arraycopy stub variations:
944 enum ArrayCopyType {
945 ac_fast, // void(ptr, ptr, size_t)
946 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
947 ac_slow, // void(ptr, int, ptr, int, int)
948 ac_generic // int(ptr, int, ptr, int, int)
949 };
950
951 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
952 // create input type (domain)
953 int num_args = (act == ac_fast ? 3 : 5);
954 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
955 int argcnt = num_args;
956 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
957 const Type** fields = TypeTuple::fields(argcnt);
958 int argp = TypeFunc::Parms;
959 fields[argp++] = TypePtr::NOTNULL; // src
960 if (num_size_args == 0) {
961 fields[argp++] = TypeInt::INT; // src_pos
962 }
963 fields[argp++] = TypePtr::NOTNULL; // dest
964 if (num_size_args == 0) {
965 fields[argp++] = TypeInt::INT; // dest_pos
966 fields[argp++] = TypeInt::INT; // length
967 }
968 while (num_size_args-- > 0) {
969 fields[argp++] = TypeX_X; // size in whatevers (size_t)
970 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
971 }
972 if (act == ac_checkcast) {
973 fields[argp++] = TypePtr::NOTNULL; // super_klass
974 }
975 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
976 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
977
978 // create result type if needed
979 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
980 fields = TypeTuple::fields(1);
981 if (retcnt == 0)
982 fields[TypeFunc::Parms+0] = nullptr; // void
983 else
984 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
985 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
986 return TypeFunc::make(domain, range);
987 }
988
989 static const TypeFunc* make_array_fill_Type() {
990 const Type** fields;
991 int argp = TypeFunc::Parms;
992 // create input type (domain): pointer, int, size_t
993 fields = TypeTuple::fields(3 LP64_ONLY( + 1));
994 fields[argp++] = TypePtr::NOTNULL;
995 fields[argp++] = TypeInt::INT;
996 fields[argp++] = TypeX_X; // size in whatevers (size_t)
997 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
998 const TypeTuple *domain = TypeTuple::make(argp, fields);
999
1000 // create result type
1001 fields = TypeTuple::fields(1);
1002 fields[TypeFunc::Parms+0] = nullptr; // void
1003 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1004
1005 return TypeFunc::make(domain, range);
1006 }
1007
1008 static const TypeFunc* make_array_partition_Type() {
1009 // create input type (domain)
1010 int num_args = 7;
1011 int argcnt = num_args;
1012 const Type** fields = TypeTuple::fields(argcnt);
1013 int argp = TypeFunc::Parms;
1014 fields[argp++] = TypePtr::NOTNULL; // array
1015 fields[argp++] = TypeInt::INT; // element type
1016 fields[argp++] = TypeInt::INT; // low
1017 fields[argp++] = TypeInt::INT; // end
1018 fields[argp++] = TypePtr::NOTNULL; // pivot_indices (int array)
1019 fields[argp++] = TypeInt::INT; // indexPivot1
1020 fields[argp++] = TypeInt::INT; // indexPivot2
1021 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1022 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1023
1024 // no result type needed
1025 fields = TypeTuple::fields(1);
1026 fields[TypeFunc::Parms+0] = nullptr; // void
1027 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1028 return TypeFunc::make(domain, range);
1029 }
1030
1031 static const TypeFunc* make_array_sort_Type() {
1032 // create input type (domain)
1033 int num_args = 4;
1034 int argcnt = num_args;
1035 const Type** fields = TypeTuple::fields(argcnt);
1036 int argp = TypeFunc::Parms;
1037 fields[argp++] = TypePtr::NOTNULL; // array
1038 fields[argp++] = TypeInt::INT; // element type
1039 fields[argp++] = TypeInt::INT; // fromIndex
1040 fields[argp++] = TypeInt::INT; // toIndex
1041 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1042 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1043
1044 // no result type needed
1045 fields = TypeTuple::fields(1);
1046 fields[TypeFunc::Parms+0] = nullptr; // void
1047 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1048 return TypeFunc::make(domain, range);
1049 }
1050
1051 static const TypeFunc* make_aescrypt_block_Type() {
1052 // create input type (domain)
1053 int num_args = 3;
1054 int argcnt = num_args;
1055 const Type** fields = TypeTuple::fields(argcnt);
1056 int argp = TypeFunc::Parms;
1057 fields[argp++] = TypePtr::NOTNULL; // src
1058 fields[argp++] = TypePtr::NOTNULL; // dest
1059 fields[argp++] = TypePtr::NOTNULL; // k array
1060 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1061 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1062
1063 // no result type needed
1064 fields = TypeTuple::fields(1);
1065 fields[TypeFunc::Parms+0] = nullptr; // void
1066 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1067 return TypeFunc::make(domain, range);
1068 }
1069
1070 static const TypeFunc* make_updateBytesCRC32_Type() {
1071 // create input type (domain)
1072 int num_args = 3;
1073 int argcnt = num_args;
1074 const Type** fields = TypeTuple::fields(argcnt);
1075 int argp = TypeFunc::Parms;
1076 fields[argp++] = TypeInt::INT; // crc
1077 fields[argp++] = TypePtr::NOTNULL; // src
1078 fields[argp++] = TypeInt::INT; // len
1079 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1080 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1081
1082 // result type needed
1083 fields = TypeTuple::fields(1);
1084 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
1085 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1086 return TypeFunc::make(domain, range);
1087 }
1088
1089 static const TypeFunc* make_updateBytesCRC32C_Type() {
1090 // create input type (domain)
1091 int num_args = 4;
1092 int argcnt = num_args;
1093 const Type** fields = TypeTuple::fields(argcnt);
1094 int argp = TypeFunc::Parms;
1095 fields[argp++] = TypeInt::INT; // crc
1096 fields[argp++] = TypePtr::NOTNULL; // buf
1097 fields[argp++] = TypeInt::INT; // len
1098 fields[argp++] = TypePtr::NOTNULL; // table
1099 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1100 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1101
1102 // result type needed
1103 fields = TypeTuple::fields(1);
1104 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
1105 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1106 return TypeFunc::make(domain, range);
1107 }
1108
1109 static const TypeFunc* make_updateBytesAdler32_Type() {
1110 // create input type (domain)
1111 int num_args = 3;
1112 int argcnt = num_args;
1113 const Type** fields = TypeTuple::fields(argcnt);
1114 int argp = TypeFunc::Parms;
1115 fields[argp++] = TypeInt::INT; // crc
1116 fields[argp++] = TypePtr::NOTNULL; // src + offset
1117 fields[argp++] = TypeInt::INT; // len
1118 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1119 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1120
1121 // result type needed
1122 fields = TypeTuple::fields(1);
1123 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
1124 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1125 return TypeFunc::make(domain, range);
1126 }
1127
1128 static const TypeFunc* make_cipherBlockChaining_aescrypt_Type() {
1129 // create input type (domain)
1130 int num_args = 5;
1131 int argcnt = num_args;
1132 const Type** fields = TypeTuple::fields(argcnt);
1133 int argp = TypeFunc::Parms;
1134 fields[argp++] = TypePtr::NOTNULL; // src
1135 fields[argp++] = TypePtr::NOTNULL; // dest
1136 fields[argp++] = TypePtr::NOTNULL; // k array
1137 fields[argp++] = TypePtr::NOTNULL; // r array
1138 fields[argp++] = TypeInt::INT; // src len
1139 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1140 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1141
1142 // returning cipher len (int)
1143 fields = TypeTuple::fields(1);
1144 fields[TypeFunc::Parms+0] = TypeInt::INT;
1145 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1146 return TypeFunc::make(domain, range);
1147 }
1148
1149 static const TypeFunc* make_electronicCodeBook_aescrypt_Type() {
1150 // create input type (domain)
1151 int num_args = 4;
1152 int argcnt = num_args;
1153 const Type** fields = TypeTuple::fields(argcnt);
1154 int argp = TypeFunc::Parms;
1155 fields[argp++] = TypePtr::NOTNULL; // src
1156 fields[argp++] = TypePtr::NOTNULL; // dest
1157 fields[argp++] = TypePtr::NOTNULL; // k array
1158 fields[argp++] = TypeInt::INT; // src len
1159 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1160 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1161
1162 // returning cipher len (int)
1163 fields = TypeTuple::fields(1);
1164 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1165 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1166 return TypeFunc::make(domain, range);
1167 }
1168
1169 static const TypeFunc* make_counterMode_aescrypt_Type() {
1170 // create input type (domain)
1171 int num_args = 7;
1172 int argcnt = num_args;
1173 const Type** fields = TypeTuple::fields(argcnt);
1174 int argp = TypeFunc::Parms;
1175 fields[argp++] = TypePtr::NOTNULL; // src
1176 fields[argp++] = TypePtr::NOTNULL; // dest
1177 fields[argp++] = TypePtr::NOTNULL; // k array
1178 fields[argp++] = TypePtr::NOTNULL; // counter array
1179 fields[argp++] = TypeInt::INT; // src len
1180 fields[argp++] = TypePtr::NOTNULL; // saved_encCounter
1181 fields[argp++] = TypePtr::NOTNULL; // saved used addr
1182 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1183 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1184 // returning cipher len (int)
1185 fields = TypeTuple::fields(1);
1186 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1187 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1188 return TypeFunc::make(domain, range);
1189 }
1190
1191 static const TypeFunc* make_galoisCounterMode_aescrypt_Type() {
1192 // create input type (domain)
1193 int num_args = 8;
1194 int argcnt = num_args;
1195 const Type** fields = TypeTuple::fields(argcnt);
1196 int argp = TypeFunc::Parms;
1197 fields[argp++] = TypePtr::NOTNULL; // byte[] in + inOfs
1198 fields[argp++] = TypeInt::INT; // int len
1199 fields[argp++] = TypePtr::NOTNULL; // byte[] ct + ctOfs
1200 fields[argp++] = TypePtr::NOTNULL; // byte[] out + outOfs
1201 fields[argp++] = TypePtr::NOTNULL; // byte[] key from AESCrypt obj
1202 fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj
1203 fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj
1204 fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj
1205
1206 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1207 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1208 // returning cipher len (int)
1209 fields = TypeTuple::fields(1);
1210 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1211 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1212 return TypeFunc::make(domain, range);
1213 }
1214
1215 static const TypeFunc* make_digestBase_implCompress_Type(bool is_sha3) {
1216 // create input type (domain)
1217 int num_args = is_sha3 ? 3 : 2;
1218 int argcnt = num_args;
1219 const Type** fields = TypeTuple::fields(argcnt);
1220 int argp = TypeFunc::Parms;
1221 fields[argp++] = TypePtr::NOTNULL; // buf
1222 fields[argp++] = TypePtr::NOTNULL; // state
1223 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1224 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1225 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1226
1227 // no result type needed
1228 fields = TypeTuple::fields(1);
1229 fields[TypeFunc::Parms+0] = nullptr; // void
1230 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1231 return TypeFunc::make(domain, range);
1232 }
1233
1234 /*
1235 * int implCompressMultiBlock(byte[] b, int ofs, int limit)
1236 */
1237 static const TypeFunc* make_digestBase_implCompressMB_Type(bool is_sha3) {
1238 // create input type (domain)
1239 int num_args = is_sha3 ? 5 : 4;
1240 int argcnt = num_args;
1241 const Type** fields = TypeTuple::fields(argcnt);
1242 int argp = TypeFunc::Parms;
1243 fields[argp++] = TypePtr::NOTNULL; // buf
1244 fields[argp++] = TypePtr::NOTNULL; // state
1245 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1246 fields[argp++] = TypeInt::INT; // ofs
1247 fields[argp++] = TypeInt::INT; // limit
1248 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1249 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1250
1251 // returning ofs (int)
1252 fields = TypeTuple::fields(1);
1253 fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs
1254 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1255 return TypeFunc::make(domain, range);
1256 }
1257
1258 // SHAKE128Parallel doubleKeccak function
1259 static const TypeFunc* make_double_keccak_Type() {
1260 int argcnt = 2;
1261
1262 const Type** fields = TypeTuple::fields(argcnt);
1263 int argp = TypeFunc::Parms;
1264 fields[argp++] = TypePtr::NOTNULL; // status0
1265 fields[argp++] = TypePtr::NOTNULL; // status1
1266
1267 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1268 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1269
1270 // result type needed
1271 fields = TypeTuple::fields(1);
1272 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1273 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1274 return TypeFunc::make(domain, range);
1275 }
1276
1277 static const TypeFunc* make_multiplyToLen_Type() {
1278 // create input type (domain)
1279 int num_args = 5;
1280 int argcnt = num_args;
1281 const Type** fields = TypeTuple::fields(argcnt);
1282 int argp = TypeFunc::Parms;
1283 fields[argp++] = TypePtr::NOTNULL; // x
1284 fields[argp++] = TypeInt::INT; // xlen
1285 fields[argp++] = TypePtr::NOTNULL; // y
1286 fields[argp++] = TypeInt::INT; // ylen
1287 fields[argp++] = TypePtr::NOTNULL; // z
1288 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1289 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1290
1291 // no result type needed
1292 fields = TypeTuple::fields(1);
1293 fields[TypeFunc::Parms+0] = nullptr;
1294 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1295 return TypeFunc::make(domain, range);
1296 }
1297
1298 static const TypeFunc* make_squareToLen_Type() {
1299 // create input type (domain)
1300 int num_args = 4;
1301 int argcnt = num_args;
1302 const Type** fields = TypeTuple::fields(argcnt);
1303 int argp = TypeFunc::Parms;
1304 fields[argp++] = TypePtr::NOTNULL; // x
1305 fields[argp++] = TypeInt::INT; // len
1306 fields[argp++] = TypePtr::NOTNULL; // z
1307 fields[argp++] = TypeInt::INT; // zlen
1308 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1309 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1310
1311 // no result type needed
1312 fields = TypeTuple::fields(1);
1313 fields[TypeFunc::Parms+0] = nullptr;
1314 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1315 return TypeFunc::make(domain, range);
1316 }
1317
1318 static const TypeFunc* make_mulAdd_Type() {
1319 // create input type (domain)
1320 int num_args = 5;
1321 int argcnt = num_args;
1322 const Type** fields = TypeTuple::fields(argcnt);
1323 int argp = TypeFunc::Parms;
1324 fields[argp++] = TypePtr::NOTNULL; // out
1325 fields[argp++] = TypePtr::NOTNULL; // in
1326 fields[argp++] = TypeInt::INT; // offset
1327 fields[argp++] = TypeInt::INT; // len
1328 fields[argp++] = TypeInt::INT; // k
1329 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1330 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1331
1332 // returning carry (int)
1333 fields = TypeTuple::fields(1);
1334 fields[TypeFunc::Parms+0] = TypeInt::INT;
1335 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1336 return TypeFunc::make(domain, range);
1337 }
1338
1339 static const TypeFunc* make_montgomeryMultiply_Type() {
1340 // create input type (domain)
1341 int num_args = 7;
1342 int argcnt = num_args;
1343 const Type** fields = TypeTuple::fields(argcnt);
1344 int argp = TypeFunc::Parms;
1345 fields[argp++] = TypePtr::NOTNULL; // a
1346 fields[argp++] = TypePtr::NOTNULL; // b
1347 fields[argp++] = TypePtr::NOTNULL; // n
1348 fields[argp++] = TypeInt::INT; // len
1349 fields[argp++] = TypeLong::LONG; // inv
1350 fields[argp++] = Type::HALF;
1351 fields[argp++] = TypePtr::NOTNULL; // result
1352 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1353 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1354
1355 // result type needed
1356 fields = TypeTuple::fields(1);
1357 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1358
1359 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1360 return TypeFunc::make(domain, range);
1361 }
1362
1363 static const TypeFunc* make_montgomerySquare_Type() {
1364 // create input type (domain)
1365 int num_args = 6;
1366 int argcnt = num_args;
1367 const Type** fields = TypeTuple::fields(argcnt);
1368 int argp = TypeFunc::Parms;
1369 fields[argp++] = TypePtr::NOTNULL; // a
1370 fields[argp++] = TypePtr::NOTNULL; // n
1371 fields[argp++] = TypeInt::INT; // len
1372 fields[argp++] = TypeLong::LONG; // inv
1373 fields[argp++] = Type::HALF;
1374 fields[argp++] = TypePtr::NOTNULL; // result
1375 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1376 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1377
1378 // result type needed
1379 fields = TypeTuple::fields(1);
1380 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1381
1382 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1383 return TypeFunc::make(domain, range);
1384 }
1385
1386 static const TypeFunc* make_bigIntegerShift_Type() {
1387 int argcnt = 5;
1388 const Type** fields = TypeTuple::fields(argcnt);
1389 int argp = TypeFunc::Parms;
1390 fields[argp++] = TypePtr::NOTNULL; // newArr
1391 fields[argp++] = TypePtr::NOTNULL; // oldArr
1392 fields[argp++] = TypeInt::INT; // newIdx
1393 fields[argp++] = TypeInt::INT; // shiftCount
1394 fields[argp++] = TypeInt::INT; // numIter
1395 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1396 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1397
1398 // no result type needed
1399 fields = TypeTuple::fields(1);
1400 fields[TypeFunc::Parms + 0] = nullptr;
1401 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1402 return TypeFunc::make(domain, range);
1403 }
1404
1405 static const TypeFunc* make_vectorizedMismatch_Type() {
1406 // create input type (domain)
1407 int num_args = 4;
1408 int argcnt = num_args;
1409 const Type** fields = TypeTuple::fields(argcnt);
1410 int argp = TypeFunc::Parms;
1411 fields[argp++] = TypePtr::NOTNULL; // obja
1412 fields[argp++] = TypePtr::NOTNULL; // objb
1413 fields[argp++] = TypeInt::INT; // length, number of elements
1414 fields[argp++] = TypeInt::INT; // log2scale, element size
1415 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1416 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1417
1418 //return mismatch index (int)
1419 fields = TypeTuple::fields(1);
1420 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1421 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1422 return TypeFunc::make(domain, range);
1423 }
1424
1425 static const TypeFunc* make_ghash_processBlocks_Type() {
1426 int argcnt = 4;
1427
1428 const Type** fields = TypeTuple::fields(argcnt);
1429 int argp = TypeFunc::Parms;
1430 fields[argp++] = TypePtr::NOTNULL; // state
1431 fields[argp++] = TypePtr::NOTNULL; // subkeyH
1432 fields[argp++] = TypePtr::NOTNULL; // data
1433 fields[argp++] = TypeInt::INT; // blocks
1434 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1435 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1436
1437 // result type needed
1438 fields = TypeTuple::fields(1);
1439 fields[TypeFunc::Parms+0] = nullptr; // void
1440 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1441 return TypeFunc::make(domain, range);
1442 }
1443
1444 static const TypeFunc* make_chacha20Block_Type() {
1445 int argcnt = 2;
1446
1447 const Type** fields = TypeTuple::fields(argcnt);
1448 int argp = TypeFunc::Parms;
1449 fields[argp++] = TypePtr::NOTNULL; // state
1450 fields[argp++] = TypePtr::NOTNULL; // result
1451
1452 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1453 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1454
1455 // result type needed
1456 fields = TypeTuple::fields(1);
1457 fields[TypeFunc::Parms + 0] = TypeInt::INT; // key stream outlen as int
1458 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1459 return TypeFunc::make(domain, range);
1460 }
1461
1462 // Kyber NTT function
1463 static const TypeFunc* make_kyberNtt_Type() {
1464 int argcnt = 2;
1465
1466 const Type** fields = TypeTuple::fields(argcnt);
1467 int argp = TypeFunc::Parms;
1468 fields[argp++] = TypePtr::NOTNULL; // coeffs
1469 fields[argp++] = TypePtr::NOTNULL; // NTT zetas
1470
1471 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1472 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1473
1474 // result type needed
1475 fields = TypeTuple::fields(1);
1476 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1477 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1478 return TypeFunc::make(domain, range);
1479 }
1480
1481 // Kyber inverse NTT function
1482 static const TypeFunc* make_kyberInverseNtt_Type() {
1483 int argcnt = 2;
1484
1485 const Type** fields = TypeTuple::fields(argcnt);
1486 int argp = TypeFunc::Parms;
1487 fields[argp++] = TypePtr::NOTNULL; // coeffs
1488 fields[argp++] = TypePtr::NOTNULL; // inverse NTT zetas
1489
1490 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1491 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1492
1493 // result type needed
1494 fields = TypeTuple::fields(1);
1495 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1496 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1497 return TypeFunc::make(domain, range);
1498 }
1499
1500 // Kyber NTT multiply function
1501 static const TypeFunc* make_kyberNttMult_Type() {
1502 int argcnt = 4;
1503
1504 const Type** fields = TypeTuple::fields(argcnt);
1505 int argp = TypeFunc::Parms;
1506 fields[argp++] = TypePtr::NOTNULL; // result
1507 fields[argp++] = TypePtr::NOTNULL; // ntta
1508 fields[argp++] = TypePtr::NOTNULL; // nttb
1509 fields[argp++] = TypePtr::NOTNULL; // NTT multiply zetas
1510
1511 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1512 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1513
1514 // result type needed
1515 fields = TypeTuple::fields(1);
1516 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1517 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1518 return TypeFunc::make(domain, range);
1519 }
1520
1521 // Kyber add 2 polynomials function
1522 static const TypeFunc* make_kyberAddPoly_2_Type() {
1523 int argcnt = 3;
1524
1525 const Type** fields = TypeTuple::fields(argcnt);
1526 int argp = TypeFunc::Parms;
1527 fields[argp++] = TypePtr::NOTNULL; // result
1528 fields[argp++] = TypePtr::NOTNULL; // a
1529 fields[argp++] = TypePtr::NOTNULL; // b
1530
1531 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1532 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1533
1534 // result type needed
1535 fields = TypeTuple::fields(1);
1536 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1537 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1538 return TypeFunc::make(domain, range);
1539 }
1540
1541
1542 // Kyber add 3 polynomials function
1543 static const TypeFunc* make_kyberAddPoly_3_Type() {
1544 int argcnt = 4;
1545
1546 const Type** fields = TypeTuple::fields(argcnt);
1547 int argp = TypeFunc::Parms;
1548 fields[argp++] = TypePtr::NOTNULL; // result
1549 fields[argp++] = TypePtr::NOTNULL; // a
1550 fields[argp++] = TypePtr::NOTNULL; // b
1551 fields[argp++] = TypePtr::NOTNULL; // c
1552
1553 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1554 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1555
1556 // result type needed
1557 fields = TypeTuple::fields(1);
1558 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1559 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1560 return TypeFunc::make(domain, range);
1561 }
1562
1563
1564 // Kyber XOF output parsing into polynomial coefficients candidates
1565 // or decompress(12,...) function
1566 static const TypeFunc* make_kyber12To16_Type() {
1567 int argcnt = 4;
1568
1569 const Type** fields = TypeTuple::fields(argcnt);
1570 int argp = TypeFunc::Parms;
1571 fields[argp++] = TypePtr::NOTNULL; // condensed
1572 fields[argp++] = TypeInt::INT; // condensedOffs
1573 fields[argp++] = TypePtr::NOTNULL; // parsed
1574 fields[argp++] = TypeInt::INT; // parsedLength
1575
1576 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1577 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1578
1579 // result type needed
1580 fields = TypeTuple::fields(1);
1581 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1582 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1583 return TypeFunc::make(domain, range);
1584 }
1585
1586 // Kyber Barrett reduce function
1587 static const TypeFunc* make_kyberBarrettReduce_Type() {
1588 int argcnt = 1;
1589
1590 const Type** fields = TypeTuple::fields(argcnt);
1591 int argp = TypeFunc::Parms;
1592 fields[argp++] = TypePtr::NOTNULL; // coeffs
1593
1594 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1595 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1596
1597 // result type needed
1598 fields = TypeTuple::fields(1);
1599 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1600 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1601 return TypeFunc::make(domain, range);
1602 }
1603
1604 // Dilithium NTT function except for the final "normalization" to |coeff| < Q
1605 static const TypeFunc* make_dilithiumAlmostNtt_Type() {
1606 int argcnt = 2;
1607
1608 const Type** fields = TypeTuple::fields(argcnt);
1609 int argp = TypeFunc::Parms;
1610 fields[argp++] = TypePtr::NOTNULL; // coeffs
1611 fields[argp++] = TypePtr::NOTNULL; // NTT zetas
1612
1613 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1614 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1615
1616 // result type needed
1617 fields = TypeTuple::fields(1);
1618 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1619 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1620 return TypeFunc::make(domain, range);
1621 }
1622
1623 // Dilithium inverse NTT function except the final mod Q division by 2^256
1624 static const TypeFunc* make_dilithiumAlmostInverseNtt_Type() {
1625 int argcnt = 2;
1626
1627 const Type** fields = TypeTuple::fields(argcnt);
1628 int argp = TypeFunc::Parms;
1629 fields[argp++] = TypePtr::NOTNULL; // coeffs
1630 fields[argp++] = TypePtr::NOTNULL; // inverse NTT zetas
1631
1632 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1633 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1634
1635 // result type needed
1636 fields = TypeTuple::fields(1);
1637 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1638 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1639 return TypeFunc::make(domain, range);
1640 }
1641
1642 // Dilithium NTT multiply function
1643 static const TypeFunc* make_dilithiumNttMult_Type() {
1644 int argcnt = 3;
1645
1646 const Type** fields = TypeTuple::fields(argcnt);
1647 int argp = TypeFunc::Parms;
1648 fields[argp++] = TypePtr::NOTNULL; // result
1649 fields[argp++] = TypePtr::NOTNULL; // ntta
1650 fields[argp++] = TypePtr::NOTNULL; // nttb
1651
1652 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1653 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1654
1655 // result type needed
1656 fields = TypeTuple::fields(1);
1657 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1658 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1659 return TypeFunc::make(domain, range);
1660 }
1661
1662 // Dilithium Montgomery multiply a polynome coefficient array by a constant
1663 static const TypeFunc* make_dilithiumMontMulByConstant_Type() {
1664 int argcnt = 2;
1665
1666 const Type** fields = TypeTuple::fields(argcnt);
1667 int argp = TypeFunc::Parms;
1668 fields[argp++] = TypePtr::NOTNULL; // coeffs
1669 fields[argp++] = TypeInt::INT; // constant multiplier
1670
1671 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1672 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1673
1674 // result type needed
1675 fields = TypeTuple::fields(1);
1676 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1677 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1678 return TypeFunc::make(domain, range);
1679 }
1680
1681 // Dilithium decompose polynomial
1682 static const TypeFunc* make_dilithiumDecomposePoly_Type() {
1683 int argcnt = 5;
1684
1685 const Type** fields = TypeTuple::fields(argcnt);
1686 int argp = TypeFunc::Parms;
1687 fields[argp++] = TypePtr::NOTNULL; // input
1688 fields[argp++] = TypePtr::NOTNULL; // lowPart
1689 fields[argp++] = TypePtr::NOTNULL; // highPart
1690 fields[argp++] = TypeInt::INT; // 2 * gamma2
1691 fields[argp++] = TypeInt::INT; // multiplier
1692
1693 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1694 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1695
1696 // result type needed
1697 fields = TypeTuple::fields(1);
1698 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1699 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1700 return TypeFunc::make(domain, range);
1701 }
1702
1703 static const TypeFunc* make_base64_encodeBlock_Type() {
1704 int argcnt = 6;
1705
1706 const Type** fields = TypeTuple::fields(argcnt);
1707 int argp = TypeFunc::Parms;
1708 fields[argp++] = TypePtr::NOTNULL; // src array
1709 fields[argp++] = TypeInt::INT; // offset
1710 fields[argp++] = TypeInt::INT; // length
1711 fields[argp++] = TypePtr::NOTNULL; // dest array
1712 fields[argp++] = TypeInt::INT; // dp
1713 fields[argp++] = TypeInt::BOOL; // isURL
1714 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1715 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1716
1717 // result type needed
1718 fields = TypeTuple::fields(1);
1719 fields[TypeFunc::Parms + 0] = nullptr; // void
1720 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1721 return TypeFunc::make(domain, range);
1722 }
1723
1724 static const TypeFunc* make_string_IndexOf_Type() {
1725 int argcnt = 4;
1726
1727 const Type** fields = TypeTuple::fields(argcnt);
1728 int argp = TypeFunc::Parms;
1729 fields[argp++] = TypePtr::NOTNULL; // haystack array
1730 fields[argp++] = TypeInt::INT; // haystack length
1731 fields[argp++] = TypePtr::NOTNULL; // needle array
1732 fields[argp++] = TypeInt::INT; // needle length
1733 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1734 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1735
1736 // result type needed
1737 fields = TypeTuple::fields(1);
1738 fields[TypeFunc::Parms + 0] = TypeInt::INT; // Index of needle in haystack
1739 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1740 return TypeFunc::make(domain, range);
1741 }
1742
1743 static const TypeFunc* make_base64_decodeBlock_Type() {
1744 int argcnt = 7;
1745
1746 const Type** fields = TypeTuple::fields(argcnt);
1747 int argp = TypeFunc::Parms;
1748 fields[argp++] = TypePtr::NOTNULL; // src array
1749 fields[argp++] = TypeInt::INT; // src offset
1750 fields[argp++] = TypeInt::INT; // src length
1751 fields[argp++] = TypePtr::NOTNULL; // dest array
1752 fields[argp++] = TypeInt::INT; // dest offset
1753 fields[argp++] = TypeInt::BOOL; // isURL
1754 fields[argp++] = TypeInt::BOOL; // isMIME
1755 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1756 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1757
1758 // result type needed
1759 fields = TypeTuple::fields(1);
1760 fields[TypeFunc::Parms + 0] = TypeInt::INT; // count of bytes written to dst
1761 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1762 return TypeFunc::make(domain, range);
1763 }
1764
1765 static const TypeFunc* make_poly1305_processBlocks_Type() {
1766 int argcnt = 4;
1767
1768 const Type** fields = TypeTuple::fields(argcnt);
1769 int argp = TypeFunc::Parms;
1770 fields[argp++] = TypePtr::NOTNULL; // input array
1771 fields[argp++] = TypeInt::INT; // input length
1772 fields[argp++] = TypePtr::NOTNULL; // accumulator array
1773 fields[argp++] = TypePtr::NOTNULL; // r array
1774 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1775 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1776
1777 // result type needed
1778 fields = TypeTuple::fields(1);
1779 fields[TypeFunc::Parms + 0] = nullptr; // void
1780 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1781 return TypeFunc::make(domain, range);
1782 }
1783
1784 static const TypeFunc* make_intpoly_montgomeryMult_P256_Type() {
1785 int argcnt = 3;
1786
1787 const Type** fields = TypeTuple::fields(argcnt);
1788 int argp = TypeFunc::Parms;
1789 fields[argp++] = TypePtr::NOTNULL; // a array
1790 fields[argp++] = TypePtr::NOTNULL; // b array
1791 fields[argp++] = TypePtr::NOTNULL; // r(esult) array
1792 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1793 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1794
1795 // result type needed
1796 fields = TypeTuple::fields(1);
1797 fields[TypeFunc::Parms + 0] = nullptr; // void
1798 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1799 return TypeFunc::make(domain, range);
1800 }
1801
1802 static const TypeFunc* make_intpoly_assign_Type() {
1803 int argcnt = 4;
1804
1805 const Type** fields = TypeTuple::fields(argcnt);
1806 int argp = TypeFunc::Parms;
1807 fields[argp++] = TypeInt::INT; // set flag
1808 fields[argp++] = TypePtr::NOTNULL; // a array (result)
1809 fields[argp++] = TypePtr::NOTNULL; // b array (if set is set)
1810 fields[argp++] = TypeInt::INT; // array length
1811 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1812 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1813
1814 // result type needed
1815 fields = TypeTuple::fields(1);
1816 fields[TypeFunc::Parms + 0] = nullptr; // void
1817 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1818 return TypeFunc::make(domain, range);
1819 }
1820
1821 //------------- Interpreter state for on stack replacement
1822 static const TypeFunc* make_osr_end_Type() {
1823 // create input type (domain)
1824 const Type **fields = TypeTuple::fields(1);
1825 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
1826 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1827
1828 // create result type
1829 fields = TypeTuple::fields(1);
1830 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
1831 fields[TypeFunc::Parms+0] = nullptr; // void
1832 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1833 return TypeFunc::make(domain, range);
1834 }
1835
1836 #ifndef PRODUCT
1837 static void debug_print_convert_type(const Type** fields, int* argp, Node *parm) {
1838 const BasicType bt = parm->bottom_type()->basic_type();
1839 fields[(*argp)++] = Type::get_const_basic_type(bt);
1840 if (bt == T_LONG || bt == T_DOUBLE) {
1841 fields[(*argp)++] = Type::HALF;
1842 }
1843 }
1844
1845 static void update_arg_cnt(const Node* parm, int* arg_cnt) {
1846 (*arg_cnt)++;
1847 const BasicType bt = parm->bottom_type()->basic_type();
1848 if (bt == T_LONG || bt == T_DOUBLE) {
1849 (*arg_cnt)++;
1850 }
1851 }
1852
1853 const TypeFunc* OptoRuntime::debug_print_Type(Node* parm0, Node* parm1,
1854 Node* parm2, Node* parm3,
1855 Node* parm4, Node* parm5,
1856 Node* parm6) {
1857 int argcnt = 1;
1858 if (parm0 != nullptr) { update_arg_cnt(parm0, &argcnt);
1859 if (parm1 != nullptr) { update_arg_cnt(parm1, &argcnt);
1860 if (parm2 != nullptr) { update_arg_cnt(parm2, &argcnt);
1861 if (parm3 != nullptr) { update_arg_cnt(parm3, &argcnt);
1862 if (parm4 != nullptr) { update_arg_cnt(parm4, &argcnt);
1863 if (parm5 != nullptr) { update_arg_cnt(parm5, &argcnt);
1864 if (parm6 != nullptr) { update_arg_cnt(parm6, &argcnt);
1865 /* close each nested if ===> */ } } } } } } }
1866
1867 // create input type (domain)
1868 const Type** fields = TypeTuple::fields(argcnt);
1869 int argp = TypeFunc::Parms;
1870 fields[argp++] = TypePtr::NOTNULL; // static string pointer
1871
1872 if (parm0 != nullptr) { debug_print_convert_type(fields, &argp, parm0);
1873 if (parm1 != nullptr) { debug_print_convert_type(fields, &argp, parm1);
1874 if (parm2 != nullptr) { debug_print_convert_type(fields, &argp, parm2);
1875 if (parm3 != nullptr) { debug_print_convert_type(fields, &argp, parm3);
1876 if (parm4 != nullptr) { debug_print_convert_type(fields, &argp, parm4);
1877 if (parm5 != nullptr) { debug_print_convert_type(fields, &argp, parm5);
1878 if (parm6 != nullptr) { debug_print_convert_type(fields, &argp, parm6);
1879 /* close each nested if ===> */ } } } } } } }
1880
1881 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1882 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1883
1884 // no result type needed
1885 fields = TypeTuple::fields(1);
1886 fields[TypeFunc::Parms+0] = nullptr; // void
1887 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1888 return TypeFunc::make(domain, range);
1889 }
1890 #endif // PRODUCT
1891
1892 //-------------------------------------------------------------------------------------
1893 // register policy
1894
1895 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
1896 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1897 switch (register_save_policy[reg]) {
1898 case 'C': return false; //SOC
1899 case 'E': return true ; //SOE
1900 case 'N': return false; //NS
1901 case 'A': return false; //AS
1902 }
1903 ShouldNotReachHere();
1904 return false;
1905 }
1906
1907 //-----------------------------------------------------------------------
1908 // Exceptions
1909 //
1910
1911 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1912
1913 // The method is an entry that is always called by a C++ method not
1914 // directly from compiled code. Compiled code will call the C++ method following.
1915 // We can't allow async exception to be installed during exception processing.
1916 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1917 // The frame we rethrow the exception to might not have been processed by the GC yet.
1918 // The stack watermark barrier takes care of detecting that and ensuring the frame
1919 // has updated oops.
1920 StackWatermarkSet::after_unwind(current);
1921
1922 // Do not confuse exception_oop with pending_exception. The exception_oop
1923 // is only used to pass arguments into the method. Not for general
1924 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1925 // the runtime stubs checks this on exit.
1926 assert(current->exception_oop() != nullptr, "exception oop is found");
1927 address handler_address = nullptr;
1928
1929 Handle exception(current, current->exception_oop());
1930 address pc = current->exception_pc();
1931
1932 // Clear out the exception oop and pc since looking up an
1933 // exception handler can cause class loading, which might throw an
1934 // exception and those fields are expected to be clear during
1935 // normal bytecode execution.
1936 current->clear_exception_oop_and_pc();
1937
1938 LogTarget(Info, exceptions) lt;
1939 if (lt.is_enabled()) {
1940 LogStream ls(lt);
1941 trace_exception(&ls, exception(), pc, "");
1942 }
1943
1944 // for AbortVMOnException flag
1945 Exceptions::debug_check_abort(exception);
1946
1947 #ifdef ASSERT
1948 if (!(exception->is_a(vmClasses::Throwable_klass()))) {
1949 // should throw an exception here
1950 ShouldNotReachHere();
1951 }
1952 #endif
1953
1954 // new exception handling: this method is entered only from adapters
1955 // exceptions from compiled java methods are handled in compiled code
1956 // using rethrow node
1957
1958 nm = CodeCache::find_nmethod(pc);
1959 assert(nm != nullptr, "No NMethod found");
1960 if (nm->is_native_method()) {
1961 fatal("Native method should not have path to exception handling");
1962 } else {
1963 // we are switching to old paradigm: search for exception handler in caller_frame
1964 // instead in exception handler of caller_frame.sender()
1965
1966 if (JvmtiExport::can_post_on_exceptions()) {
1967 // "Full-speed catching" is not necessary here,
1968 // since we're notifying the VM on every catch.
1969 // Force deoptimization and the rest of the lookup
1970 // will be fine.
1971 deoptimize_caller_frame(current);
1972 }
1973
1974 // Check the stack guard pages. If enabled, look for handler in this frame;
1975 // otherwise, forcibly unwind the frame.
1976 //
1977 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
1978 bool force_unwind = !current->stack_overflow_state()->reguard_stack();
1979 bool deopting = false;
1980 if (nm->is_deopt_pc(pc)) {
1981 deopting = true;
1982 RegisterMap map(current,
1983 RegisterMap::UpdateMap::skip,
1984 RegisterMap::ProcessFrames::include,
1985 RegisterMap::WalkContinuation::skip);
1986 frame deoptee = current->last_frame().sender(&map);
1987 assert(deoptee.is_deoptimized_frame(), "must be deopted");
1988 // Adjust the pc back to the original throwing pc
1989 pc = deoptee.pc();
1990 }
1991
1992 // If we are forcing an unwind because of stack overflow then deopt is
1993 // irrelevant since we are throwing the frame away anyway.
1994
1995 if (deopting && !force_unwind) {
1996 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1997 } else {
1998
1999 handler_address =
2000 force_unwind ? nullptr : nm->handler_for_exception_and_pc(exception, pc);
2001
2002 if (handler_address == nullptr) {
2003 bool recursive_exception = false;
2004 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
2005 assert (handler_address != nullptr, "must have compiled handler");
2006 // Update the exception cache only when the unwind was not forced
2007 // and there didn't happen another exception during the computation of the
2008 // compiled exception handler. Checking for exception oop equality is not
2009 // sufficient because some exceptions are pre-allocated and reused.
2010 if (!force_unwind && !recursive_exception) {
2011 nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
2012 }
2013 } else {
2014 #ifdef ASSERT
2015 bool recursive_exception = false;
2016 address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
2017 vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT,
2018 p2i(handler_address), p2i(computed_address));
2019 #endif
2020 }
2021 }
2022
2023 current->set_exception_pc(pc);
2024 current->set_exception_handler_pc(handler_address);
2025 }
2026
2027 // Restore correct return pc. Was saved above.
2028 current->set_exception_oop(exception());
2029 return handler_address;
2030
2031 JRT_END
2032
2033 // We are entering here from exception_blob
2034 // If there is a compiled exception handler in this method, we will continue there;
2035 // otherwise we will unwind the stack and continue at the caller of top frame method
2036 // Note we enter without the usual JRT wrapper. We will call a helper routine that
2037 // will do the normal VM entry. We do it this way so that we can see if the nmethod
2038 // we looked up the handler for has been deoptimized in the meantime. If it has been
2039 // we must not use the handler and instead return the deopt blob.
2040 address OptoRuntime::handle_exception_C(JavaThread* current) {
2041 //
2042 // We are in Java not VM and in debug mode we have a NoHandleMark
2043 //
2044 #ifndef PRODUCT
2045 SharedRuntime::_find_handler_ctr++; // find exception handler
2046 #endif
2047 DEBUG_ONLY(NoHandleMark __hm;)
2048 nmethod* nm = nullptr;
2049 address handler_address = nullptr;
2050 {
2051 // Enter the VM
2052
2053 ResetNoHandleMark rnhm;
2054 handler_address = handle_exception_C_helper(current, nm);
2055 }
2056
2057 // Back in java: Use no oops, DON'T safepoint
2058
2059 // Now check to see if the handler we are returning is in a now
2060 // deoptimized frame
2061
2062 if (nm != nullptr) {
2063 RegisterMap map(current,
2064 RegisterMap::UpdateMap::skip,
2065 RegisterMap::ProcessFrames::skip,
2066 RegisterMap::WalkContinuation::skip);
2067 frame caller = current->last_frame().sender(&map);
2068 #ifdef ASSERT
2069 assert(caller.is_compiled_frame(), "must be");
2070 #endif // ASSERT
2071 if (caller.is_deoptimized_frame()) {
2072 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
2073 }
2074 }
2075 return handler_address;
2076 }
2077
2078 //------------------------------rethrow----------------------------------------
2079 // We get here after compiled code has executed a 'RethrowNode'. The callee
2080 // is either throwing or rethrowing an exception. The callee-save registers
2081 // have been restored, synchronized objects have been unlocked and the callee
2082 // stack frame has been removed. The return address was passed in.
2083 // Exception oop is passed as the 1st argument. This routine is then called
2084 // from the stub. On exit, we know where to jump in the caller's code.
2085 // After this C code exits, the stub will pop his frame and end in a jump
2086 // (instead of a return). We enter the caller's default handler.
2087 //
2088 // This must be JRT_LEAF:
2089 // - caller will not change its state as we cannot block on exit,
2090 // therefore raw_exception_handler_for_return_address is all it takes
2091 // to handle deoptimized blobs
2092 //
2093 // However, there needs to be a safepoint check in the middle! So compiled
2094 // safepoints are completely watertight.
2095 //
2096 // Thus, it cannot be a leaf since it contains the NoSafepointVerifier.
2097 //
2098 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
2099 //
2100 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
2101 // ret_pc will have been loaded from the stack, so for AArch64 will be signed.
2102 AARCH64_PORT_ONLY(ret_pc = pauth_strip_verifiable(ret_pc));
2103
2104 #ifndef PRODUCT
2105 SharedRuntime::_rethrow_ctr++; // count rethrows
2106 #endif
2107 assert (exception != nullptr, "should have thrown a NullPointerException");
2108 #ifdef ASSERT
2109 if (!(exception->is_a(vmClasses::Throwable_klass()))) {
2110 // should throw an exception here
2111 ShouldNotReachHere();
2112 }
2113 #endif
2114
2115 thread->set_vm_result_oop(exception);
2116 // Frame not compiled (handles deoptimization blob)
2117 return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
2118 }
2119
2120 static const TypeFunc* make_rethrow_Type() {
2121 // create input type (domain)
2122 const Type **fields = TypeTuple::fields(1);
2123 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
2124 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2125
2126 // create result type (range)
2127 fields = TypeTuple::fields(1);
2128 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
2129 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
2130
2131 return TypeFunc::make(domain, range);
2132 }
2133
2134
2135 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
2136 // Deoptimize the caller before continuing, as the compiled
2137 // exception handler table may not be valid.
2138 if (DeoptimizeOnAllocationException && doit) {
2139 deoptimize_caller_frame(thread);
2140 }
2141 }
2142
2143 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) {
2144 // Called from within the owner thread, so no need for safepoint
2145 RegisterMap reg_map(thread,
2146 RegisterMap::UpdateMap::include,
2147 RegisterMap::ProcessFrames::include,
2148 RegisterMap::WalkContinuation::skip);
2149 frame stub_frame = thread->last_frame();
2150 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
2151 frame caller_frame = stub_frame.sender(®_map);
2152
2153 // Deoptimize the caller frame.
2154 Deoptimization::deoptimize_frame(thread, caller_frame.id());
2155 }
2156
2157
2158 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
2159 // Called from within the owner thread, so no need for safepoint
2160 RegisterMap reg_map(thread,
2161 RegisterMap::UpdateMap::include,
2162 RegisterMap::ProcessFrames::include,
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;
2252 while (c) {
2253 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
2254 int count = c->count();
2255 if (count > 0) {
2256 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
2257 if (Verbose) {
2258 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
2259 }
2260 total_lock_count += count;
2261 if (eliminated) {
2262 eliminated_lock_count += count;
2263 }
2264 }
2265 }
2266 c = c->next();
2267 }
2268 if (total_lock_count > 0) {
2269 tty->print_cr("dynamic locks: %d", total_lock_count);
2270 if (eliminated_lock_count) {
2271 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
2272 (int)(eliminated_lock_count * 100.0 / total_lock_count));
2273 }
2274 }
2275 }
2276
2277 //
2278 // Allocate a new NamedCounter. The JVMState is used to generate the
2279 // name which consists of method@line for the inlining tree.
2280 //
2281
2282 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
2283 int max_depth = youngest_jvms->depth();
2284
2285 // Visit scopes from youngest to oldest.
2286 bool first = true;
2287 stringStream st;
2288 for (int depth = max_depth; depth >= 1; depth--) {
2289 JVMState* jvms = youngest_jvms->of_depth(depth);
2290 ciMethod* m = jvms->has_method() ? jvms->method() : nullptr;
2291 if (!first) {
2292 st.print(" ");
2293 } else {
2294 first = false;
2295 }
2296 int bci = jvms->bci();
2297 if (bci < 0) bci = 0;
2298 if (m != nullptr) {
2299 st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8());
2300 } else {
2301 st.print("no method");
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);
2343 _checkcast_arraycopy_Type = make_arraycopy_Type(ac_checkcast);
2344 _generic_arraycopy_Type = make_arraycopy_Type(ac_generic);
2345 _slow_arraycopy_Type = make_arraycopy_Type(ac_slow);
2346 _unsafe_setmemory_Type = make_setmemory_Type();
2347 _array_fill_Type = make_array_fill_Type();
2348 _array_sort_Type = make_array_sort_Type();
2349 _array_partition_Type = make_array_partition_Type();
2350 _aescrypt_block_Type = make_aescrypt_block_Type();
2351 _cipherBlockChaining_aescrypt_Type = make_cipherBlockChaining_aescrypt_Type();
2352 _electronicCodeBook_aescrypt_Type = make_electronicCodeBook_aescrypt_Type();
2353 _counterMode_aescrypt_Type = make_counterMode_aescrypt_Type();
2354 _galoisCounterMode_aescrypt_Type = make_galoisCounterMode_aescrypt_Type();
2355 _digestBase_implCompress_with_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ true);
2356 _digestBase_implCompress_without_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ false);;
2357 _digestBase_implCompressMB_with_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ true);
2358 _digestBase_implCompressMB_without_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ false);
2359 _double_keccak_Type = make_double_keccak_Type();
2360 _multiplyToLen_Type = make_multiplyToLen_Type();
2361 _montgomeryMultiply_Type = make_montgomeryMultiply_Type();
2362 _montgomerySquare_Type = make_montgomerySquare_Type();
2363 _squareToLen_Type = make_squareToLen_Type();
2364 _mulAdd_Type = make_mulAdd_Type();
2365 _bigIntegerShift_Type = make_bigIntegerShift_Type();
2366 _vectorizedMismatch_Type = make_vectorizedMismatch_Type();
2367 _ghash_processBlocks_Type = make_ghash_processBlocks_Type();
2368 _chacha20Block_Type = make_chacha20Block_Type();
2369 _kyberNtt_Type = make_kyberNtt_Type();
2370 _kyberInverseNtt_Type = make_kyberInverseNtt_Type();
2371 _kyberNttMult_Type = make_kyberNttMult_Type();
2372 _kyberAddPoly_2_Type = make_kyberAddPoly_2_Type();
2373 _kyberAddPoly_3_Type = make_kyberAddPoly_3_Type();
2374 _kyber12To16_Type = make_kyber12To16_Type();
2375 _kyberBarrettReduce_Type = make_kyberBarrettReduce_Type();
2376 _dilithiumAlmostNtt_Type = make_dilithiumAlmostNtt_Type();
2377 _dilithiumAlmostInverseNtt_Type = make_dilithiumAlmostInverseNtt_Type();
2378 _dilithiumNttMult_Type = make_dilithiumNttMult_Type();
2379 _dilithiumMontMulByConstant_Type = make_dilithiumMontMulByConstant_Type();
2380 _dilithiumDecomposePoly_Type = make_dilithiumDecomposePoly_Type();
2381 _base64_encodeBlock_Type = make_base64_encodeBlock_Type();
2382 _base64_decodeBlock_Type = make_base64_decodeBlock_Type();
2383 _string_IndexOf_Type = make_string_IndexOf_Type();
2384 _poly1305_processBlocks_Type = make_poly1305_processBlocks_Type();
2385 _intpoly_montgomeryMult_P256_Type = make_intpoly_montgomeryMult_P256_Type();
2386 _intpoly_assign_Type = make_intpoly_assign_Type();
2387 _updateBytesCRC32_Type = make_updateBytesCRC32_Type();
2388 _updateBytesCRC32C_Type = make_updateBytesCRC32C_Type();
2389 _updateBytesAdler32_Type = make_updateBytesAdler32_Type();
2390 _osr_end_Type = make_osr_end_Type();
2391 _register_finalizer_Type = make_register_finalizer_Type();
2392 JFR_ONLY(
2393 _class_id_load_barrier_Type = make_class_id_load_barrier_Type();
2394 )
2395 #if INCLUDE_JVMTI
2396 _notify_jvmti_vthread_Type = make_notify_jvmti_vthread_Type();
2397 #endif // INCLUDE_JVMTI
2398 _dtrace_method_entry_exit_Type = make_dtrace_method_entry_exit_Type();
2399 _dtrace_object_alloc_Type = make_dtrace_object_alloc_Type();
2400 }
2401
2402 int trace_exception_counter = 0;
2403 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2404 trace_exception_counter++;
2405 stringStream tempst;
2406
2407 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2408 exception_oop->print_value_on(&tempst);
2409 tempst.print(" in ");
2410 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2411 if (blob->is_nmethod()) {
2412 blob->as_nmethod()->method()->print_value_on(&tempst);
2413 } else if (blob->is_runtime_stub()) {
2414 tempst.print("<runtime-stub>");
2415 } else {
2416 tempst.print("<unknown>");
2417 }
2418 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2419 tempst.print("]");
2420
2421 st->print_raw_cr(tempst.freeze());
2422 }
2423
2424 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
2425 // create input type (domain)
2426 uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2427 const Type **fields = TypeTuple::fields(total);
2428 // We don't know the number of returned values and their
2429 // types. Assume all registers available to the return convention
2430 // are used.
2431 fields[TypeFunc::Parms] = TypePtr::BOTTOM;
2432 uint i = 1;
2433 for (; i < SharedRuntime::java_return_convention_max_int; i++) {
2434 fields[TypeFunc::Parms+i] = TypeInt::INT;
2435 }
2436 for (; i < total; i+=2) {
2437 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2438 fields[TypeFunc::Parms+i+1] = Type::HALF;
2439 }
2440 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2441
2442 // create result type (range)
2443 fields = TypeTuple::fields(1);
2444 fields[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM;
2445
2446 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2447
2448 return TypeFunc::make(domain, range);
2449 }
2450
2451 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
2452 // create input type (domain)
2453 uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
2454 const Type **fields = TypeTuple::fields(total);
2455 // We don't know the number of returned values and their
2456 // types. Assume all registers available to the return convention
2457 // are used.
2458 fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
2459 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
2460 uint i = 2;
2461 for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
2462 fields[TypeFunc::Parms+i] = TypeInt::INT;
2463 }
2464 for (; i < total; i+=2) {
2465 fields[TypeFunc::Parms+i] = Type::DOUBLE;
2466 fields[TypeFunc::Parms+i+1] = Type::HALF;
2467 }
2468 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
2469
2470 // create result type (range)
2471 fields = TypeTuple::fields(1);
2472 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
2473
2474 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
2475
2476 return TypeFunc::make(domain, range);
2477 }
2478
2479 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline_C(flatArrayOopDesc* array, int index, JavaThread* current))
2480 JRT_BLOCK;
2481 oop buffer = array->obj_at(index, THREAD);
2482 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
2483 current->set_vm_result_oop(buffer);
2484 JRT_BLOCK_END;
2485 JRT_END
2486
2487 const TypeFunc* OptoRuntime::load_unknown_inline_Type() {
2488 // create input type (domain)
2489 const Type** fields = TypeTuple::fields(2);
2490 fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
2491 fields[TypeFunc::Parms+1] = TypeInt::POS;
2492
2493 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
2494
2495 // create result type (range)
2496 fields = TypeTuple::fields(1);
2497 fields[TypeFunc::Parms] = TypeInstPtr::BOTTOM;
2498
2499 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
2500
2501 return TypeFunc::make(domain, range);
2502 }
2503
2504 JRT_BLOCK_ENTRY(void, OptoRuntime::store_unknown_inline_C(instanceOopDesc* buffer, flatArrayOopDesc* array, int index, JavaThread* current))
2505 JRT_BLOCK;
2506 array->obj_at_put(index, buffer, THREAD);
2507 if (HAS_PENDING_EXCEPTION) {
2508 fatal("This entry must be changed to be a non-leaf entry because writing to a flat array can now throw an exception");
2509 }
2510 JRT_BLOCK_END;
2511 JRT_END
2512
2513 const TypeFunc* OptoRuntime::store_unknown_inline_Type() {
2514 // create input type (domain)
2515 const Type** fields = TypeTuple::fields(3);
2516 fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2517 fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
2518 fields[TypeFunc::Parms+2] = TypeInt::POS;
2519
2520 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
2521
2522 // create result type (range)
2523 fields = TypeTuple::fields(0);
2524 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
2525
2526 return TypeFunc::make(domain, range);
2527 }