Mercurial > hg > truffle
annotate src/share/vm/memory/allocation.inline.hpp @ 8719:c8b31b461e1a
8003419: NPG: Clean up metadata created during class loading if failure
Summary: Store metadata on ClassFileParser instance to be cleaned up by destructor. This enabled some refactoring of the enormous parseClassFile function.
Reviewed-by: jmasa, acorn
author | coleenp |
---|---|
date | Wed, 13 Mar 2013 17:34:29 -0400 |
parents | 63e54c37ac64 |
children | 83f27710f5f7 |
rev | line source |
---|---|
0 | 1 /* |
8675
63e54c37ac64
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
6872
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
26 #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP | |
27 | |
8675
63e54c37ac64
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
6872
diff
changeset
|
28 #include "runtime/atomic.inline.hpp" |
1972 | 29 #include "runtime/os.hpp" |
30 | |
0 | 31 // Explicit C-heap memory management |
32 | |
33 void trace_heap_malloc(size_t size, const char* name, void *p); | |
34 void trace_heap_free(void *p); | |
35 | |
2255 | 36 #ifndef PRODUCT |
2250 | 37 // Increments unsigned long value for statistics (not atomic on MP). |
38 inline void inc_stat_counter(volatile julong* dest, julong add_value) { | |
2255 | 39 #if defined(SPARC) || defined(X86) |
40 // Sparc and X86 have atomic jlong (8 bytes) instructions | |
2250 | 41 julong value = Atomic::load((volatile jlong*)dest); |
42 value += add_value; | |
43 Atomic::store((jlong)value, (volatile jlong*)dest); | |
2255 | 44 #else |
45 // possible word-tearing during load/store | |
46 *dest += add_value; | |
47 #endif | |
2250 | 48 } |
2255 | 49 #endif |
0 | 50 |
51 // allocate using malloc; will fail if no memory available | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
52 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0, |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
53 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
6197 | 54 if (pc == 0) { |
55 pc = CURRENT_PC; | |
56 } | |
57 char* p = (char*) os::malloc(size, flags, pc); | |
0 | 58 #ifdef ASSERT |
6197 | 59 if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p); |
0 | 60 #endif |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
61 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "AllocateHeap"); |
6197 | 62 return p; |
63 } | |
64 | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
65 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags, |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
66 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
6197 | 67 char* p = (char*) os::realloc(old, size, flags, CURRENT_PC); |
68 #ifdef ASSERT | |
69 if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p); | |
70 #endif | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
71 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "ReallocateHeap"); |
0 | 72 return p; |
73 } | |
74 | |
6197 | 75 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) { |
0 | 76 #ifdef ASSERT |
77 if (PrintMallocFree) trace_heap_free(p); | |
78 #endif | |
6197 | 79 os::free(p, memflags); |
0 | 80 } |
1972 | 81 |
6197 | 82 |
83 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size, | |
84 address caller_pc){ | |
85 #ifdef ASSERT | |
86 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
87 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); | |
88 return p; | |
89 #else | |
90 return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
91 #endif | |
92 } | |
93 | |
94 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, | |
95 const std::nothrow_t& nothrow_constant, address caller_pc) { | |
96 #ifdef ASSERT | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
97 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC), |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
98 AllocFailStrategy::RETURN_NULL); |
6197 | 99 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
100 return p; | |
101 #else | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
102 return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC), |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
103 AllocFailStrategy::RETURN_NULL); |
6197 | 104 #endif |
105 } | |
106 | |
107 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){ | |
108 FreeHeap(p, F); | |
109 } | |
110 | |
111 | |
1972 | 112 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |