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