twisti@2047: /* coleenp@4037: * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. twisti@2047: * Copyright 2009, 2010 Red Hat, Inc. twisti@2047: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@2047: * twisti@2047: * This code is free software; you can redistribute it and/or modify it twisti@2047: * under the terms of the GNU General Public License version 2 only, as twisti@2047: * published by the Free Software Foundation. twisti@2047: * twisti@2047: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@2047: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@2047: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@2047: * version 2 for more details (a copy is included in the LICENSE file that twisti@2047: * accompanied this code). twisti@2047: * twisti@2047: * You should have received a copy of the GNU General Public License version twisti@2047: * 2 along with this work; if not, write to the Free Software Foundation, twisti@2047: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@2047: * twisti@2047: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA twisti@2047: * or visit www.oracle.com if you need additional information or have any twisti@2047: * questions. twisti@2047: * twisti@2047: */ twisti@2047: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "oops/arrayOop.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: #include "shark/llvmHeaders.hpp" stefank@2314: #include "shark/sharkContext.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" twisti@4314: #include "memory/allocation.hpp" twisti@2047: twisti@2047: using namespace llvm; twisti@2047: twisti@2047: SharkContext::SharkContext(const char* name) twisti@2047: : LLVMContext(), twisti@2047: _free_queue(NULL) { twisti@2047: // Create a module to build our functions into twisti@2047: _module = new Module(name, *this); twisti@2047: twisti@2047: // Create basic types twisti@2047: _void_type = Type::getVoidTy(*this); twisti@2047: _bit_type = Type::getInt1Ty(*this); twisti@2047: _jbyte_type = Type::getInt8Ty(*this); twisti@2047: _jshort_type = Type::getInt16Ty(*this); twisti@2047: _jint_type = Type::getInt32Ty(*this); twisti@2047: _jlong_type = Type::getInt64Ty(*this); twisti@2047: _jfloat_type = Type::getFloatTy(*this); twisti@2047: _jdouble_type = Type::getDoubleTy(*this); twisti@2047: twisti@2047: // Create compound types twisti@2047: _itableOffsetEntry_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), itableOffsetEntry::size() * wordSize)); twisti@2047: twisti@4314: _Metadata_type = PointerType::getUnqual( twisti@4314: ArrayType::get(jbyte_type(), sizeof(Metadata))); twisti@4314: twisti@2047: _klass_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(Klass))); twisti@2047: twisti@2047: _jniEnv_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(JNIEnv))); twisti@2047: twisti@2047: _jniHandleBlock_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(JNIHandleBlock))); twisti@2047: twisti@4314: _Method_type = PointerType::getUnqual( coleenp@4037: ArrayType::get(jbyte_type(), sizeof(Method))); twisti@2047: twisti@2047: _monitor_type = ArrayType::get( twisti@2047: jbyte_type(), frame::interpreter_frame_monitor_size() * wordSize); twisti@2047: twisti@2047: _oop_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(oopDesc))); twisti@2047: twisti@2047: _thread_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(JavaThread))); twisti@2047: twisti@2047: _zeroStack_type = PointerType::getUnqual( twisti@2047: ArrayType::get(jbyte_type(), sizeof(ZeroStack))); twisti@2047: twisti@4314: std::vector params; twisti@4314: params.push_back(Method_type()); twisti@2047: params.push_back(intptr_type()); twisti@2047: params.push_back(thread_type()); twisti@2047: _entry_point_type = FunctionType::get(jint_type(), params, false); twisti@2047: twisti@2047: params.clear(); twisti@4314: params.push_back(Method_type()); twisti@2047: params.push_back(PointerType::getUnqual(jbyte_type())); twisti@2047: params.push_back(intptr_type()); twisti@2047: params.push_back(thread_type()); twisti@2047: _osr_entry_point_type = FunctionType::get(jint_type(), params, false); twisti@2047: twisti@2047: // Create mappings twisti@2047: for (int i = 0; i < T_CONFLICT; i++) { twisti@2047: switch (i) { twisti@2047: case T_BOOLEAN: twisti@2047: _to_stackType[i] = jint_type(); twisti@2047: _to_arrayType[i] = jbyte_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_BYTE: twisti@2047: _to_stackType[i] = jint_type(); twisti@2047: _to_arrayType[i] = jbyte_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_CHAR: twisti@2047: _to_stackType[i] = jint_type(); twisti@2047: _to_arrayType[i] = jshort_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_SHORT: twisti@2047: _to_stackType[i] = jint_type(); twisti@2047: _to_arrayType[i] = jshort_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_INT: twisti@2047: _to_stackType[i] = jint_type(); twisti@2047: _to_arrayType[i] = jint_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_LONG: twisti@2047: _to_stackType[i] = jlong_type(); twisti@2047: _to_arrayType[i] = jlong_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_FLOAT: twisti@2047: _to_stackType[i] = jfloat_type(); twisti@2047: _to_arrayType[i] = jfloat_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_DOUBLE: twisti@2047: _to_stackType[i] = jdouble_type(); twisti@2047: _to_arrayType[i] = jdouble_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_OBJECT: twisti@2047: case T_ARRAY: twisti@2047: _to_stackType[i] = oop_type(); twisti@2047: _to_arrayType[i] = oop_type(); twisti@2047: break; twisti@2047: twisti@2047: case T_ADDRESS: twisti@2047: _to_stackType[i] = intptr_type(); twisti@2047: _to_arrayType[i] = NULL; twisti@2047: break; twisti@2047: twisti@2047: default: twisti@2047: _to_stackType[i] = NULL; twisti@2047: _to_arrayType[i] = NULL; twisti@2047: } twisti@2047: } twisti@2047: } twisti@2047: twisti@4314: class SharkFreeQueueItem : public CHeapObj { twisti@2047: public: twisti@2047: SharkFreeQueueItem(llvm::Function* function, SharkFreeQueueItem *next) twisti@2047: : _function(function), _next(next) {} twisti@2047: twisti@2047: private: twisti@2047: llvm::Function* _function; twisti@2047: SharkFreeQueueItem* _next; twisti@2047: twisti@2047: public: twisti@2047: llvm::Function* function() const { twisti@2047: return _function; twisti@2047: } twisti@2047: SharkFreeQueueItem* next() const { twisti@2047: return _next; twisti@2047: } twisti@2047: }; twisti@2047: twisti@2047: void SharkContext::push_to_free_queue(Function* function) { twisti@2047: _free_queue = new SharkFreeQueueItem(function, _free_queue); twisti@2047: } twisti@2047: twisti@2047: Function* SharkContext::pop_from_free_queue() { twisti@2047: if (_free_queue == NULL) twisti@2047: return NULL; twisti@2047: twisti@2047: SharkFreeQueueItem *item = _free_queue; twisti@2047: Function *function = item->function(); twisti@2047: _free_queue = item->next(); twisti@2047: delete item; twisti@2047: return function; twisti@2047: }