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