Wed, 11 Aug 2010 05:51:21 -0700
6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>
twisti@2047 | 1 | /* |
twisti@2047 | 2 | * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. |
twisti@2047 | 3 | * Copyright 2008, 2009, 2010 Red Hat, Inc. |
twisti@2047 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
twisti@2047 | 5 | * |
twisti@2047 | 6 | * This code is free software; you can redistribute it and/or modify it |
twisti@2047 | 7 | * under the terms of the GNU General Public License version 2 only, as |
twisti@2047 | 8 | * published by the Free Software Foundation. |
twisti@2047 | 9 | * |
twisti@2047 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
twisti@2047 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
twisti@2047 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
twisti@2047 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
twisti@2047 | 14 | * accompanied this code). |
twisti@2047 | 15 | * |
twisti@2047 | 16 | * You should have received a copy of the GNU General Public License version |
twisti@2047 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
twisti@2047 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
twisti@2047 | 19 | * |
twisti@2047 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
twisti@2047 | 21 | * or visit www.oracle.com if you need additional information or have any |
twisti@2047 | 22 | * questions. |
twisti@2047 | 23 | * |
twisti@2047 | 24 | */ |
twisti@2047 | 25 | |
twisti@2047 | 26 | class SharkBuilder : public llvm::IRBuilder<> { |
twisti@2047 | 27 | friend class SharkCompileInvariants; |
twisti@2047 | 28 | |
twisti@2047 | 29 | public: |
twisti@2047 | 30 | SharkBuilder(SharkCodeBuffer* code_buffer); |
twisti@2047 | 31 | |
twisti@2047 | 32 | // The code buffer we are building into. |
twisti@2047 | 33 | private: |
twisti@2047 | 34 | SharkCodeBuffer* _code_buffer; |
twisti@2047 | 35 | |
twisti@2047 | 36 | protected: |
twisti@2047 | 37 | SharkCodeBuffer* code_buffer() const { |
twisti@2047 | 38 | return _code_buffer; |
twisti@2047 | 39 | } |
twisti@2047 | 40 | |
twisti@2047 | 41 | // Helpers for accessing structures. |
twisti@2047 | 42 | public: |
twisti@2047 | 43 | llvm::Value* CreateAddressOfStructEntry(llvm::Value* base, |
twisti@2047 | 44 | ByteSize offset, |
twisti@2047 | 45 | const llvm::Type* type, |
twisti@2047 | 46 | const char *name = ""); |
twisti@2047 | 47 | llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base, |
twisti@2047 | 48 | ByteSize offset, |
twisti@2047 | 49 | const llvm::Type* type, |
twisti@2047 | 50 | const char *name = ""); |
twisti@2047 | 51 | |
twisti@2047 | 52 | // Helpers for accessing arrays. |
twisti@2047 | 53 | public: |
twisti@2047 | 54 | llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop); |
twisti@2047 | 55 | llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, |
twisti@2047 | 56 | const llvm::Type* element_type, |
twisti@2047 | 57 | int element_bytes, |
twisti@2047 | 58 | ByteSize base_offset, |
twisti@2047 | 59 | llvm::Value* index, |
twisti@2047 | 60 | const char* name = ""); |
twisti@2047 | 61 | llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, |
twisti@2047 | 62 | BasicType basic_type, |
twisti@2047 | 63 | ByteSize base_offset, |
twisti@2047 | 64 | llvm::Value* index, |
twisti@2047 | 65 | const char* name = ""); |
twisti@2047 | 66 | llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, |
twisti@2047 | 67 | BasicType basic_type, |
twisti@2047 | 68 | llvm::Value* index, |
twisti@2047 | 69 | const char* name = ""); |
twisti@2047 | 70 | |
twisti@2047 | 71 | // Helpers for creating intrinsics and external functions. |
twisti@2047 | 72 | private: |
twisti@2047 | 73 | static const llvm::Type* make_type(char type, bool void_ok); |
twisti@2047 | 74 | static const llvm::FunctionType* make_ftype(const char* params, |
twisti@2047 | 75 | const char* ret); |
twisti@2047 | 76 | llvm::Value* make_function(const char* name, |
twisti@2047 | 77 | const char* params, |
twisti@2047 | 78 | const char* ret); |
twisti@2047 | 79 | llvm::Value* make_function(address func, |
twisti@2047 | 80 | const char* params, |
twisti@2047 | 81 | const char* ret); |
twisti@2047 | 82 | |
twisti@2047 | 83 | // Intrinsics and external functions, part 1: VM calls. |
twisti@2047 | 84 | // These are functions declared with JRT_ENTRY and JRT_EXIT, |
twisti@2047 | 85 | // macros which flip the thread from _thread_in_Java to |
twisti@2047 | 86 | // _thread_in_vm and back. VM calls always safepoint, and can |
twisti@2047 | 87 | // therefore throw exceptions. VM calls require of setup and |
twisti@2047 | 88 | // teardown, and must be called with SharkTopLevelBlock::call_vm. |
twisti@2047 | 89 | public: |
twisti@2047 | 90 | llvm::Value* find_exception_handler(); |
twisti@2047 | 91 | llvm::Value* monitorenter(); |
twisti@2047 | 92 | llvm::Value* monitorexit(); |
twisti@2047 | 93 | llvm::Value* new_instance(); |
twisti@2047 | 94 | llvm::Value* newarray(); |
twisti@2047 | 95 | llvm::Value* anewarray(); |
twisti@2047 | 96 | llvm::Value* multianewarray(); |
twisti@2047 | 97 | llvm::Value* register_finalizer(); |
twisti@2047 | 98 | llvm::Value* safepoint(); |
twisti@2047 | 99 | llvm::Value* throw_ArithmeticException(); |
twisti@2047 | 100 | llvm::Value* throw_ArrayIndexOutOfBoundsException(); |
twisti@2047 | 101 | llvm::Value* throw_ClassCastException(); |
twisti@2047 | 102 | llvm::Value* throw_NullPointerException(); |
twisti@2047 | 103 | |
twisti@2047 | 104 | // Intrinsics and external functions, part 2: High-level non-VM calls. |
twisti@2047 | 105 | // These are called like normal functions. The stack is not set |
twisti@2047 | 106 | // up for walking so they must not safepoint or throw exceptions, |
twisti@2047 | 107 | // or call anything that might. |
twisti@2047 | 108 | public: |
twisti@2047 | 109 | llvm::Value* f2i(); |
twisti@2047 | 110 | llvm::Value* f2l(); |
twisti@2047 | 111 | llvm::Value* d2i(); |
twisti@2047 | 112 | llvm::Value* d2l(); |
twisti@2047 | 113 | llvm::Value* is_subtype_of(); |
twisti@2047 | 114 | llvm::Value* current_time_millis(); |
twisti@2047 | 115 | llvm::Value* sin(); |
twisti@2047 | 116 | llvm::Value* cos(); |
twisti@2047 | 117 | llvm::Value* tan(); |
twisti@2047 | 118 | llvm::Value* atan2(); |
twisti@2047 | 119 | llvm::Value* sqrt(); |
twisti@2047 | 120 | llvm::Value* log(); |
twisti@2047 | 121 | llvm::Value* log10(); |
twisti@2047 | 122 | llvm::Value* pow(); |
twisti@2047 | 123 | llvm::Value* exp(); |
twisti@2047 | 124 | llvm::Value* fabs(); |
twisti@2047 | 125 | llvm::Value* unsafe_field_offset_to_byte_offset(); |
twisti@2047 | 126 | llvm::Value* osr_migration_end(); |
twisti@2047 | 127 | |
twisti@2047 | 128 | // Intrinsics and external functions, part 3: semi-VM calls. |
twisti@2047 | 129 | // These are special cases that do VM call stuff but are invoked |
twisti@2047 | 130 | // as though they were normal calls. This is acceptable so long |
twisti@2047 | 131 | // as the method that calls them returns to its immediately that |
twisti@2047 | 132 | // the semi VM call returns. |
twisti@2047 | 133 | public: |
twisti@2047 | 134 | llvm::Value* throw_StackOverflowError(); |
twisti@2047 | 135 | llvm::Value* uncommon_trap(); |
twisti@2047 | 136 | llvm::Value* deoptimized_entry_point(); |
twisti@2047 | 137 | |
twisti@2047 | 138 | // Intrinsics and external functions, part 4: Native-Java transition. |
twisti@2047 | 139 | // This is a special case in that it is invoked during a thread |
twisti@2047 | 140 | // state transition. The stack must be set up for walking, and it |
twisti@2047 | 141 | // may throw exceptions, but the state is _thread_in_native_trans. |
twisti@2047 | 142 | public: |
twisti@2047 | 143 | llvm::Value* check_special_condition_for_native_trans(); |
twisti@2047 | 144 | |
twisti@2047 | 145 | // Intrinsics and external functions, part 5: Low-level non-VM calls. |
twisti@2047 | 146 | // These have the same caveats as the high-level non-VM calls |
twisti@2047 | 147 | // above. They are not accessed directly; rather, you should |
twisti@2047 | 148 | // access them via the various Create* methods below. |
twisti@2047 | 149 | private: |
twisti@2047 | 150 | llvm::Value* cmpxchg_int(); |
twisti@2047 | 151 | llvm::Value* cmpxchg_ptr(); |
twisti@2047 | 152 | llvm::Value* frame_address(); |
twisti@2047 | 153 | llvm::Value* memory_barrier(); |
twisti@2047 | 154 | llvm::Value* memset(); |
twisti@2047 | 155 | llvm::Value* unimplemented(); |
twisti@2047 | 156 | llvm::Value* should_not_reach_here(); |
twisti@2047 | 157 | llvm::Value* dump(); |
twisti@2047 | 158 | |
twisti@2047 | 159 | // Public interface to low-level non-VM calls. |
twisti@2047 | 160 | public: |
twisti@2047 | 161 | llvm::CallInst* CreateCmpxchgInt(llvm::Value* exchange_value, |
twisti@2047 | 162 | llvm::Value* dst, |
twisti@2047 | 163 | llvm::Value* compare_value); |
twisti@2047 | 164 | llvm::CallInst* CreateCmpxchgPtr(llvm::Value* exchange_value, |
twisti@2047 | 165 | llvm::Value* dst, |
twisti@2047 | 166 | llvm::Value* compare_value); |
twisti@2047 | 167 | llvm::CallInst* CreateGetFrameAddress(); |
twisti@2047 | 168 | llvm::CallInst* CreateMemoryBarrier(int flags); |
twisti@2047 | 169 | llvm::CallInst* CreateMemset(llvm::Value* dst, |
twisti@2047 | 170 | llvm::Value* value, |
twisti@2047 | 171 | llvm::Value* len, |
twisti@2047 | 172 | llvm::Value* align); |
twisti@2047 | 173 | llvm::CallInst* CreateUnimplemented(const char* file, int line); |
twisti@2047 | 174 | llvm::CallInst* CreateShouldNotReachHere(const char* file, int line); |
twisti@2047 | 175 | NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value)); |
twisti@2047 | 176 | |
twisti@2047 | 177 | // Flags for CreateMemoryBarrier. |
twisti@2047 | 178 | public: |
twisti@2047 | 179 | enum BarrierFlags { |
twisti@2047 | 180 | BARRIER_LOADLOAD = 1, |
twisti@2047 | 181 | BARRIER_LOADSTORE = 2, |
twisti@2047 | 182 | BARRIER_STORELOAD = 4, |
twisti@2047 | 183 | BARRIER_STORESTORE = 8 |
twisti@2047 | 184 | }; |
twisti@2047 | 185 | |
twisti@2047 | 186 | // HotSpot memory barriers |
twisti@2047 | 187 | public: |
twisti@2047 | 188 | void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field); |
twisti@2047 | 189 | |
twisti@2047 | 190 | // Helpers for accessing the code buffer. |
twisti@2047 | 191 | public: |
twisti@2047 | 192 | llvm::Value* code_buffer_address(int offset); |
twisti@2047 | 193 | llvm::Value* CreateInlineOop(jobject object, const char* name = ""); |
twisti@2047 | 194 | llvm::Value* CreateInlineOop(ciObject* object, const char* name = "") { |
twisti@2047 | 195 | return CreateInlineOop(object->constant_encoding(), name); |
twisti@2047 | 196 | } |
twisti@2047 | 197 | llvm::Value* CreateInlineData(void* data, |
twisti@2047 | 198 | size_t size, |
twisti@2047 | 199 | const llvm::Type* type, |
twisti@2047 | 200 | const char* name = ""); |
twisti@2047 | 201 | |
twisti@2047 | 202 | // Helpers for creating basic blocks. |
twisti@2047 | 203 | // NB don't use unless SharkFunction::CreateBlock is unavailable. |
twisti@2047 | 204 | // XXX these are hacky and should be removed. |
twisti@2047 | 205 | public: |
twisti@2047 | 206 | llvm::BasicBlock* GetBlockInsertionPoint() const; |
twisti@2047 | 207 | llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip, |
twisti@2047 | 208 | const char* name="") const; |
twisti@2047 | 209 | }; |