Tue, 27 Nov 2012 12:48:52 -0800
8003868: fix shark for latest HotSpot and LLVM
Reviewed-by: twisti
Contributed-by: Roman Kennke <rkennke@redhat.com>
twisti@2047 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1999, 2012, 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 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
stefank@2314 | 27 | #include "oops/arrayOop.hpp" |
stefank@2314 | 28 | #include "oops/oop.hpp" |
stefank@2314 | 29 | #include "shark/llvmHeaders.hpp" |
stefank@2314 | 30 | #include "shark/sharkContext.hpp" |
stefank@2314 | 31 | #include "utilities/globalDefinitions.hpp" |
twisti@4314 | 32 | #include "memory/allocation.hpp" |
twisti@2047 | 33 | |
twisti@2047 | 34 | using namespace llvm; |
twisti@2047 | 35 | |
twisti@2047 | 36 | SharkContext::SharkContext(const char* name) |
twisti@2047 | 37 | : LLVMContext(), |
twisti@2047 | 38 | _free_queue(NULL) { |
twisti@2047 | 39 | // Create a module to build our functions into |
twisti@2047 | 40 | _module = new Module(name, *this); |
twisti@2047 | 41 | |
twisti@2047 | 42 | // Create basic types |
twisti@2047 | 43 | _void_type = Type::getVoidTy(*this); |
twisti@2047 | 44 | _bit_type = Type::getInt1Ty(*this); |
twisti@2047 | 45 | _jbyte_type = Type::getInt8Ty(*this); |
twisti@2047 | 46 | _jshort_type = Type::getInt16Ty(*this); |
twisti@2047 | 47 | _jint_type = Type::getInt32Ty(*this); |
twisti@2047 | 48 | _jlong_type = Type::getInt64Ty(*this); |
twisti@2047 | 49 | _jfloat_type = Type::getFloatTy(*this); |
twisti@2047 | 50 | _jdouble_type = Type::getDoubleTy(*this); |
twisti@2047 | 51 | |
twisti@2047 | 52 | // Create compound types |
twisti@2047 | 53 | _itableOffsetEntry_type = PointerType::getUnqual( |
twisti@2047 | 54 | ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize)); |
twisti@2047 | 55 | |
twisti@4314 | 56 | _Metadata_type = PointerType::getUnqual( |
twisti@4314 | 57 | ArrayType::get(jbyte_type(), sizeof(Metadata))); |
twisti@4314 | 58 | |
twisti@2047 | 59 | _klass_type = PointerType::getUnqual( |
twisti@2047 | 60 | ArrayType::get(jbyte_type(), sizeof(Klass))); |
twisti@2047 | 61 | |
twisti@2047 | 62 | _jniEnv_type = PointerType::getUnqual( |
twisti@2047 | 63 | ArrayType::get(jbyte_type(), sizeof(JNIEnv))); |
twisti@2047 | 64 | |
twisti@2047 | 65 | _jniHandleBlock_type = PointerType::getUnqual( |
twisti@2047 | 66 | ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock))); |
twisti@2047 | 67 | |
twisti@4314 | 68 | _Method_type = PointerType::getUnqual( |
coleenp@4037 | 69 | ArrayType::get(jbyte_type(), sizeof(Method))); |
twisti@2047 | 70 | |
twisti@2047 | 71 | _monitor_type = ArrayType::get( |
twisti@2047 | 72 | jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize); |
twisti@2047 | 73 | |
twisti@2047 | 74 | _oop_type = PointerType::getUnqual( |
twisti@2047 | 75 | ArrayType::get(jbyte_type(), sizeof(oopDesc))); |
twisti@2047 | 76 | |
twisti@2047 | 77 | _thread_type = PointerType::getUnqual( |
twisti@2047 | 78 | ArrayType::get(jbyte_type(), sizeof(JavaThread))); |
twisti@2047 | 79 | |
twisti@2047 | 80 | _zeroStack_type = PointerType::getUnqual( |
twisti@2047 | 81 | ArrayType::get(jbyte_type(), sizeof(ZeroStack))); |
twisti@2047 | 82 | |
twisti@4314 | 83 | std::vector<Type*> params; |
twisti@4314 | 84 | params.push_back(Method_type()); |
twisti@2047 | 85 | params.push_back(intptr_type()); |
twisti@2047 | 86 | params.push_back(thread_type()); |
twisti@2047 | 87 | _entry_point_type = FunctionType::get(jint_type(), params, false); |
twisti@2047 | 88 | |
twisti@2047 | 89 | params.clear(); |
twisti@4314 | 90 | params.push_back(Method_type()); |
twisti@2047 | 91 | params.push_back(PointerType::getUnqual(jbyte_type())); |
twisti@2047 | 92 | params.push_back(intptr_type()); |
twisti@2047 | 93 | params.push_back(thread_type()); |
twisti@2047 | 94 | _osr_entry_point_type = FunctionType::get(jint_type(), params, false); |
twisti@2047 | 95 | |
twisti@2047 | 96 | // Create mappings |
twisti@2047 | 97 | for (int i = 0; i < T_CONFLICT; i++) { |
twisti@2047 | 98 | switch (i) { |
twisti@2047 | 99 | case T_BOOLEAN: |
twisti@2047 | 100 | _to_stackType[i] = jint_type(); |
twisti@2047 | 101 | _to_arrayType[i] = jbyte_type(); |
twisti@2047 | 102 | break; |
twisti@2047 | 103 | |
twisti@2047 | 104 | case T_BYTE: |
twisti@2047 | 105 | _to_stackType[i] = jint_type(); |
twisti@2047 | 106 | _to_arrayType[i] = jbyte_type(); |
twisti@2047 | 107 | break; |
twisti@2047 | 108 | |
twisti@2047 | 109 | case T_CHAR: |
twisti@2047 | 110 | _to_stackType[i] = jint_type(); |
twisti@2047 | 111 | _to_arrayType[i] = jshort_type(); |
twisti@2047 | 112 | break; |
twisti@2047 | 113 | |
twisti@2047 | 114 | case T_SHORT: |
twisti@2047 | 115 | _to_stackType[i] = jint_type(); |
twisti@2047 | 116 | _to_arrayType[i] = jshort_type(); |
twisti@2047 | 117 | break; |
twisti@2047 | 118 | |
twisti@2047 | 119 | case T_INT: |
twisti@2047 | 120 | _to_stackType[i] = jint_type(); |
twisti@2047 | 121 | _to_arrayType[i] = jint_type(); |
twisti@2047 | 122 | break; |
twisti@2047 | 123 | |
twisti@2047 | 124 | case T_LONG: |
twisti@2047 | 125 | _to_stackType[i] = jlong_type(); |
twisti@2047 | 126 | _to_arrayType[i] = jlong_type(); |
twisti@2047 | 127 | break; |
twisti@2047 | 128 | |
twisti@2047 | 129 | case T_FLOAT: |
twisti@2047 | 130 | _to_stackType[i] = jfloat_type(); |
twisti@2047 | 131 | _to_arrayType[i] = jfloat_type(); |
twisti@2047 | 132 | break; |
twisti@2047 | 133 | |
twisti@2047 | 134 | case T_DOUBLE: |
twisti@2047 | 135 | _to_stackType[i] = jdouble_type(); |
twisti@2047 | 136 | _to_arrayType[i] = jdouble_type(); |
twisti@2047 | 137 | break; |
twisti@2047 | 138 | |
twisti@2047 | 139 | case T_OBJECT: |
twisti@2047 | 140 | case T_ARRAY: |
twisti@2047 | 141 | _to_stackType[i] = oop_type(); |
twisti@2047 | 142 | _to_arrayType[i] = oop_type(); |
twisti@2047 | 143 | break; |
twisti@2047 | 144 | |
twisti@2047 | 145 | case T_ADDRESS: |
twisti@2047 | 146 | _to_stackType[i] = intptr_type(); |
twisti@2047 | 147 | _to_arrayType[i] = NULL; |
twisti@2047 | 148 | break; |
twisti@2047 | 149 | |
twisti@2047 | 150 | default: |
twisti@2047 | 151 | _to_stackType[i] = NULL; |
twisti@2047 | 152 | _to_arrayType[i] = NULL; |
twisti@2047 | 153 | } |
twisti@2047 | 154 | } |
twisti@2047 | 155 | } |
twisti@2047 | 156 | |
twisti@4314 | 157 | class SharkFreeQueueItem : public CHeapObj<mtNone> { |
twisti@2047 | 158 | public: |
twisti@2047 | 159 | SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next) |
twisti@2047 | 160 | : _function(function), _next(next) {} |
twisti@2047 | 161 | |
twisti@2047 | 162 | private: |
twisti@2047 | 163 | llvm::Function* _function; |
twisti@2047 | 164 | SharkFreeQueueItem* _next; |
twisti@2047 | 165 | |
twisti@2047 | 166 | public: |
twisti@2047 | 167 | llvm::Function* function() const { |
twisti@2047 | 168 | return _function; |
twisti@2047 | 169 | } |
twisti@2047 | 170 | SharkFreeQueueItem* next() const { |
twisti@2047 | 171 | return _next; |
twisti@2047 | 172 | } |
twisti@2047 | 173 | }; |
twisti@2047 | 174 | |
twisti@2047 | 175 | void SharkContext::push_to_free_queue(Function* function) { |
twisti@2047 | 176 | _free_queue = new SharkFreeQueueItem(function, _free_queue); |
twisti@2047 | 177 | } |
twisti@2047 | 178 | |
twisti@2047 | 179 | Function* SharkContext::pop_from_free_queue() { |
twisti@2047 | 180 | if (_free_queue == NULL) |
twisti@2047 | 181 | return NULL; |
twisti@2047 | 182 | |
twisti@2047 | 183 | SharkFreeQueueItem *item = _free_queue; |
twisti@2047 | 184 | Function *function = item->function(); |
twisti@2047 | 185 | _free_queue = item->next(); |
twisti@2047 | 186 | delete item; |
twisti@2047 | 187 | return function; |
twisti@2047 | 188 | } |