comparison src/share/vm/utilities/elfFile.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
27 #ifndef _WINDOWS 27 #ifndef _WINDOWS
28 28
29 #include <string.h> 29 #include <string.h>
30 #include <stdio.h> 30 #include <stdio.h>
31 #include <limits.h> 31 #include <limits.h>
32 #include <new>
32 33
33 #include "memory/allocation.inline.hpp" 34 #include "memory/allocation.inline.hpp"
34 #include "utilities/decoder.hpp" 35 #include "utilities/decoder.hpp"
35 #include "utilities/elfFile.hpp" 36 #include "utilities/elfFile.hpp"
36 #include "utilities/elfStringTable.hpp" 37 #include "utilities/elfStringTable.hpp"
44 m_symbol_tables = NULL; 45 m_symbol_tables = NULL;
45 m_next = NULL; 46 m_next = NULL;
46 m_status = Decoder::no_error; 47 m_status = Decoder::no_error;
47 48
48 int len = strlen(filepath) + 1; 49 int len = strlen(filepath) + 1;
49 m_filepath = NEW_C_HEAP_ARRAY(char, len); 50 m_filepath = (const char*)os::malloc(len * sizeof(char));
50 if (m_filepath != NULL) { 51 if (m_filepath != NULL) {
51 strcpy((char*)m_filepath, filepath); 52 strcpy((char*)m_filepath, filepath);
52 m_file = fopen(filepath, "r"); 53 m_file = fopen(filepath, "r");
53 if (m_file != NULL) { 54 if (m_file != NULL) {
54 load_tables(); 55 load_tables();
72 if (m_file != NULL) { 73 if (m_file != NULL) {
73 fclose(m_file); 74 fclose(m_file);
74 } 75 }
75 76
76 if (m_filepath != NULL) { 77 if (m_filepath != NULL) {
77 FREE_C_HEAP_ARRAY(char, m_filepath); 78 os::free((void*)m_filepath);
78 } 79 }
79 80
80 if (m_next != NULL) { 81 if (m_next != NULL) {
81 delete m_next; 82 delete m_next;
82 } 83 }
118 m_status = Decoder::file_invalid; 119 m_status = Decoder::file_invalid;
119 return false; 120 return false;
120 } 121 }
121 // string table 122 // string table
122 if (shdr.sh_type == SHT_STRTAB) { 123 if (shdr.sh_type == SHT_STRTAB) {
123 ElfStringTable* table = new ElfStringTable(m_file, shdr, index); 124 ElfStringTable* table = new (std::nothrow) ElfStringTable(m_file, shdr, index);
124 if (table == NULL) { 125 if (table == NULL) {
125 m_status = Decoder::out_of_memory; 126 m_status = Decoder::out_of_memory;
126 return false; 127 return false;
127 } 128 }
128 add_string_table(table); 129 add_string_table(table);
129 } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) { 130 } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
130 ElfSymbolTable* table = new ElfSymbolTable(m_file, shdr); 131 ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(m_file, shdr);
131 if (table == NULL) { 132 if (table == NULL) {
132 m_status = Decoder::out_of_memory; 133 m_status = Decoder::out_of_memory;
133 return false; 134 return false;
134 } 135 }
135 add_symbol_table(table); 136 add_symbol_table(table);