1 /*
  2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2024, Red Hat, Inc. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_RUNTIME_STUBDECLARATIONS_HPP
 27 #define SHARE_RUNTIME_STUBDECLARATIONS_HPP
 28 
 29 #include "utilities/macros.hpp"
 30 
 31 // macros for generating definitions and declarations for shared, c1
 32 // and opto blob fields and associated stub ids
 33 
 34 // Different shared stubs can have different blob types and may
 35 // include some JFR stubs
 36 //
 37 // n.b resolve, handler and throw stubs must remain grouped in the
 38 // same order to allow id values to be range checked
 39 
 40 #if INCLUDE_JFR
 41 // do_blob(name, type)
 42 #define SHARED_JFR_STUBS_DO(do_blob)                                   \
 43   do_blob(jfr_write_checkpoint, RuntimeStub*)                          \
 44   do_blob(jfr_return_lease, RuntimeStub*)                              \
 45 
 46 #else
 47 #define SHARED_JFR_STUBS_DO(do_blob)
 48 #endif
 49 
 50 // do_blob(name, type)
 51 #define SHARED_STUBS_DO(do_blob)                                       \
 52   do_blob(deopt, DeoptimizationBlob*)                                  \
 53   /* resolve stubs */                                                  \
 54   do_blob(wrong_method, RuntimeStub*)                                  \
 55   do_blob(wrong_method_abstract, RuntimeStub*)                         \
 56   do_blob(ic_miss, RuntimeStub*)                                       \
 57   do_blob(resolve_opt_virtual_call, RuntimeStub*)                      \
 58   do_blob(resolve_virtual_call, RuntimeStub*)                          \
 59   do_blob(resolve_static_call, RuntimeStub*)                           \
 60   /* handler stubs */                                                  \
 61   do_blob(polling_page_vectors_safepoint_handler, SafepointBlob*)      \
 62   do_blob(polling_page_safepoint_handler, SafepointBlob*)              \
 63   do_blob(polling_page_return_handler, SafepointBlob*)                 \
 64   /* throw stubs */                                                    \
 65   do_blob(throw_AbstractMethodError, RuntimeStub*)                     \
 66   do_blob(throw_IncompatibleClassChangeError, RuntimeStub*)            \
 67   do_blob(throw_NullPointerException_at_call, RuntimeStub*)            \
 68   do_blob(throw_StackOverflowError, RuntimeStub*)                      \
 69   do_blob(throw_delayed_StackOverflowError, RuntimeStub*)              \
 70   /* other stubs */                                                    \
 71   SHARED_JFR_STUBS_DO(do_blob)                                         \
 72 
 73 // C1 stubs are always generated in a generic CodeBlob
 74 
 75 #ifdef COMPILER1
 76 // do_blob(name)
 77 #define C1_STUBS_DO(do_blob)                                           \
 78   do_blob(dtrace_object_alloc)                                         \
 79   do_blob(unwind_exception)                                            \
 80   do_blob(forward_exception)                                           \
 81   do_blob(throw_range_check_failed)       /* throws ArrayIndexOutOfBoundsException */ \
 82   do_blob(throw_index_exception)          /* throws IndexOutOfBoundsException */ \
 83   do_blob(throw_div0_exception)                                        \
 84   do_blob(throw_null_pointer_exception)                                \
 85   do_blob(register_finalizer)                                          \
 86   do_blob(new_instance)                                                \
 87   do_blob(fast_new_instance)                                           \
 88   do_blob(fast_new_instance_init_check)                                \
 89   do_blob(new_type_array)                                              \
 90   do_blob(new_object_array)                                            \
 91   do_blob(new_multi_array)                                             \
 92   do_blob(handle_exception_nofpu)         /* optimized version that does not preserve fpu registers */ \
 93   do_blob(handle_exception)                                            \
 94   do_blob(handle_exception_from_callee)                                \
 95   do_blob(throw_array_store_exception)                                 \
 96   do_blob(throw_class_cast_exception)                                  \
 97   do_blob(throw_incompatible_class_change_error)                       \
 98   do_blob(slow_subtype_check)                                          \
 99   do_blob(monitorenter)                                                \
100   do_blob(monitorenter_nofpu)             /* optimized version that does not preserve fpu registers */ \
101   do_blob(monitorexit)                                                 \
102   do_blob(monitorexit_nofpu)              /* optimized version that does not preserve fpu registers */ \
103   do_blob(deoptimize)                                                  \
104   do_blob(access_field_patching)                                       \
105   do_blob(load_klass_patching)                                         \
106   do_blob(load_mirror_patching)                                        \
107   do_blob(load_appendix_patching)                                      \
108   do_blob(fpu2long_stub)                                               \
109   do_blob(counter_overflow)                                            \
110   do_blob(predicate_failed_trap)                                       \
111 
112 #else
113 #define C1_STUBS_DO(do_blob)
114 #endif
115 
116 // Opto stubs can be stored as entries with just an address or as
117 // blobs of different types. The former may include some JVMTI stubs.
118 //
119 // n.b. blobs and stub defines are generated in the order defined by
120 // C2_STUBS_DO, allowing dependencies from any givem stub on its
121 // predecessors to be guaranteed. That explains the initial placement
122 // of the blob declarations and intermediate placement of the jvmti
123 // stubs.
124 
125 #ifdef COMPILER2
126 // do_jvmti_stub(name)
127 #if INCLUDE_JVMTI
128 #define C2_JVMTI_STUBS_DO(do_jvmti_stub)                               \
129   do_jvmti_stub(notify_jvmti_vthread_start)                            \
130   do_jvmti_stub(notify_jvmti_vthread_end)                              \
131   do_jvmti_stub(notify_jvmti_vthread_mount)                            \
132   do_jvmti_stub(notify_jvmti_vthread_unmount)                          \
133 
134 #else
135 #define C2_JVMTI_STUBS_DO(do_jvmti_stub)
136 #endif // INCLUDE_JVMTI
137 
138 // do_blob(name, type)
139 // do_stub(name, fancy_jump, pass_tls, return_pc)
140 // do_jvmti_stub(name)
141 //
142 // n.b. non-jvmti stubs may employ a special type of jump (0, 1 or 2)
143 // and require access to TLS and the return pc. jvmti stubs always
144 // employ jump 0, and require no special access
145 #define C2_STUBS_DO(do_blob, do_stub, do_jvmti_stub)                   \
146   do_blob(uncommon_trap, UncommonTrapBlob*)                            \
147   do_blob(exception, ExceptionBlob*)                                   \
148   do_stub(new_instance, 0, true, false)                                \
149   do_stub(new_array, 0, true, false)                                   \
150   do_stub(new_array_nozero, 0, true, false)                            \
151   do_stub(multianewarray2, 0, true, false)                             \
152   do_stub(multianewarray3, 0, true, false)                             \
153   do_stub(multianewarray4, 0, true, false)                             \
154   do_stub(multianewarray5, 0, true, false)                             \
155   do_stub(multianewarrayN, 0, true, false)                             \
156   C2_JVMTI_STUBS_DO(do_jvmti_stub)                                     \
157   do_stub(complete_monitor_locking, 0, false, false)                   \
158   do_stub(monitor_notify, 0, false, false)                             \
159   do_stub(monitor_notifyAll, 0, false, false)                          \
160   do_stub(rethrow, 2, true, true)                                      \
161   do_stub(slow_arraycopy, 0, false, false)                             \
162   do_stub(register_finalizer, 0, false, false)                         \
163 
164 #else
165 #define C2_STUBS_DO(do_blob, do_stub, do_jvmti_stub)
166 #endif
167 
168 // generate a stub or blob id enum tag from a name
169 
170 #define STUB_ID_NAME(base) base##_id
171 
172 // generate a stub field name
173 
174 #define STUB_FIELD_NAME(base) _##base
175 
176 // generate a blob field name
177 
178 #define BLOB_FIELD_NAME(base) _##base##_blob
179 
180 #endif // SHARE_RUNTIME_STUBDECLARATIONS_HPP
181