src/share/vm/shark/sharkContext.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4314
2cd5e15048e6
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2009, 2010 Red Hat, Inc.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "oops/arrayOop.hpp"
aoqi@0 28 #include "oops/oop.hpp"
aoqi@0 29 #include "shark/llvmHeaders.hpp"
aoqi@0 30 #include "shark/sharkContext.hpp"
aoqi@0 31 #include "utilities/globalDefinitions.hpp"
aoqi@0 32 #include "memory/allocation.hpp"
aoqi@0 33
aoqi@0 34 using namespace llvm;
aoqi@0 35
aoqi@0 36 SharkContext::SharkContext(const char* name)
aoqi@0 37 : LLVMContext(),
aoqi@0 38 _free_queue(NULL) {
aoqi@0 39 // Create a module to build our functions into
aoqi@0 40 _module = new Module(name, *this);
aoqi@0 41
aoqi@0 42 // Create basic types
aoqi@0 43 _void_type = Type::getVoidTy(*this);
aoqi@0 44 _bit_type = Type::getInt1Ty(*this);
aoqi@0 45 _jbyte_type = Type::getInt8Ty(*this);
aoqi@0 46 _jshort_type = Type::getInt16Ty(*this);
aoqi@0 47 _jint_type = Type::getInt32Ty(*this);
aoqi@0 48 _jlong_type = Type::getInt64Ty(*this);
aoqi@0 49 _jfloat_type = Type::getFloatTy(*this);
aoqi@0 50 _jdouble_type = Type::getDoubleTy(*this);
aoqi@0 51
aoqi@0 52 // Create compound types
aoqi@0 53 _itableOffsetEntry_type = PointerType::getUnqual(
aoqi@0 54 ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize));
aoqi@0 55
aoqi@0 56 _Metadata_type = PointerType::getUnqual(
aoqi@0 57 ArrayType::get(jbyte_type(), sizeof(Metadata)));
aoqi@0 58
aoqi@0 59 _klass_type = PointerType::getUnqual(
aoqi@0 60 ArrayType::get(jbyte_type(), sizeof(Klass)));
aoqi@0 61
aoqi@0 62 _jniEnv_type = PointerType::getUnqual(
aoqi@0 63 ArrayType::get(jbyte_type(), sizeof(JNIEnv)));
aoqi@0 64
aoqi@0 65 _jniHandleBlock_type = PointerType::getUnqual(
aoqi@0 66 ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock)));
aoqi@0 67
aoqi@0 68 _Method_type = PointerType::getUnqual(
aoqi@0 69 ArrayType::get(jbyte_type(), sizeof(Method)));
aoqi@0 70
aoqi@0 71 _monitor_type = ArrayType::get(
aoqi@0 72 jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 73
aoqi@0 74 _oop_type = PointerType::getUnqual(
aoqi@0 75 ArrayType::get(jbyte_type(), sizeof(oopDesc)));
aoqi@0 76
aoqi@0 77 _thread_type = PointerType::getUnqual(
aoqi@0 78 ArrayType::get(jbyte_type(), sizeof(JavaThread)));
aoqi@0 79
aoqi@0 80 _zeroStack_type = PointerType::getUnqual(
aoqi@0 81 ArrayType::get(jbyte_type(), sizeof(ZeroStack)));
aoqi@0 82
aoqi@0 83 std::vector<Type*> params;
aoqi@0 84 params.push_back(Method_type());
aoqi@0 85 params.push_back(intptr_type());
aoqi@0 86 params.push_back(thread_type());
aoqi@0 87 _entry_point_type = FunctionType::get(jint_type(), params, false);
aoqi@0 88
aoqi@0 89 params.clear();
aoqi@0 90 params.push_back(Method_type());
aoqi@0 91 params.push_back(PointerType::getUnqual(jbyte_type()));
aoqi@0 92 params.push_back(intptr_type());
aoqi@0 93 params.push_back(thread_type());
aoqi@0 94 _osr_entry_point_type = FunctionType::get(jint_type(), params, false);
aoqi@0 95
aoqi@0 96 // Create mappings
aoqi@0 97 for (int i = 0; i < T_CONFLICT; i++) {
aoqi@0 98 switch (i) {
aoqi@0 99 case T_BOOLEAN:
aoqi@0 100 _to_stackType[i] = jint_type();
aoqi@0 101 _to_arrayType[i] = jbyte_type();
aoqi@0 102 break;
aoqi@0 103
aoqi@0 104 case T_BYTE:
aoqi@0 105 _to_stackType[i] = jint_type();
aoqi@0 106 _to_arrayType[i] = jbyte_type();
aoqi@0 107 break;
aoqi@0 108
aoqi@0 109 case T_CHAR:
aoqi@0 110 _to_stackType[i] = jint_type();
aoqi@0 111 _to_arrayType[i] = jshort_type();
aoqi@0 112 break;
aoqi@0 113
aoqi@0 114 case T_SHORT:
aoqi@0 115 _to_stackType[i] = jint_type();
aoqi@0 116 _to_arrayType[i] = jshort_type();
aoqi@0 117 break;
aoqi@0 118
aoqi@0 119 case T_INT:
aoqi@0 120 _to_stackType[i] = jint_type();
aoqi@0 121 _to_arrayType[i] = jint_type();
aoqi@0 122 break;
aoqi@0 123
aoqi@0 124 case T_LONG:
aoqi@0 125 _to_stackType[i] = jlong_type();
aoqi@0 126 _to_arrayType[i] = jlong_type();
aoqi@0 127 break;
aoqi@0 128
aoqi@0 129 case T_FLOAT:
aoqi@0 130 _to_stackType[i] = jfloat_type();
aoqi@0 131 _to_arrayType[i] = jfloat_type();
aoqi@0 132 break;
aoqi@0 133
aoqi@0 134 case T_DOUBLE:
aoqi@0 135 _to_stackType[i] = jdouble_type();
aoqi@0 136 _to_arrayType[i] = jdouble_type();
aoqi@0 137 break;
aoqi@0 138
aoqi@0 139 case T_OBJECT:
aoqi@0 140 case T_ARRAY:
aoqi@0 141 _to_stackType[i] = oop_type();
aoqi@0 142 _to_arrayType[i] = oop_type();
aoqi@0 143 break;
aoqi@0 144
aoqi@0 145 case T_ADDRESS:
aoqi@0 146 _to_stackType[i] = intptr_type();
aoqi@0 147 _to_arrayType[i] = NULL;
aoqi@0 148 break;
aoqi@0 149
aoqi@0 150 default:
aoqi@0 151 _to_stackType[i] = NULL;
aoqi@0 152 _to_arrayType[i] = NULL;
aoqi@0 153 }
aoqi@0 154 }
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 class SharkFreeQueueItem : public CHeapObj<mtNone> {
aoqi@0 158 public:
aoqi@0 159 SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next)
aoqi@0 160 : _function(function), _next(next) {}
aoqi@0 161
aoqi@0 162 private:
aoqi@0 163 llvm::Function* _function;
aoqi@0 164 SharkFreeQueueItem* _next;
aoqi@0 165
aoqi@0 166 public:
aoqi@0 167 llvm::Function* function() const {
aoqi@0 168 return _function;
aoqi@0 169 }
aoqi@0 170 SharkFreeQueueItem* next() const {
aoqi@0 171 return _next;
aoqi@0 172 }
aoqi@0 173 };
aoqi@0 174
aoqi@0 175 void SharkContext::push_to_free_queue(Function* function) {
aoqi@0 176 _free_queue = new SharkFreeQueueItem(function, _free_queue);
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 Function* SharkContext::pop_from_free_queue() {
aoqi@0 180 if (_free_queue == NULL)
aoqi@0 181 return NULL;
aoqi@0 182
aoqi@0 183 SharkFreeQueueItem *item = _free_queue;
aoqi@0 184 Function *function = item->function();
aoqi@0 185 _free_queue = item->next();
aoqi@0 186 delete item;
aoqi@0 187 return function;
aoqi@0 188 }

mercurial