7036747: 7017009 reappeared, problem with ElfStringTable

Wed, 27 Apr 2011 09:09:57 -0400

author
zgu
date
Wed, 27 Apr 2011 09:09:57 -0400
changeset 2834
2a3da7eaf4a6
parent 2759
3449f5e02cc4
child 2835
e534ac80e49a

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

src/share/vm/memory/allocation.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/allocation.hpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/elfFile.cpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/elfStringTable.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/memory/allocation.cpp	Tue Apr 12 14:18:53 2011 -0700
     1.2 +++ b/src/share/vm/memory/allocation.cpp	Wed Apr 27 09:09:57 2011 -0400
     1.3 @@ -44,6 +44,14 @@
     1.4    return (void *) AllocateHeap(size, "CHeapObj-new");
     1.5  }
     1.6  
     1.7 +void* CHeapObj::operator new (size_t size, const std::nothrow_t&  nothrow_constant) {
     1.8 +  char* p = (char*) os::malloc(size);
     1.9 +#ifdef ASSERT
    1.10 +  if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
    1.11 +#endif
    1.12 +  return p;
    1.13 +}
    1.14 +
    1.15  void CHeapObj::operator delete(void* p){
    1.16   FreeHeap(p);
    1.17  }
     2.1 --- a/src/share/vm/memory/allocation.hpp	Tue Apr 12 14:18:53 2011 -0700
     2.2 +++ b/src/share/vm/memory/allocation.hpp	Wed Apr 27 09:09:57 2011 -0400
     2.3 @@ -34,6 +34,8 @@
     2.4  #include "opto/c2_globals.hpp"
     2.5  #endif
     2.6  
     2.7 +#include <new>
     2.8 +
     2.9  #define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1)
    2.10  #define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1))
    2.11  #define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK)
    2.12 @@ -99,6 +101,7 @@
    2.13  class CHeapObj ALLOCATION_SUPER_CLASS_SPEC {
    2.14   public:
    2.15    void* operator new(size_t size);
    2.16 +  void* operator new (size_t size, const std::nothrow_t&  nothrow_constant);
    2.17    void  operator delete(void* p);
    2.18    void* new_array(size_t size);
    2.19  };
     3.1 --- a/src/share/vm/utilities/elfFile.cpp	Tue Apr 12 14:18:53 2011 -0700
     3.2 +++ b/src/share/vm/utilities/elfFile.cpp	Wed Apr 27 09:09:57 2011 -0400
     3.3 @@ -29,6 +29,7 @@
     3.4  #include <string.h>
     3.5  #include <stdio.h>
     3.6  #include <limits.h>
     3.7 +#include <new>
     3.8  
     3.9  #include "memory/allocation.inline.hpp"
    3.10  #include "utilities/decoder.hpp"
    3.11 @@ -46,7 +47,7 @@
    3.12    m_status = Decoder::no_error;
    3.13  
    3.14    int len = strlen(filepath) + 1;
    3.15 -  m_filepath = NEW_C_HEAP_ARRAY(char, len);
    3.16 +  m_filepath = (const char*)os::malloc(len * sizeof(char));
    3.17    if (m_filepath != NULL) {
    3.18      strcpy((char*)m_filepath, filepath);
    3.19      m_file = fopen(filepath, "r");
    3.20 @@ -74,7 +75,7 @@
    3.21    }
    3.22  
    3.23    if (m_filepath != NULL) {
    3.24 -    FREE_C_HEAP_ARRAY(char, m_filepath);
    3.25 +    os::free((void*)m_filepath);
    3.26    }
    3.27  
    3.28    if (m_next != NULL) {
    3.29 @@ -120,14 +121,14 @@
    3.30        }
    3.31        // string table
    3.32        if (shdr.sh_type == SHT_STRTAB) {
    3.33 -        ElfStringTable* table = new ElfStringTable(m_file, shdr, index);
    3.34 +        ElfStringTable* table = new (std::nothrow) ElfStringTable(m_file, shdr, index);
    3.35          if (table == NULL) {
    3.36            m_status = Decoder::out_of_memory;
    3.37            return false;
    3.38          }
    3.39          add_string_table(table);
    3.40        } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
    3.41 -        ElfSymbolTable* table = new ElfSymbolTable(m_file, shdr);
    3.42 +        ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(m_file, shdr);
    3.43          if (table == NULL) {
    3.44            m_status = Decoder::out_of_memory;
    3.45            return false;
     4.1 --- a/src/share/vm/utilities/elfStringTable.cpp	Tue Apr 12 14:18:53 2011 -0700
     4.2 +++ b/src/share/vm/utilities/elfStringTable.cpp	Wed Apr 27 09:09:57 2011 -0400
     4.3 @@ -27,6 +27,7 @@
     4.4  #ifndef _WINDOWS
     4.5  
     4.6  #include "memory/allocation.inline.hpp"
     4.7 +#include "runtime/os.hpp"
     4.8  #include "utilities/elfStringTable.hpp"
     4.9  
    4.10  // We will try to load whole string table into memory if we can.
    4.11 @@ -41,14 +42,14 @@
    4.12  
    4.13    // try to load the string table
    4.14    long cur_offset = ftell(file);
    4.15 -  m_table = (char*)NEW_C_HEAP_ARRAY(char, shdr.sh_size);
    4.16 +  m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size);
    4.17    if (m_table != NULL) {
    4.18      // if there is an error, mark the error
    4.19      if (fseek(file, shdr.sh_offset, SEEK_SET) ||
    4.20        fread((void*)m_table, shdr.sh_size, 1, file) != 1 ||
    4.21        fseek(file, cur_offset, SEEK_SET)) {
    4.22        m_status = Decoder::file_invalid;
    4.23 -      FREE_C_HEAP_ARRAY(char, m_table);
    4.24 +      os::free((void*)m_table);
    4.25        m_table = NULL;
    4.26      }
    4.27    } else {
    4.28 @@ -58,7 +59,7 @@
    4.29  
    4.30  ElfStringTable::~ElfStringTable() {
    4.31    if (m_table != NULL) {
    4.32 -    FREE_C_HEAP_ARRAY(char, m_table);
    4.33 +    os::free((void*)m_table);
    4.34    }
    4.35  
    4.36    if (m_next != NULL) {

mercurial