Mercurial > hg > truffle
comparison src/share/vm/utilities/elfStringTable.cpp @ 3302:2a3da7eaf4a6
7036747: 7017009 reappeared, problem with ElfStringTable
Summary: Created new "new" operator for CHeapObj that allows malloc to fail without causing fatal error. Also replaced "HeapAllocate" with "os::malloc" in decoder code to allow decoder to handle low memory scenario.
Reviewed-by: coleenp, dholmes
author | zgu |
---|---|
date | Wed, 27 Apr 2011 09:09:57 -0400 |
parents | 2d4762ec74af |
children | f08d439fab8c |
comparison
equal
deleted
inserted
replaced
2477:3449f5e02cc4 | 3302:2a3da7eaf4a6 |
---|---|
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 | 26 |
27 #ifndef _WINDOWS | 27 #ifndef _WINDOWS |
28 | 28 |
29 #include "memory/allocation.inline.hpp" | 29 #include "memory/allocation.inline.hpp" |
30 #include "runtime/os.hpp" | |
30 #include "utilities/elfStringTable.hpp" | 31 #include "utilities/elfStringTable.hpp" |
31 | 32 |
32 // We will try to load whole string table into memory if we can. | 33 // We will try to load whole string table into memory if we can. |
33 // Otherwise, fallback to more expensive file operation. | 34 // Otherwise, fallback to more expensive file operation. |
34 ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) { | 35 ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) { |
39 m_file = file; | 40 m_file = file; |
40 m_status = Decoder::no_error; | 41 m_status = Decoder::no_error; |
41 | 42 |
42 // try to load the string table | 43 // try to load the string table |
43 long cur_offset = ftell(file); | 44 long cur_offset = ftell(file); |
44 m_table = (char*)NEW_C_HEAP_ARRAY(char, shdr.sh_size); | 45 m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size); |
45 if (m_table != NULL) { | 46 if (m_table != NULL) { |
46 // if there is an error, mark the error | 47 // if there is an error, mark the error |
47 if (fseek(file, shdr.sh_offset, SEEK_SET) || | 48 if (fseek(file, shdr.sh_offset, SEEK_SET) || |
48 fread((void*)m_table, shdr.sh_size, 1, file) != 1 || | 49 fread((void*)m_table, shdr.sh_size, 1, file) != 1 || |
49 fseek(file, cur_offset, SEEK_SET)) { | 50 fseek(file, cur_offset, SEEK_SET)) { |
50 m_status = Decoder::file_invalid; | 51 m_status = Decoder::file_invalid; |
51 FREE_C_HEAP_ARRAY(char, m_table); | 52 os::free((void*)m_table); |
52 m_table = NULL; | 53 m_table = NULL; |
53 } | 54 } |
54 } else { | 55 } else { |
55 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); | 56 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); |
56 } | 57 } |
57 } | 58 } |
58 | 59 |
59 ElfStringTable::~ElfStringTable() { | 60 ElfStringTable::~ElfStringTable() { |
60 if (m_table != NULL) { | 61 if (m_table != NULL) { |
61 FREE_C_HEAP_ARRAY(char, m_table); | 62 os::free((void*)m_table); |
62 } | 63 } |
63 | 64 |
64 if (m_next != NULL) { | 65 if (m_next != NULL) { |
65 delete m_next; | 66 delete m_next; |
66 } | 67 } |