1.1 --- a/src/share/vm/memory/allocation.hpp Wed Apr 17 10:12:42 2013 -0700 1.2 +++ b/src/share/vm/memory/allocation.hpp Thu Mar 07 11:49:38 2013 -0500 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -274,7 +274,7 @@ 1.11 Chunk* _next; // Next Chunk in list 1.12 const size_t _len; // Size of this Chunk 1.13 public: 1.14 - void* operator new(size_t size, size_t length); 1.15 + void* operator new(size_t size, AllocFailType alloc_failmode, size_t length); 1.16 void operator delete(void* p); 1.17 Chunk(size_t length); 1.18 1.19 @@ -337,10 +337,15 @@ 1.20 1.21 void signal_out_of_memory(size_t request, const char* whence) const; 1.22 1.23 - void check_for_overflow(size_t request, const char* whence) const { 1.24 + bool check_for_overflow(size_t request, const char* whence, 1.25 + AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) const { 1.26 if (UINTPTR_MAX - request < (uintptr_t)_hwm) { 1.27 + if (alloc_failmode == AllocFailStrategy::RETURN_NULL) { 1.28 + return false; 1.29 + } 1.30 signal_out_of_memory(request, whence); 1.31 } 1.32 + return true; 1.33 } 1.34 1.35 public: 1.36 @@ -364,7 +369,8 @@ 1.37 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); 1.38 x = ARENA_ALIGN(x); 1.39 debug_only(if (UseMallocOnly) return malloc(x);) 1.40 - check_for_overflow(x, "Arena::Amalloc"); 1.41 + if (!check_for_overflow(x, "Arena::Amalloc", alloc_failmode)) 1.42 + return NULL; 1.43 NOT_PRODUCT(inc_bytes_allocated(x);) 1.44 if (_hwm + x > _max) { 1.45 return grow(x, alloc_failmode); 1.46 @@ -378,7 +384,8 @@ 1.47 void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { 1.48 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); 1.49 debug_only(if (UseMallocOnly) return malloc(x);) 1.50 - check_for_overflow(x, "Arena::Amalloc_4"); 1.51 + if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode)) 1.52 + return NULL; 1.53 NOT_PRODUCT(inc_bytes_allocated(x);) 1.54 if (_hwm + x > _max) { 1.55 return grow(x, alloc_failmode); 1.56 @@ -399,7 +406,8 @@ 1.57 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; 1.58 x += delta; 1.59 #endif 1.60 - check_for_overflow(x, "Arena::Amalloc_D"); 1.61 + if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode)) 1.62 + return NULL; 1.63 NOT_PRODUCT(inc_bytes_allocated(x);) 1.64 if (_hwm + x > _max) { 1.65 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes. 1.66 @@ -539,6 +547,9 @@ 1.67 #define NEW_RESOURCE_ARRAY(type, size)\ 1.68 (type*) resource_allocate_bytes((size) * sizeof(type)) 1.69 1.70 +#define NEW_RESOURCE_ARRAY_RETURN_NULL(type, size)\ 1.71 + (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL) 1.72 + 1.73 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ 1.74 (type*) resource_allocate_bytes(thread, (size) * sizeof(type)) 1.75