1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkMemoryManager.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2009 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 +#ifndef SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP 1.30 +#define SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP 1.31 + 1.32 +#include "shark/llvmHeaders.hpp" 1.33 +#include "shark/sharkEntry.hpp" 1.34 + 1.35 +// SharkMemoryManager wraps the LLVM JIT Memory Manager. We could use 1.36 +// this to run our own memory allocation policies, but for now all we 1.37 +// use it for is figuring out where the resulting native code ended up. 1.38 + 1.39 +class SharkMemoryManager : public llvm::JITMemoryManager { 1.40 + public: 1.41 + SharkMemoryManager() 1.42 + : _mm(llvm::JITMemoryManager::CreateDefaultMemManager()) {} 1.43 + 1.44 + private: 1.45 + llvm::JITMemoryManager* _mm; 1.46 + 1.47 + private: 1.48 + llvm::JITMemoryManager* mm() const { 1.49 + return _mm; 1.50 + } 1.51 + 1.52 + private: 1.53 + std::map<const llvm::Function*, SharkEntry*> _entry_map; 1.54 + 1.55 + public: 1.56 + void set_entry_for_function(const llvm::Function* function, 1.57 + SharkEntry* entry) { 1.58 + _entry_map[function] = entry; 1.59 + } 1.60 + SharkEntry* get_entry_for_function(const llvm::Function* function) { 1.61 + return _entry_map[function]; 1.62 + } 1.63 + 1.64 + public: 1.65 + void AllocateGOT(); 1.66 + unsigned char* getGOTBase() const; 1.67 + unsigned char* allocateStub(const llvm::GlobalValue* F, 1.68 + unsigned StubSize, 1.69 + unsigned Alignment); 1.70 + unsigned char* startFunctionBody(const llvm::Function* F, 1.71 + uintptr_t& ActualSize); 1.72 + void endFunctionBody(const llvm::Function* F, 1.73 + unsigned char* FunctionStart, 1.74 + unsigned char* FunctionEnd); 1.75 + 1.76 + void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true); 1.77 + void setPoisonMemory(bool); 1.78 + uint8_t* allocateGlobal(uintptr_t, unsigned int); 1.79 + void setMemoryWritable(); 1.80 + void setMemoryExecutable(); 1.81 + void deallocateFunctionBody(void *ptr); 1.82 + unsigned char *allocateSpace(intptr_t Size, 1.83 + unsigned int Alignment); 1.84 + 1.85 +#if SHARK_LLVM_VERSION <= 32 1.86 +uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); 1.87 +uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); 1.88 +unsigned char* startExceptionTable(const llvm::Function* F, 1.89 + uintptr_t& ActualSize); 1.90 +void deallocateExceptionTable(void *ptr); 1.91 +void endExceptionTable(const llvm::Function* F, 1.92 + unsigned char* TableStart, 1.93 + unsigned char* TableEnd, 1.94 + unsigned char* FrameRegister); 1.95 +#else 1.96 +uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName); 1.97 +uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName, bool IsReadOnly); 1.98 +bool finalizeMemory(std::string *ErrMsg = 0); 1.99 +#endif 1.100 + 1.101 +}; 1.102 + 1.103 +#endif // SHARE_VM_SHARK_SHARKMEMORYMANAGER_HPP