src/share/vm/memory/allocation.inline.hpp

Tue, 12 Mar 2013 08:33:57 +0100

author
brutisso
date
Tue, 12 Mar 2013 08:33:57 +0100
changeset 4741
eac371996b44
parent 4675
63e54c37ac64
child 4901
83f27710f5f7
permissions
-rw-r--r--

8001049: VM crashes when running with large -Xms and not specifying ObjectAlignmentInBytes
Summary: Take the initial heap size into account when checking the heap size for compressed oops
Reviewed-by: jmasa, kvn, hseigel, ctornqvi

duke@435 1 /*
simonis@4675 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
stefank@2314 26 #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
stefank@2314 27
simonis@4675 28 #include "runtime/atomic.inline.hpp"
stefank@2314 29 #include "runtime/os.hpp"
stefank@2314 30
duke@435 31 // Explicit C-heap memory management
duke@435 32
duke@435 33 void trace_heap_malloc(size_t size, const char* name, void *p);
duke@435 34 void trace_heap_free(void *p);
duke@435 35
kvn@2562 36 #ifndef PRODUCT
kvn@2557 37 // Increments unsigned long value for statistics (not atomic on MP).
kvn@2557 38 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
kvn@2562 39 #if defined(SPARC) || defined(X86)
kvn@2562 40 // Sparc and X86 have atomic jlong (8 bytes) instructions
kvn@2557 41 julong value = Atomic::load((volatile jlong*)dest);
kvn@2557 42 value += add_value;
kvn@2557 43 Atomic::store((jlong)value, (volatile jlong*)dest);
kvn@2562 44 #else
kvn@2562 45 // possible word-tearing during load/store
kvn@2562 46 *dest += add_value;
kvn@2562 47 #endif
kvn@2557 48 }
kvn@2562 49 #endif
duke@435 50
duke@435 51 // allocate using malloc; will fail if no memory available
nloodin@4183 52 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0,
nloodin@4183 53 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
zgu@3900 54 if (pc == 0) {
zgu@3900 55 pc = CURRENT_PC;
zgu@3900 56 }
zgu@3900 57 char* p = (char*) os::malloc(size, flags, pc);
duke@435 58 #ifdef ASSERT
zgu@3900 59 if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
duke@435 60 #endif
nloodin@4183 61 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "AllocateHeap");
duke@435 62 return p;
duke@435 63 }
duke@435 64
nloodin@4183 65 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags,
nloodin@4183 66 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
zgu@3900 67 char* p = (char*) os::realloc(old, size, flags, CURRENT_PC);
duke@435 68 #ifdef ASSERT
zgu@3900 69 if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
duke@435 70 #endif
nloodin@4183 71 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "ReallocateHeap");
duke@435 72 return p;
duke@435 73 }
duke@435 74
zgu@3900 75 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) {
duke@435 76 #ifdef ASSERT
duke@435 77 if (PrintMallocFree) trace_heap_free(p);
duke@435 78 #endif
zgu@3900 79 os::free(p, memflags);
duke@435 80 }
stefank@2314 81
zgu@3900 82
zgu@3900 83 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
zgu@3900 84 address caller_pc){
zgu@3900 85 #ifdef ASSERT
zgu@3900 86 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
zgu@3900 87 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
zgu@3900 88 return p;
zgu@3900 89 #else
zgu@3900 90 return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
zgu@3900 91 #endif
zgu@3900 92 }
zgu@3900 93
zgu@3900 94 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
zgu@3900 95 const std::nothrow_t& nothrow_constant, address caller_pc) {
zgu@3900 96 #ifdef ASSERT
nloodin@4183 97 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
nloodin@4183 98 AllocFailStrategy::RETURN_NULL);
zgu@3900 99 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
zgu@3900 100 return p;
zgu@3900 101 #else
nloodin@4183 102 return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
nloodin@4183 103 AllocFailStrategy::RETURN_NULL);
zgu@3900 104 #endif
zgu@3900 105 }
zgu@3900 106
zgu@3900 107 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
zgu@3900 108 FreeHeap(p, F);
zgu@3900 109 }
zgu@3900 110
zgu@3900 111
stefank@2314 112 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP

mercurial