1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
47 if (PSScavenge::is_obj_in_young(o)) {
48 PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
49 }
50 oopDesc::encode_store_heap_oop_not_null(p, o);
51 } else {
52 push_depth(p);
53 }
54 }
55 }
56
57 template <class T>
58 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
59 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
60 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
61 "Sanity");
62 assert(Universe::heap()->is_in(p), "pointer outside heap");
63
64 claim_or_forward_internal_depth(p);
65 }
66
67 //
68 // This method is pretty bulky. It would be nice to split it up
69 // into smaller submethods, but we need to be careful not to hurt
70 // performance.
71 //
72 template<bool promote_immediately>
73 oop PSPromotionManager::copy_to_survivor_space(oop o) {
74 assert(PSScavenge::should_scavenge(&o), "Sanity");
75
76 oop new_obj = NULL;
77
78 // NOTE! We must be very careful with any methods that access the mark
79 // in o. There may be multiple threads racing on it, and it may be forwarded
80 // at any time. Do not use oop methods for accessing the mark!
81 markOop test_mark = o->mark();
82
83 // The same test as "o->is_forwarded()"
84 if (!test_mark->is_marked()) {
85 bool new_obj_is_tenured = false;
86 size_t new_obj_size = o->size();
87
88 if (!promote_immediately) {
89 // Find the objects age, MT safe.
90 uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
91 test_mark->displaced_mark_helper()->age() : test_mark->age();
92
93 // Try allocating obj in to-space (unless too old)
94 if (age < PSScavenge::tenuring_threshold()) {
95 new_obj = (oop) _young_lab.allocate(new_obj_size);
96 if (new_obj == NULL && !_young_gen_is_full) {
97 // Do we allocate directly, or flush and refill?
98 if (new_obj_size > (YoungPLABSize / 2)) {
99 // Allocate this object directly
100 new_obj = (oop)young_space()->cas_allocate(new_obj_size);
101 } else {
102 // Flush and fill
103 _young_lab.flush();
104
105 HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
106 if (lab_base != NULL) {
107 _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
108 // Try the young lab allocation again.
109 new_obj = (oop) _young_lab.allocate(new_obj_size);
110 } else {
111 _young_gen_is_full = true;
112 }
113 }
114 }
115 }
116 }
117
118 // Otherwise try allocating obj tenured
119 if (new_obj == NULL) {
120 #ifndef PRODUCT
121 if (Universe::heap()->promotion_should_fail()) {
122 return oop_promotion_failed(o, test_mark);
123 }
124 #endif // #ifndef PRODUCT
125
126 new_obj = (oop) _old_lab.allocate(new_obj_size);
127 new_obj_is_tenured = true;
128
129 if (new_obj == NULL) {
130 if (!_old_gen_is_full) {
131 // Do we allocate directly, or flush and refill?
132 if (new_obj_size > (OldPLABSize / 2)) {
133 // Allocate this object directly
134 new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
135 } else {
136 // Flush and fill
137 _old_lab.flush();
138
139 HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
140 if(lab_base != NULL) {
141 #ifdef ASSERT
142 // Delay the initialization of the promotion lab (plab).
143 // This exposes uninitialized plabs to card table processing.
144 if (GCWorkerDelayMillis > 0) {
145 os::sleep(Thread::current(), GCWorkerDelayMillis, false);
146 }
147 #endif
148 _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
149 // Try the old lab allocation again.
150 new_obj = (oop) _old_lab.allocate(new_obj_size);
151 }
152 }
153 }
154
155 // This is the promotion failed test, and code handling.
156 // The code belongs here for two reasons. It is slightly
157 // different than the code below, and cannot share the
158 // CAS testing code. Keeping the code here also minimizes
159 // the impact on the common case fast path code.
160
161 if (new_obj == NULL) {
162 _old_gen_is_full = true;
163 return oop_promotion_failed(o, test_mark);
164 }
165 }
166 }
167
168 assert(new_obj != NULL, "allocation should have succeeded");
169
170 // Copy obj
|
1 /*
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
47 if (PSScavenge::is_obj_in_young(o)) {
48 PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
49 }
50 oopDesc::encode_store_heap_oop_not_null(p, o);
51 } else {
52 push_depth(p);
53 }
54 }
55 }
56
57 template <class T>
58 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
59 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
60 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
61 "Sanity");
62 assert(Universe::heap()->is_in(p), "pointer outside heap");
63
64 claim_or_forward_internal_depth(p);
65 }
66
67 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
68 size_t obj_size,
69 uint age, bool tenured,
70 const PSPromotionLAB* lab) {
71 assert(EnableJFR, "sanity check");
72 // Skip if memory allocation failed
73 if (new_obj != NULL) {
74 const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
75
76 if (lab != NULL) {
77 // Promotion of object through newly allocated PLAB
78 if (gc_tracer->should_report_promotion_in_new_plab_event()) {
79 size_t obj_bytes = obj_size * HeapWordSize;
80 size_t lab_size = lab->capacity();
81 gc_tracer->report_promotion_in_new_plab_event(old_obj->klass(), obj_bytes,
82 age, tenured, lab_size);
83 }
84 } else {
85 // Promotion of object directly to heap
86 if (gc_tracer->should_report_promotion_outside_plab_event()) {
87 size_t obj_bytes = obj_size * HeapWordSize;
88 gc_tracer->report_promotion_outside_plab_event(old_obj->klass(), obj_bytes,
89 age, tenured);
90 }
91 }
92 }
93 }
94
95 //
96 // This method is pretty bulky. It would be nice to split it up
97 // into smaller submethods, but we need to be careful not to hurt
98 // performance.
99 //
100 template<bool promote_immediately>
101 oop PSPromotionManager::copy_to_survivor_space(oop o) {
102 assert(PSScavenge::should_scavenge(&o), "Sanity");
103
104 oop new_obj = NULL;
105
106 // NOTE! We must be very careful with any methods that access the mark
107 // in o. There may be multiple threads racing on it, and it may be forwarded
108 // at any time. Do not use oop methods for accessing the mark!
109 markOop test_mark = o->mark();
110
111 // The same test as "o->is_forwarded()"
112 if (!test_mark->is_marked()) {
113 bool new_obj_is_tenured = false;
114 size_t new_obj_size = o->size();
115
116 if (!promote_immediately) {
117 // Find the objects age, MT safe.
118 uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
119 test_mark->displaced_mark_helper()->age() : test_mark->age();
120
121 // Try allocating obj in to-space (unless too old)
122 if (age < PSScavenge::tenuring_threshold()) {
123 new_obj = (oop) _young_lab.allocate(new_obj_size);
124 if (new_obj == NULL && !_young_gen_is_full) {
125 // Do we allocate directly, or flush and refill?
126 if (new_obj_size > (YoungPLABSize / 2)) {
127 // Allocate this object directly
128 new_obj = (oop)young_space()->cas_allocate(new_obj_size);
129 if (EnableJFR) {
130 promotion_trace_event(new_obj, o, new_obj_size, age, false, NULL);
131 }
132 } else {
133 // Flush and fill
134 _young_lab.flush();
135
136 HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
137 if (lab_base != NULL) {
138 _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
139 // Try the young lab allocation again.
140 new_obj = (oop) _young_lab.allocate(new_obj_size);
141 if (EnableJFR) {
142 promotion_trace_event(new_obj, o, new_obj_size, age, false, &_young_lab);
143 }
144 } else {
145 _young_gen_is_full = true;
146 }
147 }
148 }
149 }
150 }
151
152 // Otherwise try allocating obj tenured
153 if (new_obj == NULL) {
154 #ifndef PRODUCT
155 if (Universe::heap()->promotion_should_fail()) {
156 return oop_promotion_failed(o, test_mark);
157 }
158 #endif // #ifndef PRODUCT
159
160 new_obj = (oop) _old_lab.allocate(new_obj_size);
161 new_obj_is_tenured = true;
162
163 if (new_obj == NULL) {
164 uint age = 0;
165 if (EnableJFR) {
166 // Find the objects age, MT safe.
167 age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
168 test_mark->displaced_mark_helper()->age() : test_mark->age();
169 }
170 if (!_old_gen_is_full) {
171 // Do we allocate directly, or flush and refill?
172 if (new_obj_size > (OldPLABSize / 2)) {
173 // Allocate this object directly
174 new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
175 if (EnableJFR) {
176 promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
177 }
178 } else {
179 // Flush and fill
180 _old_lab.flush();
181
182 HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
183 if(lab_base != NULL) {
184 #ifdef ASSERT
185 // Delay the initialization of the promotion lab (plab).
186 // This exposes uninitialized plabs to card table processing.
187 if (GCWorkerDelayMillis > 0) {
188 os::sleep(Thread::current(), GCWorkerDelayMillis, false);
189 }
190 #endif
191 _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
192 // Try the old lab allocation again.
193 new_obj = (oop) _old_lab.allocate(new_obj_size);
194 if (EnableJFR) {
195 promotion_trace_event(new_obj, o, new_obj_size, age, true, &_old_lab);
196 }
197 }
198 }
199 }
200
201 // This is the promotion failed test, and code handling.
202 // The code belongs here for two reasons. It is slightly
203 // different than the code below, and cannot share the
204 // CAS testing code. Keeping the code here also minimizes
205 // the impact on the common case fast path code.
206
207 if (new_obj == NULL) {
208 _old_gen_is_full = true;
209 return oop_promotion_failed(o, test_mark);
210 }
211 }
212 }
213
214 assert(new_obj != NULL, "allocation should have succeeded");
215
216 // Copy obj
|