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