OpenJDK / jdk6 / jdk6 / hotspot
changeset 2002:a6f5011d46a9
6878713: Verifier heap corruption, relating to backward jsrs
Summary: Added overflow detection in arena Amalloc methods
Reviewed-by: coleenp, phh
author | kamg |
---|---|
date | Mon, 31 Jan 2011 15:17:26 -0500 |
parents | 2c8e1acf0433 |
children | 9047e801725b |
files | src/share/vm/memory/allocation.cpp src/share/vm/memory/allocation.hpp src/share/vm/utilities/globalDefinitions_gcc.hpp src/share/vm/utilities/globalDefinitions_sparcWorks.hpp src/share/vm/utilities/globalDefinitions_visCPP.hpp |
diffstat | 5 files changed, 40 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/memory/allocation.cpp Wed Jan 12 13:59:18 2011 -0800 +++ b/src/share/vm/memory/allocation.cpp Mon Jan 31 15:17:26 2011 -0500 @@ -377,6 +377,9 @@ return sum; // Return total consumed space. } +void Arena::signal_out_of_memory(size_t sz, const char* whence) const { + vm_exit_out_of_memory(sz, whence); +} // Grow a new Chunk void* Arena::grow( size_t x ) { @@ -386,8 +389,9 @@ Chunk *k = _chunk; // Get filled-up chunk address _chunk = new (len) Chunk(len); - if (_chunk == NULL) - vm_exit_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow"); + if (_chunk == NULL) { + signal_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow"); + } if (k) k->set_next(_chunk); // Append new chunk to end of linked list else _first = _chunk; @@ -484,6 +488,7 @@ // for debugging with UseMallocOnly void* Arena::internal_malloc_4(size_t x) { assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); + check_for_overflow(x, "Arena::internal_malloc_4"); if (_hwm + x > _max) { return grow(x); } else {
--- a/src/share/vm/memory/allocation.hpp Wed Jan 12 13:59:18 2011 -0800 +++ b/src/share/vm/memory/allocation.hpp Mon Jan 31 15:17:26 2011 -0500 @@ -194,6 +194,15 @@ friend class AllocStats; debug_only(void* malloc(size_t size);) debug_only(void* internal_malloc_4(size_t x);) + + void signal_out_of_memory(size_t request, const char* whence) const; + + void check_for_overflow(size_t request, const char* whence) const { + if (UINTPTR_MAX - request < (uintptr_t)_hwm) { + signal_out_of_memory(request, whence); + } + } + public: Arena(); Arena(size_t init_size); @@ -207,6 +216,7 @@ assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); x = ARENA_ALIGN(x); debug_only(if (UseMallocOnly) return malloc(x);) + check_for_overflow(x, "Arena::Amalloc"); NOT_PRODUCT(_bytes_allocated += x); if (_hwm + x > _max) { return grow(x); @@ -220,6 +230,7 @@ void *Amalloc_4(size_t x) { assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); debug_only(if (UseMallocOnly) return malloc(x);) + check_for_overflow(x, "Arena::Amalloc_4"); NOT_PRODUCT(_bytes_allocated += x); if (_hwm + x > _max) { return grow(x); @@ -240,6 +251,7 @@ size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; x += delta; #endif + check_for_overflow(x, "Arena::Amalloc_D"); NOT_PRODUCT(_bytes_allocated += x); if (_hwm + x > _max) { return grow(x); // grow() returns a result aligned >= 8 bytes.
--- a/src/share/vm/utilities/globalDefinitions_gcc.hpp Wed Jan 12 13:59:18 2011 -0800 +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp Mon Jan 31 15:17:26 2011 -0500 @@ -72,6 +72,7 @@ # endif #ifdef LINUX +#define __STDC_LIMIT_MACROS #include <inttypes.h> #include <signal.h> #include <ucontext.h>
--- a/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp Wed Jan 12 13:59:18 2011 -0800 +++ b/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp Mon Jan 31 15:17:26 2011 -0500 @@ -143,6 +143,17 @@ #endif #endif +// On solaris 8, UINTPTR_MAX is defined as empty. +// Everywhere else it's an actual value. +#if UINTPTR_MAX - 1 == -1 +#undef UINTPTR_MAX +#ifdef _LP64 +#define UINTPTR_MAX UINT64_MAX +#else +#define UINTPTR_MAX UINT32_MAX +#endif /* ifdef _LP64 */ +#endif + // Additional Java basic types typedef unsigned char jubyte;
--- a/src/share/vm/utilities/globalDefinitions_visCPP.hpp Wed Jan 12 13:59:18 2011 -0800 +++ b/src/share/vm/utilities/globalDefinitions_visCPP.hpp Mon Jan 31 15:17:26 2011 -0500 @@ -36,6 +36,7 @@ # include <stdio.h> // for va_list # include <time.h> # include <fcntl.h> +# include <limits.h> // Need this on windows to get the math constants (e.g., M_PI). #define _USE_MATH_DEFINES # include <math.h> @@ -94,6 +95,14 @@ typedef signed int ssize_t; #endif +#ifndef UINTPTR_MAX +#ifdef _WIN64 +#define UINTPTR_MAX _UI64_MAX +#else +#define UINTPTR_MAX _UI32_MAX +#endif +#endif + //---------------------------------------------------------------------------------------------------- // Additional Java basic types