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 
 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     // Minimum alignment of an offset into CodeBuffer::SECT_CONSTS
 94     static int data_section_item_alignment;
 95 
 96    public:
 97      static void initialize(JVMCI_TRAPS);
 98 
 99     static int max_oop_map_stack_offset() {
100       assert(_max_oop_map_stack_offset > 0, "must be initialized");
101       return Data::_max_oop_map_stack_offset;
102     }
103 
104     static int get_data_section_item_alignment() {
105       return data_section_item_alignment;
106     }
107   };
108 
109   static bool cstring_equals(const char* const& s0, const char* const& s1) {
110     return strcmp(s0, s1) == 0;
111   }
112 
113   static unsigned cstring_hash(const char* const& s) {
114     int h = 0;
115     const char* p = s;
116     while (*p != '\0') {
117       h = 31 * h + *p;
118       p++;
119     }
120     return h;
121   }
122 
123   static JNINativeMethod methods[];
124   static JNINativeMethod jni_methods[];
125 
126   static JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS);
127  public:
128   static int methods_count();
129 
130 };
131 
132 
133 class JavaArgumentUnboxer : public SignatureIterator {
134  protected:
135   JavaCallArguments*  _jca;
136   arrayOop _args;
137   int _index;
138 
139   Handle next_arg(BasicType expectedType);
140 
141  public:
142   JavaArgumentUnboxer(Symbol* signature,
143                       JavaCallArguments* jca,
144                       arrayOop args,
145                       bool is_static)
146     : SignatureIterator(signature)
147   {
148     this->_return_type = T_ILLEGAL;
149     _jca = jca;
150     _index = 0;
151     _args = args;
152     if (!is_static) {
153       _jca->push_oop(next_arg(T_OBJECT));
154     }
155     do_parameters_on(this);
156     assert(_index == args->length(), "arg count mismatch with signature");
157   }
158 
159  private:
160   friend class SignatureIterator;  // so do_parameters_on can call do_type
161   void do_type(BasicType type) {
162     if (is_reference_type(type)) {
163       _jca->push_oop(next_arg(T_OBJECT));
164       return;
165     }
166     Handle arg = next_arg(type);
167     int box_offset = java_lang_boxing_object::value_offset(type);
168     switch (type) {
169     case T_BOOLEAN:     _jca->push_int(arg->bool_field(box_offset));    break;
170     case T_CHAR:        _jca->push_int(arg->char_field(box_offset));    break;
171     case T_SHORT:       _jca->push_int(arg->short_field(box_offset));   break;
172     case T_BYTE:        _jca->push_int(arg->byte_field(box_offset));    break;
173     case T_INT:         _jca->push_int(arg->int_field(box_offset));     break;
174     case T_LONG:        _jca->push_long(arg->long_field(box_offset));   break;
175     case T_FLOAT:       _jca->push_float(arg->float_field(box_offset));    break;
176     case T_DOUBLE:      _jca->push_double(arg->double_field(box_offset));  break;
177     default:            ShouldNotReachHere();
178     }
179   }
180 };
181 
182 #endif // SHARE_JVMCI_JVMCICOMPILERTOVM_HPP