src/share/vm/memory/space.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/systemDictionary.hpp"
aoqi@0 27 #include "classfile/vmSymbols.hpp"
aoqi@0 28 #include "gc_implementation/shared/liveRange.hpp"
aoqi@0 29 #include "gc_implementation/shared/markSweep.hpp"
aoqi@0 30 #include "gc_implementation/shared/spaceDecorator.hpp"
aoqi@0 31 #include "memory/blockOffsetTable.inline.hpp"
aoqi@0 32 #include "memory/defNewGeneration.hpp"
aoqi@0 33 #include "memory/genCollectedHeap.hpp"
aoqi@0 34 #include "memory/space.hpp"
aoqi@0 35 #include "memory/space.inline.hpp"
aoqi@0 36 #include "memory/universe.inline.hpp"
aoqi@0 37 #include "oops/oop.inline.hpp"
aoqi@0 38 #include "oops/oop.inline2.hpp"
aoqi@0 39 #include "runtime/java.hpp"
aoqi@0 40 #include "runtime/safepoint.hpp"
aoqi@0 41 #include "utilities/copy.hpp"
aoqi@0 42 #include "utilities/globalDefinitions.hpp"
aoqi@0 43 #include "utilities/macros.hpp"
aoqi@0 44
aoqi@0 45 void SpaceMemRegionOopsIterClosure::do_oop(oop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
aoqi@0 46 void SpaceMemRegionOopsIterClosure::do_oop(narrowOop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
aoqi@0 47
aoqi@0 48 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 49
aoqi@0 50 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
aoqi@0 51 HeapWord* top_obj) {
aoqi@0 52 if (top_obj != NULL) {
aoqi@0 53 if (_sp->block_is_obj(top_obj)) {
aoqi@0 54 if (_precision == CardTableModRefBS::ObjHeadPreciseArray) {
aoqi@0 55 if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
aoqi@0 56 // An arrayOop is starting on the dirty card - since we do exact
aoqi@0 57 // store checks for objArrays we are done.
aoqi@0 58 } else {
aoqi@0 59 // Otherwise, it is possible that the object starting on the dirty
aoqi@0 60 // card spans the entire card, and that the store happened on a
aoqi@0 61 // later card. Figure out where the object ends.
aoqi@0 62 // Use the block_size() method of the space over which
aoqi@0 63 // the iteration is being done. That space (e.g. CMS) may have
aoqi@0 64 // specific requirements on object sizes which will
aoqi@0 65 // be reflected in the block_size() method.
aoqi@0 66 top = top_obj + oop(top_obj)->size();
aoqi@0 67 }
aoqi@0 68 }
aoqi@0 69 } else {
aoqi@0 70 top = top_obj;
aoqi@0 71 }
aoqi@0 72 } else {
aoqi@0 73 assert(top == _sp->end(), "only case where top_obj == NULL");
aoqi@0 74 }
aoqi@0 75 return top;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 void DirtyCardToOopClosure::walk_mem_region(MemRegion mr,
aoqi@0 79 HeapWord* bottom,
aoqi@0 80 HeapWord* top) {
aoqi@0 81 // 1. Blocks may or may not be objects.
aoqi@0 82 // 2. Even when a block_is_obj(), it may not entirely
aoqi@0 83 // occupy the block if the block quantum is larger than
aoqi@0 84 // the object size.
aoqi@0 85 // We can and should try to optimize by calling the non-MemRegion
aoqi@0 86 // version of oop_iterate() for all but the extremal objects
aoqi@0 87 // (for which we need to call the MemRegion version of
aoqi@0 88 // oop_iterate()) To be done post-beta XXX
aoqi@0 89 for (; bottom < top; bottom += _sp->block_size(bottom)) {
aoqi@0 90 // As in the case of contiguous space above, we'd like to
aoqi@0 91 // just use the value returned by oop_iterate to increment the
aoqi@0 92 // current pointer; unfortunately, that won't work in CMS because
aoqi@0 93 // we'd need an interface change (it seems) to have the space
aoqi@0 94 // "adjust the object size" (for instance pad it up to its
aoqi@0 95 // block alignment or minimum block size restrictions. XXX
aoqi@0 96 if (_sp->block_is_obj(bottom) &&
aoqi@0 97 !_sp->obj_allocated_since_save_marks(oop(bottom))) {
aoqi@0 98 oop(bottom)->oop_iterate(_cl, mr);
aoqi@0 99 }
aoqi@0 100 }
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 // We get called with "mr" representing the dirty region
aoqi@0 104 // that we want to process. Because of imprecise marking,
aoqi@0 105 // we may need to extend the incoming "mr" to the right,
aoqi@0 106 // and scan more. However, because we may already have
aoqi@0 107 // scanned some of that extended region, we may need to
aoqi@0 108 // trim its right-end back some so we do not scan what
aoqi@0 109 // we (or another worker thread) may already have scanned
aoqi@0 110 // or planning to scan.
aoqi@0 111 void DirtyCardToOopClosure::do_MemRegion(MemRegion mr) {
aoqi@0 112
aoqi@0 113 // Some collectors need to do special things whenever their dirty
aoqi@0 114 // cards are processed. For instance, CMS must remember mutator updates
aoqi@0 115 // (i.e. dirty cards) so as to re-scan mutated objects.
aoqi@0 116 // Such work can be piggy-backed here on dirty card scanning, so as to make
aoqi@0 117 // it slightly more efficient than doing a complete non-detructive pre-scan
aoqi@0 118 // of the card table.
aoqi@0 119 MemRegionClosure* pCl = _sp->preconsumptionDirtyCardClosure();
aoqi@0 120 if (pCl != NULL) {
aoqi@0 121 pCl->do_MemRegion(mr);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 HeapWord* bottom = mr.start();
aoqi@0 125 HeapWord* last = mr.last();
aoqi@0 126 HeapWord* top = mr.end();
aoqi@0 127 HeapWord* bottom_obj;
aoqi@0 128 HeapWord* top_obj;
aoqi@0 129
aoqi@0 130 assert(_precision == CardTableModRefBS::ObjHeadPreciseArray ||
aoqi@0 131 _precision == CardTableModRefBS::Precise,
aoqi@0 132 "Only ones we deal with for now.");
aoqi@0 133
aoqi@0 134 assert(_precision != CardTableModRefBS::ObjHeadPreciseArray ||
aoqi@0 135 _cl->idempotent() || _last_bottom == NULL ||
aoqi@0 136 top <= _last_bottom,
aoqi@0 137 "Not decreasing");
aoqi@0 138 NOT_PRODUCT(_last_bottom = mr.start());
aoqi@0 139
aoqi@0 140 bottom_obj = _sp->block_start(bottom);
aoqi@0 141 top_obj = _sp->block_start(last);
aoqi@0 142
aoqi@0 143 assert(bottom_obj <= bottom, "just checking");
aoqi@0 144 assert(top_obj <= top, "just checking");
aoqi@0 145
aoqi@0 146 // Given what we think is the top of the memory region and
aoqi@0 147 // the start of the object at the top, get the actual
aoqi@0 148 // value of the top.
aoqi@0 149 top = get_actual_top(top, top_obj);
aoqi@0 150
aoqi@0 151 // If the previous call did some part of this region, don't redo.
aoqi@0 152 if (_precision == CardTableModRefBS::ObjHeadPreciseArray &&
aoqi@0 153 _min_done != NULL &&
aoqi@0 154 _min_done < top) {
aoqi@0 155 top = _min_done;
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 // Top may have been reset, and in fact may be below bottom,
aoqi@0 159 // e.g. the dirty card region is entirely in a now free object
aoqi@0 160 // -- something that could happen with a concurrent sweeper.
aoqi@0 161 bottom = MIN2(bottom, top);
aoqi@0 162 MemRegion extended_mr = MemRegion(bottom, top);
aoqi@0 163 assert(bottom <= top &&
aoqi@0 164 (_precision != CardTableModRefBS::ObjHeadPreciseArray ||
aoqi@0 165 _min_done == NULL ||
aoqi@0 166 top <= _min_done),
aoqi@0 167 "overlap!");
aoqi@0 168
aoqi@0 169 // Walk the region if it is not empty; otherwise there is nothing to do.
aoqi@0 170 if (!extended_mr.is_empty()) {
aoqi@0 171 walk_mem_region(extended_mr, bottom_obj, top);
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // An idempotent closure might be applied in any order, so we don't
aoqi@0 175 // record a _min_done for it.
aoqi@0 176 if (!_cl->idempotent()) {
aoqi@0 177 _min_done = bottom;
aoqi@0 178 } else {
aoqi@0 179 assert(_min_done == _last_explicit_min_done,
aoqi@0 180 "Don't update _min_done for idempotent cl");
aoqi@0 181 }
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 DirtyCardToOopClosure* Space::new_dcto_cl(ExtendedOopClosure* cl,
aoqi@0 185 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 186 HeapWord* boundary) {
aoqi@0 187 return new DirtyCardToOopClosure(this, cl, precision, boundary);
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 HeapWord* ContiguousSpaceDCTOC::get_actual_top(HeapWord* top,
aoqi@0 191 HeapWord* top_obj) {
aoqi@0 192 if (top_obj != NULL && top_obj < (_sp->toContiguousSpace())->top()) {
aoqi@0 193 if (_precision == CardTableModRefBS::ObjHeadPreciseArray) {
aoqi@0 194 if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
aoqi@0 195 // An arrayOop is starting on the dirty card - since we do exact
aoqi@0 196 // store checks for objArrays we are done.
aoqi@0 197 } else {
aoqi@0 198 // Otherwise, it is possible that the object starting on the dirty
aoqi@0 199 // card spans the entire card, and that the store happened on a
aoqi@0 200 // later card. Figure out where the object ends.
aoqi@0 201 assert(_sp->block_size(top_obj) == (size_t) oop(top_obj)->size(),
aoqi@0 202 "Block size and object size mismatch");
aoqi@0 203 top = top_obj + oop(top_obj)->size();
aoqi@0 204 }
aoqi@0 205 }
aoqi@0 206 } else {
aoqi@0 207 top = (_sp->toContiguousSpace())->top();
aoqi@0 208 }
aoqi@0 209 return top;
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 void Filtering_DCTOC::walk_mem_region(MemRegion mr,
aoqi@0 213 HeapWord* bottom,
aoqi@0 214 HeapWord* top) {
aoqi@0 215 // Note that this assumption won't hold if we have a concurrent
aoqi@0 216 // collector in this space, which may have freed up objects after
aoqi@0 217 // they were dirtied and before the stop-the-world GC that is
aoqi@0 218 // examining cards here.
aoqi@0 219 assert(bottom < top, "ought to be at least one obj on a dirty card.");
aoqi@0 220
aoqi@0 221 if (_boundary != NULL) {
aoqi@0 222 // We have a boundary outside of which we don't want to look
aoqi@0 223 // at objects, so create a filtering closure around the
aoqi@0 224 // oop closure before walking the region.
aoqi@0 225 FilteringClosure filter(_boundary, _cl);
aoqi@0 226 walk_mem_region_with_cl(mr, bottom, top, &filter);
aoqi@0 227 } else {
aoqi@0 228 // No boundary, simply walk the heap with the oop closure.
aoqi@0 229 walk_mem_region_with_cl(mr, bottom, top, _cl);
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 // We must replicate this so that the static type of "FilteringClosure"
aoqi@0 235 // (see above) is apparent at the oop_iterate calls.
aoqi@0 236 #define ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \
aoqi@0 237 void ContiguousSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \
aoqi@0 238 HeapWord* bottom, \
aoqi@0 239 HeapWord* top, \
aoqi@0 240 ClosureType* cl) { \
aoqi@0 241 bottom += oop(bottom)->oop_iterate(cl, mr); \
aoqi@0 242 if (bottom < top) { \
aoqi@0 243 HeapWord* next_obj = bottom + oop(bottom)->size(); \
aoqi@0 244 while (next_obj < top) { \
aoqi@0 245 /* Bottom lies entirely below top, so we can call the */ \
aoqi@0 246 /* non-memRegion version of oop_iterate below. */ \
aoqi@0 247 oop(bottom)->oop_iterate(cl); \
aoqi@0 248 bottom = next_obj; \
aoqi@0 249 next_obj = bottom + oop(bottom)->size(); \
aoqi@0 250 } \
aoqi@0 251 /* Last object. */ \
aoqi@0 252 oop(bottom)->oop_iterate(cl, mr); \
aoqi@0 253 } \
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 // (There are only two of these, rather than N, because the split is due
aoqi@0 257 // only to the introduction of the FilteringClosure, a local part of the
aoqi@0 258 // impl of this abstraction.)
aoqi@0 259 ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(ExtendedOopClosure)
aoqi@0 260 ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure)
aoqi@0 261
aoqi@0 262 DirtyCardToOopClosure*
aoqi@0 263 ContiguousSpace::new_dcto_cl(ExtendedOopClosure* cl,
aoqi@0 264 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 265 HeapWord* boundary) {
aoqi@0 266 return new ContiguousSpaceDCTOC(this, cl, precision, boundary);
aoqi@0 267 }
aoqi@0 268
aoqi@0 269 void Space::initialize(MemRegion mr,
aoqi@0 270 bool clear_space,
aoqi@0 271 bool mangle_space) {
aoqi@0 272 HeapWord* bottom = mr.start();
aoqi@0 273 HeapWord* end = mr.end();
aoqi@0 274 assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
aoqi@0 275 "invalid space boundaries");
aoqi@0 276 set_bottom(bottom);
aoqi@0 277 set_end(end);
aoqi@0 278 if (clear_space) clear(mangle_space);
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 void Space::clear(bool mangle_space) {
aoqi@0 282 if (ZapUnusedHeapArea && mangle_space) {
aoqi@0 283 mangle_unused_area();
aoqi@0 284 }
aoqi@0 285 }
aoqi@0 286
aoqi@0 287 ContiguousSpace::ContiguousSpace(): CompactibleSpace(), _top(NULL),
aoqi@0 288 _concurrent_iteration_safe_limit(NULL) {
aoqi@0 289 _mangler = new GenSpaceMangler(this);
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 ContiguousSpace::~ContiguousSpace() {
aoqi@0 293 delete _mangler;
aoqi@0 294 }
aoqi@0 295
aoqi@0 296 void ContiguousSpace::initialize(MemRegion mr,
aoqi@0 297 bool clear_space,
aoqi@0 298 bool mangle_space)
aoqi@0 299 {
aoqi@0 300 CompactibleSpace::initialize(mr, clear_space, mangle_space);
aoqi@0 301 set_concurrent_iteration_safe_limit(top());
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 void ContiguousSpace::clear(bool mangle_space) {
aoqi@0 305 set_top(bottom());
aoqi@0 306 set_saved_mark();
aoqi@0 307 CompactibleSpace::clear(mangle_space);
aoqi@0 308 }
aoqi@0 309
aoqi@0 310 bool ContiguousSpace::is_in(const void* p) const {
aoqi@0 311 return _bottom <= p && p < _top;
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 bool ContiguousSpace::is_free_block(const HeapWord* p) const {
aoqi@0 315 return p >= _top;
aoqi@0 316 }
aoqi@0 317
aoqi@0 318 void OffsetTableContigSpace::clear(bool mangle_space) {
aoqi@0 319 ContiguousSpace::clear(mangle_space);
aoqi@0 320 _offsets.initialize_threshold();
aoqi@0 321 }
aoqi@0 322
aoqi@0 323 void OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
aoqi@0 324 Space::set_bottom(new_bottom);
aoqi@0 325 _offsets.set_bottom(new_bottom);
aoqi@0 326 }
aoqi@0 327
aoqi@0 328 void OffsetTableContigSpace::set_end(HeapWord* new_end) {
aoqi@0 329 // Space should not advertize an increase in size
aoqi@0 330 // until after the underlying offest table has been enlarged.
aoqi@0 331 _offsets.resize(pointer_delta(new_end, bottom()));
aoqi@0 332 Space::set_end(new_end);
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 #ifndef PRODUCT
aoqi@0 336
aoqi@0 337 void ContiguousSpace::set_top_for_allocations(HeapWord* v) {
aoqi@0 338 mangler()->set_top_for_allocations(v);
aoqi@0 339 }
aoqi@0 340 void ContiguousSpace::set_top_for_allocations() {
aoqi@0 341 mangler()->set_top_for_allocations(top());
aoqi@0 342 }
aoqi@0 343 void ContiguousSpace::check_mangled_unused_area(HeapWord* limit) {
aoqi@0 344 mangler()->check_mangled_unused_area(limit);
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 void ContiguousSpace::check_mangled_unused_area_complete() {
aoqi@0 348 mangler()->check_mangled_unused_area_complete();
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 // Mangled only the unused space that has not previously
aoqi@0 352 // been mangled and that has not been allocated since being
aoqi@0 353 // mangled.
aoqi@0 354 void ContiguousSpace::mangle_unused_area() {
aoqi@0 355 mangler()->mangle_unused_area();
aoqi@0 356 }
aoqi@0 357 void ContiguousSpace::mangle_unused_area_complete() {
aoqi@0 358 mangler()->mangle_unused_area_complete();
aoqi@0 359 }
aoqi@0 360 void ContiguousSpace::mangle_region(MemRegion mr) {
aoqi@0 361 // Although this method uses SpaceMangler::mangle_region() which
aoqi@0 362 // is not specific to a space, the when the ContiguousSpace version
aoqi@0 363 // is called, it is always with regard to a space and this
aoqi@0 364 // bounds checking is appropriate.
aoqi@0 365 MemRegion space_mr(bottom(), end());
aoqi@0 366 assert(space_mr.contains(mr), "Mangling outside space");
aoqi@0 367 SpaceMangler::mangle_region(mr);
aoqi@0 368 }
aoqi@0 369 #endif // NOT_PRODUCT
aoqi@0 370
aoqi@0 371 void CompactibleSpace::initialize(MemRegion mr,
aoqi@0 372 bool clear_space,
aoqi@0 373 bool mangle_space) {
aoqi@0 374 Space::initialize(mr, clear_space, mangle_space);
aoqi@0 375 set_compaction_top(bottom());
aoqi@0 376 _next_compaction_space = NULL;
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 void CompactibleSpace::clear(bool mangle_space) {
aoqi@0 380 Space::clear(mangle_space);
aoqi@0 381 _compaction_top = bottom();
aoqi@0 382 }
aoqi@0 383
aoqi@0 384 HeapWord* CompactibleSpace::forward(oop q, size_t size,
aoqi@0 385 CompactPoint* cp, HeapWord* compact_top) {
aoqi@0 386 // q is alive
aoqi@0 387 // First check if we should switch compaction space
aoqi@0 388 assert(this == cp->space, "'this' should be current compaction space.");
aoqi@0 389 size_t compaction_max_size = pointer_delta(end(), compact_top);
aoqi@0 390 while (size > compaction_max_size) {
aoqi@0 391 // switch to next compaction space
aoqi@0 392 cp->space->set_compaction_top(compact_top);
aoqi@0 393 cp->space = cp->space->next_compaction_space();
aoqi@0 394 if (cp->space == NULL) {
aoqi@0 395 cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
aoqi@0 396 assert(cp->gen != NULL, "compaction must succeed");
aoqi@0 397 cp->space = cp->gen->first_compaction_space();
aoqi@0 398 assert(cp->space != NULL, "generation must have a first compaction space");
aoqi@0 399 }
aoqi@0 400 compact_top = cp->space->bottom();
aoqi@0 401 cp->space->set_compaction_top(compact_top);
aoqi@0 402 cp->threshold = cp->space->initialize_threshold();
aoqi@0 403 compaction_max_size = pointer_delta(cp->space->end(), compact_top);
aoqi@0 404 }
aoqi@0 405
aoqi@0 406 // store the forwarding pointer into the mark word
aoqi@0 407 if ((HeapWord*)q != compact_top) {
aoqi@0 408 q->forward_to(oop(compact_top));
aoqi@0 409 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
aoqi@0 410 } else {
aoqi@0 411 // if the object isn't moving we can just set the mark to the default
aoqi@0 412 // mark and handle it specially later on.
aoqi@0 413 q->init_mark();
aoqi@0 414 assert(q->forwardee() == NULL, "should be forwarded to NULL");
aoqi@0 415 }
aoqi@0 416
aoqi@0 417 compact_top += size;
aoqi@0 418
aoqi@0 419 // we need to update the offset table so that the beginnings of objects can be
aoqi@0 420 // found during scavenge. Note that we are updating the offset table based on
aoqi@0 421 // where the object will be once the compaction phase finishes.
aoqi@0 422 if (compact_top > cp->threshold)
aoqi@0 423 cp->threshold =
aoqi@0 424 cp->space->cross_threshold(compact_top - size, compact_top);
aoqi@0 425 return compact_top;
aoqi@0 426 }
aoqi@0 427
aoqi@0 428
aoqi@0 429 bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
aoqi@0 430 HeapWord* q, size_t deadlength) {
aoqi@0 431 if (allowed_deadspace_words >= deadlength) {
aoqi@0 432 allowed_deadspace_words -= deadlength;
aoqi@0 433 CollectedHeap::fill_with_object(q, deadlength);
aoqi@0 434 oop(q)->set_mark(oop(q)->mark()->set_marked());
aoqi@0 435 assert((int) deadlength == oop(q)->size(), "bad filler object size");
aoqi@0 436 // Recall that we required "q == compaction_top".
aoqi@0 437 return true;
aoqi@0 438 } else {
aoqi@0 439 allowed_deadspace_words = 0;
aoqi@0 440 return false;
aoqi@0 441 }
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 #define block_is_always_obj(q) true
aoqi@0 445 #define obj_size(q) oop(q)->size()
aoqi@0 446 #define adjust_obj_size(s) s
aoqi@0 447
aoqi@0 448 void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
aoqi@0 449 SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
aoqi@0 450 }
aoqi@0 451
aoqi@0 452 // Faster object search.
aoqi@0 453 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
aoqi@0 454 SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
aoqi@0 455 }
aoqi@0 456
aoqi@0 457 void Space::adjust_pointers() {
aoqi@0 458 // adjust all the interior pointers to point at the new locations of objects
aoqi@0 459 // Used by MarkSweep::mark_sweep_phase3()
aoqi@0 460
aoqi@0 461 // First check to see if there is any work to be done.
aoqi@0 462 if (used() == 0) {
aoqi@0 463 return; // Nothing to do.
aoqi@0 464 }
aoqi@0 465
aoqi@0 466 // Otherwise...
aoqi@0 467 HeapWord* q = bottom();
aoqi@0 468 HeapWord* t = end();
aoqi@0 469
aoqi@0 470 debug_only(HeapWord* prev_q = NULL);
aoqi@0 471 while (q < t) {
aoqi@0 472 if (oop(q)->is_gc_marked()) {
aoqi@0 473 // q is alive
aoqi@0 474
aoqi@0 475 // point all the oops to the new location
aoqi@0 476 size_t size = oop(q)->adjust_pointers();
aoqi@0 477
aoqi@0 478 debug_only(prev_q = q);
aoqi@0 479
aoqi@0 480 q += size;
aoqi@0 481 } else {
aoqi@0 482 // q is not a live object. But we're not in a compactible space,
aoqi@0 483 // So we don't have live ranges.
aoqi@0 484 debug_only(prev_q = q);
aoqi@0 485 q += block_size(q);
aoqi@0 486 assert(q > prev_q, "we should be moving forward through memory");
aoqi@0 487 }
aoqi@0 488 }
aoqi@0 489 assert(q == t, "just checking");
aoqi@0 490 }
aoqi@0 491
aoqi@0 492 void CompactibleSpace::adjust_pointers() {
aoqi@0 493 // Check first is there is any work to do.
aoqi@0 494 if (used() == 0) {
aoqi@0 495 return; // Nothing to do.
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
aoqi@0 499 }
aoqi@0 500
aoqi@0 501 void CompactibleSpace::compact() {
aoqi@0 502 SCAN_AND_COMPACT(obj_size);
aoqi@0 503 }
aoqi@0 504
aoqi@0 505 void Space::print_short() const { print_short_on(tty); }
aoqi@0 506
aoqi@0 507 void Space::print_short_on(outputStream* st) const {
aoqi@0 508 st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
aoqi@0 509 (int) ((double) used() * 100 / capacity()));
aoqi@0 510 }
aoqi@0 511
aoqi@0 512 void Space::print() const { print_on(tty); }
aoqi@0 513
aoqi@0 514 void Space::print_on(outputStream* st) const {
aoqi@0 515 print_short_on(st);
aoqi@0 516 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
aoqi@0 517 bottom(), end());
aoqi@0 518 }
aoqi@0 519
aoqi@0 520 void ContiguousSpace::print_on(outputStream* st) const {
aoqi@0 521 print_short_on(st);
aoqi@0 522 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
aoqi@0 523 bottom(), top(), end());
aoqi@0 524 }
aoqi@0 525
aoqi@0 526 void OffsetTableContigSpace::print_on(outputStream* st) const {
aoqi@0 527 print_short_on(st);
aoqi@0 528 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
aoqi@0 529 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
aoqi@0 530 bottom(), top(), _offsets.threshold(), end());
aoqi@0 531 }
aoqi@0 532
aoqi@0 533 void ContiguousSpace::verify() const {
aoqi@0 534 HeapWord* p = bottom();
aoqi@0 535 HeapWord* t = top();
aoqi@0 536 HeapWord* prev_p = NULL;
aoqi@0 537 while (p < t) {
aoqi@0 538 oop(p)->verify();
aoqi@0 539 prev_p = p;
aoqi@0 540 p += oop(p)->size();
aoqi@0 541 }
aoqi@0 542 guarantee(p == top(), "end of last object must match end of space");
aoqi@0 543 if (top() != end()) {
aoqi@0 544 guarantee(top() == block_start_const(end()-1) &&
aoqi@0 545 top() == block_start_const(top()),
aoqi@0 546 "top should be start of unallocated block, if it exists");
aoqi@0 547 }
aoqi@0 548 }
aoqi@0 549
aoqi@0 550 void Space::oop_iterate(ExtendedOopClosure* blk) {
aoqi@0 551 ObjectToOopClosure blk2(blk);
aoqi@0 552 object_iterate(&blk2);
aoqi@0 553 }
aoqi@0 554
aoqi@0 555 HeapWord* Space::object_iterate_careful(ObjectClosureCareful* cl) {
aoqi@0 556 guarantee(false, "NYI");
aoqi@0 557 return bottom();
aoqi@0 558 }
aoqi@0 559
aoqi@0 560 HeapWord* Space::object_iterate_careful_m(MemRegion mr,
aoqi@0 561 ObjectClosureCareful* cl) {
aoqi@0 562 guarantee(false, "NYI");
aoqi@0 563 return bottom();
aoqi@0 564 }
aoqi@0 565
aoqi@0 566
aoqi@0 567 void Space::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) {
aoqi@0 568 assert(!mr.is_empty(), "Should be non-empty");
aoqi@0 569 // We use MemRegion(bottom(), end()) rather than used_region() below
aoqi@0 570 // because the two are not necessarily equal for some kinds of
aoqi@0 571 // spaces, in particular, certain kinds of free list spaces.
aoqi@0 572 // We could use the more complicated but more precise:
aoqi@0 573 // MemRegion(used_region().start(), round_to(used_region().end(), CardSize))
aoqi@0 574 // but the slight imprecision seems acceptable in the assertion check.
aoqi@0 575 assert(MemRegion(bottom(), end()).contains(mr),
aoqi@0 576 "Should be within used space");
aoqi@0 577 HeapWord* prev = cl->previous(); // max address from last time
aoqi@0 578 if (prev >= mr.end()) { // nothing to do
aoqi@0 579 return;
aoqi@0 580 }
aoqi@0 581 // This assert will not work when we go from cms space to perm
aoqi@0 582 // space, and use same closure. Easy fix deferred for later. XXX YSR
aoqi@0 583 // assert(prev == NULL || contains(prev), "Should be within space");
aoqi@0 584
aoqi@0 585 bool last_was_obj_array = false;
aoqi@0 586 HeapWord *blk_start_addr, *region_start_addr;
aoqi@0 587 if (prev > mr.start()) {
aoqi@0 588 region_start_addr = prev;
aoqi@0 589 blk_start_addr = prev;
aoqi@0 590 // The previous invocation may have pushed "prev" beyond the
aoqi@0 591 // last allocated block yet there may be still be blocks
aoqi@0 592 // in this region due to a particular coalescing policy.
aoqi@0 593 // Relax the assertion so that the case where the unallocated
aoqi@0 594 // block is maintained and "prev" is beyond the unallocated
aoqi@0 595 // block does not cause the assertion to fire.
aoqi@0 596 assert((BlockOffsetArrayUseUnallocatedBlock &&
aoqi@0 597 (!is_in(prev))) ||
aoqi@0 598 (blk_start_addr == block_start(region_start_addr)), "invariant");
aoqi@0 599 } else {
aoqi@0 600 region_start_addr = mr.start();
aoqi@0 601 blk_start_addr = block_start(region_start_addr);
aoqi@0 602 }
aoqi@0 603 HeapWord* region_end_addr = mr.end();
aoqi@0 604 MemRegion derived_mr(region_start_addr, region_end_addr);
aoqi@0 605 while (blk_start_addr < region_end_addr) {
aoqi@0 606 const size_t size = block_size(blk_start_addr);
aoqi@0 607 if (block_is_obj(blk_start_addr)) {
aoqi@0 608 last_was_obj_array = cl->do_object_bm(oop(blk_start_addr), derived_mr);
aoqi@0 609 } else {
aoqi@0 610 last_was_obj_array = false;
aoqi@0 611 }
aoqi@0 612 blk_start_addr += size;
aoqi@0 613 }
aoqi@0 614 if (!last_was_obj_array) {
aoqi@0 615 assert((bottom() <= blk_start_addr) && (blk_start_addr <= end()),
aoqi@0 616 "Should be within (closed) used space");
aoqi@0 617 assert(blk_start_addr > prev, "Invariant");
aoqi@0 618 cl->set_previous(blk_start_addr); // min address for next time
aoqi@0 619 }
aoqi@0 620 }
aoqi@0 621
aoqi@0 622 bool Space::obj_is_alive(const HeapWord* p) const {
aoqi@0 623 assert (block_is_obj(p), "The address should point to an object");
aoqi@0 624 return true;
aoqi@0 625 }
aoqi@0 626
aoqi@0 627 void ContiguousSpace::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) {
aoqi@0 628 assert(!mr.is_empty(), "Should be non-empty");
aoqi@0 629 assert(used_region().contains(mr), "Should be within used space");
aoqi@0 630 HeapWord* prev = cl->previous(); // max address from last time
aoqi@0 631 if (prev >= mr.end()) { // nothing to do
aoqi@0 632 return;
aoqi@0 633 }
aoqi@0 634 // See comment above (in more general method above) in case you
aoqi@0 635 // happen to use this method.
aoqi@0 636 assert(prev == NULL || is_in_reserved(prev), "Should be within space");
aoqi@0 637
aoqi@0 638 bool last_was_obj_array = false;
aoqi@0 639 HeapWord *obj_start_addr, *region_start_addr;
aoqi@0 640 if (prev > mr.start()) {
aoqi@0 641 region_start_addr = prev;
aoqi@0 642 obj_start_addr = prev;
aoqi@0 643 assert(obj_start_addr == block_start(region_start_addr), "invariant");
aoqi@0 644 } else {
aoqi@0 645 region_start_addr = mr.start();
aoqi@0 646 obj_start_addr = block_start(region_start_addr);
aoqi@0 647 }
aoqi@0 648 HeapWord* region_end_addr = mr.end();
aoqi@0 649 MemRegion derived_mr(region_start_addr, region_end_addr);
aoqi@0 650 while (obj_start_addr < region_end_addr) {
aoqi@0 651 oop obj = oop(obj_start_addr);
aoqi@0 652 const size_t size = obj->size();
aoqi@0 653 last_was_obj_array = cl->do_object_bm(obj, derived_mr);
aoqi@0 654 obj_start_addr += size;
aoqi@0 655 }
aoqi@0 656 if (!last_was_obj_array) {
aoqi@0 657 assert((bottom() <= obj_start_addr) && (obj_start_addr <= end()),
aoqi@0 658 "Should be within (closed) used space");
aoqi@0 659 assert(obj_start_addr > prev, "Invariant");
aoqi@0 660 cl->set_previous(obj_start_addr); // min address for next time
aoqi@0 661 }
aoqi@0 662 }
aoqi@0 663
aoqi@0 664 #if INCLUDE_ALL_GCS
aoqi@0 665 #define ContigSpace_PAR_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
aoqi@0 666 \
aoqi@0 667 void ContiguousSpace::par_oop_iterate(MemRegion mr, OopClosureType* blk) {\
aoqi@0 668 HeapWord* obj_addr = mr.start(); \
aoqi@0 669 HeapWord* t = mr.end(); \
aoqi@0 670 while (obj_addr < t) { \
aoqi@0 671 assert(oop(obj_addr)->is_oop(), "Should be an oop"); \
aoqi@0 672 obj_addr += oop(obj_addr)->oop_iterate(blk); \
aoqi@0 673 } \
aoqi@0 674 }
aoqi@0 675
aoqi@0 676 ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DEFN)
aoqi@0 677
aoqi@0 678 #undef ContigSpace_PAR_OOP_ITERATE_DEFN
aoqi@0 679 #endif // INCLUDE_ALL_GCS
aoqi@0 680
aoqi@0 681 void ContiguousSpace::oop_iterate(ExtendedOopClosure* blk) {
aoqi@0 682 if (is_empty()) return;
aoqi@0 683 HeapWord* obj_addr = bottom();
aoqi@0 684 HeapWord* t = top();
aoqi@0 685 // Could call objects iterate, but this is easier.
aoqi@0 686 while (obj_addr < t) {
aoqi@0 687 obj_addr += oop(obj_addr)->oop_iterate(blk);
aoqi@0 688 }
aoqi@0 689 }
aoqi@0 690
aoqi@0 691 void ContiguousSpace::oop_iterate(MemRegion mr, ExtendedOopClosure* blk) {
aoqi@0 692 if (is_empty()) {
aoqi@0 693 return;
aoqi@0 694 }
aoqi@0 695 MemRegion cur = MemRegion(bottom(), top());
aoqi@0 696 mr = mr.intersection(cur);
aoqi@0 697 if (mr.is_empty()) {
aoqi@0 698 return;
aoqi@0 699 }
aoqi@0 700 if (mr.equals(cur)) {
aoqi@0 701 oop_iterate(blk);
aoqi@0 702 return;
aoqi@0 703 }
aoqi@0 704 assert(mr.end() <= top(), "just took an intersection above");
aoqi@0 705 HeapWord* obj_addr = block_start(mr.start());
aoqi@0 706 HeapWord* t = mr.end();
aoqi@0 707
aoqi@0 708 // Handle first object specially.
aoqi@0 709 oop obj = oop(obj_addr);
aoqi@0 710 SpaceMemRegionOopsIterClosure smr_blk(blk, mr);
aoqi@0 711 obj_addr += obj->oop_iterate(&smr_blk);
aoqi@0 712 while (obj_addr < t) {
aoqi@0 713 oop obj = oop(obj_addr);
aoqi@0 714 assert(obj->is_oop(), "expected an oop");
aoqi@0 715 obj_addr += obj->size();
aoqi@0 716 // If "obj_addr" is not greater than top, then the
aoqi@0 717 // entire object "obj" is within the region.
aoqi@0 718 if (obj_addr <= t) {
aoqi@0 719 obj->oop_iterate(blk);
aoqi@0 720 } else {
aoqi@0 721 // "obj" extends beyond end of region
aoqi@0 722 obj->oop_iterate(&smr_blk);
aoqi@0 723 break;
aoqi@0 724 }
aoqi@0 725 };
aoqi@0 726 }
aoqi@0 727
aoqi@0 728 void ContiguousSpace::object_iterate(ObjectClosure* blk) {
aoqi@0 729 if (is_empty()) return;
aoqi@0 730 WaterMark bm = bottom_mark();
aoqi@0 731 object_iterate_from(bm, blk);
aoqi@0 732 }
aoqi@0 733
aoqi@0 734 // For a continguous space object_iterate() and safe_object_iterate()
aoqi@0 735 // are the same.
aoqi@0 736 void ContiguousSpace::safe_object_iterate(ObjectClosure* blk) {
aoqi@0 737 object_iterate(blk);
aoqi@0 738 }
aoqi@0 739
aoqi@0 740 void ContiguousSpace::object_iterate_from(WaterMark mark, ObjectClosure* blk) {
aoqi@0 741 assert(mark.space() == this, "Mark does not match space");
aoqi@0 742 HeapWord* p = mark.point();
aoqi@0 743 while (p < top()) {
aoqi@0 744 blk->do_object(oop(p));
aoqi@0 745 p += oop(p)->size();
aoqi@0 746 }
aoqi@0 747 }
aoqi@0 748
aoqi@0 749 HeapWord*
aoqi@0 750 ContiguousSpace::object_iterate_careful(ObjectClosureCareful* blk) {
aoqi@0 751 HeapWord * limit = concurrent_iteration_safe_limit();
aoqi@0 752 assert(limit <= top(), "sanity check");
aoqi@0 753 for (HeapWord* p = bottom(); p < limit;) {
aoqi@0 754 size_t size = blk->do_object_careful(oop(p));
aoqi@0 755 if (size == 0) {
aoqi@0 756 return p; // failed at p
aoqi@0 757 } else {
aoqi@0 758 p += size;
aoqi@0 759 }
aoqi@0 760 }
aoqi@0 761 return NULL; // all done
aoqi@0 762 }
aoqi@0 763
aoqi@0 764 #define ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \
aoqi@0 765 \
aoqi@0 766 void ContiguousSpace:: \
aoqi@0 767 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \
aoqi@0 768 HeapWord* t; \
aoqi@0 769 HeapWord* p = saved_mark_word(); \
aoqi@0 770 assert(p != NULL, "expected saved mark"); \
aoqi@0 771 \
aoqi@0 772 const intx interval = PrefetchScanIntervalInBytes; \
aoqi@0 773 do { \
aoqi@0 774 t = top(); \
aoqi@0 775 while (p < t) { \
aoqi@0 776 Prefetch::write(p, interval); \
aoqi@0 777 debug_only(HeapWord* prev = p); \
aoqi@0 778 oop m = oop(p); \
aoqi@0 779 p += m->oop_iterate(blk); \
aoqi@0 780 } \
aoqi@0 781 } while (t < top()); \
aoqi@0 782 \
aoqi@0 783 set_saved_mark_word(p); \
aoqi@0 784 }
aoqi@0 785
aoqi@0 786 ALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN)
aoqi@0 787
aoqi@0 788 #undef ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN
aoqi@0 789
aoqi@0 790 // Very general, slow implementation.
aoqi@0 791 HeapWord* ContiguousSpace::block_start_const(const void* p) const {
aoqi@0 792 assert(MemRegion(bottom(), end()).contains(p),
aoqi@0 793 err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
aoqi@0 794 p, bottom(), end()));
aoqi@0 795 if (p >= top()) {
aoqi@0 796 return top();
aoqi@0 797 } else {
aoqi@0 798 HeapWord* last = bottom();
aoqi@0 799 HeapWord* cur = last;
aoqi@0 800 while (cur <= p) {
aoqi@0 801 last = cur;
aoqi@0 802 cur += oop(cur)->size();
aoqi@0 803 }
aoqi@0 804 assert(oop(last)->is_oop(),
aoqi@0 805 err_msg(PTR_FORMAT " should be an object start", last));
aoqi@0 806 return last;
aoqi@0 807 }
aoqi@0 808 }
aoqi@0 809
aoqi@0 810 size_t ContiguousSpace::block_size(const HeapWord* p) const {
aoqi@0 811 assert(MemRegion(bottom(), end()).contains(p),
aoqi@0 812 err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
aoqi@0 813 p, bottom(), end()));
aoqi@0 814 HeapWord* current_top = top();
aoqi@0 815 assert(p <= current_top,
aoqi@0 816 err_msg("p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT,
aoqi@0 817 p, current_top));
aoqi@0 818 assert(p == current_top || oop(p)->is_oop(),
aoqi@0 819 err_msg("p (" PTR_FORMAT ") is not a block start - "
aoqi@0 820 "current_top: " PTR_FORMAT ", is_oop: %s",
aoqi@0 821 p, current_top, BOOL_TO_STR(oop(p)->is_oop())));
aoqi@0 822 if (p < current_top) {
aoqi@0 823 return oop(p)->size();
aoqi@0 824 } else {
aoqi@0 825 assert(p == current_top, "just checking");
aoqi@0 826 return pointer_delta(end(), (HeapWord*) p);
aoqi@0 827 }
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 // This version requires locking.
aoqi@0 831 inline HeapWord* ContiguousSpace::allocate_impl(size_t size,
aoqi@0 832 HeapWord* const end_value) {
aoqi@0 833 // In G1 there are places where a GC worker can allocates into a
aoqi@0 834 // region using this serial allocation code without being prone to a
aoqi@0 835 // race with other GC workers (we ensure that no other GC worker can
aoqi@0 836 // access the same region at the same time). So the assert below is
aoqi@0 837 // too strong in the case of G1.
aoqi@0 838 assert(Heap_lock->owned_by_self() ||
aoqi@0 839 (SafepointSynchronize::is_at_safepoint() &&
aoqi@0 840 (Thread::current()->is_VM_thread() || UseG1GC)),
aoqi@0 841 "not locked");
aoqi@0 842 HeapWord* obj = top();
aoqi@0 843 if (pointer_delta(end_value, obj) >= size) {
aoqi@0 844 HeapWord* new_top = obj + size;
aoqi@0 845 set_top(new_top);
aoqi@0 846 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
aoqi@0 847 return obj;
aoqi@0 848 } else {
aoqi@0 849 return NULL;
aoqi@0 850 }
aoqi@0 851 }
aoqi@0 852
aoqi@0 853 // This version is lock-free.
aoqi@0 854 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size,
aoqi@0 855 HeapWord* const end_value) {
aoqi@0 856 do {
aoqi@0 857 HeapWord* obj = top();
aoqi@0 858 if (pointer_delta(end_value, obj) >= size) {
aoqi@0 859 HeapWord* new_top = obj + size;
aoqi@0 860 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
aoqi@0 861 // result can be one of two:
aoqi@0 862 // the old top value: the exchange succeeded
aoqi@0 863 // otherwise: the new value of the top is returned.
aoqi@0 864 if (result == obj) {
aoqi@0 865 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
aoqi@0 866 return obj;
aoqi@0 867 }
aoqi@0 868 } else {
aoqi@0 869 return NULL;
aoqi@0 870 }
aoqi@0 871 } while (true);
aoqi@0 872 }
aoqi@0 873
aoqi@0 874 // Requires locking.
aoqi@0 875 HeapWord* ContiguousSpace::allocate(size_t size) {
aoqi@0 876 return allocate_impl(size, end());
aoqi@0 877 }
aoqi@0 878
aoqi@0 879 // Lock-free.
aoqi@0 880 HeapWord* ContiguousSpace::par_allocate(size_t size) {
aoqi@0 881 return par_allocate_impl(size, end());
aoqi@0 882 }
aoqi@0 883
aoqi@0 884 void ContiguousSpace::allocate_temporary_filler(int factor) {
aoqi@0 885 // allocate temporary type array decreasing free size with factor 'factor'
aoqi@0 886 assert(factor >= 0, "just checking");
aoqi@0 887 size_t size = pointer_delta(end(), top());
aoqi@0 888
aoqi@0 889 // if space is full, return
aoqi@0 890 if (size == 0) return;
aoqi@0 891
aoqi@0 892 if (factor > 0) {
aoqi@0 893 size -= size/factor;
aoqi@0 894 }
aoqi@0 895 size = align_object_size(size);
aoqi@0 896
aoqi@0 897 const size_t array_header_size = typeArrayOopDesc::header_size(T_INT);
aoqi@0 898 if (size >= (size_t)align_object_size(array_header_size)) {
aoqi@0 899 size_t length = (size - array_header_size) * (HeapWordSize / sizeof(jint));
aoqi@0 900 // allocate uninitialized int array
aoqi@0 901 typeArrayOop t = (typeArrayOop) allocate(size);
aoqi@0 902 assert(t != NULL, "allocation should succeed");
aoqi@0 903 t->set_mark(markOopDesc::prototype());
aoqi@0 904 t->set_klass(Universe::intArrayKlassObj());
aoqi@0 905 t->set_length((int)length);
aoqi@0 906 } else {
aoqi@0 907 assert(size == CollectedHeap::min_fill_size(),
aoqi@0 908 "size for smallest fake object doesn't match");
aoqi@0 909 instanceOop obj = (instanceOop) allocate(size);
aoqi@0 910 obj->set_mark(markOopDesc::prototype());
aoqi@0 911 obj->set_klass_gap(0);
aoqi@0 912 obj->set_klass(SystemDictionary::Object_klass());
aoqi@0 913 }
aoqi@0 914 }
aoqi@0 915
aoqi@0 916 void EdenSpace::clear(bool mangle_space) {
aoqi@0 917 ContiguousSpace::clear(mangle_space);
aoqi@0 918 set_soft_end(end());
aoqi@0 919 }
aoqi@0 920
aoqi@0 921 // Requires locking.
aoqi@0 922 HeapWord* EdenSpace::allocate(size_t size) {
aoqi@0 923 return allocate_impl(size, soft_end());
aoqi@0 924 }
aoqi@0 925
aoqi@0 926 // Lock-free.
aoqi@0 927 HeapWord* EdenSpace::par_allocate(size_t size) {
aoqi@0 928 return par_allocate_impl(size, soft_end());
aoqi@0 929 }
aoqi@0 930
aoqi@0 931 HeapWord* ConcEdenSpace::par_allocate(size_t size)
aoqi@0 932 {
aoqi@0 933 do {
aoqi@0 934 // The invariant is top() should be read before end() because
aoqi@0 935 // top() can't be greater than end(), so if an update of _soft_end
aoqi@0 936 // occurs between 'end_val = end();' and 'top_val = top();' top()
aoqi@0 937 // also can grow up to the new end() and the condition
aoqi@0 938 // 'top_val > end_val' is true. To ensure the loading order
aoqi@0 939 // OrderAccess::loadload() is required after top() read.
aoqi@0 940 HeapWord* obj = top();
aoqi@0 941 OrderAccess::loadload();
aoqi@0 942 if (pointer_delta(*soft_end_addr(), obj) >= size) {
aoqi@0 943 HeapWord* new_top = obj + size;
aoqi@0 944 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
aoqi@0 945 // result can be one of two:
aoqi@0 946 // the old top value: the exchange succeeded
aoqi@0 947 // otherwise: the new value of the top is returned.
aoqi@0 948 if (result == obj) {
aoqi@0 949 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
aoqi@0 950 return obj;
aoqi@0 951 }
aoqi@0 952 } else {
aoqi@0 953 return NULL;
aoqi@0 954 }
aoqi@0 955 } while (true);
aoqi@0 956 }
aoqi@0 957
aoqi@0 958
aoqi@0 959 HeapWord* OffsetTableContigSpace::initialize_threshold() {
aoqi@0 960 return _offsets.initialize_threshold();
aoqi@0 961 }
aoqi@0 962
aoqi@0 963 HeapWord* OffsetTableContigSpace::cross_threshold(HeapWord* start, HeapWord* end) {
aoqi@0 964 _offsets.alloc_block(start, end);
aoqi@0 965 return _offsets.threshold();
aoqi@0 966 }
aoqi@0 967
aoqi@0 968 OffsetTableContigSpace::OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray,
aoqi@0 969 MemRegion mr) :
aoqi@0 970 _offsets(sharedOffsetArray, mr),
aoqi@0 971 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true)
aoqi@0 972 {
aoqi@0 973 _offsets.set_contig_space(this);
aoqi@0 974 initialize(mr, SpaceDecorator::Clear, SpaceDecorator::Mangle);
aoqi@0 975 }
aoqi@0 976
aoqi@0 977 #define OBJ_SAMPLE_INTERVAL 0
aoqi@0 978 #define BLOCK_SAMPLE_INTERVAL 100
aoqi@0 979
aoqi@0 980 void OffsetTableContigSpace::verify() const {
aoqi@0 981 HeapWord* p = bottom();
aoqi@0 982 HeapWord* prev_p = NULL;
aoqi@0 983 int objs = 0;
aoqi@0 984 int blocks = 0;
aoqi@0 985
aoqi@0 986 if (VerifyObjectStartArray) {
aoqi@0 987 _offsets.verify();
aoqi@0 988 }
aoqi@0 989
aoqi@0 990 while (p < top()) {
aoqi@0 991 size_t size = oop(p)->size();
aoqi@0 992 // For a sampling of objects in the space, find it using the
aoqi@0 993 // block offset table.
aoqi@0 994 if (blocks == BLOCK_SAMPLE_INTERVAL) {
aoqi@0 995 guarantee(p == block_start_const(p + (size/2)),
aoqi@0 996 "check offset computation");
aoqi@0 997 blocks = 0;
aoqi@0 998 } else {
aoqi@0 999 blocks++;
aoqi@0 1000 }
aoqi@0 1001
aoqi@0 1002 if (objs == OBJ_SAMPLE_INTERVAL) {
aoqi@0 1003 oop(p)->verify();
aoqi@0 1004 objs = 0;
aoqi@0 1005 } else {
aoqi@0 1006 objs++;
aoqi@0 1007 }
aoqi@0 1008 prev_p = p;
aoqi@0 1009 p += size;
aoqi@0 1010 }
aoqi@0 1011 guarantee(p == top(), "end of last object must match end of space");
aoqi@0 1012 }
aoqi@0 1013
aoqi@0 1014
aoqi@0 1015 size_t TenuredSpace::allowed_dead_ratio() const {
aoqi@0 1016 return MarkSweepDeadRatio;
aoqi@0 1017 }

mercurial