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 #ifndef SHARE_OPTO_RUNTIME_HPP
 26 #define SHARE_OPTO_RUNTIME_HPP
 27 
 28 #include "code/codeBlob.hpp"
 29 #include "opto/machnode.hpp"
 30 #include "opto/optoreg.hpp"
 31 #include "runtime/stubDeclarations.hpp"
 32 #include "runtime/stubInfo.hpp"
 33 #include "runtime/vframe.hpp"
 34 
 35 //------------------------------OptoRuntime------------------------------------
 36 // Opto compiler runtime routines
 37 //
 38 // These are all generated from Ideal graphs.  They are called with the
 39 // Java calling convention.  Internally they call C++.  They are made once at
 40 // startup time and Opto compiles calls to them later.
 41 // Things are broken up into quads: the signature they will be called with,
 42 // the address of the generated code, the corresponding C++ code and an
 43 // nmethod.
 44 
 45 // The signature (returned by "xxx_Type()") is used at startup time by the
 46 // Generator to make the generated code "xxx_Java".  Opto compiles calls
 47 // to the generated code "xxx_Java".  When the compiled code gets executed,
 48 // it calls the C++ code "xxx_C".  The generated nmethod is saved in the
 49 // CodeCache.  Exception handlers use the nmethod to get the callee-save
 50 // register OopMaps.
 51 class CallInfo;
 52 
 53 //
 54 // NamedCounters are tagged counters which can be used for profiling
 55 // code in various ways.  Currently they are used by the lock coarsening code
 56 //
 57 
 58 class NamedCounter : public CHeapObj<mtCompiler> {
 59 public:
 60     enum CounterTag {
 61     NoTag,
 62     LockCounter,
 63     EliminatedLockCounter
 64   };
 65 
 66 private:
 67   const char *  _name;
 68   int           _count;
 69   CounterTag    _tag;
 70   NamedCounter* _next;
 71 
 72  public:
 73   NamedCounter(const char *n, CounterTag tag = NoTag):
 74     _name(n == nullptr ? nullptr : os::strdup(n)),
 75     _count(0),
 76     _tag(tag),
 77     _next(nullptr) {}
 78 
 79   ~NamedCounter() {
 80     if (_name != nullptr) {
 81       os::free((void*)_name);
 82     }
 83   }
 84 
 85   const char * name() const     { return _name; }
 86   int count() const             { return _count; }
 87   address addr()                { return (address)&_count; }
 88   CounterTag tag() const        { return _tag; }
 89   void set_tag(CounterTag tag)  { _tag = tag; }
 90 
 91   NamedCounter* next() const    { return _next; }
 92   void set_next(NamedCounter* next) {
 93     assert(_next == nullptr || next == nullptr, "already set");
 94     _next = next;
 95   }
 96 
 97 };
 98 
 99 typedef const TypeFunc*(*TypeFunc_generator)();
100 
101 class OptoRuntime : public AllStatic {
102   friend class Matcher;  // allow access to stub names
103   friend class AOTCodeAddressTable;
104 
105  private:
106   // declare opto stub address/blob holder static fields
107 #define C2_BLOB_FIELD_DECLARE(name, type) \
108   static type*       BLOB_FIELD_NAME(name);
109 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
110 #define C2_STUB_FIELD_DECLARE(name, f, t, r) \
111   static address     C2_STUB_FIELD_NAME(name) ;
112 #define C2_JVMTI_STUB_FIELD_DECLARE(name) \
113   static address     STUB_FIELD_NAME(name);
114 
115   C2_STUBS_DO(C2_BLOB_FIELD_DECLARE, C2_STUB_FIELD_DECLARE, C2_JVMTI_STUB_FIELD_DECLARE)
116 
117 #undef C2_BLOB_FIELD_DECLARE
118 #undef C2_STUB_FIELD_NAME
119 #undef C2_STUB_FIELD_DECLARE
120 #undef C2_JVMTI_STUB_FIELD_DECLARE
121 
122   // static TypeFunc* data members
123   static const TypeFunc* _new_instance_Type;
124   static const TypeFunc* _new_array_Type;
125   static const TypeFunc* _multianewarray2_Type;
126   static const TypeFunc* _multianewarray3_Type;
127   static const TypeFunc* _multianewarray4_Type;
128   static const TypeFunc* _multianewarray5_Type;
129   static const TypeFunc* _multianewarrayN_Type;
130   static const TypeFunc* _complete_monitor_enter_Type;
131   static const TypeFunc* _complete_monitor_exit_Type;
132   static const TypeFunc* _monitor_notify_Type;
133   static const TypeFunc* _uncommon_trap_Type;
134   static const TypeFunc* _athrow_Type;
135   static const TypeFunc* _rethrow_Type;
136   static const TypeFunc* _Math_D_D_Type;
137   static const TypeFunc* _Math_DD_D_Type;
138   static const TypeFunc* _modf_Type;
139   static const TypeFunc* _l2f_Type;
140   static const TypeFunc* _void_long_Type;
141   static const TypeFunc* _void_void_Type;
142   static const TypeFunc* _jfr_write_checkpoint_Type;
143   static const TypeFunc* _flush_windows_Type;
144   static const TypeFunc* _fast_arraycopy_Type;
145   static const TypeFunc* _checkcast_arraycopy_Type;
146   static const TypeFunc* _generic_arraycopy_Type;
147   static const TypeFunc* _slow_arraycopy_Type;
148   static const TypeFunc* _unsafe_setmemory_Type;
149   static const TypeFunc* _array_fill_Type;
150   static const TypeFunc* _array_sort_Type;
151   static const TypeFunc* _array_partition_Type;
152   static const TypeFunc* _aescrypt_block_Type;
153   static const TypeFunc* _cipherBlockChaining_aescrypt_Type;
154   static const TypeFunc* _electronicCodeBook_aescrypt_Type;
155   static const TypeFunc* _counterMode_aescrypt_Type;
156   static const TypeFunc* _galoisCounterMode_aescrypt_Type;
157   static const TypeFunc* _digestBase_implCompress_with_sha3_Type;
158   static const TypeFunc* _digestBase_implCompress_without_sha3_Type;
159   static const TypeFunc* _digestBase_implCompressMB_with_sha3_Type;
160   static const TypeFunc* _digestBase_implCompressMB_without_sha3_Type;
161   static const TypeFunc* _double_keccak_Type;
162   static const TypeFunc* _multiplyToLen_Type;
163   static const TypeFunc* _montgomeryMultiply_Type;
164   static const TypeFunc* _montgomerySquare_Type;
165   static const TypeFunc* _squareToLen_Type;
166   static const TypeFunc* _mulAdd_Type;
167   static const TypeFunc* _bigIntegerShift_Type;
168   static const TypeFunc* _vectorizedMismatch_Type;
169   static const TypeFunc* _ghash_processBlocks_Type;
170   static const TypeFunc* _chacha20Block_Type;
171   static const TypeFunc* _kyberNtt_Type;
172   static const TypeFunc* _kyberInverseNtt_Type;
173   static const TypeFunc* _kyberNttMult_Type;
174   static const TypeFunc* _kyberAddPoly_2_Type;
175   static const TypeFunc* _kyberAddPoly_3_Type;
176   static const TypeFunc* _kyber12To16_Type;
177   static const TypeFunc* _kyberBarrettReduce_Type;
178   static const TypeFunc* _dilithiumAlmostNtt_Type;
179   static const TypeFunc* _dilithiumAlmostInverseNtt_Type;
180   static const TypeFunc* _dilithiumNttMult_Type;
181   static const TypeFunc* _dilithiumMontMulByConstant_Type;
182   static const TypeFunc* _dilithiumDecomposePoly_Type;
183   static const TypeFunc* _base64_encodeBlock_Type;
184   static const TypeFunc* _base64_decodeBlock_Type;
185   static const TypeFunc* _string_IndexOf_Type;
186   static const TypeFunc* _poly1305_processBlocks_Type;
187   static const TypeFunc* _intpoly_montgomeryMult_P256_Type;
188   static const TypeFunc* _intpoly_assign_Type;
189   static const TypeFunc* _updateBytesCRC32_Type;
190   static const TypeFunc* _updateBytesCRC32C_Type;
191   static const TypeFunc* _updateBytesAdler32_Type;
192   static const TypeFunc* _osr_end_Type;
193   static const TypeFunc* _register_finalizer_Type;
194 #if INCLUDE_JFR
195   static const TypeFunc* _class_id_load_barrier_Type;
196 #endif // INCLUDE_JFR
197 #if INCLUDE_JVMTI
198   static const TypeFunc* _notify_jvmti_vthread_Type;
199 #endif // INCLUDE_JVMTI
200   static const TypeFunc* _dtrace_method_entry_exit_Type;
201   static const TypeFunc* _dtrace_object_alloc_Type;
202 
203   // define stubs
204   static address generate_stub(ciEnv* ci_env, TypeFunc_generator gen, address C_function, const char* name, StubId stub_id, int is_fancy_jump, bool pass_tls, bool return_pc);
205 
206   //
207   // Implementation of runtime methods
208   // =================================
209 
210   // Allocate storage for a Java instance.
211   static void new_instance_C(Klass* instance_klass, JavaThread* current);
212 
213   // Allocate storage for a objArray or typeArray
214   static void new_array_C(Klass* array_klass, int len, JavaThread* current);
215   static void new_array_nozero_C(Klass* array_klass, int len, JavaThread* current);
216 
217   // Allocate storage for a multi-dimensional arrays
218   // Note: needs to be fixed for arbitrary number of dimensions
219   static void multianewarray2_C(Klass* klass, int len1, int len2, JavaThread* current);
220   static void multianewarray3_C(Klass* klass, int len1, int len2, int len3, JavaThread* current);
221   static void multianewarray4_C(Klass* klass, int len1, int len2, int len3, int len4, JavaThread* current);
222   static void multianewarray5_C(Klass* klass, int len1, int len2, int len3, int len4, int len5, JavaThread* current);
223   static void multianewarrayN_C(Klass* klass, arrayOopDesc* dims, JavaThread* current);
224 
225   // local methods passed as arguments to stub generator that forward
226   // control to corresponding JRT methods of SharedRuntime
227   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
228                                oopDesc* dest, jint dest_pos,
229                                jint length, JavaThread* thread);
230   static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
231 
232 public:
233   static void monitor_notify_C(oopDesc* obj, JavaThread* current);
234   static void monitor_notifyAll_C(oopDesc* obj, JavaThread* current);
235 
236 private:
237 
238   // Implicit exception support
239   static void throw_null_exception_C(JavaThread* thread);
240 
241   // Exception handling
242   static address handle_exception_C       (JavaThread* current);
243   static address handle_exception_C_helper(JavaThread* current, nmethod*& nm);
244   static address rethrow_C                (oopDesc* exception, JavaThread *thread, address return_pc );
245   static void deoptimize_caller_frame     (JavaThread *thread);
246   static void deoptimize_caller_frame     (JavaThread *thread, bool doit);
247   static bool is_deoptimized_caller_frame (JavaThread *thread);
248 
249   // CodeBlob support
250   // ===================================================================
251 
252   static UncommonTrapBlob* generate_uncommon_trap_blob(void);
253   static ExceptionBlob* generate_exception_blob();
254 
255   static void register_finalizer_C(oopDesc* obj, JavaThread* current);
256 
257  public:
258 
259   static bool is_callee_saved_register(MachRegisterNumbers reg);
260 
261   // One time only generate runtime code stubs. Returns true
262   // when runtime stubs have been generated successfully and
263   // false otherwise.
264   static bool generate(ciEnv* env);
265 
266   // Returns the name of a stub
267   static const char* stub_name(address entry);
268 
269   // Returns the name associated with a given stub id
270   static const char* stub_name(StubId id) {
271     assert(StubInfo::is_c2(id), "not a C2 stub %s", StubInfo::name(id));
272     return StubInfo::name(id);
273   }
274 
275   // access to runtime stubs entry points for java code
276   static address new_instance_Java()                     { return _new_instance_Java; }
277   static address new_array_Java()                        { return _new_array_Java; }
278   static address new_array_nozero_Java()                 { return _new_array_nozero_Java; }
279   static address multianewarray2_Java()                  { return _multianewarray2_Java; }
280   static address multianewarray3_Java()                  { return _multianewarray3_Java; }
281   static address multianewarray4_Java()                  { return _multianewarray4_Java; }
282   static address multianewarray5_Java()                  { return _multianewarray5_Java; }
283   static address multianewarrayN_Java()                  { return _multianewarrayN_Java; }
284   static address complete_monitor_locking_Java()         { return _complete_monitor_locking_Java; }
285   static address monitor_notify_Java()                   { return _monitor_notify_Java; }
286   static address monitor_notifyAll_Java()                { return _monitor_notifyAll_Java; }
287 
288   static address slow_arraycopy_Java()                   { return _slow_arraycopy_Java; }
289   static address register_finalizer_Java()               { return _register_finalizer_Java; }
290 #if INCLUDE_JVMTI
291   static address notify_jvmti_vthread_start()            { return _notify_jvmti_vthread_start; }
292   static address notify_jvmti_vthread_end()              { return _notify_jvmti_vthread_end; }
293   static address notify_jvmti_vthread_mount()            { return _notify_jvmti_vthread_mount; }
294   static address notify_jvmti_vthread_unmount()          { return _notify_jvmti_vthread_unmount; }
295 #endif
296 
297   static UncommonTrapBlob* uncommon_trap_blob()                  { return _uncommon_trap_blob; }
298   static ExceptionBlob*    exception_blob()                      { return _exception_blob; }
299 
300   // Implicit exception support
301   static void throw_div0_exception_C      (JavaThread* thread);
302   static void throw_stack_overflow_error_C(JavaThread* thread);
303 
304   // Exception handling
305   static address rethrow_stub()             { return _rethrow_Java; }
306 
307 
308   // Type functions
309   // ======================================================
310 
311   static inline const TypeFunc* new_instance_Type() {
312     assert(_new_instance_Type != nullptr, "should be initialized");
313     return _new_instance_Type;
314   }
315 
316   static inline const TypeFunc* new_array_Type() {
317     assert(_new_array_Type != nullptr, "should be initialized");
318     return _new_array_Type;
319   }
320 
321   static inline const TypeFunc* new_array_nozero_Type() {
322     return new_array_Type();
323   }
324 
325   static const TypeFunc* multianewarray_Type(int ndim); // multianewarray
326 
327   static inline const TypeFunc* multianewarray2_Type() {
328     assert(_multianewarray2_Type != nullptr, "should be initialized");
329     return _multianewarray2_Type;
330   }
331 
332   static inline const TypeFunc* multianewarray3_Type() {
333     assert(_multianewarray3_Type != nullptr, "should be initialized");
334     return _multianewarray3_Type;
335   }
336 
337   static inline const TypeFunc* multianewarray4_Type() {
338     assert(_multianewarray4_Type != nullptr, "should be initialized");
339     return _multianewarray4_Type;
340   }
341 
342   static inline const TypeFunc* multianewarray5_Type() {
343     assert(_multianewarray5_Type != nullptr, "should be initialized");
344     return _multianewarray5_Type;
345   }
346 
347   static inline const TypeFunc* multianewarrayN_Type() {
348     assert(_multianewarrayN_Type != nullptr, "should be initialized");
349     return _multianewarrayN_Type;
350   }
351 
352   static inline const TypeFunc* complete_monitor_enter_Type() {
353     assert(_complete_monitor_enter_Type != nullptr, "should be initialized");
354     return _complete_monitor_enter_Type;
355   }
356 
357   static inline const TypeFunc* complete_monitor_locking_Type() {
358     return complete_monitor_enter_Type();
359   }
360 
361   static inline const TypeFunc* complete_monitor_exit_Type() {
362     assert(_complete_monitor_exit_Type != nullptr, "should be initialized");
363     return _complete_monitor_exit_Type;
364   }
365 
366   static inline const TypeFunc* monitor_notify_Type() {
367     assert(_monitor_notify_Type != nullptr, "should be initialized");
368     return _monitor_notify_Type;
369   }
370 
371   static inline const TypeFunc* monitor_notifyAll_Type() {
372     return monitor_notify_Type();
373   }
374 
375   static inline const TypeFunc* uncommon_trap_Type() {
376     assert(_uncommon_trap_Type != nullptr, "should be initialized");
377     return _uncommon_trap_Type;
378   }
379 
380   static inline const TypeFunc* athrow_Type() {
381     assert(_athrow_Type != nullptr, "should be initialized");
382     return _athrow_Type;
383   }
384 
385   static inline const TypeFunc* rethrow_Type() {
386     assert(_rethrow_Type != nullptr, "should be initialized");
387     return _rethrow_Type;
388   }
389 
390   static inline const TypeFunc* Math_D_D_Type() {
391     assert(_Math_D_D_Type != nullptr, "should be initialized");
392     return _Math_D_D_Type;
393   }
394 
395   static inline const TypeFunc* Math_DD_D_Type() {
396     assert(_Math_DD_D_Type != nullptr, "should be initialized");
397     return _Math_DD_D_Type;
398   }
399 
400   static const TypeFunc* Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type);
401 
402   static inline const TypeFunc* modf_Type() {
403     assert(_modf_Type != nullptr, "should be initialized");
404     return _modf_Type;
405   }
406 
407   static inline const TypeFunc* l2f_Type() {
408     assert(_l2f_Type != nullptr, "should be initialized");
409     return _l2f_Type;
410   }
411 
412   static inline const TypeFunc* void_long_Type() {
413     assert(_void_long_Type != nullptr, "should be initialized");
414     return _void_long_Type;
415   }
416 
417   static inline const TypeFunc* void_void_Type() {
418     assert(_void_void_Type != nullptr, "should be initialized");
419     return _void_void_Type;
420   }
421 
422   static const TypeFunc* jfr_write_checkpoint_Type() {
423     assert(_jfr_write_checkpoint_Type != nullptr, "should be initialized");
424     return _jfr_write_checkpoint_Type;
425   }
426 
427   static const TypeFunc* flush_windows_Type() {
428     assert(_flush_windows_Type != nullptr, "should be initialized");
429     return _flush_windows_Type;
430   }
431 
432   // arraycopy routine types
433   static inline const TypeFunc* fast_arraycopy_Type() {
434     assert(_fast_arraycopy_Type != nullptr, "should be initialized");
435     // This signature is simple:  Two base pointers and a size_t.
436     return _fast_arraycopy_Type;
437   }
438 
439   static inline const TypeFunc* checkcast_arraycopy_Type() {
440     assert(_checkcast_arraycopy_Type != nullptr, "should be initialized");
441     // An extension of fast_arraycopy_Type which adds type checking.
442     return _checkcast_arraycopy_Type;
443   }
444 
445   static inline const TypeFunc* generic_arraycopy_Type() {
446     assert(_generic_arraycopy_Type != nullptr, "should be initialized");
447     // This signature is like System.arraycopy, except that it returns status.
448     return _generic_arraycopy_Type;
449   }
450 
451   static inline const TypeFunc* slow_arraycopy_Type() {
452     assert(_slow_arraycopy_Type != nullptr, "should be initialized");
453     // This signature is exactly the same as System.arraycopy.
454     // There are no intptr_t (int/long) arguments.
455     return _slow_arraycopy_Type;
456   }   // the full routine
457 
458   static inline const TypeFunc* unsafe_setmemory_Type() {
459     assert(_unsafe_setmemory_Type != nullptr, "should be initialized");
460     return _unsafe_setmemory_Type;
461   }
462 
463 //  static const TypeFunc* digestBase_implCompress_Type(bool is_sha3);
464 //  static const TypeFunc* digestBase_implCompressMB_Type(bool is_sha3);
465 //  static const TypeFunc* double_keccak_Type();
466 
467   static inline const TypeFunc* array_fill_Type() {
468     assert(_array_fill_Type != nullptr, "should be initialized");
469     return _array_fill_Type;
470   }
471 
472   static inline const TypeFunc* array_sort_Type() {
473     assert(_array_sort_Type != nullptr, "should be initialized");
474     return _array_sort_Type;
475   }
476 
477   static inline const TypeFunc* array_partition_Type() {
478     assert(_array_partition_Type != nullptr, "should be initialized");
479     return _array_partition_Type;
480   }
481 
482   // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant)
483   static inline const TypeFunc* aescrypt_block_Type() {
484     assert(_aescrypt_block_Type != nullptr, "should be initialized");
485     return _aescrypt_block_Type;
486   }
487 
488   // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
489   static inline const TypeFunc* cipherBlockChaining_aescrypt_Type() {
490     assert(_cipherBlockChaining_aescrypt_Type != nullptr, "should be initialized");
491     return _cipherBlockChaining_aescrypt_Type;
492   }
493 
494   // for electronicCodeBook calls of aescrypt encrypt/decrypt, three pointers and a length, returning int
495   static inline const TypeFunc* electronicCodeBook_aescrypt_Type() {
496     assert(_electronicCodeBook_aescrypt_Type != nullptr, "should be initialized");
497     return _electronicCodeBook_aescrypt_Type;
498   }
499 
500   //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
501   static inline const TypeFunc* counterMode_aescrypt_Type() {
502     assert(_counterMode_aescrypt_Type != nullptr, "should be initialized");
503     return _counterMode_aescrypt_Type;
504   }
505 
506   //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
507   static inline const TypeFunc* galoisCounterMode_aescrypt_Type() {
508     assert(_galoisCounterMode_aescrypt_Type != nullptr, "should be initialized");
509     return _galoisCounterMode_aescrypt_Type;
510   }
511 
512   /*
513    * void implCompress(byte[] buf, int ofs)
514    */
515   static inline const TypeFunc* digestBase_implCompress_Type(bool is_sha3) {
516     assert((_digestBase_implCompress_with_sha3_Type != nullptr) &&
517            (_digestBase_implCompress_without_sha3_Type != nullptr), "should be initialized");
518     return is_sha3 ? _digestBase_implCompress_with_sha3_Type : _digestBase_implCompress_without_sha3_Type;
519   }
520 
521   /*
522    * int implCompressMultiBlock(byte[] b, int ofs, int limit)
523    */
524   static inline const TypeFunc* digestBase_implCompressMB_Type(bool is_sha3) {
525     assert((_digestBase_implCompressMB_with_sha3_Type != nullptr) &&
526            (_digestBase_implCompressMB_without_sha3_Type != nullptr), "should be initialized");
527     return is_sha3 ? _digestBase_implCompressMB_with_sha3_Type : _digestBase_implCompressMB_without_sha3_Type;
528   }
529 
530   static inline const TypeFunc* double_keccak_Type() {
531     assert(_double_keccak_Type != nullptr, "should be initialized");
532     return _double_keccak_Type;
533   }
534 
535   static inline const TypeFunc* multiplyToLen_Type() {
536     assert(_multiplyToLen_Type != nullptr, "should be initialized");
537     return _multiplyToLen_Type;
538   }
539 
540   static inline const TypeFunc* montgomeryMultiply_Type() {
541     assert(_montgomeryMultiply_Type != nullptr, "should be initialized");
542     return _montgomeryMultiply_Type;
543   }
544 
545   static inline const TypeFunc* montgomerySquare_Type() {
546     assert(_montgomerySquare_Type != nullptr, "should be initialized");
547     return _montgomerySquare_Type;
548   }
549 
550   static inline const TypeFunc* squareToLen_Type() {
551     assert(_squareToLen_Type != nullptr, "should be initialized");
552     return _squareToLen_Type;
553   }
554 
555   // for mulAdd calls, 2 pointers and 3 ints, returning int
556   static inline const TypeFunc* mulAdd_Type() {
557     assert(_mulAdd_Type != nullptr, "should be initialized");
558     return _mulAdd_Type;
559   }
560 
561   static inline const TypeFunc* bigIntegerShift_Type() {
562     assert(_bigIntegerShift_Type != nullptr, "should be initialized");
563     return _bigIntegerShift_Type;
564   }
565 
566   static inline const TypeFunc* vectorizedMismatch_Type() {
567     assert(_vectorizedMismatch_Type != nullptr, "should be initialized");
568     return _vectorizedMismatch_Type;
569   }
570 
571   // GHASH block processing
572   static inline const TypeFunc* ghash_processBlocks_Type() {
573     assert(_ghash_processBlocks_Type != nullptr, "should be initialized");
574     return _ghash_processBlocks_Type;
575   }
576 
577   // ChaCha20 Block function
578   static inline const TypeFunc* chacha20Block_Type() {
579     assert(_chacha20Block_Type != nullptr, "should be initialized");
580     return _chacha20Block_Type;
581   }
582 
583   static inline const TypeFunc* kyberNtt_Type() {
584     assert(_kyberNtt_Type != nullptr, "should be initialized");
585     return _kyberNtt_Type;
586   }
587 
588   static inline const TypeFunc* kyberInverseNtt_Type() {
589     assert(_kyberInverseNtt_Type != nullptr, "should be initialized");
590     return _kyberInverseNtt_Type;
591   }
592 
593   static inline const TypeFunc* kyberNttMult_Type() {
594     assert(_kyberNttMult_Type != nullptr, "should be initialized");
595     return _kyberNttMult_Type;
596   }
597 
598   static inline const TypeFunc* kyberAddPoly_2_Type() {
599     assert(_kyberAddPoly_2_Type != nullptr, "should be initialized");
600     return _kyberAddPoly_2_Type;
601   }
602 
603   static inline const TypeFunc* kyberAddPoly_3_Type() {
604     assert(_kyberAddPoly_3_Type != nullptr, "should be initialized");
605     return _kyberAddPoly_3_Type;
606   }
607 
608   static inline const TypeFunc* kyber12To16_Type() {
609     assert(_kyber12To16_Type != nullptr, "should be initialized");
610     return _kyber12To16_Type;
611   }
612 
613   static inline const TypeFunc* kyberBarrettReduce_Type() {
614     assert(_kyberBarrettReduce_Type != nullptr, "should be initialized");
615     return _kyberBarrettReduce_Type;
616   }
617 
618   static inline const TypeFunc* dilithiumAlmostNtt_Type() {
619     assert(_dilithiumAlmostNtt_Type != nullptr, "should be initialized");
620     return _dilithiumAlmostNtt_Type;
621   }
622 
623   static inline const TypeFunc* dilithiumAlmostInverseNtt_Type() {
624     assert(_dilithiumAlmostInverseNtt_Type != nullptr, "should be initialized");
625     return _dilithiumAlmostInverseNtt_Type;
626   }
627 
628   static inline const TypeFunc* dilithiumNttMult_Type() {
629     assert(_dilithiumNttMult_Type != nullptr, "should be initialized");
630     return _dilithiumNttMult_Type;
631   }
632 
633   static inline const TypeFunc* dilithiumMontMulByConstant_Type() {
634     assert(_dilithiumMontMulByConstant_Type != nullptr, "should be initialized");
635     return _dilithiumMontMulByConstant_Type;
636   }
637 
638   static inline const TypeFunc* dilithiumDecomposePoly_Type() {
639     assert(_dilithiumDecomposePoly_Type != nullptr, "should be initialized");
640     return _dilithiumDecomposePoly_Type;
641   }
642 
643   // Base64 encode function
644   static inline const TypeFunc* base64_encodeBlock_Type() {
645     assert(_base64_encodeBlock_Type != nullptr, "should be initialized");
646     return _base64_encodeBlock_Type;
647   }
648 
649   // Base64 decode function
650   static inline const TypeFunc* base64_decodeBlock_Type() {
651     assert(_base64_decodeBlock_Type != nullptr, "should be initialized");
652     return _base64_decodeBlock_Type;
653   }
654 
655   // String IndexOf function
656   static inline const TypeFunc* string_IndexOf_Type() {
657     assert(_string_IndexOf_Type != nullptr, "should be initialized");
658     return _string_IndexOf_Type;
659   }
660 
661   // Poly1305 processMultipleBlocks function
662   static inline const TypeFunc* poly1305_processBlocks_Type() {
663     assert(_poly1305_processBlocks_Type != nullptr, "should be initialized");
664     return _poly1305_processBlocks_Type;
665   }
666 
667   // MontgomeryIntegerPolynomialP256 multiply function
668   static inline const TypeFunc* intpoly_montgomeryMult_P256_Type() {
669     assert(_intpoly_montgomeryMult_P256_Type != nullptr, "should be initialized");
670     return _intpoly_montgomeryMult_P256_Type;
671   }
672 
673   // IntegerPolynomial constant time assignment function
674   static inline const TypeFunc* intpoly_assign_Type() {
675     assert(_intpoly_assign_Type != nullptr, "should be initialized");
676     return _intpoly_assign_Type;
677   }
678 
679   /**
680    * int updateBytesCRC32(int crc, byte* b, int len)
681    */
682   static inline const TypeFunc* updateBytesCRC32_Type() {
683     assert(_updateBytesCRC32_Type != nullptr, "should be initialized");
684     return _updateBytesCRC32_Type;
685   }
686 
687   /**
688    * int updateBytesCRC32C(int crc, byte* buf, int len, int* table)
689    */
690   static inline const TypeFunc* updateBytesCRC32C_Type() {
691     assert(_updateBytesCRC32C_Type != nullptr, "should be initialized");
692     return _updateBytesCRC32C_Type;
693   }
694 
695   /**
696    *  int updateBytesAdler32(int adler, bytes* b, int off, int len)
697    */
698   static inline const TypeFunc* updateBytesAdler32_Type() {
699     assert(_updateBytesAdler32_Type != nullptr, "should be initialized");
700     return _updateBytesAdler32_Type;
701   }
702 
703 
704   // leaf on stack replacement interpreter accessor types
705   static inline const TypeFunc* osr_end_Type() {
706     assert(_osr_end_Type != nullptr, "should be initialized");
707     return _osr_end_Type;
708   }
709 
710   static inline const TypeFunc* register_finalizer_Type() {
711     assert(_register_finalizer_Type != nullptr, "should be initialized");
712     return _register_finalizer_Type;
713   }
714 
715 #if INCLUDE_JFR
716   static inline const TypeFunc* class_id_load_barrier_Type() {
717     assert(_class_id_load_barrier_Type != nullptr, "should be initialized");
718     return _class_id_load_barrier_Type;
719   }
720 #endif // INCLUDE_JFR
721 
722 #if INCLUDE_JVMTI
723   static inline const TypeFunc* notify_jvmti_vthread_Type() {
724     assert(_notify_jvmti_vthread_Type != nullptr, "should be initialized");
725     return _notify_jvmti_vthread_Type;
726   }
727 #endif
728 
729   // Dtrace support. entry and exit probes have the same signature
730   static inline const TypeFunc* dtrace_method_entry_exit_Type() {
731     assert(_dtrace_method_entry_exit_Type != nullptr, "should be initialized");
732     return _dtrace_method_entry_exit_Type;
733   }
734 
735   static inline const TypeFunc* dtrace_object_alloc_Type() {
736     assert(_dtrace_object_alloc_Type != nullptr, "should be initialized");
737     return _dtrace_object_alloc_Type;
738   }
739 
740  private:
741  static NamedCounter * volatile _named_counters;
742 
743  public:
744  // helper function which creates a named counter labeled with the
745  // if they are available
746  static NamedCounter* new_named_counter(JVMState* jvms, NamedCounter::CounterTag tag);
747 
748  // dumps all the named counters
749  static void          print_named_counters();
750 
751  static void          initialize_types();
752 };
753 
754 #endif // SHARE_OPTO_RUNTIME_HPP