提交 2c79479b 编写于 作者: Z zgu

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
上级 9e148566
...@@ -44,6 +44,14 @@ void* CHeapObj::operator new(size_t size){ ...@@ -44,6 +44,14 @@ void* CHeapObj::operator new(size_t size){
return (void *) AllocateHeap(size, "CHeapObj-new"); return (void *) AllocateHeap(size, "CHeapObj-new");
} }
void* CHeapObj::operator new (size_t size, const std::nothrow_t& nothrow_constant) {
char* p = (char*) os::malloc(size);
#ifdef ASSERT
if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
#endif
return p;
}
void CHeapObj::operator delete(void* p){ void CHeapObj::operator delete(void* p){
FreeHeap(p); FreeHeap(p);
} }
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "opto/c2_globals.hpp" #include "opto/c2_globals.hpp"
#endif #endif
#include <new>
#define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1) #define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1)
#define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1)) #define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1))
#define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK) #define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK)
...@@ -99,6 +101,7 @@ class AllocatedObj { ...@@ -99,6 +101,7 @@ class AllocatedObj {
class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { class CHeapObj ALLOCATION_SUPER_CLASS_SPEC {
public: public:
void* operator new(size_t size); void* operator new(size_t size);
void* operator new (size_t size, const std::nothrow_t& nothrow_constant);
void operator delete(void* p); void operator delete(void* p);
void* new_array(size_t size); void* new_array(size_t size);
}; };
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <new>
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "utilities/decoder.hpp" #include "utilities/decoder.hpp"
...@@ -46,7 +47,7 @@ ElfFile::ElfFile(const char* filepath) { ...@@ -46,7 +47,7 @@ ElfFile::ElfFile(const char* filepath) {
m_status = Decoder::no_error; m_status = Decoder::no_error;
int len = strlen(filepath) + 1; int len = strlen(filepath) + 1;
m_filepath = NEW_C_HEAP_ARRAY(char, len); m_filepath = (const char*)os::malloc(len * sizeof(char));
if (m_filepath != NULL) { if (m_filepath != NULL) {
strcpy((char*)m_filepath, filepath); strcpy((char*)m_filepath, filepath);
m_file = fopen(filepath, "r"); m_file = fopen(filepath, "r");
...@@ -74,7 +75,7 @@ ElfFile::~ElfFile() { ...@@ -74,7 +75,7 @@ ElfFile::~ElfFile() {
} }
if (m_filepath != NULL) { if (m_filepath != NULL) {
FREE_C_HEAP_ARRAY(char, m_filepath); os::free((void*)m_filepath);
} }
if (m_next != NULL) { if (m_next != NULL) {
...@@ -120,14 +121,14 @@ bool ElfFile::load_tables() { ...@@ -120,14 +121,14 @@ bool ElfFile::load_tables() {
} }
// string table // string table
if (shdr.sh_type == SHT_STRTAB) { if (shdr.sh_type == SHT_STRTAB) {
ElfStringTable* table = new ElfStringTable(m_file, shdr, index); ElfStringTable* table = new (std::nothrow) ElfStringTable(m_file, shdr, index);
if (table == NULL) { if (table == NULL) {
m_status = Decoder::out_of_memory; m_status = Decoder::out_of_memory;
return false; return false;
} }
add_string_table(table); add_string_table(table);
} else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) { } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
ElfSymbolTable* table = new ElfSymbolTable(m_file, shdr); ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(m_file, shdr);
if (table == NULL) { if (table == NULL) {
m_status = Decoder::out_of_memory; m_status = Decoder::out_of_memory;
return false; return false;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#ifndef _WINDOWS #ifndef _WINDOWS
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "runtime/os.hpp"
#include "utilities/elfStringTable.hpp" #include "utilities/elfStringTable.hpp"
// We will try to load whole string table into memory if we can. // We will try to load whole string table into memory if we can.
...@@ -41,14 +42,14 @@ ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) { ...@@ -41,14 +42,14 @@ ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) {
// try to load the string table // try to load the string table
long cur_offset = ftell(file); long cur_offset = ftell(file);
m_table = (char*)NEW_C_HEAP_ARRAY(char, shdr.sh_size); m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size);
if (m_table != NULL) { if (m_table != NULL) {
// if there is an error, mark the error // if there is an error, mark the error
if (fseek(file, shdr.sh_offset, SEEK_SET) || if (fseek(file, shdr.sh_offset, SEEK_SET) ||
fread((void*)m_table, shdr.sh_size, 1, file) != 1 || fread((void*)m_table, shdr.sh_size, 1, file) != 1 ||
fseek(file, cur_offset, SEEK_SET)) { fseek(file, cur_offset, SEEK_SET)) {
m_status = Decoder::file_invalid; m_status = Decoder::file_invalid;
FREE_C_HEAP_ARRAY(char, m_table); os::free((void*)m_table);
m_table = NULL; m_table = NULL;
} }
} else { } else {
...@@ -58,7 +59,7 @@ ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) { ...@@ -58,7 +59,7 @@ ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) {
ElfStringTable::~ElfStringTable() { ElfStringTable::~ElfStringTable() {
if (m_table != NULL) { if (m_table != NULL) {
FREE_C_HEAP_ARRAY(char, m_table); os::free((void*)m_table);
} }
if (m_next != NULL) { if (m_next != NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册