1612N/A/*
1879N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1612N/A * Copyright 2009 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#ifndef SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP
1879N/A#define SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP
1879N/A
1879N/A#include "shark/llvmHeaders.hpp"
1879N/A#include "shark/sharkEntry.hpp"
1879N/A
1612N/A// SharkMemoryManager wraps the LLVM JIT Memory Manager. We could use
1612N/A// this to run our own memory allocation policies, but for now all we
1612N/A// use it for is figuring out where the resulting native code ended up.
1612N/A
1612N/Aclass SharkMemoryManager : public llvm::JITMemoryManager {
1612N/A public:
1612N/A SharkMemoryManager()
1612N/A : _mm(llvm::JITMemoryManager::CreateDefaultMemManager()) {}
1612N/A
1612N/A private:
1612N/A llvm::JITMemoryManager* _mm;
1612N/A
1612N/A private:
1612N/A llvm::JITMemoryManager* mm() const {
1612N/A return _mm;
1612N/A }
1612N/A
1612N/A private:
1612N/A std::map<const llvm::Function*, SharkEntry*> _entry_map;
1612N/A
1612N/A public:
1612N/A void set_entry_for_function(const llvm::Function* function,
1612N/A SharkEntry* entry) {
1612N/A _entry_map[function] = entry;
1612N/A }
1612N/A SharkEntry* get_entry_for_function(const llvm::Function* function) {
1612N/A return _entry_map[function];
1612N/A }
1612N/A
1612N/A public:
1612N/A void AllocateGOT();
1612N/A unsigned char* getGOTBase() const;
1612N/A unsigned char* allocateStub(const llvm::GlobalValue* F,
1612N/A unsigned StubSize,
1612N/A unsigned Alignment);
1612N/A unsigned char* startFunctionBody(const llvm::Function* F,
1612N/A uintptr_t& ActualSize);
1612N/A void endFunctionBody(const llvm::Function* F,
1612N/A unsigned char* FunctionStart,
1612N/A unsigned char* FunctionEnd);
1612N/A unsigned char* startExceptionTable(const llvm::Function* F,
1612N/A uintptr_t& ActualSize);
1612N/A void endExceptionTable(const llvm::Function* F,
1612N/A unsigned char* TableStart,
1612N/A unsigned char* TableEnd,
1612N/A unsigned char* FrameRegister);
1612N/A#if SHARK_LLVM_VERSION < 27
1612N/A void* getDlsymTable() const;
1612N/A void SetDlsymTable(void *ptr);
1612N/A#endif
1612N/A void setPoisonMemory(bool);
1612N/A uint8_t* allocateGlobal(uintptr_t, unsigned int);
1612N/A void setMemoryWritable();
1612N/A void setMemoryExecutable();
1612N/A#if SHARK_LLVM_VERSION >= 27
1612N/A void deallocateExceptionTable(void *ptr);
1612N/A void deallocateFunctionBody(void *ptr);
1612N/A#else
1612N/A void deallocateMemForFunction(const llvm::Function* F);
1612N/A#endif
1612N/A unsigned char *allocateSpace(intptr_t Size,
1612N/A unsigned int Alignment);
1612N/A};
1879N/A
1879N/A#endif // SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP