Mercurial > hg > truffle
comparison src/share/vm/memory/allocation.hpp @ 2307:4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
Summary: Added overflow detection in arena Amalloc methods
Reviewed-by: coleenp, phh
author | kamg |
---|---|
date | Wed, 02 Mar 2011 08:18:35 -0500 |
parents | f7de3327c683 |
children | 2a3da7eaf4a6 |
comparison
equal
deleted
inserted
replaced
2306:5584e20db481 | 2307:4a9604cd7c5f |
---|---|
205 NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start | 205 NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start |
206 friend class AllocStats; | 206 friend class AllocStats; |
207 debug_only(void* malloc(size_t size);) | 207 debug_only(void* malloc(size_t size);) |
208 debug_only(void* internal_malloc_4(size_t x);) | 208 debug_only(void* internal_malloc_4(size_t x);) |
209 NOT_PRODUCT(void inc_bytes_allocated(size_t x);) | 209 NOT_PRODUCT(void inc_bytes_allocated(size_t x);) |
210 | |
211 void signal_out_of_memory(size_t request, const char* whence) const; | |
212 | |
213 void check_for_overflow(size_t request, const char* whence) const { | |
214 if (UINTPTR_MAX - request < (uintptr_t)_hwm) { | |
215 signal_out_of_memory(request, whence); | |
216 } | |
217 } | |
218 | |
210 public: | 219 public: |
211 Arena(); | 220 Arena(); |
212 Arena(size_t init_size); | 221 Arena(size_t init_size); |
213 Arena(Arena *old); | 222 Arena(Arena *old); |
214 ~Arena(); | 223 ~Arena(); |
218 // Fast allocate in the arena. Common case is: pointer test + increment. | 227 // Fast allocate in the arena. Common case is: pointer test + increment. |
219 void* Amalloc(size_t x) { | 228 void* Amalloc(size_t x) { |
220 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); | 229 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); |
221 x = ARENA_ALIGN(x); | 230 x = ARENA_ALIGN(x); |
222 debug_only(if (UseMallocOnly) return malloc(x);) | 231 debug_only(if (UseMallocOnly) return malloc(x);) |
232 check_for_overflow(x, "Arena::Amalloc"); | |
223 NOT_PRODUCT(inc_bytes_allocated(x);) | 233 NOT_PRODUCT(inc_bytes_allocated(x);) |
224 if (_hwm + x > _max) { | 234 if (_hwm + x > _max) { |
225 return grow(x); | 235 return grow(x); |
226 } else { | 236 } else { |
227 char *old = _hwm; | 237 char *old = _hwm; |
231 } | 241 } |
232 // Further assume size is padded out to words | 242 // Further assume size is padded out to words |
233 void *Amalloc_4(size_t x) { | 243 void *Amalloc_4(size_t x) { |
234 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); | 244 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); |
235 debug_only(if (UseMallocOnly) return malloc(x);) | 245 debug_only(if (UseMallocOnly) return malloc(x);) |
246 check_for_overflow(x, "Arena::Amalloc_4"); | |
236 NOT_PRODUCT(inc_bytes_allocated(x);) | 247 NOT_PRODUCT(inc_bytes_allocated(x);) |
237 if (_hwm + x > _max) { | 248 if (_hwm + x > _max) { |
238 return grow(x); | 249 return grow(x); |
239 } else { | 250 } else { |
240 char *old = _hwm; | 251 char *old = _hwm; |
251 #if defined(SPARC) && !defined(_LP64) | 262 #if defined(SPARC) && !defined(_LP64) |
252 #define DALIGN_M1 7 | 263 #define DALIGN_M1 7 |
253 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; | 264 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; |
254 x += delta; | 265 x += delta; |
255 #endif | 266 #endif |
267 check_for_overflow(x, "Arena::Amalloc_D"); | |
256 NOT_PRODUCT(inc_bytes_allocated(x);) | 268 NOT_PRODUCT(inc_bytes_allocated(x);) |
257 if (_hwm + x > _max) { | 269 if (_hwm + x > _max) { |
258 return grow(x); // grow() returns a result aligned >= 8 bytes. | 270 return grow(x); // grow() returns a result aligned >= 8 bytes. |
259 } else { | 271 } else { |
260 char *old = _hwm; | 272 char *old = _hwm; |