src/share/vm/utilities/elfFile.hpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2364
2d4762ec74af
child 3156
f08d439fab8c
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

zgu@2364 1 /*
zgu@2364 2 * Copyright (c) 1997, 2010, 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@2364 25 #ifndef __ELF_FILE_HPP
zgu@2364 26 #define __ELF_FILE_HPP
zgu@2364 27
zgu@2364 28 #ifndef _WINDOWS
zgu@2364 29
zgu@2364 30 #include <elf.h>
zgu@2364 31 #include <stdio.h>
zgu@2364 32
zgu@2364 33 #ifdef _LP64
zgu@2364 34
zgu@2364 35 typedef Elf64_Half Elf_Half;
zgu@2364 36 typedef Elf64_Word Elf_Word;
zgu@2364 37 typedef Elf64_Off Elf_Off;
zgu@2364 38 typedef Elf64_Addr Elf_Addr;
zgu@2364 39
zgu@2364 40 typedef Elf64_Ehdr Elf_Ehdr;
zgu@2364 41 typedef Elf64_Shdr Elf_Shdr;
zgu@2364 42 typedef Elf64_Sym Elf_Sym;
zgu@2364 43
zgu@2364 44 #define ELF_ST_TYPE ELF64_ST_TYPE
zgu@2364 45
zgu@2364 46 #else
zgu@2364 47
zgu@2364 48 typedef Elf32_Half Elf_Half;
zgu@2364 49 typedef Elf32_Word Elf_Word;
zgu@2364 50 typedef Elf32_Off Elf_Off;
zgu@2364 51 typedef Elf32_Addr Elf_Addr;
zgu@2364 52
zgu@2364 53
zgu@2364 54 typedef Elf32_Ehdr Elf_Ehdr;
zgu@2364 55 typedef Elf32_Shdr Elf_Shdr;
zgu@2364 56 typedef Elf32_Sym Elf_Sym;
zgu@2364 57
zgu@2364 58 #define ELF_ST_TYPE ELF32_ST_TYPE
zgu@2364 59 #endif
zgu@2364 60
zgu@2364 61 #include "globalDefinitions.hpp"
zgu@2364 62 #include "memory/allocation.hpp"
zgu@2364 63 #include "utilities/decoder.hpp"
zgu@2364 64
zgu@2364 65
zgu@2364 66 class ElfStringTable;
zgu@2364 67 class ElfSymbolTable;
zgu@2364 68
zgu@2364 69
zgu@2364 70 // On Solaris/Linux platforms, libjvm.so does contain all private symbols.
zgu@2364 71 // ElfFile is basically an elf file parser, which can lookup the symbol
zgu@2364 72 // that is the nearest to the given address.
zgu@2364 73 // Beware, this code is called from vm error reporting code, when vm is already
zgu@2364 74 // in "error" state, so there are scenarios, lookup will fail. We want this
zgu@2364 75 // part of code to be very defensive, and bait out if anything went wrong.
zgu@2364 76
zgu@2364 77 class ElfFile: public CHeapObj {
zgu@2364 78 friend class Decoder;
zgu@2364 79 public:
zgu@2364 80 ElfFile(const char* filepath);
zgu@2364 81 ~ElfFile();
zgu@2364 82
zgu@2364 83 const char* decode(address addr, int* offset);
zgu@2364 84 const char* filepath() {
zgu@2364 85 return m_filepath;
zgu@2364 86 }
zgu@2364 87
zgu@2364 88 bool same_elf_file(const char* filepath) {
zgu@2364 89 assert(filepath, "null file path");
zgu@2364 90 assert(m_filepath, "already out of memory");
zgu@2364 91 return (m_filepath && !strcmp(filepath, m_filepath));
zgu@2364 92 }
zgu@2364 93
zgu@2364 94 Decoder::decoder_status get_status() {
zgu@2364 95 return m_status;
zgu@2364 96 }
zgu@2364 97
zgu@2364 98 private:
zgu@2364 99 // sanity check, if the file is a real elf file
zgu@2364 100 bool is_elf_file(Elf_Ehdr&);
zgu@2364 101
zgu@2364 102 // load string tables from the elf file
zgu@2364 103 bool load_tables();
zgu@2364 104
zgu@2364 105 // string tables are stored in a linked list
zgu@2364 106 void add_string_table(ElfStringTable* table);
zgu@2364 107
zgu@2364 108 // symbol tables are stored in a linked list
zgu@2364 109 void add_symbol_table(ElfSymbolTable* table);
zgu@2364 110
zgu@2364 111 // return a string table at specified section index
zgu@2364 112 ElfStringTable* get_string_table(int index);
zgu@2364 113
zgu@2364 114 // look up an address and return the nearest symbol
zgu@2364 115 const char* look_up(Elf_Shdr shdr, address addr, int* offset);
zgu@2364 116
zgu@2364 117 protected:
zgu@2364 118 ElfFile* m_next;
zgu@2364 119
zgu@2364 120 private:
zgu@2364 121 // file
zgu@2364 122 const char* m_filepath;
zgu@2364 123 FILE* m_file;
zgu@2364 124
zgu@2364 125 // Elf header
zgu@2364 126 Elf_Ehdr m_elfHdr;
zgu@2364 127
zgu@2364 128 // symbol tables
zgu@2364 129 ElfSymbolTable* m_symbol_tables;
zgu@2364 130
zgu@2364 131 // string tables
zgu@2364 132 ElfStringTable* m_string_tables;
zgu@2364 133
zgu@2364 134 Decoder::decoder_status m_status;
zgu@2364 135 };
zgu@2364 136
zgu@2364 137 #endif // _WINDOWS
zgu@2364 138
zgu@2364 139 #endif // __ELF_FILE_HPP
zgu@2364 140

mercurial