src/share/vm/shark/sharkContext.cpp

changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/shark/sharkContext.cpp	Wed Aug 11 05:51:21 2010 -0700
     1.3 @@ -0,0 +1,180 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2007, 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 +#include "incls/_precompiled.incl"
    1.30 +#include "incls/_sharkContext.cpp.incl"
    1.31 +
    1.32 +using namespace llvm;
    1.33 +
    1.34 +SharkContext::SharkContext(const char* name)
    1.35 +  : LLVMContext(),
    1.36 +    _free_queue(NULL) {
    1.37 +  // Create a module to build our functions into
    1.38 +  _module = new Module(name, *this);
    1.39 +
    1.40 +  // Create basic types
    1.41 +  _void_type    = Type::getVoidTy(*this);
    1.42 +  _bit_type     = Type::getInt1Ty(*this);
    1.43 +  _jbyte_type   = Type::getInt8Ty(*this);
    1.44 +  _jshort_type  = Type::getInt16Ty(*this);
    1.45 +  _jint_type    = Type::getInt32Ty(*this);
    1.46 +  _jlong_type   = Type::getInt64Ty(*this);
    1.47 +  _jfloat_type  = Type::getFloatTy(*this);
    1.48 +  _jdouble_type = Type::getDoubleTy(*this);
    1.49 +
    1.50 +  // Create compound types
    1.51 +  _itableOffsetEntry_type = PointerType::getUnqual(
    1.52 +    ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize));
    1.53 +
    1.54 +  _klass_type = PointerType::getUnqual(
    1.55 +    ArrayType::get(jbyte_type(), sizeof(Klass)));
    1.56 +
    1.57 +  _jniEnv_type = PointerType::getUnqual(
    1.58 +    ArrayType::get(jbyte_type(), sizeof(JNIEnv)));
    1.59 +
    1.60 +  _jniHandleBlock_type = PointerType::getUnqual(
    1.61 +    ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock)));
    1.62 +
    1.63 +  _methodOop_type = PointerType::getUnqual(
    1.64 +    ArrayType::get(jbyte_type(), sizeof(methodOopDesc)));
    1.65 +
    1.66 +  _monitor_type = ArrayType::get(
    1.67 +    jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize);
    1.68 +
    1.69 +  _oop_type = PointerType::getUnqual(
    1.70 +    ArrayType::get(jbyte_type(), sizeof(oopDesc)));
    1.71 +
    1.72 +  _thread_type = PointerType::getUnqual(
    1.73 +    ArrayType::get(jbyte_type(), sizeof(JavaThread)));
    1.74 +
    1.75 +  _zeroStack_type = PointerType::getUnqual(
    1.76 +    ArrayType::get(jbyte_type(), sizeof(ZeroStack)));
    1.77 +
    1.78 +  std::vector<const Type*> params;
    1.79 +  params.push_back(methodOop_type());
    1.80 +  params.push_back(intptr_type());
    1.81 +  params.push_back(thread_type());
    1.82 +  _entry_point_type = FunctionType::get(jint_type(), params, false);
    1.83 +
    1.84 +  params.clear();
    1.85 +  params.push_back(methodOop_type());
    1.86 +  params.push_back(PointerType::getUnqual(jbyte_type()));
    1.87 +  params.push_back(intptr_type());
    1.88 +  params.push_back(thread_type());
    1.89 +  _osr_entry_point_type = FunctionType::get(jint_type(), params, false);
    1.90 +
    1.91 +  // Create mappings
    1.92 +  for (int i = 0; i < T_CONFLICT; i++) {
    1.93 +    switch (i) {
    1.94 +    case T_BOOLEAN:
    1.95 +      _to_stackType[i] = jint_type();
    1.96 +      _to_arrayType[i] = jbyte_type();
    1.97 +      break;
    1.98 +
    1.99 +    case T_BYTE:
   1.100 +      _to_stackType[i] = jint_type();
   1.101 +      _to_arrayType[i] = jbyte_type();
   1.102 +      break;
   1.103 +
   1.104 +    case T_CHAR:
   1.105 +      _to_stackType[i] = jint_type();
   1.106 +      _to_arrayType[i] = jshort_type();
   1.107 +      break;
   1.108 +
   1.109 +    case T_SHORT:
   1.110 +      _to_stackType[i] = jint_type();
   1.111 +      _to_arrayType[i] = jshort_type();
   1.112 +      break;
   1.113 +
   1.114 +    case T_INT:
   1.115 +      _to_stackType[i] = jint_type();
   1.116 +      _to_arrayType[i] = jint_type();
   1.117 +      break;
   1.118 +
   1.119 +    case T_LONG:
   1.120 +      _to_stackType[i] = jlong_type();
   1.121 +      _to_arrayType[i] = jlong_type();
   1.122 +      break;
   1.123 +
   1.124 +    case T_FLOAT:
   1.125 +      _to_stackType[i] = jfloat_type();
   1.126 +      _to_arrayType[i] = jfloat_type();
   1.127 +      break;
   1.128 +
   1.129 +    case T_DOUBLE:
   1.130 +      _to_stackType[i] = jdouble_type();
   1.131 +      _to_arrayType[i] = jdouble_type();
   1.132 +      break;
   1.133 +
   1.134 +    case T_OBJECT:
   1.135 +    case T_ARRAY:
   1.136 +      _to_stackType[i] = oop_type();
   1.137 +      _to_arrayType[i] = oop_type();
   1.138 +      break;
   1.139 +
   1.140 +    case T_ADDRESS:
   1.141 +      _to_stackType[i] = intptr_type();
   1.142 +      _to_arrayType[i] = NULL;
   1.143 +      break;
   1.144 +
   1.145 +    default:
   1.146 +      _to_stackType[i] = NULL;
   1.147 +      _to_arrayType[i] = NULL;
   1.148 +    }
   1.149 +  }
   1.150 +}
   1.151 +
   1.152 +class SharkFreeQueueItem : public CHeapObj {
   1.153 + public:
   1.154 +  SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next)
   1.155 +    : _function(function), _next(next) {}
   1.156 +
   1.157 + private:
   1.158 +  llvm::Function*     _function;
   1.159 +  SharkFreeQueueItem* _next;
   1.160 +
   1.161 + public:
   1.162 +  llvm::Function* function() const {
   1.163 +    return _function;
   1.164 +  }
   1.165 +  SharkFreeQueueItem* next() const {
   1.166 +    return _next;
   1.167 +  }
   1.168 +};
   1.169 +
   1.170 +void SharkContext::push_to_free_queue(Function* function) {
   1.171 +  _free_queue = new SharkFreeQueueItem(function, _free_queue);
   1.172 +}
   1.173 +
   1.174 +Function* SharkContext::pop_from_free_queue() {
   1.175 +  if (_free_queue == NULL)
   1.176 +    return NULL;
   1.177 +
   1.178 +  SharkFreeQueueItem *item = _free_queue;
   1.179 +  Function *function = item->function();
   1.180 +  _free_queue = item->next();
   1.181 +  delete item;
   1.182 +  return function;
   1.183 +}

mercurial