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