sharkMemoryManager.hpp revision 1612
2934N/A/*
2934N/A * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
2934N/A * Copyright 2009 Red Hat, Inc.
2934N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2934N/A *
2934N/A * This code is free software; you can redistribute it and/or modify it
2934N/A * under the terms of the GNU General Public License version 2 only, as
2934N/A * published by the Free Software Foundation.
2934N/A *
2934N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2934N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2934N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2934N/A * version 2 for more details (a copy is included in the LICENSE file that
2934N/A * accompanied this code).
2934N/A *
2934N/A * You should have received a copy of the GNU General Public License version
2934N/A * 2 along with this work; if not, write to the Free Software Foundation,
2934N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2934N/A *
2934N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2934N/A * or visit www.oracle.com if you need additional information or have any
2934N/A * questions.
2934N/A *
2934N/A */
2934N/A
2935N/A// SharkMemoryManager wraps the LLVM JIT Memory Manager. We could use
2934N/A// this to run our own memory allocation policies, but for now all we
2934N/A// use it for is figuring out where the resulting native code ended up.
2934N/A
2934N/Aclass SharkMemoryManager : public llvm::JITMemoryManager {
2934N/A public:
2934N/A SharkMemoryManager()
2934N/A : _mm(llvm::JITMemoryManager::CreateDefaultMemManager()) {}
2934N/A
2934N/A private:
2934N/A llvm::JITMemoryManager* _mm;
2934N/A
2934N/A private:
2934N/A llvm::JITMemoryManager* mm() const {
2935N/A return _mm;
2934N/A }
2934N/A
2934N/A private:
2934N/A std::map<const llvm::Function*, SharkEntry*> _entry_map;
2934N/A
2934N/A public:
2934N/A void set_entry_for_function(const llvm::Function* function,
2934N/A SharkEntry* entry) {
2934N/A _entry_map[function] = entry;
2934N/A }
2934N/A SharkEntry* get_entry_for_function(const llvm::Function* function) {
2934N/A return _entry_map[function];
2934N/A }
2934N/A
2934N/A public:
2934N/A void AllocateGOT();
2934N/A unsigned char* getGOTBase() const;
2934N/A unsigned char* allocateStub(const llvm::GlobalValue* F,
2934N/A unsigned StubSize,
2934N/A unsigned Alignment);
2934N/A unsigned char* startFunctionBody(const llvm::Function* F,
2934N/A uintptr_t& ActualSize);
2934N/A void endFunctionBody(const llvm::Function* F,
2934N/A unsigned char* FunctionStart,
2934N/A unsigned char* FunctionEnd);
2934N/A unsigned char* startExceptionTable(const llvm::Function* F,
2934N/A uintptr_t& ActualSize);
2934N/A void endExceptionTable(const llvm::Function* F,
2934N/A unsigned char* TableStart,
2934N/A unsigned char* TableEnd,
2934N/A unsigned char* FrameRegister);
2934N/A#if SHARK_LLVM_VERSION < 27
2935N/A void* getDlsymTable() const;
2935N/A void SetDlsymTable(void *ptr);
2935N/A#endif
2935N/A void setPoisonMemory(bool);
2935N/A uint8_t* allocateGlobal(uintptr_t, unsigned int);
2935N/A void setMemoryWritable();
2935N/A void setMemoryExecutable();
2935N/A#if SHARK_LLVM_VERSION >= 27
2935N/A void deallocateExceptionTable(void *ptr);
2935N/A void deallocateFunctionBody(void *ptr);
2935N/A#else
2935N/A void deallocateMemForFunction(const llvm::Function* F);
2935N/A#endif
2935N/A unsigned char *allocateSpace(intptr_t Size,
2935N/A unsigned int Alignment);
2935N/A};
2935N/A