src/share/vm/shark/sharkContext.hpp

Print this page
rev 3850 : [mq]: shark.patch


  25 
  26 #ifndef SHARE_VM_SHARK_SHARKCONTEXT_HPP
  27 #define SHARE_VM_SHARK_SHARKCONTEXT_HPP
  28 
  29 #include "shark/llvmHeaders.hpp"
  30 #include "shark/sharkCompiler.hpp"
  31 
  32 // The LLVMContext class allows multiple instances of LLVM to operate
  33 // independently of each other in a multithreaded context.  We extend
  34 // this here to store things in Shark that are LLVMContext-specific.
  35 
  36 class SharkFreeQueueItem;
  37 
  38 class SharkContext : public llvm::LLVMContext {
  39  public:
  40   SharkContext(const char* name);
  41 
  42  private:
  43   llvm::Module* _module;
  44 
  45 #if SHARK_LLVM_VERSION >= 27
  46  public:
  47 #else
  48  private:
  49 #endif
  50   llvm::Module* module() const {
  51     return _module;
  52   }
  53 
  54   // Get this thread's SharkContext
  55  public:
  56   static SharkContext& current() {
  57     return *SharkCompiler::compiler()->context();
  58   }
  59 
  60   // Module accessors
  61  public:
  62 #if SHARK_LLVM_VERSION < 27
  63   llvm::ModuleProvider* module_provider() const {
  64     return new llvm::ExistingModuleProvider(module());
  65   }
  66 #endif
  67   void add_function(llvm::Function* function) const {
  68     module()->getFunctionList().push_back(function);
  69   }
  70   llvm::Constant* get_external(const char*               name,
  71                                const llvm::FunctionType* sig) {
  72     return module()->getOrInsertFunction(name, sig);
  73   }
  74 
  75   // Basic types
  76  private:
  77   const llvm::Type*        _void_type;
  78   const llvm::IntegerType* _bit_type;
  79   const llvm::IntegerType* _jbyte_type;
  80   const llvm::IntegerType* _jshort_type;
  81   const llvm::IntegerType* _jint_type;
  82   const llvm::IntegerType* _jlong_type;
  83   const llvm::Type*        _jfloat_type;
  84   const llvm::Type*        _jdouble_type;
  85 
  86  public:
  87   const llvm::Type* void_type() const {
  88     return _void_type;
  89   }
  90   const llvm::IntegerType* bit_type() const {
  91     return _bit_type;
  92   }
  93   const llvm::IntegerType* jbyte_type() const {
  94     return _jbyte_type;
  95   }
  96   const llvm::IntegerType* jshort_type() const {
  97     return _jshort_type;
  98   }
  99   const llvm::IntegerType* jint_type() const {
 100     return _jint_type;
 101   }
 102   const llvm::IntegerType* jlong_type() const {
 103     return _jlong_type;
 104   }
 105   const llvm::Type* jfloat_type() const {
 106     return _jfloat_type;
 107   }
 108   const llvm::Type* jdouble_type() const {
 109     return _jdouble_type;
 110   }
 111   const llvm::IntegerType* intptr_type() const {
 112     return LP64_ONLY(jlong_type()) NOT_LP64(jint_type());
 113   }
 114 
 115   // Compound types
 116  private:
 117   const llvm::PointerType*  _itableOffsetEntry_type;
 118   const llvm::PointerType*  _jniEnv_type;
 119   const llvm::PointerType*  _jniHandleBlock_type;
 120   const llvm::PointerType*  _klass_type;
 121   const llvm::PointerType*  _Method*_type;
 122   const llvm::ArrayType*    _monitor_type;
 123   const llvm::PointerType*  _oop_type;
 124   const llvm::PointerType*  _thread_type;
 125   const llvm::PointerType*  _zeroStack_type;
 126   const llvm::FunctionType* _entry_point_type;
 127   const llvm::FunctionType* _osr_entry_point_type;

 128 
 129  public:
 130   const llvm::PointerType* itableOffsetEntry_type() const {
 131     return _itableOffsetEntry_type;
 132   }
 133   const llvm::PointerType* jniEnv_type() const {
 134     return _jniEnv_type;
 135   }
 136   const llvm::PointerType* jniHandleBlock_type() const {
 137     return _jniHandleBlock_type;
 138   }
 139   const llvm::PointerType* klass_type() const {



 140     return _klass_type;
 141   }
 142   const llvm::PointerType* Method*_type() const {
 143     return _Method*_type;
 144   }
 145   const llvm::ArrayType* monitor_type() const {
 146     return _monitor_type;
 147   }
 148   const llvm::PointerType* oop_type() const {
 149     return _oop_type;
 150   }
 151   const llvm::PointerType* thread_type() const {
 152     return _thread_type;
 153   }
 154   const llvm::PointerType* zeroStack_type() const {
 155     return _zeroStack_type;
 156   }
 157   const llvm::FunctionType* entry_point_type() const {
 158     return _entry_point_type;
 159   }
 160   const llvm::FunctionType* osr_entry_point_type() const {
 161     return _osr_entry_point_type;
 162   }
 163 
 164   // Mappings
 165  private:
 166   const llvm::Type* _to_stackType[T_CONFLICT];
 167   const llvm::Type* _to_arrayType[T_CONFLICT];
 168 
 169  private:
 170   const llvm::Type* map_type(const llvm::Type* const* table,
 171                              BasicType                type) const {
 172     assert(type >= 0 && type < T_CONFLICT, "unhandled type");
 173     const llvm::Type* result = table[type];
 174     assert(result != NULL, "unhandled type");
 175     return result;
 176   }
 177 
 178  public:
 179   const llvm::Type* to_stackType(BasicType type) const {
 180     return map_type(_to_stackType, type);
 181   }
 182   const llvm::Type* to_arrayType(BasicType type) const {
 183     return map_type(_to_arrayType, type);
 184   }
 185 
 186   // Functions queued for freeing
 187  private:
 188   SharkFreeQueueItem* _free_queue;
 189 
 190  public:
 191   void push_to_free_queue(llvm::Function* function);
 192   llvm::Function* pop_from_free_queue();
 193 };
 194 
 195 #endif // SHARE_VM_SHARK_SHARKCONTEXT_HPP


  25 
  26 #ifndef SHARE_VM_SHARK_SHARKCONTEXT_HPP
  27 #define SHARE_VM_SHARK_SHARKCONTEXT_HPP
  28 
  29 #include "shark/llvmHeaders.hpp"
  30 #include "shark/sharkCompiler.hpp"
  31 
  32 // The LLVMContext class allows multiple instances of LLVM to operate
  33 // independently of each other in a multithreaded context.  We extend
  34 // this here to store things in Shark that are LLVMContext-specific.
  35 
  36 class SharkFreeQueueItem;
  37 
  38 class SharkContext : public llvm::LLVMContext {
  39  public:
  40   SharkContext(const char* name);
  41 
  42  private:
  43   llvm::Module* _module;
  44 

  45  public:



  46   llvm::Module* module() const {
  47     return _module;
  48   }
  49 
  50   // Get this thread's SharkContext
  51  public:
  52   static SharkContext& current() {
  53     return *SharkCompiler::compiler()->context();
  54   }
  55 
  56   // Module accessors
  57  public:





  58   void add_function(llvm::Function* function) const {
  59     module()->getFunctionList().push_back(function);
  60   }
  61   llvm::Constant* get_external(const char*               name,
  62                                llvm::FunctionType* sig) {
  63     return module()->getOrInsertFunction(name, sig);
  64   }
  65 
  66   // Basic types
  67  private:
  68   llvm::Type*        _void_type;
  69   llvm::IntegerType* _bit_type;
  70   llvm::IntegerType* _jbyte_type;
  71   llvm::IntegerType* _jshort_type;
  72   llvm::IntegerType* _jint_type;
  73   llvm::IntegerType* _jlong_type;
  74   llvm::Type*        _jfloat_type;
  75   llvm::Type*        _jdouble_type;
  76 
  77  public:
  78   llvm::Type* void_type() const {
  79     return _void_type;
  80   }
  81   llvm::IntegerType* bit_type() const {
  82     return _bit_type;
  83   }
  84   llvm::IntegerType* jbyte_type() const {
  85     return _jbyte_type;
  86   }
  87   llvm::IntegerType* jshort_type() const {
  88     return _jshort_type;
  89   }
  90   llvm::IntegerType* jint_type() const {
  91     return _jint_type;
  92   }
  93   llvm::IntegerType* jlong_type() const {
  94     return _jlong_type;
  95   }
  96   llvm::Type* jfloat_type() const {
  97     return _jfloat_type;
  98   }
  99   llvm::Type* jdouble_type() const {
 100     return _jdouble_type;
 101   }
 102   llvm::IntegerType* intptr_type() const {
 103     return LP64_ONLY(jlong_type()) NOT_LP64(jint_type());
 104   }
 105 
 106   // Compound types
 107  private:
 108   llvm::PointerType*  _itableOffsetEntry_type;
 109   llvm::PointerType*  _jniEnv_type;
 110   llvm::PointerType*  _jniHandleBlock_type;
 111   llvm::PointerType*  _Metadata_type;
 112   llvm::PointerType*  _klass_type;
 113   llvm::PointerType*  _Method_type;
 114   llvm::ArrayType*    _monitor_type;
 115   llvm::PointerType*  _oop_type;
 116   llvm::PointerType*  _thread_type;
 117   llvm::PointerType*  _zeroStack_type;
 118   llvm::FunctionType* _entry_point_type;
 119   llvm::FunctionType* _osr_entry_point_type;
 120 
 121  public:
 122   llvm::PointerType* itableOffsetEntry_type() const {
 123     return _itableOffsetEntry_type;
 124   }
 125   llvm::PointerType* jniEnv_type() const {
 126     return _jniEnv_type;
 127   }
 128   llvm::PointerType* jniHandleBlock_type() const {
 129     return _jniHandleBlock_type;
 130   }
 131   llvm::PointerType* Metadata_type() const {
 132     return _Metadata_type;
 133   }
 134   llvm::PointerType* klass_type() const {
 135     return _klass_type;
 136   }
 137   llvm::PointerType* Method_type() const {
 138     return _Method_type;
 139   }
 140   llvm::ArrayType* monitor_type() const {
 141     return _monitor_type;
 142   }
 143   llvm::PointerType* oop_type() const {
 144     return _oop_type;
 145   }
 146   llvm::PointerType* thread_type() const {
 147     return _thread_type;
 148   }
 149   llvm::PointerType* zeroStack_type() const {
 150     return _zeroStack_type;
 151   }
 152   llvm::FunctionType* entry_point_type() const {
 153     return _entry_point_type;
 154   }
 155   llvm::FunctionType* osr_entry_point_type() const {
 156     return _osr_entry_point_type;
 157   }
 158 
 159   // Mappings
 160  private:
 161   llvm::Type* _to_stackType[T_CONFLICT];
 162   llvm::Type* _to_arrayType[T_CONFLICT];
 163 
 164  private:
 165   llvm::Type* map_type(llvm::Type* const* table,
 166                              BasicType                type) const {
 167     assert(type >= 0 && type < T_CONFLICT, "unhandled type");
 168     llvm::Type* result = table[type];
 169     assert(result != NULL, "unhandled type");
 170     return result;
 171   }
 172 
 173  public:
 174   llvm::Type* to_stackType(BasicType type) const {
 175     return map_type(_to_stackType, type);
 176   }
 177   llvm::Type* to_arrayType(BasicType type) const {
 178     return map_type(_to_arrayType, type);
 179   }
 180 
 181   // Functions queued for freeing
 182  private:
 183   SharkFreeQueueItem* _free_queue;
 184 
 185  public:
 186   void push_to_free_queue(llvm::Function* function);
 187   llvm::Function* pop_from_free_queue();
 188 };
 189 
 190 #endif // SHARE_VM_SHARK_SHARKCONTEXT_HPP