annotate src/share/vm/gc_implementation/shared/mutableSpace.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 89152779163c 78bbf4d43a14
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14223
diff changeset
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
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: 579
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6725
diff changeset
26 #include "utilities/macros.hpp"
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6725
diff changeset
27 #if INCLUDE_ALL_GCS
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/shared/mutableSpace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "gc_implementation/shared/spaceDecorator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/safepoint.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/thread.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6725
diff changeset
33 #endif // INCLUDE_ALL_GCS
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14223
diff changeset
35 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14223
diff changeset
36
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
37 MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
38 assert(MutableSpace::alignment() >= 0 &&
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
39 MutableSpace::alignment() % os::vm_page_size() == 0,
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
40 "Space should be aligned");
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
41 _mangler = new MutableSpaceMangler(this);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
42 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
43
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
44 MutableSpace::~MutableSpace() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
45 delete _mangler;
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
46 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
47
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
48 void MutableSpace::numa_setup_pages(MemRegion mr, bool clear_space) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
49 if (!mr.is_empty()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
50 size_t page_size = UseLargePages ? alignment() : os::vm_page_size();
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
51 HeapWord *start = (HeapWord*)round_to((intptr_t) mr.start(), page_size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
52 HeapWord *end = (HeapWord*)round_down((intptr_t) mr.end(), page_size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
53 if (end > start) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
54 size_t size = pointer_delta(end, start, sizeof(char));
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
55 if (clear_space) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
56 // Prefer page reallocation to migration.
4734
20bfb6d15a94 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 1972
diff changeset
57 os::free_memory((char*)start, size, page_size);
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
58 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
59 os::numa_make_global((char*)start, size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
60 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
61 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
62 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
63
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
64 void MutableSpace::pretouch_pages(MemRegion mr) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
65 for (volatile char *p = (char*)mr.start(); p < (char*)mr.end(); p += os::vm_page_size()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
66 char t = *p; *p = t;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
67 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
68 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
69
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
70 void MutableSpace::initialize(MemRegion mr,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
71 bool clear_space,
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
72 bool mangle_space,
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
73 bool setup_pages) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
74
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
75 assert(Universe::on_page_boundary(mr.start()) && Universe::on_page_boundary(mr.end()),
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
76 "invalid space boundaries");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
77
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
78 if (setup_pages && (UseNUMA || AlwaysPreTouch)) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
79 // The space may move left and right or expand/shrink.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
80 // We'd like to enforce the desired page placement.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
81 MemRegion head, tail;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
82 if (last_setup_region().is_empty()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
83 // If it's the first initialization don't limit the amount of work.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
84 head = mr;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
85 tail = MemRegion(mr.end(), mr.end());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
86 } else {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
87 // Is there an intersection with the address space?
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
88 MemRegion intersection = last_setup_region().intersection(mr);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
89 if (intersection.is_empty()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
90 intersection = MemRegion(mr.end(), mr.end());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
91 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
92 // All the sizes below are in words.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
93 size_t head_size = 0, tail_size = 0;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
94 if (mr.start() <= intersection.start()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
95 head_size = pointer_delta(intersection.start(), mr.start());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
96 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
97 if(intersection.end() <= mr.end()) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
98 tail_size = pointer_delta(mr.end(), intersection.end());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
99 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
100 // Limit the amount of page manipulation if necessary.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
101 if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
102 const size_t change_size = head_size + tail_size;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
103 const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord;
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
104 head_size = MIN2((size_t)(setup_rate_words * head_size / change_size),
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
105 head_size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
106 tail_size = MIN2((size_t)(setup_rate_words * tail_size / change_size),
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
107 tail_size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
108 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
109 head = MemRegion(intersection.start() - head_size, intersection.start());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
110 tail = MemRegion(intersection.end(), intersection.end() + tail_size);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
111 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
112 assert(mr.contains(head) && mr.contains(tail), "Sanity");
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
113
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
114 if (UseNUMA) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
115 numa_setup_pages(head, clear_space);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
116 numa_setup_pages(tail, clear_space);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
117 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
118
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
119 if (AlwaysPreTouch) {
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
120 pretouch_pages(head);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
121 pretouch_pages(tail);
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
122 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
123
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
124 // Remember where we stopped so that we can continue later.
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
125 set_last_setup_region(MemRegion(head.start(), tail.end()));
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
126 }
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
127
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
128 set_bottom(mr.start());
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 269
diff changeset
129 set_end(mr.end());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
130
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
131 if (clear_space) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
132 clear(mangle_space);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
133 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
134 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
135
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
136 void MutableSpace::clear(bool mangle_space) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
137 set_top(bottom());
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
138 if (ZapUnusedHeapArea && mangle_space) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
139 mangle_unused_area();
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
140 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
141 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
142
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
143 #ifndef PRODUCT
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
144 void MutableSpace::check_mangled_unused_area(HeapWord* limit) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
145 mangler()->check_mangled_unused_area(limit);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
146 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
147
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
148 void MutableSpace::check_mangled_unused_area_complete() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
149 mangler()->check_mangled_unused_area_complete();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
152 // Mangle only the unused space that has not previously
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
153 // been mangled and that has not been allocated since being
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
154 // mangled.
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
155 void MutableSpace::mangle_unused_area() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
156 mangler()->mangle_unused_area();
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
157 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
158
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
159 void MutableSpace::mangle_unused_area_complete() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
160 mangler()->mangle_unused_area_complete();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
163 void MutableSpace::mangle_region(MemRegion mr) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
164 SpaceMangler::mangle_region(mr);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
165 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
166
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
167 void MutableSpace::set_top_for_allocations(HeapWord* v) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
168 mangler()->set_top_for_allocations(v);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
169 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
170
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
171 void MutableSpace::set_top_for_allocations() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
172 mangler()->set_top_for_allocations(top());
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
173 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
174 #endif
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
175
0
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // This version requires locking. */
a61af66fc99e Initial load
duke
parents:
diff changeset
177 HeapWord* MutableSpace::allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(Heap_lock->owned_by_self() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
179 (SafepointSynchronize::is_at_safepoint() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Thread::current()->is_VM_thread()),
a61af66fc99e Initial load
duke
parents:
diff changeset
181 "not locked");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 set_top(new_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
187 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // This version is lock-free.
a61af66fc99e Initial load
duke
parents:
diff changeset
195 HeapWord* MutableSpace::cas_allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // result can be one of two:
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // the old top value: the exchange succeeded
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // otherwise: the new value of the top is returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 if (result != obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 continue; // another thread beat us to the allocation, try again
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
208 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } while (true);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // Try to deallocate previous allocation. Returns true upon success.
a61af66fc99e Initial load
duke
parents:
diff changeset
217 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 HeapWord* expected_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
222 void MutableSpace::oop_iterate(ExtendedOopClosure* cl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
223 HeapWord* obj_addr = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
224 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // Could call objects iterate, but this is easier.
a61af66fc99e Initial load
duke
parents:
diff changeset
226 while (obj_addr < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 obj_addr += oop(obj_addr)->oop_iterate(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
231 void MutableSpace::oop_iterate_no_header(OopClosure* cl) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
232 HeapWord* obj_addr = bottom();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
233 HeapWord* t = top();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
234 // Could call objects iterate, but this is easier.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
235 while (obj_addr < t) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
236 obj_addr += oop(obj_addr)->oop_iterate_no_header(cl);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
237 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
238 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6008
diff changeset
239
0
a61af66fc99e Initial load
duke
parents:
diff changeset
240 void MutableSpace::object_iterate(ObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 while (p < top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 cl->do_object(oop(p));
a61af66fc99e Initial load
duke
parents:
diff changeset
244 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 void MutableSpace::print_short() const { print_short_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 void MutableSpace::print_short_on( outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
251 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 void MutableSpace::print() const { print_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 void MutableSpace::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 MutableSpace::print_short_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
258 bottom(), top(), end());
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
6008
b632e80fc9dc 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 4734
diff changeset
261 void MutableSpace::verify() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 HeapWord* prev_p = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 while (p < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 oop(p)->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 prev_p = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 guarantee(p == top(), "end of last object must match end of space");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }