Mercurial > hg > truffle
annotate src/share/vm/utilities/elfFuncDescTable.cpp @ 17977:0b9500028980
8029381: assert(is_method_type()) failed: bad cast
Summary: Access to method_type and appendix from constant pool (cpcache) needs to be guarded by is_f1_null() because of racy update/initialization.
Reviewed-by: kvn, coleenp, jrose
author | drchase |
---|---|
date | Mon, 02 Jun 2014 14:32:29 -0400 |
parents | e7cbc95179c4 |
children |
rev | line source |
---|---|
14441
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
1 /* |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
3 * Copyright 2012, 2013 SAP AG. All rights reserved. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
5 * |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
6 * This code is free software; you can redistribute it and/or modify it |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
7 * under the terms of the GNU General Public License version 2 only, as |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
8 * published by the Free Software Foundation. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
9 * |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
14 * accompanied this code). |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
15 * |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License version |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
19 * |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
21 * or visit www.oracle.com if you need additional information or have any |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
22 * questions. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
23 * |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
24 */ |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
25 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
26 #include "precompiled.hpp" |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
27 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
28 #if !defined(_WINDOWS) && !defined(__APPLE__) |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
29 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
30 #include "memory/allocation.inline.hpp" |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
31 #include "utilities/elfFuncDescTable.hpp" |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
32 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
33 ElfFuncDescTable::ElfFuncDescTable(FILE* file, Elf_Shdr shdr, int index) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
34 assert(file, "null file handle"); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
35 // The actual function address (i.e. function entry point) is always the |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
36 // first value in the function descriptor (on IA64 and PPC64 they look as follows): |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
37 // PPC64: [function entry point, TOC pointer, environment pointer] |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
38 // IA64 : [function entry point, GP (global pointer) value] |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
39 // Unfortunately 'shdr.sh_entsize' doesn't always seem to contain this size (it's zero on PPC64) so we can't assert |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
40 // assert(IA64_ONLY(2) PPC64_ONLY(3) * sizeof(address) == shdr.sh_entsize, "Size mismatch for '.opd' section entries"); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
41 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
42 m_funcDescs = NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
43 m_file = file; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
44 m_index = index; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
45 m_status = NullDecoder::no_error; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
46 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
47 // try to load the function descriptor table |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
48 long cur_offset = ftell(file); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
49 if (cur_offset != -1) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
50 // call malloc so we can back up if memory allocation fails. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
51 m_funcDescs = (address*)os::malloc(shdr.sh_size, mtInternal); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
52 if (m_funcDescs) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
53 if (fseek(file, shdr.sh_offset, SEEK_SET) || |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
54 fread((void*)m_funcDescs, shdr.sh_size, 1, file) != 1 || |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
55 fseek(file, cur_offset, SEEK_SET)) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
56 m_status = NullDecoder::file_invalid; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
57 os::free(m_funcDescs); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
58 m_funcDescs = NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
59 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
60 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
61 if (!NullDecoder::is_error(m_status)) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
62 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
63 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
64 } else { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
65 m_status = NullDecoder::file_invalid; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
66 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
67 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
68 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
69 ElfFuncDescTable::~ElfFuncDescTable() { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
70 if (m_funcDescs != NULL) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
71 os::free(m_funcDescs); |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
72 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
73 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
74 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
75 address ElfFuncDescTable::lookup(Elf_Word index) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
76 if (NullDecoder::is_error(m_status)) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
77 return NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
78 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
79 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
80 if (m_funcDescs != NULL) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
81 if (m_shdr.sh_size > 0 && m_shdr.sh_addr <= index && index <= m_shdr.sh_addr + m_shdr.sh_size) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
82 // Notice that 'index' is a byte-offset into the function descriptor table. |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
83 return m_funcDescs[(index - m_shdr.sh_addr) / sizeof(address)]; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
84 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
85 return NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
86 } else { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
87 long cur_pos; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
88 address addr; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
89 if (!(m_shdr.sh_size > 0 && m_shdr.sh_addr <= index && index <= m_shdr.sh_addr + m_shdr.sh_size)) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
90 // don't put the whole decoder in error mode if we just tried a wrong index |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
91 return NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
92 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
93 if ((cur_pos = ftell(m_file)) == -1 || |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
94 fseek(m_file, m_shdr.sh_offset + index - m_shdr.sh_addr, SEEK_SET) || |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
95 fread(&addr, sizeof(addr), 1, m_file) != 1 || |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
96 fseek(m_file, cur_pos, SEEK_SET)) { |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
97 m_status = NullDecoder::file_invalid; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
98 return NULL; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
99 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
100 return addr; |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
101 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
102 } |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
103 |
e7cbc95179c4
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff
changeset
|
104 #endif // !_WINDOWS && !__APPLE__ |