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