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