annotate hotspot/src/share/vm/utilities/elfStringTable.cpp @ 46545:b970b6e40209

8181450: assert in BasicHashtable::verify_table Summary: remove assert as it has small probability of happening and added logging Reviewed-by: kbarrett, sspitsyn
author coleenp
date Fri, 16 Jun 2017 09:13:56 -0400
parents e5b53c306fb5
children 388aa8d67c80
rev   line source
zgu@7447 1 /*
simonis@22857 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
zgu@7447 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@7447 4 *
zgu@7447 5 * This code is free software; you can redistribute it and/or modify it
zgu@7447 6 * under the terms of the GNU General Public License version 2 only, as
zgu@7447 7 * published by the Free Software Foundation.
zgu@7447 8 *
zgu@7447 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@7447 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@7447 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@7447 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@7447 13 * accompanied this code).
zgu@7447 14 *
zgu@7447 15 * You should have received a copy of the GNU General Public License version
zgu@7447 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@7447 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@7447 18 *
zgu@7447 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@7447 20 * or visit www.oracle.com if you need additional information or have any
zgu@7447 21 * questions.
zgu@7447 22 *
zgu@7447 23 */
zgu@7447 24
zgu@7447 25 #include "precompiled.hpp"
zgu@7447 26
never@10565 27 #if !defined(_WINDOWS) && !defined(__APPLE__)
zgu@7447 28
zgu@7447 29 #include "memory/allocation.inline.hpp"
zgu@9403 30 #include "runtime/os.hpp"
zgu@7447 31 #include "utilities/elfStringTable.hpp"
zgu@7447 32
zgu@7447 33 // We will try to load whole string table into memory if we can.
zgu@7447 34 // Otherwise, fallback to more expensive file operation.
zgu@7447 35 ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) {
zgu@7447 36 assert(file, "null file handle");
zgu@7447 37 m_table = NULL;
zgu@7447 38 m_index = index;
zgu@7447 39 m_next = NULL;
zgu@7447 40 m_file = file;
zgu@11483 41 m_status = NullDecoder::no_error;
zgu@7447 42
zgu@7447 43 // try to load the string table
zgu@7447 44 long cur_offset = ftell(file);
zgu@13195 45 m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size, mtInternal);
zgu@7447 46 if (m_table != NULL) {
zgu@7447 47 // if there is an error, mark the error
zgu@7447 48 if (fseek(file, shdr.sh_offset, SEEK_SET) ||
zgu@7447 49 fread((void*)m_table, shdr.sh_size, 1, file) != 1 ||
zgu@7447 50 fseek(file, cur_offset, SEEK_SET)) {
zgu@11483 51 m_status = NullDecoder::file_invalid;
zgu@9403 52 os::free((void*)m_table);
zgu@7447 53 m_table = NULL;
zgu@7447 54 }
zgu@7447 55 } else {
zgu@7447 56 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr));
zgu@7447 57 }
zgu@7447 58 }
zgu@7447 59
zgu@7447 60 ElfStringTable::~ElfStringTable() {
zgu@7447 61 if (m_table != NULL) {
zgu@9403 62 os::free((void*)m_table);
zgu@7447 63 }
zgu@7447 64
zgu@7447 65 if (m_next != NULL) {
zgu@7447 66 delete m_next;
zgu@7447 67 }
zgu@7447 68 }
zgu@7447 69
zgu@11483 70 bool ElfStringTable::string_at(int pos, char* buf, int buflen) {
zgu@11483 71 if (NullDecoder::is_error(m_status)) {
zgu@11483 72 return false;
zgu@7447 73 }
zgu@7447 74 if (m_table != NULL) {
zgu@11483 75 jio_snprintf(buf, buflen, "%s", (const char*)(m_table + pos));
zgu@11483 76 return true;
zgu@7447 77 } else {
zgu@7447 78 long cur_pos = ftell(m_file);
zgu@7447 79 if (cur_pos == -1 ||
zgu@7447 80 fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) ||
zgu@11483 81 fread(buf, 1, buflen, m_file) <= 0 ||
zgu@7447 82 fseek(m_file, cur_pos, SEEK_SET)) {
zgu@11483 83 m_status = NullDecoder::file_invalid;
zgu@11483 84 return false;
zgu@7447 85 }
zgu@11483 86 return true;
zgu@7447 87 }
zgu@7447 88 }
zgu@7447 89
simonis@22857 90 #endif // !_WINDOWS && !__APPLE__