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