src/share/vm/shark/sharkContext.cpp

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


  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "oops/arrayOop.hpp"
  28 #include "oops/oop.hpp"
  29 #include "shark/llvmHeaders.hpp"
  30 #include "shark/sharkContext.hpp"
  31 #include "utilities/globalDefinitions.hpp"

  32 
  33 using namespace llvm;
  34 
  35 SharkContext::SharkContext(const char* name)
  36   : LLVMContext(),
  37     _free_queue(NULL) {
  38   // Create a module to build our functions into
  39   _module = new Module(name, *this);
  40 
  41   // Create basic types
  42   _void_type    = Type::getVoidTy(*this);
  43   _bit_type     = Type::getInt1Ty(*this);
  44   _jbyte_type   = Type::getInt8Ty(*this);
  45   _jshort_type  = Type::getInt16Ty(*this);
  46   _jint_type    = Type::getInt32Ty(*this);
  47   _jlong_type   = Type::getInt64Ty(*this);
  48   _jfloat_type  = Type::getFloatTy(*this);
  49   _jdouble_type = Type::getDoubleTy(*this);
  50 
  51   // Create compound types
  52   _itableOffsetEntry_type = PointerType::getUnqual(
  53     ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize));
  54 



  55   _klass_type = PointerType::getUnqual(
  56     ArrayType::get(jbyte_type(), sizeof(Klass)));
  57 
  58   _jniEnv_type = PointerType::getUnqual(
  59     ArrayType::get(jbyte_type(), sizeof(JNIEnv)));
  60 
  61   _jniHandleBlock_type = PointerType::getUnqual(
  62     ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock)));
  63 
  64   _Method*_type = PointerType::getUnqual(
  65     ArrayType::get(jbyte_type(), sizeof(Method)));
  66 
  67   _monitor_type = ArrayType::get(
  68     jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize);
  69 
  70   _oop_type = PointerType::getUnqual(
  71     ArrayType::get(jbyte_type(), sizeof(oopDesc)));
  72 
  73   _thread_type = PointerType::getUnqual(
  74     ArrayType::get(jbyte_type(), sizeof(JavaThread)));
  75 
  76   _zeroStack_type = PointerType::getUnqual(
  77     ArrayType::get(jbyte_type(), sizeof(ZeroStack)));
  78 
  79   std::vector<const Type*> params;
  80   params.push_back(Method*_type());
  81   params.push_back(intptr_type());
  82   params.push_back(thread_type());
  83   _entry_point_type = FunctionType::get(jint_type(), params, false);
  84 
  85   params.clear();
  86   params.push_back(Method*_type());
  87   params.push_back(PointerType::getUnqual(jbyte_type()));
  88   params.push_back(intptr_type());
  89   params.push_back(thread_type());
  90   _osr_entry_point_type = FunctionType::get(jint_type(), params, false);
  91 
  92   // Create mappings
  93   for (int i = 0; i < T_CONFLICT; i++) {
  94     switch (i) {
  95     case T_BOOLEAN:
  96       _to_stackType[i] = jint_type();
  97       _to_arrayType[i] = jbyte_type();
  98       break;
  99 
 100     case T_BYTE:
 101       _to_stackType[i] = jint_type();
 102       _to_arrayType[i] = jbyte_type();
 103       break;
 104 
 105     case T_CHAR:
 106       _to_stackType[i] = jint_type();


 133       break;
 134 
 135     case T_OBJECT:
 136     case T_ARRAY:
 137       _to_stackType[i] = oop_type();
 138       _to_arrayType[i] = oop_type();
 139       break;
 140 
 141     case T_ADDRESS:
 142       _to_stackType[i] = intptr_type();
 143       _to_arrayType[i] = NULL;
 144       break;
 145 
 146     default:
 147       _to_stackType[i] = NULL;
 148       _to_arrayType[i] = NULL;
 149     }
 150   }
 151 }
 152 
 153 class SharkFreeQueueItem : public CHeapObj {
 154  public:
 155   SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next)
 156     : _function(function), _next(next) {}
 157 
 158  private:
 159   llvm::Function*     _function;
 160   SharkFreeQueueItem* _next;
 161 
 162  public:
 163   llvm::Function* function() const {
 164     return _function;
 165   }
 166   SharkFreeQueueItem* next() const {
 167     return _next;
 168   }
 169 };
 170 
 171 void SharkContext::push_to_free_queue(Function* function) {
 172   _free_queue = new SharkFreeQueueItem(function, _free_queue);
 173 }


  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "oops/arrayOop.hpp"
  28 #include "oops/oop.hpp"
  29 #include "shark/llvmHeaders.hpp"
  30 #include "shark/sharkContext.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 #include "memory/allocation.hpp"
  33 
  34 using namespace llvm;
  35 
  36 SharkContext::SharkContext(const char* name)
  37   : LLVMContext(),
  38     _free_queue(NULL) {
  39   // Create a module to build our functions into
  40   _module = new Module(name, *this);
  41 
  42   // Create basic types
  43   _void_type    = Type::getVoidTy(*this);
  44   _bit_type     = Type::getInt1Ty(*this);
  45   _jbyte_type   = Type::getInt8Ty(*this);
  46   _jshort_type  = Type::getInt16Ty(*this);
  47   _jint_type    = Type::getInt32Ty(*this);
  48   _jlong_type   = Type::getInt64Ty(*this);
  49   _jfloat_type  = Type::getFloatTy(*this);
  50   _jdouble_type = Type::getDoubleTy(*this);
  51 
  52   // Create compound types
  53   _itableOffsetEntry_type = PointerType::getUnqual(
  54     ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize));
  55 
  56   _Metadata_type = PointerType::getUnqual(
  57     ArrayType::get(jbyte_type(), sizeof(Metadata)));
  58 
  59   _klass_type = PointerType::getUnqual(
  60     ArrayType::get(jbyte_type(), sizeof(Klass)));
  61 
  62   _jniEnv_type = PointerType::getUnqual(
  63     ArrayType::get(jbyte_type(), sizeof(JNIEnv)));
  64 
  65   _jniHandleBlock_type = PointerType::getUnqual(
  66     ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock)));
  67 
  68   _Method_type = PointerType::getUnqual(
  69     ArrayType::get(jbyte_type(), sizeof(Method)));
  70 
  71   _monitor_type = ArrayType::get(
  72     jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize);
  73 
  74   _oop_type = PointerType::getUnqual(
  75     ArrayType::get(jbyte_type(), sizeof(oopDesc)));
  76 
  77   _thread_type = PointerType::getUnqual(
  78     ArrayType::get(jbyte_type(), sizeof(JavaThread)));
  79 
  80   _zeroStack_type = PointerType::getUnqual(
  81     ArrayType::get(jbyte_type(), sizeof(ZeroStack)));
  82 
  83   std::vector<Type*> params;
  84   params.push_back(Method_type());
  85   params.push_back(intptr_type());
  86   params.push_back(thread_type());
  87   _entry_point_type = FunctionType::get(jint_type(), params, false);
  88 
  89   params.clear();
  90   params.push_back(Method_type());
  91   params.push_back(PointerType::getUnqual(jbyte_type()));
  92   params.push_back(intptr_type());
  93   params.push_back(thread_type());
  94   _osr_entry_point_type = FunctionType::get(jint_type(), params, false);
  95 
  96   // Create mappings
  97   for (int i = 0; i < T_CONFLICT; i++) {
  98     switch (i) {
  99     case T_BOOLEAN:
 100       _to_stackType[i] = jint_type();
 101       _to_arrayType[i] = jbyte_type();
 102       break;
 103 
 104     case T_BYTE:
 105       _to_stackType[i] = jint_type();
 106       _to_arrayType[i] = jbyte_type();
 107       break;
 108 
 109     case T_CHAR:
 110       _to_stackType[i] = jint_type();


 137       break;
 138 
 139     case T_OBJECT:
 140     case T_ARRAY:
 141       _to_stackType[i] = oop_type();
 142       _to_arrayType[i] = oop_type();
 143       break;
 144 
 145     case T_ADDRESS:
 146       _to_stackType[i] = intptr_type();
 147       _to_arrayType[i] = NULL;
 148       break;
 149 
 150     default:
 151       _to_stackType[i] = NULL;
 152       _to_arrayType[i] = NULL;
 153     }
 154   }
 155 }
 156 
 157 class SharkFreeQueueItem : public CHeapObj<mtNone> {
 158  public:
 159   SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next)
 160     : _function(function), _next(next) {}
 161 
 162  private:
 163   llvm::Function*     _function;
 164   SharkFreeQueueItem* _next;
 165 
 166  public:
 167   llvm::Function* function() const {
 168     return _function;
 169   }
 170   SharkFreeQueueItem* next() const {
 171     return _next;
 172   }
 173 };
 174 
 175 void SharkContext::push_to_free_queue(Function* function) {
 176   _free_queue = new SharkFreeQueueItem(function, _free_queue);
 177 }