1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkBuilder.hpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,209 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009, 2010 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +class SharkBuilder : public llvm::IRBuilder<> { 1.30 + friend class SharkCompileInvariants; 1.31 + 1.32 + public: 1.33 + SharkBuilder(SharkCodeBuffer* code_buffer); 1.34 + 1.35 + // The code buffer we are building into. 1.36 + private: 1.37 + SharkCodeBuffer* _code_buffer; 1.38 + 1.39 + protected: 1.40 + SharkCodeBuffer* code_buffer() const { 1.41 + return _code_buffer; 1.42 + } 1.43 + 1.44 + // Helpers for accessing structures. 1.45 + public: 1.46 + llvm::Value* CreateAddressOfStructEntry(llvm::Value* base, 1.47 + ByteSize offset, 1.48 + const llvm::Type* type, 1.49 + const char *name = ""); 1.50 + llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base, 1.51 + ByteSize offset, 1.52 + const llvm::Type* type, 1.53 + const char *name = ""); 1.54 + 1.55 + // Helpers for accessing arrays. 1.56 + public: 1.57 + llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop); 1.58 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.59 + const llvm::Type* element_type, 1.60 + int element_bytes, 1.61 + ByteSize base_offset, 1.62 + llvm::Value* index, 1.63 + const char* name = ""); 1.64 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.65 + BasicType basic_type, 1.66 + ByteSize base_offset, 1.67 + llvm::Value* index, 1.68 + const char* name = ""); 1.69 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.70 + BasicType basic_type, 1.71 + llvm::Value* index, 1.72 + const char* name = ""); 1.73 + 1.74 + // Helpers for creating intrinsics and external functions. 1.75 + private: 1.76 + static const llvm::Type* make_type(char type, bool void_ok); 1.77 + static const llvm::FunctionType* make_ftype(const char* params, 1.78 + const char* ret); 1.79 + llvm::Value* make_function(const char* name, 1.80 + const char* params, 1.81 + const char* ret); 1.82 + llvm::Value* make_function(address func, 1.83 + const char* params, 1.84 + const char* ret); 1.85 + 1.86 + // Intrinsics and external functions, part 1: VM calls. 1.87 + // These are functions declared with JRT_ENTRY and JRT_EXIT, 1.88 + // macros which flip the thread from _thread_in_Java to 1.89 + // _thread_in_vm and back. VM calls always safepoint, and can 1.90 + // therefore throw exceptions. VM calls require of setup and 1.91 + // teardown, and must be called with SharkTopLevelBlock::call_vm. 1.92 + public: 1.93 + llvm::Value* find_exception_handler(); 1.94 + llvm::Value* monitorenter(); 1.95 + llvm::Value* monitorexit(); 1.96 + llvm::Value* new_instance(); 1.97 + llvm::Value* newarray(); 1.98 + llvm::Value* anewarray(); 1.99 + llvm::Value* multianewarray(); 1.100 + llvm::Value* register_finalizer(); 1.101 + llvm::Value* safepoint(); 1.102 + llvm::Value* throw_ArithmeticException(); 1.103 + llvm::Value* throw_ArrayIndexOutOfBoundsException(); 1.104 + llvm::Value* throw_ClassCastException(); 1.105 + llvm::Value* throw_NullPointerException(); 1.106 + 1.107 + // Intrinsics and external functions, part 2: High-level non-VM calls. 1.108 + // These are called like normal functions. The stack is not set 1.109 + // up for walking so they must not safepoint or throw exceptions, 1.110 + // or call anything that might. 1.111 + public: 1.112 + llvm::Value* f2i(); 1.113 + llvm::Value* f2l(); 1.114 + llvm::Value* d2i(); 1.115 + llvm::Value* d2l(); 1.116 + llvm::Value* is_subtype_of(); 1.117 + llvm::Value* current_time_millis(); 1.118 + llvm::Value* sin(); 1.119 + llvm::Value* cos(); 1.120 + llvm::Value* tan(); 1.121 + llvm::Value* atan2(); 1.122 + llvm::Value* sqrt(); 1.123 + llvm::Value* log(); 1.124 + llvm::Value* log10(); 1.125 + llvm::Value* pow(); 1.126 + llvm::Value* exp(); 1.127 + llvm::Value* fabs(); 1.128 + llvm::Value* unsafe_field_offset_to_byte_offset(); 1.129 + llvm::Value* osr_migration_end(); 1.130 + 1.131 + // Intrinsics and external functions, part 3: semi-VM calls. 1.132 + // These are special cases that do VM call stuff but are invoked 1.133 + // as though they were normal calls. This is acceptable so long 1.134 + // as the method that calls them returns to its immediately that 1.135 + // the semi VM call returns. 1.136 + public: 1.137 + llvm::Value* throw_StackOverflowError(); 1.138 + llvm::Value* uncommon_trap(); 1.139 + llvm::Value* deoptimized_entry_point(); 1.140 + 1.141 + // Intrinsics and external functions, part 4: Native-Java transition. 1.142 + // This is a special case in that it is invoked during a thread 1.143 + // state transition. The stack must be set up for walking, and it 1.144 + // may throw exceptions, but the state is _thread_in_native_trans. 1.145 + public: 1.146 + llvm::Value* check_special_condition_for_native_trans(); 1.147 + 1.148 + // Intrinsics and external functions, part 5: Low-level non-VM calls. 1.149 + // These have the same caveats as the high-level non-VM calls 1.150 + // above. They are not accessed directly; rather, you should 1.151 + // access them via the various Create* methods below. 1.152 + private: 1.153 + llvm::Value* cmpxchg_int(); 1.154 + llvm::Value* cmpxchg_ptr(); 1.155 + llvm::Value* frame_address(); 1.156 + llvm::Value* memory_barrier(); 1.157 + llvm::Value* memset(); 1.158 + llvm::Value* unimplemented(); 1.159 + llvm::Value* should_not_reach_here(); 1.160 + llvm::Value* dump(); 1.161 + 1.162 + // Public interface to low-level non-VM calls. 1.163 + public: 1.164 + llvm::CallInst* CreateCmpxchgInt(llvm::Value* exchange_value, 1.165 + llvm::Value* dst, 1.166 + llvm::Value* compare_value); 1.167 + llvm::CallInst* CreateCmpxchgPtr(llvm::Value* exchange_value, 1.168 + llvm::Value* dst, 1.169 + llvm::Value* compare_value); 1.170 + llvm::CallInst* CreateGetFrameAddress(); 1.171 + llvm::CallInst* CreateMemoryBarrier(int flags); 1.172 + llvm::CallInst* CreateMemset(llvm::Value* dst, 1.173 + llvm::Value* value, 1.174 + llvm::Value* len, 1.175 + llvm::Value* align); 1.176 + llvm::CallInst* CreateUnimplemented(const char* file, int line); 1.177 + llvm::CallInst* CreateShouldNotReachHere(const char* file, int line); 1.178 + NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value)); 1.179 + 1.180 + // Flags for CreateMemoryBarrier. 1.181 + public: 1.182 + enum BarrierFlags { 1.183 + BARRIER_LOADLOAD = 1, 1.184 + BARRIER_LOADSTORE = 2, 1.185 + BARRIER_STORELOAD = 4, 1.186 + BARRIER_STORESTORE = 8 1.187 + }; 1.188 + 1.189 + // HotSpot memory barriers 1.190 + public: 1.191 + void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field); 1.192 + 1.193 + // Helpers for accessing the code buffer. 1.194 + public: 1.195 + llvm::Value* code_buffer_address(int offset); 1.196 + llvm::Value* CreateInlineOop(jobject object, const char* name = ""); 1.197 + llvm::Value* CreateInlineOop(ciObject* object, const char* name = "") { 1.198 + return CreateInlineOop(object->constant_encoding(), name); 1.199 + } 1.200 + llvm::Value* CreateInlineData(void* data, 1.201 + size_t size, 1.202 + const llvm::Type* type, 1.203 + const char* name = ""); 1.204 + 1.205 + // Helpers for creating basic blocks. 1.206 + // NB don't use unless SharkFunction::CreateBlock is unavailable. 1.207 + // XXX these are hacky and should be removed. 1.208 + public: 1.209 + llvm::BasicBlock* GetBlockInsertionPoint() const; 1.210 + llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip, 1.211 + const char* name="") const; 1.212 +};