author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 59290 | 97d13893ec3c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53703
24341625d8f2
8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
53108
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/allocation.hpp" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
46818 | 28 |
#include "memory/arena.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
29 |
#include "memory/metaspaceShared.hpp" |
7397 | 30 |
#include "memory/resourceArea.hpp" |
31 |
#include "runtime/os.hpp" |
|
32 |
#include "runtime/task.hpp" |
|
33 |
#include "runtime/threadCritical.hpp" |
|
13195 | 34 |
#include "services/memTracker.hpp" |
7397 | 35 |
#include "utilities/ostream.hpp" |
13195 | 36 |
|
49465
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
37 |
// allocate using malloc; will fail if no memory available |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
38 |
char* AllocateHeap(size_t size, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
39 |
MEMFLAGS flags, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
40 |
const NativeCallStack& stack, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
41 |
AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
42 |
char* p = (char*) os::malloc(size, flags, stack); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
43 |
if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
44 |
vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
45 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
46 |
return p; |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
47 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
48 |
|
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
49 |
char* AllocateHeap(size_t size, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
50 |
MEMFLAGS flags, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
51 |
AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
52 |
return AllocateHeap(size, flags, CALLER_PC); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
53 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
54 |
|
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
55 |
char* ReallocateHeap(char *old, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
56 |
size_t size, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
57 |
MEMFLAGS flag, |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
58 |
AllocFailType alloc_failmode) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
59 |
char* p = (char*) os::realloc(old, size, flag, CALLER_PC); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
60 |
if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
61 |
vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
62 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
63 |
return p; |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
64 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
65 |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
55745
diff
changeset
|
66 |
// handles NULL pointers |
49465
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
67 |
void FreeHeap(void* p) { |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
68 |
os::free(p); |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
69 |
} |
4881673579b7
8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers)
simonis
parents:
49392
diff
changeset
|
70 |
|
48794
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47216
diff
changeset
|
71 |
void* MetaspaceObj::_shared_metaspace_base = NULL; |
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47216
diff
changeset
|
72 |
void* MetaspaceObj::_shared_metaspace_top = NULL; |
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47216
diff
changeset
|
73 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
74 |
void* StackObj::operator new(size_t size) throw() { ShouldNotCallThis(); return 0; } |
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
75 |
void StackObj::operator delete(void* p) { ShouldNotCallThis(); } |
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
76 |
void* StackObj::operator new [](size_t size) throw() { ShouldNotCallThis(); return 0; } |
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
77 |
void StackObj::operator delete [](void* p) { ShouldNotCallThis(); } |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
78 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
79 |
void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data, |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
40655
diff
changeset
|
80 |
size_t word_size, |
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
81 |
MetaspaceObj::Type type, TRAPS) throw() { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
82 |
// Klass has it's own operator new |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
40655
diff
changeset
|
83 |
return Metaspace::allocate(loader_data, word_size, type, THREAD); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
84 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
85 |
|
54437
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
86 |
bool MetaspaceObj::is_valid(const MetaspaceObj* p) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
87 |
// Weed out obvious bogus values first without traversing metaspace |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
88 |
if ((size_t)p < os::min_page_size()) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
89 |
return false; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
90 |
} else if (!is_aligned((address)p, sizeof(MetaWord))) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
91 |
return false; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
92 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
53703
diff
changeset
|
93 |
return Metaspace::contains((void*)p); |
14579
7f6ce6e3dd80
8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents:
14120
diff
changeset
|
94 |
} |
7f6ce6e3dd80
8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents:
14120
diff
changeset
|
95 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
96 |
void MetaspaceObj::print_address_on(outputStream* st) const { |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23446
diff
changeset
|
97 |
st->print(" {" INTPTR_FORMAT "}", p2i(this)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
98 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
99 |
|
46818 | 100 |
void* ResourceObj::operator new(size_t size, Arena *arena) throw() { |
101 |
address res = (address)arena->Amalloc(size); |
|
102 |
DEBUG_ONLY(set_allocation_type(res, ARENA);) |
|
103 |
return res; |
|
104 |
} |
|
105 |
||
106 |
void* ResourceObj::operator new [](size_t size, Arena *arena) throw() { |
|
107 |
address res = (address)arena->Amalloc(size); |
|
108 |
DEBUG_ONLY(set_allocation_type(res, ARENA);) |
|
109 |
return res; |
|
110 |
} |
|
111 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
112 |
void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) throw() { |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33105
diff
changeset
|
113 |
address res = NULL; |
1 | 114 |
switch (type) { |
115 |
case C_HEAP: |
|
13195 | 116 |
res = (address)AllocateHeap(size, flags, CALLER_PC); |
6180 | 117 |
DEBUG_ONLY(set_allocation_type(res, C_HEAP);) |
1 | 118 |
break; |
119 |
case RESOURCE_AREA: |
|
6183
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
6180
diff
changeset
|
120 |
// new(size) sets allocation type RESOURCE_AREA. |
1 | 121 |
res = (address)operator new(size); |
122 |
break; |
|
123 |
default: |
|
124 |
ShouldNotReachHere(); |
|
125 |
} |
|
126 |
return res; |
|
127 |
} |
|
128 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
129 |
void* ResourceObj::operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
130 |
return (address) operator new(size, type, flags); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
131 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
132 |
|
14083
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
133 |
void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_constant, |
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
134 |
allocation_type type, MEMFLAGS flags) throw() { |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33105
diff
changeset
|
135 |
// should only call this with std::nothrow, use other operator new() otherwise |
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33105
diff
changeset
|
136 |
address res = NULL; |
14083
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
137 |
switch (type) { |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
138 |
case C_HEAP: |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
139 |
res = (address)AllocateHeap(size, flags, CALLER_PC, AllocFailStrategy::RETURN_NULL); |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
140 |
DEBUG_ONLY(if (res!= NULL) set_allocation_type(res, C_HEAP);) |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
141 |
break; |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
142 |
case RESOURCE_AREA: |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
143 |
// new(size) sets allocation type RESOURCE_AREA. |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
144 |
res = (address)operator new(size, std::nothrow); |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
145 |
break; |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
146 |
default: |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
147 |
ShouldNotReachHere(); |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
148 |
} |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
149 |
return res; |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
150 |
} |
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
151 |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
152 |
void* ResourceObj::operator new [](size_t size, const std::nothrow_t& nothrow_constant, |
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
153 |
allocation_type type, MEMFLAGS flags) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
154 |
return (address)operator new(size, nothrow_constant, type, flags); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
155 |
} |
14083
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13728
diff
changeset
|
156 |
|
1 | 157 |
void ResourceObj::operator delete(void* p) { |
158 |
assert(((ResourceObj *)p)->allocated_on_C_heap(), |
|
159 |
"delete only allowed for C_HEAP objects"); |
|
7440
eabaf35910a1
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
7397
diff
changeset
|
160 |
DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;) |
1 | 161 |
FreeHeap(p); |
162 |
} |
|
163 |
||
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
164 |
void ResourceObj::operator delete [](void* p) { |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
165 |
operator delete(p); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
166 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17087
diff
changeset
|
167 |
|
6180 | 168 |
#ifdef ASSERT |
169 |
void ResourceObj::set_allocation_type(address res, allocation_type type) { |
|
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
170 |
// Set allocation type in the resource object |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
171 |
uintptr_t allocation = (uintptr_t)res; |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
172 |
assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least: " INTPTR_FORMAT, p2i(res)); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
173 |
assert(type <= allocation_mask, "incorrect allocation type"); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
174 |
ResourceObj* resobj = (ResourceObj *)res; |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
175 |
resobj->_allocation_t[0] = ~(allocation + type); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
176 |
if (type != STACK_OR_EMBEDDED) { |
53703
24341625d8f2
8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
53108
diff
changeset
|
177 |
// Called from operator new(), set verification value. |
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
178 |
resobj->_allocation_t[1] = (uintptr_t)&(resobj->_allocation_t[1]) + type; |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
179 |
} |
6180 | 180 |
} |
181 |
||
6183
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
6180
diff
changeset
|
182 |
ResourceObj::allocation_type ResourceObj::get_allocation_type() const { |
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
183 |
assert(~(_allocation_t[0] | allocation_mask) == (uintptr_t)this, "lost resource object"); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
184 |
return (allocation_type)((~_allocation_t[0]) & allocation_mask); |
7440
eabaf35910a1
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
7397
diff
changeset
|
185 |
} |
eabaf35910a1
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
7397
diff
changeset
|
186 |
|
eabaf35910a1
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
7397
diff
changeset
|
187 |
bool ResourceObj::is_type_set() const { |
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
188 |
allocation_type type = (allocation_type)(_allocation_t[1] & allocation_mask); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
189 |
return get_allocation_type() == type && |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
190 |
(_allocation_t[1] - type) == (uintptr_t)(&_allocation_t[1]); |
6180 | 191 |
} |
192 |
||
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
193 |
// This whole business of passing information from ResourceObj::operator new |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
194 |
// to the ResourceObj constructor via fields in the "object" is technically UB. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
195 |
// But it seems to work within the limitations of HotSpot usage (such as no |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
196 |
// multiple inheritance) with the compilers and compiler options we're using. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
197 |
// And it gives some possibly useful checking for misuse of ResourceObj. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
198 |
void ResourceObj::initialize_allocation_info() { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
199 |
if (~(_allocation_t[0] | allocation_mask) != (uintptr_t)this) { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
200 |
// Operator new() is not called for allocations |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
201 |
// on stack and for embedded objects. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
202 |
set_allocation_type((address)this, STACK_OR_EMBEDDED); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
203 |
} else if (allocated_on_stack()) { // STACK_OR_EMBEDDED |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
204 |
// For some reason we got a value which resembles |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
205 |
// an embedded or stack object (operator new() does not |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
206 |
// set such type). Keep it since it is valid value |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
207 |
// (even if it was garbage). |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
208 |
// Ignore garbage in other fields. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
209 |
} else if (is_type_set()) { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
210 |
// Operator new() was called and type was set. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
211 |
assert(!allocated_on_stack(), |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
212 |
"not embedded or stack, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")", |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
213 |
p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
214 |
} else { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
215 |
// Operator new() was not called. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
216 |
// Assume that it is embedded or stack object. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
217 |
set_allocation_type((address)this, STACK_OR_EMBEDDED); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
218 |
} |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
219 |
_allocation_t[1] = 0; // Zap verification value |
6180 | 220 |
} |
221 |
||
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
222 |
ResourceObj::ResourceObj() { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
223 |
initialize_allocation_info(); |
6180 | 224 |
} |
225 |
||
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
226 |
ResourceObj::ResourceObj(const ResourceObj&) { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
227 |
// Initialize _allocation_t as a new object, ignoring object being copied. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
228 |
initialize_allocation_info(); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
229 |
} |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
230 |
|
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
231 |
ResourceObj& ResourceObj::operator=(const ResourceObj& r) { |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
232 |
assert(allocated_on_stack(), |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
233 |
"copy only into local, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")", |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
234 |
p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]); |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
235 |
// Keep current _allocation_t value; |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
236 |
return *this; |
6180 | 237 |
} |
238 |
||
239 |
ResourceObj::~ResourceObj() { |
|
53108
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
240 |
// allocated_on_C_heap() also checks that encoded (in _allocation) address == this. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
241 |
if (!allocated_on_C_heap()) { // ResourceObj::delete() will zap _allocation for C_heap. |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
242 |
_allocation_t[0] = (uintptr_t)badHeapOopVal; // zap type |
e90315ae8aa9
8213481: [REDO] Fix incorrect copy constructors in hotspot
kbarrett
parents:
49734
diff
changeset
|
243 |
} |
6180 | 244 |
} |
245 |
#endif // ASSERT |
|
246 |
||
1 | 247 |
//-------------------------------------------------------------------------------------- |
248 |
// Non-product code |
|
249 |
||
250 |
#ifndef PRODUCT |
|
251 |
void AllocatedObj::print() const { print_on(tty); } |
|
252 |
void AllocatedObj::print_value() const { print_value_on(tty); } |
|
253 |
||
254 |
void AllocatedObj::print_on(outputStream* st) const { |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23446
diff
changeset
|
255 |
st->print_cr("AllocatedObj(" INTPTR_FORMAT ")", p2i(this)); |
1 | 256 |
} |
257 |
||
258 |
void AllocatedObj::print_value_on(outputStream* st) const { |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23446
diff
changeset
|
259 |
st->print("AllocatedObj(" INTPTR_FORMAT ")", p2i(this)); |
1 | 260 |
} |
261 |
||
262 |
ReallocMark::ReallocMark() { |
|
263 |
#ifdef ASSERT |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33589
diff
changeset
|
264 |
Thread *thread = Thread::current(); |
1 | 265 |
_nesting = thread->resource_area()->nesting(); |
266 |
#endif |
|
267 |
} |
|
268 |
||
269 |
void ReallocMark::check() { |
|
270 |
#ifdef ASSERT |
|
271 |
if (_nesting != Thread::current()->resource_area()->nesting()) { |
|
272 |
fatal("allocation bug: array could grow within nested ResourceMark"); |
|
273 |
} |
|
274 |
#endif |
|
275 |
} |
|
276 |
||
277 |
#endif // Non-product |