Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2009, 2010 Red Hat, Inc. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | #ifndef SHARE_VM_SHARK_SHARKCONTEXT_HPP |
aoqi@0 | 27 | #define SHARE_VM_SHARK_SHARKCONTEXT_HPP |
aoqi@0 | 28 | |
aoqi@0 | 29 | #include "shark/llvmHeaders.hpp" |
aoqi@0 | 30 | #include "shark/sharkCompiler.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | // The LLVMContext class allows multiple instances of LLVM to operate |
aoqi@0 | 33 | // independently of each other in a multithreaded context. We extend |
aoqi@0 | 34 | // this here to store things in Shark that are LLVMContext-specific. |
aoqi@0 | 35 | |
aoqi@0 | 36 | class SharkFreeQueueItem; |
aoqi@0 | 37 | |
aoqi@0 | 38 | class SharkContext : public llvm::LLVMContext { |
aoqi@0 | 39 | public: |
aoqi@0 | 40 | SharkContext(const char* name); |
aoqi@0 | 41 | |
aoqi@0 | 42 | private: |
aoqi@0 | 43 | llvm::Module* _module; |
aoqi@0 | 44 | |
aoqi@0 | 45 | public: |
aoqi@0 | 46 | llvm::Module* module() const { |
aoqi@0 | 47 | return _module; |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | // Get this thread's SharkContext |
aoqi@0 | 51 | public: |
aoqi@0 | 52 | static SharkContext& current() { |
aoqi@0 | 53 | return *SharkCompiler::compiler()->context(); |
aoqi@0 | 54 | } |
aoqi@0 | 55 | |
aoqi@0 | 56 | // Module accessors |
aoqi@0 | 57 | public: |
aoqi@0 | 58 | void add_function(llvm::Function* function) const { |
aoqi@0 | 59 | module()->getFunctionList().push_back(function); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | llvm::Constant* get_external(const char* name, |
aoqi@0 | 62 | llvm::FunctionType* sig) { |
aoqi@0 | 63 | return module()->getOrInsertFunction(name, sig); |
aoqi@0 | 64 | } |
aoqi@0 | 65 | |
aoqi@0 | 66 | // Basic types |
aoqi@0 | 67 | private: |
aoqi@0 | 68 | llvm::Type* _void_type; |
aoqi@0 | 69 | llvm::IntegerType* _bit_type; |
aoqi@0 | 70 | llvm::IntegerType* _jbyte_type; |
aoqi@0 | 71 | llvm::IntegerType* _jshort_type; |
aoqi@0 | 72 | llvm::IntegerType* _jint_type; |
aoqi@0 | 73 | llvm::IntegerType* _jlong_type; |
aoqi@0 | 74 | llvm::Type* _jfloat_type; |
aoqi@0 | 75 | llvm::Type* _jdouble_type; |
aoqi@0 | 76 | |
aoqi@0 | 77 | public: |
aoqi@0 | 78 | llvm::Type* void_type() const { |
aoqi@0 | 79 | return _void_type; |
aoqi@0 | 80 | } |
aoqi@0 | 81 | llvm::IntegerType* bit_type() const { |
aoqi@0 | 82 | return _bit_type; |
aoqi@0 | 83 | } |
aoqi@0 | 84 | llvm::IntegerType* jbyte_type() const { |
aoqi@0 | 85 | return _jbyte_type; |
aoqi@0 | 86 | } |
aoqi@0 | 87 | llvm::IntegerType* jshort_type() const { |
aoqi@0 | 88 | return _jshort_type; |
aoqi@0 | 89 | } |
aoqi@0 | 90 | llvm::IntegerType* jint_type() const { |
aoqi@0 | 91 | return _jint_type; |
aoqi@0 | 92 | } |
aoqi@0 | 93 | llvm::IntegerType* jlong_type() const { |
aoqi@0 | 94 | return _jlong_type; |
aoqi@0 | 95 | } |
aoqi@0 | 96 | llvm::Type* jfloat_type() const { |
aoqi@0 | 97 | return _jfloat_type; |
aoqi@0 | 98 | } |
aoqi@0 | 99 | llvm::Type* jdouble_type() const { |
aoqi@0 | 100 | return _jdouble_type; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | llvm::IntegerType* intptr_type() const { |
aoqi@0 | 103 | return LP64_ONLY(jlong_type()) NOT_LP64(jint_type()); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | // Compound types |
aoqi@0 | 107 | private: |
aoqi@0 | 108 | llvm::PointerType* _itableOffsetEntry_type; |
aoqi@0 | 109 | llvm::PointerType* _jniEnv_type; |
aoqi@0 | 110 | llvm::PointerType* _jniHandleBlock_type; |
aoqi@0 | 111 | llvm::PointerType* _Metadata_type; |
aoqi@0 | 112 | llvm::PointerType* _klass_type; |
aoqi@0 | 113 | llvm::PointerType* _Method_type; |
aoqi@0 | 114 | llvm::ArrayType* _monitor_type; |
aoqi@0 | 115 | llvm::PointerType* _oop_type; |
aoqi@0 | 116 | llvm::PointerType* _thread_type; |
aoqi@0 | 117 | llvm::PointerType* _zeroStack_type; |
aoqi@0 | 118 | llvm::FunctionType* _entry_point_type; |
aoqi@0 | 119 | llvm::FunctionType* _osr_entry_point_type; |
aoqi@0 | 120 | |
aoqi@0 | 121 | public: |
aoqi@0 | 122 | llvm::PointerType* itableOffsetEntry_type() const { |
aoqi@0 | 123 | return _itableOffsetEntry_type; |
aoqi@0 | 124 | } |
aoqi@0 | 125 | llvm::PointerType* jniEnv_type() const { |
aoqi@0 | 126 | return _jniEnv_type; |
aoqi@0 | 127 | } |
aoqi@0 | 128 | llvm::PointerType* jniHandleBlock_type() const { |
aoqi@0 | 129 | return _jniHandleBlock_type; |
aoqi@0 | 130 | } |
aoqi@0 | 131 | llvm::PointerType* Metadata_type() const { |
aoqi@0 | 132 | return _Metadata_type; |
aoqi@0 | 133 | } |
aoqi@0 | 134 | llvm::PointerType* klass_type() const { |
aoqi@0 | 135 | return _klass_type; |
aoqi@0 | 136 | } |
aoqi@0 | 137 | llvm::PointerType* Method_type() const { |
aoqi@0 | 138 | return _Method_type; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | llvm::ArrayType* monitor_type() const { |
aoqi@0 | 141 | return _monitor_type; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | llvm::PointerType* oop_type() const { |
aoqi@0 | 144 | return _oop_type; |
aoqi@0 | 145 | } |
aoqi@0 | 146 | llvm::PointerType* thread_type() const { |
aoqi@0 | 147 | return _thread_type; |
aoqi@0 | 148 | } |
aoqi@0 | 149 | llvm::PointerType* zeroStack_type() const { |
aoqi@0 | 150 | return _zeroStack_type; |
aoqi@0 | 151 | } |
aoqi@0 | 152 | llvm::FunctionType* entry_point_type() const { |
aoqi@0 | 153 | return _entry_point_type; |
aoqi@0 | 154 | } |
aoqi@0 | 155 | llvm::FunctionType* osr_entry_point_type() const { |
aoqi@0 | 156 | return _osr_entry_point_type; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | // Mappings |
aoqi@0 | 160 | private: |
aoqi@0 | 161 | llvm::Type* _to_stackType[T_CONFLICT]; |
aoqi@0 | 162 | llvm::Type* _to_arrayType[T_CONFLICT]; |
aoqi@0 | 163 | |
aoqi@0 | 164 | private: |
aoqi@0 | 165 | llvm::Type* map_type(llvm::Type* const* table, |
aoqi@0 | 166 | BasicType type) const { |
aoqi@0 | 167 | assert(type >= 0 && type < T_CONFLICT, "unhandled type"); |
aoqi@0 | 168 | llvm::Type* result = table[type]; |
aoqi@0 | 169 | assert(result != NULL, "unhandled type"); |
aoqi@0 | 170 | return result; |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | public: |
aoqi@0 | 174 | llvm::Type* to_stackType(BasicType type) const { |
aoqi@0 | 175 | return map_type(_to_stackType, type); |
aoqi@0 | 176 | } |
aoqi@0 | 177 | llvm::Type* to_arrayType(BasicType type) const { |
aoqi@0 | 178 | return map_type(_to_arrayType, type); |
aoqi@0 | 179 | } |
aoqi@0 | 180 | |
aoqi@0 | 181 | // Functions queued for freeing |
aoqi@0 | 182 | private: |
aoqi@0 | 183 | SharkFreeQueueItem* _free_queue; |
aoqi@0 | 184 | |
aoqi@0 | 185 | public: |
aoqi@0 | 186 | void push_to_free_queue(llvm::Function* function); |
aoqi@0 | 187 | llvm::Function* pop_from_free_queue(); |
aoqi@0 | 188 | }; |
aoqi@0 | 189 | |
aoqi@0 | 190 | #endif // SHARE_VM_SHARK_SHARKCONTEXT_HPP |