src/share/vm/shark/sharkContext.hpp

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

mercurial