1 /*
  2  * Copyright (c) 2011, 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 #ifndef SHARE_JVMCI_JVMCICOMPILERTOVM_HPP
 25 #define SHARE_JVMCI_JVMCICOMPILERTOVM_HPP
 26 
 27 #include "gc/shared/barrierSetAssembler.hpp"
 28 #include "gc/shared/cardTable.hpp"
 29 #include "jvmci/jvmciExceptions.hpp"
 30 #include "runtime/javaCalls.hpp"
 31 #include "runtime/signature.hpp"
 32 
 33 class CollectedHeap;
 34 class JVMCIObjectArray;
 35 
 36 class CompilerToVM {
 37  public:
 38   class Data {
 39     friend class JVMCIVMStructs;
 40 
 41    private:
 42     static int oopDesc_klass_offset_in_bytes;
 43     static int arrayOopDesc_length_offset_in_bytes;
 44 
 45     static int Klass_vtable_start_offset;
 46     static int Klass_vtable_length_offset;
 47 
 48     static int Method_extra_stack_entries;
 49 
 50     static address SharedRuntime_ic_miss_stub;
 51     static address SharedRuntime_handle_wrong_method_stub;
 52     static address SharedRuntime_deopt_blob_unpack;
 53     static address SharedRuntime_deopt_blob_unpack_with_exception_in_tls;
 54     static address SharedRuntime_deopt_blob_uncommon_trap;
 55     static address SharedRuntime_polling_page_return_handler;
 56     static address SharedRuntime_throw_delayed_StackOverflowError_entry;
 57 
 58     static address nmethod_entry_barrier;
 59     static int thread_disarmed_guard_value_offset;
 60     static int thread_address_bad_mask_offset;
 61 #ifdef AARCH64
 62     static int BarrierSetAssembler_nmethod_patching_type;
 63     static address BarrierSetAssembler_patching_epoch_addr;
 64 #endif
 65 
 66     static address ZBarrierSetRuntime_load_barrier_on_oop_field_preloaded;
 67     static address ZBarrierSetRuntime_load_barrier_on_weak_oop_field_preloaded;
 68     static address ZBarrierSetRuntime_load_barrier_on_phantom_oop_field_preloaded;
 69     static address ZBarrierSetRuntime_weak_load_barrier_on_oop_field_preloaded;
 70     static address ZBarrierSetRuntime_weak_load_barrier_on_weak_oop_field_preloaded;
 71     static address ZBarrierSetRuntime_weak_load_barrier_on_phantom_oop_field_preloaded;
 72     static address ZBarrierSetRuntime_load_barrier_on_oop_array;
 73     static address ZBarrierSetRuntime_clone;
 74 
 75     static address ZPointerVectorLoadBadMask_address;
 76     static address ZPointerVectorStoreBadMask_address;
 77     static address ZPointerVectorStoreGoodMask_address;
 78 
 79     static bool continuations_enabled;
 80 
 81     static size_t ThreadLocalAllocBuffer_alignment_reserve;
 82 
 83     static CollectedHeap* Universe_collectedHeap;
 84     static int Universe_base_vtable_size;
 85     static address Universe_narrow_oop_base;
 86     static int Universe_narrow_oop_shift;
 87     static address Universe_narrow_klass_base;
 88     static int Universe_narrow_klass_shift;
 89     static uintptr_t Universe_verify_oop_mask;
 90     static uintptr_t Universe_verify_oop_bits;
 91     static void* Universe_non_oop_bits;
 92 
 93     static bool _supports_inline_contig_alloc;
 94     static HeapWord** _heap_end_addr;
 95     static HeapWord* volatile* _heap_top_addr;
 96     static int _max_oop_map_stack_offset;
 97     static int _fields_annotations_base_offset;
 98 
 99     static CardTable::CardValue* cardtable_start_address;
100     static int cardtable_shift;
101 
102     static size_t vm_page_size;
103 
104     static int sizeof_vtableEntry;
105     static int sizeof_ExceptionTableElement;
106     static int sizeof_LocalVariableTableElement;
107     static int sizeof_ConstantPool;
108     static int sizeof_narrowKlass;
109     static int sizeof_arrayOopDesc;
110     static int sizeof_BasicLock;
111 #if INCLUDE_ZGC
112     static int sizeof_ZStoreBarrierEntry;
113 #endif
114 #if INCLUDE_SHENANDOAHGC
115     static address shenandoah_in_cset_fast_test_addr;
116     static int shenandoah_region_size_bytes_shift;
117 #endif
118 
119 #ifdef X86
120     static int L1_line_size;
121     static bool supports_avx512_simd_sort;
122 #endif
123 
124     static address dsin;
125     static address dcos;
126     static address dtan;
127     static address dtanh;
128     static address dcbrt;
129     static address dexp;
130     static address dlog;
131     static address dlog10;
132     static address dpow;
133 
134     static address symbol_init;
135     static address symbol_clinit;
136 
137     // Minimum alignment of an offset into CodeBuffer::SECT_CONSTS
138     static int data_section_item_alignment;
139 
140 #if INCLUDE_JVMTI
141     /*
142      * Pointer to JvmtiExport::_should_notify_object_alloc.
143      * Exposed as an int* instead of an address so the
144      * underlying type is part of the JVMCIVMStructs definition.
145      */
146     static int* _should_notify_object_alloc;
147 #endif
148 
149    public:
150      static void initialize(JVMCI_TRAPS);
151 
152     static int max_oop_map_stack_offset() {
153       assert(_max_oop_map_stack_offset > 0, "must be initialized");
154       return Data::_max_oop_map_stack_offset;
155     }
156 
157     static int get_data_section_item_alignment() {
158       return data_section_item_alignment;
159     }
160   };
161 
162   static bool cstring_equals(const char* const& s0, const char* const& s1) {
163     return strcmp(s0, s1) == 0;
164   }
165 
166   static unsigned cstring_hash(const char* const& s) {
167     unsigned h = 0;
168     const char* p = s;
169     while (*p != '\0') {
170       h = 31 * h + *p;
171       p++;
172     }
173     return h;
174   }
175 
176   static JNINativeMethod methods[];
177   static JNINativeMethod jni_methods[];
178 
179   static JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS);
180  public:
181   static int methods_count();
182 
183 };
184 #endif // SHARE_JVMCI_JVMCICOMPILERTOVM_HPP