src/share/vm/utilities/elfFile.hpp

Thu, 28 Jun 2012 17:03:16 -0400

author
zgu
date
Thu, 28 Jun 2012 17:03:16 -0400
changeset 3900
d2a62e0f25eb
parent 3430
d7e3846464d0
child 4153
b9a9ed0f8eeb
permissions
-rw-r--r--

6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain

zgu@2364 1 /*
zgu@3430 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
zgu@2364 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@2364 4 *
zgu@2364 5 * This code is free software; you can redistribute it and/or modify it
zgu@2364 6 * under the terms of the GNU General Public License version 2 only, as
zgu@2364 7 * published by the Free Software Foundation.
zgu@2364 8 *
zgu@2364 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@2364 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@2364 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@2364 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@2364 13 * accompanied this code).
zgu@2364 14 *
zgu@2364 15 * You should have received a copy of the GNU General Public License version
zgu@2364 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@2364 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@2364 18 *
zgu@2364 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@2364 20 * or visit www.oracle.com if you need additional information or have any
zgu@2364 21 * questions.
zgu@2364 22 *
zgu@2364 23 */
zgu@2364 24
zgu@3430 25 #ifndef SHARE_VM_UTILITIES_ELF_FILE_HPP
zgu@3430 26 #define SHARE_VM_UTILITIES_ELF_FILE_HPP
zgu@2364 27
never@3156 28 #if !defined(_WINDOWS) && !defined(__APPLE__)
zgu@2364 29
never@3156 30 #if defined(__OpenBSD__)
never@3156 31 #include <sys/exec_elf.h>
never@3156 32 #else
zgu@2364 33 #include <elf.h>
never@3156 34 #endif
zgu@2364 35 #include <stdio.h>
zgu@2364 36
zgu@2364 37 #ifdef _LP64
zgu@2364 38
zgu@2364 39 typedef Elf64_Half Elf_Half;
zgu@2364 40 typedef Elf64_Word Elf_Word;
zgu@2364 41 typedef Elf64_Off Elf_Off;
zgu@2364 42 typedef Elf64_Addr Elf_Addr;
zgu@2364 43
zgu@2364 44 typedef Elf64_Ehdr Elf_Ehdr;
zgu@2364 45 typedef Elf64_Shdr Elf_Shdr;
zgu@2364 46 typedef Elf64_Sym Elf_Sym;
zgu@2364 47
never@3156 48 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
zgu@2364 49 #define ELF_ST_TYPE ELF64_ST_TYPE
never@3156 50 #endif
zgu@2364 51
zgu@2364 52 #else
zgu@2364 53
zgu@2364 54 typedef Elf32_Half Elf_Half;
zgu@2364 55 typedef Elf32_Word Elf_Word;
zgu@2364 56 typedef Elf32_Off Elf_Off;
zgu@2364 57 typedef Elf32_Addr Elf_Addr;
zgu@2364 58
zgu@2364 59
zgu@2364 60 typedef Elf32_Ehdr Elf_Ehdr;
zgu@2364 61 typedef Elf32_Shdr Elf_Shdr;
zgu@2364 62 typedef Elf32_Sym Elf_Sym;
zgu@2364 63
never@3156 64 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
zgu@2364 65 #define ELF_ST_TYPE ELF32_ST_TYPE
zgu@2364 66 #endif
never@3156 67 #endif
zgu@2364 68
zgu@2364 69 #include "globalDefinitions.hpp"
zgu@2364 70 #include "memory/allocation.hpp"
zgu@2364 71 #include "utilities/decoder.hpp"
zgu@2364 72
zgu@2364 73
zgu@2364 74 class ElfStringTable;
zgu@2364 75 class ElfSymbolTable;
zgu@2364 76
zgu@2364 77
zgu@2364 78 // On Solaris/Linux platforms, libjvm.so does contain all private symbols.
zgu@2364 79 // ElfFile is basically an elf file parser, which can lookup the symbol
zgu@2364 80 // that is the nearest to the given address.
zgu@2364 81 // Beware, this code is called from vm error reporting code, when vm is already
zgu@2364 82 // in "error" state, so there are scenarios, lookup will fail. We want this
zgu@2364 83 // part of code to be very defensive, and bait out if anything went wrong.
zgu@2364 84
zgu@3900 85 class ElfFile: public CHeapObj<mtInternal> {
zgu@3430 86 friend class ElfDecoder;
zgu@2364 87 public:
zgu@2364 88 ElfFile(const char* filepath);
zgu@2364 89 ~ElfFile();
zgu@2364 90
zgu@3430 91 bool decode(address addr, char* buf, int buflen, int* offset);
zgu@2364 92 const char* filepath() {
zgu@2364 93 return m_filepath;
zgu@2364 94 }
zgu@2364 95
zgu@2364 96 bool same_elf_file(const char* filepath) {
zgu@2364 97 assert(filepath, "null file path");
zgu@2364 98 assert(m_filepath, "already out of memory");
zgu@2364 99 return (m_filepath && !strcmp(filepath, m_filepath));
zgu@2364 100 }
zgu@2364 101
zgu@3430 102 NullDecoder::decoder_status get_status() {
zgu@2364 103 return m_status;
zgu@2364 104 }
zgu@2364 105
zgu@2364 106 private:
zgu@2364 107 // sanity check, if the file is a real elf file
zgu@2364 108 bool is_elf_file(Elf_Ehdr&);
zgu@2364 109
zgu@2364 110 // load string tables from the elf file
zgu@2364 111 bool load_tables();
zgu@2364 112
zgu@2364 113 // string tables are stored in a linked list
zgu@2364 114 void add_string_table(ElfStringTable* table);
zgu@2364 115
zgu@2364 116 // symbol tables are stored in a linked list
zgu@2364 117 void add_symbol_table(ElfSymbolTable* table);
zgu@2364 118
zgu@2364 119 // return a string table at specified section index
zgu@2364 120 ElfStringTable* get_string_table(int index);
zgu@2364 121
zgu@3430 122 protected:
zgu@3430 123 ElfFile* next() const { return m_next; }
zgu@3430 124 void set_next(ElfFile* file) { m_next = file; }
zgu@2364 125
zgu@2364 126 protected:
zgu@2364 127 ElfFile* m_next;
zgu@2364 128
zgu@2364 129 private:
zgu@2364 130 // file
zgu@2364 131 const char* m_filepath;
zgu@2364 132 FILE* m_file;
zgu@2364 133
zgu@2364 134 // Elf header
zgu@3430 135 Elf_Ehdr m_elfHdr;
zgu@2364 136
zgu@2364 137 // symbol tables
zgu@3430 138 ElfSymbolTable* m_symbol_tables;
zgu@2364 139
zgu@2364 140 // string tables
zgu@3430 141 ElfStringTable* m_string_tables;
zgu@2364 142
zgu@3430 143 NullDecoder::decoder_status m_status;
zgu@2364 144 };
zgu@2364 145
zgu@2364 146 #endif // _WINDOWS
zgu@2364 147
zgu@3430 148 #endif // SHARE_VM_UTILITIES_ELF_FILE_HPP

mercurial