annotate src/share/vm/utilities/elfSymbolTable.cpp @ 20543:e7d0505c8a30

8059758: Footprint regressions with JDK-8038423 Summary: Changes in JDK-8038423 always initialize (zero out) virtual memory used for auxiliary data structures. This causes a footprint regression for G1 in startup benchmarks. This is because they do not touch that memory at all, so the operating system does not actually commit these pages. The fix is to, if the initialization value of the data structures matches the default value of just committed memory (=0), do not do anything. Reviewed-by: jwilhelm, brutisso
author tschatzl
date Fri, 10 Oct 2014 15:51:58 +0200
parents e7cbc95179c4
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
1 /*
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
4 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
7 * published by the Free Software Foundation.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
8 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
13 * accompanied this code).
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
14 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
18 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
21 * questions.
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
22 *
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
23 */
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
24
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
25 #include "precompiled.hpp"
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
26
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2426
diff changeset
27 #if !defined(_WINDOWS) && !defined(__APPLE__)
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
28
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
29 #include "memory/allocation.inline.hpp"
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
30 #include "utilities/elfFuncDescTable.hpp"
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
31 #include "utilities/elfSymbolTable.hpp"
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
32
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
33 ElfSymbolTable::ElfSymbolTable(FILE* file, Elf_Shdr shdr) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
34 assert(file, "null file handle");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
35 m_symbols = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
36 m_next = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
37 m_file = file;
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
38 m_status = NullDecoder::no_error;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
39
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
40 // try to load the string table
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
41 long cur_offset = ftell(file);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
42 if (cur_offset != -1) {
2196
d28def44457d 7017009: Secondary out of c-heap memory error reporting out of memory
coleenp
parents: 2022
diff changeset
43 // call malloc so we can back up if memory allocation fails.
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4803
diff changeset
44 m_symbols = (Elf_Sym*)os::malloc(shdr.sh_size, mtInternal);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
45 if (m_symbols) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
46 if (fseek(file, shdr.sh_offset, SEEK_SET) ||
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
47 fread((void*)m_symbols, shdr.sh_size, 1, file) != 1 ||
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
48 fseek(file, cur_offset, SEEK_SET)) {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
49 m_status = NullDecoder::file_invalid;
2196
d28def44457d 7017009: Secondary out of c-heap memory error reporting out of memory
coleenp
parents: 2022
diff changeset
50 os::free(m_symbols);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
51 m_symbols = NULL;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
52 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
53 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
54 if (!NullDecoder::is_error(m_status)) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
55 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr));
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
56 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
57 } else {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
58 m_status = NullDecoder::file_invalid;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
59 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
60 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
61
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
62 ElfSymbolTable::~ElfSymbolTable() {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
63 if (m_symbols != NULL) {
2196
d28def44457d 7017009: Secondary out of c-heap memory error reporting out of memory
coleenp
parents: 2022
diff changeset
64 os::free(m_symbols);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
65 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
66
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
67 if (m_next != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
68 delete m_next;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
69 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
70 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
71
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
72 bool ElfSymbolTable::lookup(address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable) {
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
73 assert(stringtableIndex, "null string table index pointer");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
74 assert(posIndex, "null string table offset pointer");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
75 assert(offset, "null offset pointer");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
76
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
77 if (NullDecoder::is_error(m_status)) {
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
78 return false;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
79 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
80
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
81 size_t sym_size = sizeof(Elf_Sym);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
82 assert((m_shdr.sh_size % sym_size) == 0, "check size");
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
83 int count = m_shdr.sh_size / sym_size;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
84 if (m_symbols != NULL) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
85 for (int index = 0; index < count; index ++) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
86 if (STT_FUNC == ELF_ST_TYPE(m_symbols[index].st_info)) {
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
87 Elf_Word st_size = m_symbols[index].st_size;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
88 address sym_addr;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
89 if (funcDescTable != NULL && funcDescTable->get_index() == m_symbols[index].st_shndx) {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
90 // We need to go another step trough the function descriptor table (currently PPC64 only)
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
91 sym_addr = funcDescTable->lookup(m_symbols[index].st_value);
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
92 } else {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
93 sym_addr = (address)m_symbols[index].st_value;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
94 }
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
95 if (sym_addr <= addr && (Elf_Word)(addr - sym_addr) < st_size) {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
96 *offset = (int)(addr - sym_addr);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
97 *posIndex = m_symbols[index].st_name;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
98 *stringtableIndex = m_shdr.sh_link;
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
99 return true;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
100 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
101 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
102 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
103 } else {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
104 long cur_pos;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
105 if ((cur_pos = ftell(m_file)) == -1 ||
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
106 fseek(m_file, m_shdr.sh_offset, SEEK_SET)) {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
107 m_status = NullDecoder::file_invalid;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
108 return false;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
109 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
110
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
111 Elf_Sym sym;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
112 for (int index = 0; index < count; index ++) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
113 if (fread(&sym, sym_size, 1, m_file) == 1) {
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
114 if (STT_FUNC == ELF_ST_TYPE(sym.st_info)) {
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
115 Elf_Word st_size = sym.st_size;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
116 address sym_addr;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
117 if (funcDescTable != NULL && funcDescTable->get_index() == sym.st_shndx) {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
118 // We need to go another step trough the function descriptor table (currently PPC64 only)
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
119 sym_addr = funcDescTable->lookup(sym.st_value);
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
120 } else {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
121 sym_addr = (address)sym.st_value;
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
122 }
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
123 if (sym_addr <= addr && (Elf_Word)(addr - sym_addr) < st_size) {
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
124 *offset = (int)(addr - sym_addr);
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
125 *posIndex = sym.st_name;
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
126 *stringtableIndex = m_shdr.sh_link;
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
127 return true;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
128 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
129 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
130 } else {
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
131 m_status = NullDecoder::file_invalid;
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
132 return false;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
133 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
134 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
135 fseek(m_file, cur_pos, SEEK_SET);
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
136 }
4803
d7e3846464d0 7071311: Decoder enhancement
zgu
parents: 3960
diff changeset
137 return true;
2022
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
138 }
2d4762ec74af 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
139
14441
e7cbc95179c4 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 6842
diff changeset
140 #endif // !_WINDOWS && !__APPLE__