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