twisti@2047: /* coleenp@4037: * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. twisti@2047: * Copyright 2009, 2010 Red Hat, Inc. twisti@2047: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@2047: * twisti@2047: * This code is free software; you can redistribute it and/or modify it twisti@2047: * under the terms of the GNU General Public License version 2 only, as twisti@2047: * published by the Free Software Foundation. twisti@2047: * twisti@2047: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@2047: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@2047: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@2047: * version 2 for more details (a copy is included in the LICENSE file that twisti@2047: * accompanied this code). twisti@2047: * twisti@2047: * You should have received a copy of the GNU General Public License version twisti@2047: * 2 along with this work; if not, write to the Free Software Foundation, twisti@2047: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@2047: * twisti@2047: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA twisti@2047: * or visit www.oracle.com if you need additional information or have any twisti@2047: * questions. twisti@2047: * twisti@2047: */ twisti@2047: stefank@2314: #ifndef SHARE_VM_SHARK_SHARKCONTEXT_HPP stefank@2314: #define SHARE_VM_SHARK_SHARKCONTEXT_HPP stefank@2314: stefank@2314: #include "shark/llvmHeaders.hpp" stefank@2314: #include "shark/sharkCompiler.hpp" stefank@2314: twisti@2047: // The LLVMContext class allows multiple instances of LLVM to operate twisti@2047: // independently of each other in a multithreaded context. We extend twisti@2047: // this here to store things in Shark that are LLVMContext-specific. twisti@2047: twisti@2047: class SharkFreeQueueItem; twisti@2047: twisti@2047: class SharkContext : public llvm::LLVMContext { twisti@2047: public: twisti@2047: SharkContext(const char* name); twisti@2047: twisti@2047: private: twisti@2047: llvm::Module* _module; twisti@2047: twisti@2047: public: twisti@2047: llvm::Module* module() const { twisti@2047: return _module; twisti@2047: } twisti@2047: twisti@2047: // Get this thread's SharkContext twisti@2047: public: twisti@2047: static SharkContext& current() { twisti@2047: return *SharkCompiler::compiler()->context(); twisti@2047: } twisti@2047: twisti@2047: // Module accessors twisti@2047: public: twisti@2047: void add_function(llvm::Function* function) const { twisti@2047: module()->getFunctionList().push_back(function); twisti@2047: } twisti@2047: llvm::Constant* get_external(const char* name, twisti@4314: llvm::FunctionType* sig) { twisti@2047: return module()->getOrInsertFunction(name, sig); twisti@2047: } twisti@2047: twisti@2047: // Basic types twisti@2047: private: twisti@4314: llvm::Type* _void_type; twisti@4314: llvm::IntegerType* _bit_type; twisti@4314: llvm::IntegerType* _jbyte_type; twisti@4314: llvm::IntegerType* _jshort_type; twisti@4314: llvm::IntegerType* _jint_type; twisti@4314: llvm::IntegerType* _jlong_type; twisti@4314: llvm::Type* _jfloat_type; twisti@4314: llvm::Type* _jdouble_type; twisti@2047: twisti@2047: public: twisti@4314: llvm::Type* void_type() const { twisti@2047: return _void_type; twisti@2047: } twisti@4314: llvm::IntegerType* bit_type() const { twisti@2047: return _bit_type; twisti@2047: } twisti@4314: llvm::IntegerType* jbyte_type() const { twisti@2047: return _jbyte_type; twisti@2047: } twisti@4314: llvm::IntegerType* jshort_type() const { twisti@2047: return _jshort_type; twisti@2047: } twisti@4314: llvm::IntegerType* jint_type() const { twisti@2047: return _jint_type; twisti@2047: } twisti@4314: llvm::IntegerType* jlong_type() const { twisti@2047: return _jlong_type; twisti@2047: } twisti@4314: llvm::Type* jfloat_type() const { twisti@2047: return _jfloat_type; twisti@2047: } twisti@4314: llvm::Type* jdouble_type() const { twisti@2047: return _jdouble_type; twisti@2047: } twisti@4314: llvm::IntegerType* intptr_type() const { twisti@2047: return LP64_ONLY(jlong_type()) NOT_LP64(jint_type()); twisti@2047: } twisti@2047: twisti@2047: // Compound types twisti@2047: private: twisti@4314: llvm::PointerType* _itableOffsetEntry_type; twisti@4314: llvm::PointerType* _jniEnv_type; twisti@4314: llvm::PointerType* _jniHandleBlock_type; twisti@4314: llvm::PointerType* _Metadata_type; twisti@4314: llvm::PointerType* _klass_type; twisti@4314: llvm::PointerType* _Method_type; twisti@4314: llvm::ArrayType* _monitor_type; twisti@4314: llvm::PointerType* _oop_type; twisti@4314: llvm::PointerType* _thread_type; twisti@4314: llvm::PointerType* _zeroStack_type; twisti@4314: llvm::FunctionType* _entry_point_type; twisti@4314: llvm::FunctionType* _osr_entry_point_type; twisti@2047: twisti@2047: public: twisti@4314: llvm::PointerType* itableOffsetEntry_type() const { twisti@2047: return _itableOffsetEntry_type; twisti@2047: } twisti@4314: llvm::PointerType* jniEnv_type() const { twisti@2047: return _jniEnv_type; twisti@2047: } twisti@4314: llvm::PointerType* jniHandleBlock_type() const { twisti@2047: return _jniHandleBlock_type; twisti@2047: } twisti@4314: llvm::PointerType* Metadata_type() const { twisti@4314: return _Metadata_type; twisti@4314: } twisti@4314: llvm::PointerType* klass_type() const { twisti@2047: return _klass_type; twisti@2047: } twisti@4314: llvm::PointerType* Method_type() const { twisti@4314: return _Method_type; twisti@2047: } twisti@4314: llvm::ArrayType* monitor_type() const { twisti@2047: return _monitor_type; twisti@2047: } twisti@4314: llvm::PointerType* oop_type() const { twisti@2047: return _oop_type; twisti@2047: } twisti@4314: llvm::PointerType* thread_type() const { twisti@2047: return _thread_type; twisti@2047: } twisti@4314: llvm::PointerType* zeroStack_type() const { twisti@2047: return _zeroStack_type; twisti@2047: } twisti@4314: llvm::FunctionType* entry_point_type() const { twisti@2047: return _entry_point_type; twisti@2047: } twisti@4314: llvm::FunctionType* osr_entry_point_type() const { twisti@2047: return _osr_entry_point_type; twisti@2047: } twisti@2047: twisti@2047: // Mappings twisti@2047: private: twisti@4314: llvm::Type* _to_stackType[T_CONFLICT]; twisti@4314: llvm::Type* _to_arrayType[T_CONFLICT]; twisti@2047: twisti@2047: private: twisti@4314: llvm::Type* map_type(llvm::Type* const* table, twisti@2047: BasicType type) const { twisti@2047: assert(type >= 0 && type < T_CONFLICT, "unhandled type"); twisti@4314: llvm::Type* result = table[type]; twisti@3045: assert(result != NULL, "unhandled type"); twisti@2047: return result; twisti@2047: } twisti@2047: twisti@2047: public: twisti@4314: llvm::Type* to_stackType(BasicType type) const { twisti@2047: return map_type(_to_stackType, type); twisti@2047: } twisti@4314: llvm::Type* to_arrayType(BasicType type) const { twisti@2047: return map_type(_to_arrayType, type); twisti@2047: } twisti@2047: twisti@2047: // Functions queued for freeing twisti@2047: private: twisti@2047: SharkFreeQueueItem* _free_queue; twisti@2047: twisti@2047: public: twisti@2047: void push_to_free_queue(llvm::Function* function); twisti@2047: llvm::Function* pop_from_free_queue(); twisti@2047: }; stefank@2314: stefank@2314: #endif // SHARE_VM_SHARK_SHARKCONTEXT_HPP