1 /* 2 * Copyright (c) 2011, 2021, 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/cardTable.hpp" 28 #include "jvmci/jvmciExceptions.hpp" 29 #include "runtime/javaCalls.hpp" 30 #include "runtime/signature.hpp" 31 32 class CollectedHeap; 33 class JVMCIObjectArray; 34 35 class CompilerToVM { 36 public: 37 class Data { 38 friend class JVMCIVMStructs; 39 40 private: 41 static int Klass_vtable_start_offset; 42 static int Klass_vtable_length_offset; 43 44 static int Method_extra_stack_entries; 45 46 static address SharedRuntime_ic_miss_stub; 47 static address SharedRuntime_handle_wrong_method_stub; 48 static address SharedRuntime_deopt_blob_unpack; 49 static address SharedRuntime_deopt_blob_unpack_with_exception_in_tls; 50 static address SharedRuntime_deopt_blob_uncommon_trap; 51 52 static size_t ThreadLocalAllocBuffer_alignment_reserve; 53 54 static CollectedHeap* Universe_collectedHeap; 55 static int Universe_base_vtable_size; 56 static address Universe_narrow_oop_base; 57 static int Universe_narrow_oop_shift; 58 static address Universe_narrow_klass_base; 59 static int Universe_narrow_klass_shift; 60 static uintptr_t Universe_verify_oop_mask; 61 static uintptr_t Universe_verify_oop_bits; 62 static void* Universe_non_oop_bits; 63 64 static bool _supports_inline_contig_alloc; 65 static HeapWord** _heap_end_addr; 66 static HeapWord* volatile* _heap_top_addr; 67 static int _max_oop_map_stack_offset; 68 static int _fields_annotations_base_offset; 69 70 static CardTable::CardValue* cardtable_start_address; 71 static int cardtable_shift; 72 73 static int vm_page_size; 74 75 static int sizeof_vtableEntry; 76 static int sizeof_ExceptionTableElement; 77 static int sizeof_LocalVariableTableElement; 78 static int sizeof_ConstantPool; 79 static int sizeof_narrowKlass; 80 static int sizeof_arrayOopDesc; 81 static int sizeof_BasicLock; 82 83 static address dsin; 84 static address dcos; 85 static address dtan; 86 static address dexp; 87 static address dlog; 88 static address dlog10; 89 static address dpow; 90 91 static address symbol_init; 92 static address symbol_clinit; 93 94 // Minimum alignment of an offset into CodeBuffer::SECT_CONSTS 95 static int data_section_item_alignment; 96 97 public: 98 static void initialize(JVMCI_TRAPS); 99 100 static int max_oop_map_stack_offset() { 101 assert(_max_oop_map_stack_offset > 0, "must be initialized"); 102 return Data::_max_oop_map_stack_offset; 103 } 104 105 static int get_data_section_item_alignment() { 106 return data_section_item_alignment; 107 } 108 }; 109 110 static bool cstring_equals(const char* const& s0, const char* const& s1) { 111 return strcmp(s0, s1) == 0; 112 } 113 114 static unsigned cstring_hash(const char* const& s) { 115 int h = 0; 116 const char* p = s; 117 while (*p != '\0') { 118 h = 31 * h + *p; 119 p++; 120 } 121 return h; 122 } 123 124 static JNINativeMethod methods[]; 125 static JNINativeMethod jni_methods[]; 126 127 static JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS); 128 public: 129 static int methods_count(); 130 131 }; 132 133 134 class JavaArgumentUnboxer : public SignatureIterator { 135 protected: 136 JavaCallArguments* _jca; 137 arrayOop _args; 138 int _index; 139 140 Handle next_arg(BasicType expectedType); 141 142 public: 143 JavaArgumentUnboxer(Symbol* signature, 144 JavaCallArguments* jca, 145 arrayOop args, 146 bool is_static) 147 : SignatureIterator(signature) 148 { 149 this->_return_type = T_ILLEGAL; 150 _jca = jca; 151 _index = 0; 152 _args = args; 153 if (!is_static) { 154 _jca->push_oop(next_arg(T_OBJECT)); 155 } 156 do_parameters_on(this); 157 assert(_index == args->length(), "arg count mismatch with signature"); 158 } 159 160 private: 161 friend class SignatureIterator; // so do_parameters_on can call do_type 162 void do_type(BasicType type) { 163 if (is_reference_type(type)) { 164 (type == T_PRIMITIVE_OBJECT) ? _jca->push_oop(next_arg(T_PRIMITIVE_OBJECT)) : _jca->push_oop(next_arg(T_OBJECT)); 165 return; 166 } 167 Handle arg = next_arg(type); 168 int box_offset = java_lang_boxing_object::value_offset(type); 169 switch (type) { 170 case T_BOOLEAN: _jca->push_int(arg->bool_field(box_offset)); break; 171 case T_CHAR: _jca->push_int(arg->char_field(box_offset)); break; 172 case T_SHORT: _jca->push_int(arg->short_field(box_offset)); break; 173 case T_BYTE: _jca->push_int(arg->byte_field(box_offset)); break; 174 case T_INT: _jca->push_int(arg->int_field(box_offset)); break; 175 case T_LONG: _jca->push_long(arg->long_field(box_offset)); break; 176 case T_FLOAT: _jca->push_float(arg->float_field(box_offset)); break; 177 case T_DOUBLE: _jca->push_double(arg->double_field(box_offset)); break; 178 default: ShouldNotReachHere(); 179 } 180 } 181 }; 182 183 #endif // SHARE_JVMCI_JVMCICOMPILERTOVM_HPP