src/share/vm/utilities/elfFile.hpp

Mon, 03 Jan 2011 14:09:11 -0500

author
coleenp
date
Mon, 03 Jan 2011 14:09:11 -0500
changeset 2418
36c186bcc085
parent 2364
2d4762ec74af
child 3156
f08d439fab8c
permissions
-rw-r--r--

6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
Summary: enhance the error reporting mechanism to help user to fix the problem rather than making it look like a VM error.
Reviewed-by: kvn, kamg

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

mercurial