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