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