src/share/vm/utilities/elfStringTable.cpp

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 2834
2a3da7eaf4a6
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

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 #include "precompiled.hpp"
zgu@2364 26
zgu@2364 27 #ifndef _WINDOWS
zgu@2364 28
zgu@2364 29 #include "memory/allocation.inline.hpp"
zgu@2364 30 #include "utilities/elfStringTable.hpp"
zgu@2364 31
zgu@2364 32 // We will try to load whole string table into memory if we can.
zgu@2364 33 // Otherwise, fallback to more expensive file operation.
zgu@2364 34 ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) {
zgu@2364 35 assert(file, "null file handle");
zgu@2364 36 m_table = NULL;
zgu@2364 37 m_index = index;
zgu@2364 38 m_next = NULL;
zgu@2364 39 m_file = file;
zgu@2364 40 m_status = Decoder::no_error;
zgu@2364 41
zgu@2364 42 // try to load the string table
zgu@2364 43 long cur_offset = ftell(file);
zgu@2364 44 m_table = (char*)NEW_C_HEAP_ARRAY(char, shdr.sh_size);
zgu@2364 45 if (m_table != NULL) {
zgu@2364 46 // if there is an error, mark the error
zgu@2364 47 if (fseek(file, shdr.sh_offset, SEEK_SET) ||
zgu@2364 48 fread((void*)m_table, shdr.sh_size, 1, file) != 1 ||
zgu@2364 49 fseek(file, cur_offset, SEEK_SET)) {
zgu@2364 50 m_status = Decoder::file_invalid;
zgu@2364 51 FREE_C_HEAP_ARRAY(char, m_table);
zgu@2364 52 m_table = NULL;
zgu@2364 53 }
zgu@2364 54 } else {
zgu@2364 55 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr));
zgu@2364 56 }
zgu@2364 57 }
zgu@2364 58
zgu@2364 59 ElfStringTable::~ElfStringTable() {
zgu@2364 60 if (m_table != NULL) {
zgu@2364 61 FREE_C_HEAP_ARRAY(char, m_table);
zgu@2364 62 }
zgu@2364 63
zgu@2364 64 if (m_next != NULL) {
zgu@2364 65 delete m_next;
zgu@2364 66 }
zgu@2364 67 }
zgu@2364 68
zgu@2364 69 const char* ElfStringTable::string_at(int pos) {
zgu@2364 70 if (m_status != Decoder::no_error) {
zgu@2364 71 return NULL;
zgu@2364 72 }
zgu@2364 73 if (m_table != NULL) {
zgu@2364 74 return (const char*)(m_table + pos);
zgu@2364 75 } else {
zgu@2364 76 long cur_pos = ftell(m_file);
zgu@2364 77 if (cur_pos == -1 ||
zgu@2364 78 fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) ||
zgu@2364 79 fread(m_symbol, 1, MAX_SYMBOL_LEN, m_file) <= 0 ||
zgu@2364 80 fseek(m_file, cur_pos, SEEK_SET)) {
zgu@2364 81 m_status = Decoder::file_invalid;
zgu@2364 82 return NULL;
zgu@2364 83 }
zgu@2364 84 return (const char*)m_symbol;
zgu@2364 85 }
zgu@2364 86 }
zgu@2364 87
zgu@2364 88 #endif // _WINDOWS
zgu@2364 89

mercurial