1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkContext.hpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,187 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 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 +// The LLVMContext class allows multiple instances of LLVM to operate 1.30 +// independently of each other in a multithreaded context. We extend 1.31 +// this here to store things in Shark that are LLVMContext-specific. 1.32 + 1.33 +class SharkFreeQueueItem; 1.34 + 1.35 +class SharkContext : public llvm::LLVMContext { 1.36 + public: 1.37 + SharkContext(const char* name); 1.38 + 1.39 + private: 1.40 + llvm::Module* _module; 1.41 + 1.42 +#if SHARK_LLVM_VERSION >= 27 1.43 + public: 1.44 +#else 1.45 + private: 1.46 +#endif 1.47 + llvm::Module* module() const { 1.48 + return _module; 1.49 + } 1.50 + 1.51 + // Get this thread's SharkContext 1.52 + public: 1.53 + static SharkContext& current() { 1.54 + return *SharkCompiler::compiler()->context(); 1.55 + } 1.56 + 1.57 + // Module accessors 1.58 + public: 1.59 +#if SHARK_LLVM_VERSION < 27 1.60 + llvm::ModuleProvider* module_provider() const { 1.61 + return new llvm::ExistingModuleProvider(module()); 1.62 + } 1.63 +#endif 1.64 + void add_function(llvm::Function* function) const { 1.65 + module()->getFunctionList().push_back(function); 1.66 + } 1.67 + llvm::Constant* get_external(const char* name, 1.68 + const llvm::FunctionType* sig) { 1.69 + return module()->getOrInsertFunction(name, sig); 1.70 + } 1.71 + 1.72 + // Basic types 1.73 + private: 1.74 + const llvm::Type* _void_type; 1.75 + const llvm::IntegerType* _bit_type; 1.76 + const llvm::IntegerType* _jbyte_type; 1.77 + const llvm::IntegerType* _jshort_type; 1.78 + const llvm::IntegerType* _jint_type; 1.79 + const llvm::IntegerType* _jlong_type; 1.80 + const llvm::Type* _jfloat_type; 1.81 + const llvm::Type* _jdouble_type; 1.82 + 1.83 + public: 1.84 + const llvm::Type* void_type() const { 1.85 + return _void_type; 1.86 + } 1.87 + const llvm::IntegerType* bit_type() const { 1.88 + return _bit_type; 1.89 + } 1.90 + const llvm::IntegerType* jbyte_type() const { 1.91 + return _jbyte_type; 1.92 + } 1.93 + const llvm::IntegerType* jshort_type() const { 1.94 + return _jshort_type; 1.95 + } 1.96 + const llvm::IntegerType* jint_type() const { 1.97 + return _jint_type; 1.98 + } 1.99 + const llvm::IntegerType* jlong_type() const { 1.100 + return _jlong_type; 1.101 + } 1.102 + const llvm::Type* jfloat_type() const { 1.103 + return _jfloat_type; 1.104 + } 1.105 + const llvm::Type* jdouble_type() const { 1.106 + return _jdouble_type; 1.107 + } 1.108 + const llvm::IntegerType* intptr_type() const { 1.109 + return LP64_ONLY(jlong_type()) NOT_LP64(jint_type()); 1.110 + } 1.111 + 1.112 + // Compound types 1.113 + private: 1.114 + const llvm::PointerType* _itableOffsetEntry_type; 1.115 + const llvm::PointerType* _jniEnv_type; 1.116 + const llvm::PointerType* _jniHandleBlock_type; 1.117 + const llvm::PointerType* _klass_type; 1.118 + const llvm::PointerType* _methodOop_type; 1.119 + const llvm::ArrayType* _monitor_type; 1.120 + const llvm::PointerType* _oop_type; 1.121 + const llvm::PointerType* _thread_type; 1.122 + const llvm::PointerType* _zeroStack_type; 1.123 + const llvm::FunctionType* _entry_point_type; 1.124 + const llvm::FunctionType* _osr_entry_point_type; 1.125 + 1.126 + public: 1.127 + const llvm::PointerType* itableOffsetEntry_type() const { 1.128 + return _itableOffsetEntry_type; 1.129 + } 1.130 + const llvm::PointerType* jniEnv_type() const { 1.131 + return _jniEnv_type; 1.132 + } 1.133 + const llvm::PointerType* jniHandleBlock_type() const { 1.134 + return _jniHandleBlock_type; 1.135 + } 1.136 + const llvm::PointerType* klass_type() const { 1.137 + return _klass_type; 1.138 + } 1.139 + const llvm::PointerType* methodOop_type() const { 1.140 + return _methodOop_type; 1.141 + } 1.142 + const llvm::ArrayType* monitor_type() const { 1.143 + return _monitor_type; 1.144 + } 1.145 + const llvm::PointerType* oop_type() const { 1.146 + return _oop_type; 1.147 + } 1.148 + const llvm::PointerType* thread_type() const { 1.149 + return _thread_type; 1.150 + } 1.151 + const llvm::PointerType* zeroStack_type() const { 1.152 + return _zeroStack_type; 1.153 + } 1.154 + const llvm::FunctionType* entry_point_type() const { 1.155 + return _entry_point_type; 1.156 + } 1.157 + const llvm::FunctionType* osr_entry_point_type() const { 1.158 + return _osr_entry_point_type; 1.159 + } 1.160 + 1.161 + // Mappings 1.162 + private: 1.163 + const llvm::Type* _to_stackType[T_CONFLICT]; 1.164 + const llvm::Type* _to_arrayType[T_CONFLICT]; 1.165 + 1.166 + private: 1.167 + const llvm::Type* map_type(const llvm::Type* const* table, 1.168 + BasicType type) const { 1.169 + assert(type >= 0 && type < T_CONFLICT, "unhandled type"); 1.170 + const llvm::Type* result = table[type]; 1.171 + assert(type != NULL, "unhandled type"); 1.172 + return result; 1.173 + } 1.174 + 1.175 + public: 1.176 + const llvm::Type* to_stackType(BasicType type) const { 1.177 + return map_type(_to_stackType, type); 1.178 + } 1.179 + const llvm::Type* to_arrayType(BasicType type) const { 1.180 + return map_type(_to_arrayType, type); 1.181 + } 1.182 + 1.183 + // Functions queued for freeing 1.184 + private: 1.185 + SharkFreeQueueItem* _free_queue; 1.186 + 1.187 + public: 1.188 + void push_to_free_queue(llvm::Function* function); 1.189 + llvm::Function* pop_from_free_queue(); 1.190 +};