src/share/vm/shark/sharkContext.hpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

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 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 // The LLVMContext class allows multiple instances of LLVM to operate
twisti@2047 27 // independently of each other in a multithreaded context. We extend
twisti@2047 28 // this here to store things in Shark that are LLVMContext-specific.
twisti@2047 29
twisti@2047 30 class SharkFreeQueueItem;
twisti@2047 31
twisti@2047 32 class SharkContext : public llvm::LLVMContext {
twisti@2047 33 public:
twisti@2047 34 SharkContext(const char* name);
twisti@2047 35
twisti@2047 36 private:
twisti@2047 37 llvm::Module* _module;
twisti@2047 38
twisti@2047 39 #if SHARK_LLVM_VERSION >= 27
twisti@2047 40 public:
twisti@2047 41 #else
twisti@2047 42 private:
twisti@2047 43 #endif
twisti@2047 44 llvm::Module* module() const {
twisti@2047 45 return _module;
twisti@2047 46 }
twisti@2047 47
twisti@2047 48 // Get this thread's SharkContext
twisti@2047 49 public:
twisti@2047 50 static SharkContext& current() {
twisti@2047 51 return *SharkCompiler::compiler()->context();
twisti@2047 52 }
twisti@2047 53
twisti@2047 54 // Module accessors
twisti@2047 55 public:
twisti@2047 56 #if SHARK_LLVM_VERSION < 27
twisti@2047 57 llvm::ModuleProvider* module_provider() const {
twisti@2047 58 return new llvm::ExistingModuleProvider(module());
twisti@2047 59 }
twisti@2047 60 #endif
twisti@2047 61 void add_function(llvm::Function* function) const {
twisti@2047 62 module()->getFunctionList().push_back(function);
twisti@2047 63 }
twisti@2047 64 llvm::Constant* get_external(const char* name,
twisti@2047 65 const llvm::FunctionType* sig) {
twisti@2047 66 return module()->getOrInsertFunction(name, sig);
twisti@2047 67 }
twisti@2047 68
twisti@2047 69 // Basic types
twisti@2047 70 private:
twisti@2047 71 const llvm::Type* _void_type;
twisti@2047 72 const llvm::IntegerType* _bit_type;
twisti@2047 73 const llvm::IntegerType* _jbyte_type;
twisti@2047 74 const llvm::IntegerType* _jshort_type;
twisti@2047 75 const llvm::IntegerType* _jint_type;
twisti@2047 76 const llvm::IntegerType* _jlong_type;
twisti@2047 77 const llvm::Type* _jfloat_type;
twisti@2047 78 const llvm::Type* _jdouble_type;
twisti@2047 79
twisti@2047 80 public:
twisti@2047 81 const llvm::Type* void_type() const {
twisti@2047 82 return _void_type;
twisti@2047 83 }
twisti@2047 84 const llvm::IntegerType* bit_type() const {
twisti@2047 85 return _bit_type;
twisti@2047 86 }
twisti@2047 87 const llvm::IntegerType* jbyte_type() const {
twisti@2047 88 return _jbyte_type;
twisti@2047 89 }
twisti@2047 90 const llvm::IntegerType* jshort_type() const {
twisti@2047 91 return _jshort_type;
twisti@2047 92 }
twisti@2047 93 const llvm::IntegerType* jint_type() const {
twisti@2047 94 return _jint_type;
twisti@2047 95 }
twisti@2047 96 const llvm::IntegerType* jlong_type() const {
twisti@2047 97 return _jlong_type;
twisti@2047 98 }
twisti@2047 99 const llvm::Type* jfloat_type() const {
twisti@2047 100 return _jfloat_type;
twisti@2047 101 }
twisti@2047 102 const llvm::Type* jdouble_type() const {
twisti@2047 103 return _jdouble_type;
twisti@2047 104 }
twisti@2047 105 const llvm::IntegerType* intptr_type() const {
twisti@2047 106 return LP64_ONLY(jlong_type()) NOT_LP64(jint_type());
twisti@2047 107 }
twisti@2047 108
twisti@2047 109 // Compound types
twisti@2047 110 private:
twisti@2047 111 const llvm::PointerType* _itableOffsetEntry_type;
twisti@2047 112 const llvm::PointerType* _jniEnv_type;
twisti@2047 113 const llvm::PointerType* _jniHandleBlock_type;
twisti@2047 114 const llvm::PointerType* _klass_type;
twisti@2047 115 const llvm::PointerType* _methodOop_type;
twisti@2047 116 const llvm::ArrayType* _monitor_type;
twisti@2047 117 const llvm::PointerType* _oop_type;
twisti@2047 118 const llvm::PointerType* _thread_type;
twisti@2047 119 const llvm::PointerType* _zeroStack_type;
twisti@2047 120 const llvm::FunctionType* _entry_point_type;
twisti@2047 121 const llvm::FunctionType* _osr_entry_point_type;
twisti@2047 122
twisti@2047 123 public:
twisti@2047 124 const llvm::PointerType* itableOffsetEntry_type() const {
twisti@2047 125 return _itableOffsetEntry_type;
twisti@2047 126 }
twisti@2047 127 const llvm::PointerType* jniEnv_type() const {
twisti@2047 128 return _jniEnv_type;
twisti@2047 129 }
twisti@2047 130 const llvm::PointerType* jniHandleBlock_type() const {
twisti@2047 131 return _jniHandleBlock_type;
twisti@2047 132 }
twisti@2047 133 const llvm::PointerType* klass_type() const {
twisti@2047 134 return _klass_type;
twisti@2047 135 }
twisti@2047 136 const llvm::PointerType* methodOop_type() const {
twisti@2047 137 return _methodOop_type;
twisti@2047 138 }
twisti@2047 139 const llvm::ArrayType* monitor_type() const {
twisti@2047 140 return _monitor_type;
twisti@2047 141 }
twisti@2047 142 const llvm::PointerType* oop_type() const {
twisti@2047 143 return _oop_type;
twisti@2047 144 }
twisti@2047 145 const llvm::PointerType* thread_type() const {
twisti@2047 146 return _thread_type;
twisti@2047 147 }
twisti@2047 148 const llvm::PointerType* zeroStack_type() const {
twisti@2047 149 return _zeroStack_type;
twisti@2047 150 }
twisti@2047 151 const llvm::FunctionType* entry_point_type() const {
twisti@2047 152 return _entry_point_type;
twisti@2047 153 }
twisti@2047 154 const llvm::FunctionType* osr_entry_point_type() const {
twisti@2047 155 return _osr_entry_point_type;
twisti@2047 156 }
twisti@2047 157
twisti@2047 158 // Mappings
twisti@2047 159 private:
twisti@2047 160 const llvm::Type* _to_stackType[T_CONFLICT];
twisti@2047 161 const llvm::Type* _to_arrayType[T_CONFLICT];
twisti@2047 162
twisti@2047 163 private:
twisti@2047 164 const llvm::Type* map_type(const llvm::Type* const* table,
twisti@2047 165 BasicType type) const {
twisti@2047 166 assert(type >= 0 && type < T_CONFLICT, "unhandled type");
twisti@2047 167 const llvm::Type* result = table[type];
twisti@2047 168 assert(type != NULL, "unhandled type");
twisti@2047 169 return result;
twisti@2047 170 }
twisti@2047 171
twisti@2047 172 public:
twisti@2047 173 const llvm::Type* to_stackType(BasicType type) const {
twisti@2047 174 return map_type(_to_stackType, type);
twisti@2047 175 }
twisti@2047 176 const llvm::Type* to_arrayType(BasicType type) const {
twisti@2047 177 return map_type(_to_arrayType, type);
twisti@2047 178 }
twisti@2047 179
twisti@2047 180 // Functions queued for freeing
twisti@2047 181 private:
twisti@2047 182 SharkFreeQueueItem* _free_queue;
twisti@2047 183
twisti@2047 184 public:
twisti@2047 185 void push_to_free_queue(llvm::Function* function);
twisti@2047 186 llvm::Function* pop_from_free_queue();
twisti@2047 187 };

mercurial