src/share/vm/memory/space.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6503
a9becfeecd1b
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, 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 #ifndef SHARE_VM_MEMORY_SPACE_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_SPACE_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29 #include "memory/blockOffsetTable.hpp"
aoqi@0 30 #include "memory/cardTableModRefBS.hpp"
aoqi@0 31 #include "memory/iterator.hpp"
aoqi@0 32 #include "memory/memRegion.hpp"
aoqi@0 33 #include "memory/watermark.hpp"
aoqi@0 34 #include "oops/markOop.hpp"
aoqi@0 35 #include "runtime/mutexLocker.hpp"
aoqi@0 36 #include "runtime/prefetch.hpp"
aoqi@0 37 #include "utilities/macros.hpp"
aoqi@0 38 #include "utilities/workgroup.hpp"
aoqi@0 39 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 40 # include "os_linux.inline.hpp"
aoqi@0 41 #endif
aoqi@0 42 #ifdef TARGET_OS_FAMILY_solaris
aoqi@0 43 # include "os_solaris.inline.hpp"
aoqi@0 44 #endif
aoqi@0 45 #ifdef TARGET_OS_FAMILY_windows
aoqi@0 46 # include "os_windows.inline.hpp"
aoqi@0 47 #endif
aoqi@0 48 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 49 # include "os_aix.inline.hpp"
aoqi@0 50 #endif
aoqi@0 51 #ifdef TARGET_OS_FAMILY_bsd
aoqi@0 52 # include "os_bsd.inline.hpp"
aoqi@0 53 #endif
aoqi@0 54
aoqi@0 55 // A space is an abstraction for the "storage units" backing
aoqi@0 56 // up the generation abstraction. It includes specific
aoqi@0 57 // implementations for keeping track of free and used space,
aoqi@0 58 // for iterating over objects and free blocks, etc.
aoqi@0 59
aoqi@0 60 // Here's the Space hierarchy:
aoqi@0 61 //
aoqi@0 62 // - Space -- an asbtract base class describing a heap area
aoqi@0 63 // - CompactibleSpace -- a space supporting compaction
aoqi@0 64 // - CompactibleFreeListSpace -- (used for CMS generation)
aoqi@0 65 // - ContiguousSpace -- a compactible space in which all free space
aoqi@0 66 // is contiguous
aoqi@0 67 // - EdenSpace -- contiguous space used as nursery
aoqi@0 68 // - ConcEdenSpace -- contiguous space with a 'soft end safe' allocation
aoqi@0 69 // - OffsetTableContigSpace -- contiguous space with a block offset array
aoqi@0 70 // that allows "fast" block_start calls
aoqi@0 71 // - TenuredSpace -- (used for TenuredGeneration)
aoqi@0 72
aoqi@0 73 // Forward decls.
aoqi@0 74 class Space;
aoqi@0 75 class BlockOffsetArray;
aoqi@0 76 class BlockOffsetArrayContigSpace;
aoqi@0 77 class Generation;
aoqi@0 78 class CompactibleSpace;
aoqi@0 79 class BlockOffsetTable;
aoqi@0 80 class GenRemSet;
aoqi@0 81 class CardTableRS;
aoqi@0 82 class DirtyCardToOopClosure;
aoqi@0 83
aoqi@0 84 // An oop closure that is circumscribed by a filtering memory region.
aoqi@0 85 class SpaceMemRegionOopsIterClosure: public ExtendedOopClosure {
aoqi@0 86 private:
aoqi@0 87 ExtendedOopClosure* _cl;
aoqi@0 88 MemRegion _mr;
aoqi@0 89 protected:
aoqi@0 90 template <class T> void do_oop_work(T* p) {
aoqi@0 91 if (_mr.contains(p)) {
aoqi@0 92 _cl->do_oop(p);
aoqi@0 93 }
aoqi@0 94 }
aoqi@0 95 public:
aoqi@0 96 SpaceMemRegionOopsIterClosure(ExtendedOopClosure* cl, MemRegion mr):
aoqi@0 97 _cl(cl), _mr(mr) {}
aoqi@0 98 virtual void do_oop(oop* p);
aoqi@0 99 virtual void do_oop(narrowOop* p);
aoqi@0 100 virtual bool do_metadata() {
aoqi@0 101 // _cl is of type ExtendedOopClosure instead of OopClosure, so that we can check this.
aoqi@0 102 assert(!_cl->do_metadata(), "I've checked all call paths, this shouldn't happen.");
aoqi@0 103 return false;
aoqi@0 104 }
aoqi@0 105 virtual void do_klass(Klass* k) { ShouldNotReachHere(); }
aoqi@0 106 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); }
aoqi@0 107 };
aoqi@0 108
aoqi@0 109 // A Space describes a heap area. Class Space is an abstract
aoqi@0 110 // base class.
aoqi@0 111 //
aoqi@0 112 // Space supports allocation, size computation and GC support is provided.
aoqi@0 113 //
aoqi@0 114 // Invariant: bottom() and end() are on page_size boundaries and
aoqi@0 115 // bottom() <= top() <= end()
aoqi@0 116 // top() is inclusive and end() is exclusive.
aoqi@0 117
aoqi@0 118 class Space: public CHeapObj<mtGC> {
aoqi@0 119 friend class VMStructs;
aoqi@0 120 protected:
aoqi@0 121 HeapWord* _bottom;
aoqi@0 122 HeapWord* _end;
aoqi@0 123
aoqi@0 124 // Used in support of save_marks()
aoqi@0 125 HeapWord* _saved_mark_word;
aoqi@0 126
aoqi@0 127 MemRegionClosure* _preconsumptionDirtyCardClosure;
aoqi@0 128
aoqi@0 129 // A sequential tasks done structure. This supports
aoqi@0 130 // parallel GC, where we have threads dynamically
aoqi@0 131 // claiming sub-tasks from a larger parallel task.
aoqi@0 132 SequentialSubTasksDone _par_seq_tasks;
aoqi@0 133
aoqi@0 134 Space():
aoqi@0 135 _bottom(NULL), _end(NULL), _preconsumptionDirtyCardClosure(NULL) { }
aoqi@0 136
aoqi@0 137 public:
aoqi@0 138 // Accessors
aoqi@0 139 HeapWord* bottom() const { return _bottom; }
aoqi@0 140 HeapWord* end() const { return _end; }
aoqi@0 141 virtual void set_bottom(HeapWord* value) { _bottom = value; }
aoqi@0 142 virtual void set_end(HeapWord* value) { _end = value; }
aoqi@0 143
aoqi@0 144 virtual HeapWord* saved_mark_word() const { return _saved_mark_word; }
aoqi@0 145
aoqi@0 146 void set_saved_mark_word(HeapWord* p) { _saved_mark_word = p; }
aoqi@0 147
aoqi@0 148 MemRegionClosure* preconsumptionDirtyCardClosure() const {
aoqi@0 149 return _preconsumptionDirtyCardClosure;
aoqi@0 150 }
aoqi@0 151 void setPreconsumptionDirtyCardClosure(MemRegionClosure* cl) {
aoqi@0 152 _preconsumptionDirtyCardClosure = cl;
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 // Returns a subregion of the space containing all the objects in
aoqi@0 156 // the space.
aoqi@0 157 virtual MemRegion used_region() const { return MemRegion(bottom(), end()); }
aoqi@0 158
aoqi@0 159 // Returns a region that is guaranteed to contain (at least) all objects
aoqi@0 160 // allocated at the time of the last call to "save_marks". If the space
aoqi@0 161 // initializes its DirtyCardToOopClosure's specifying the "contig" option
aoqi@0 162 // (that is, if the space is contiguous), then this region must contain only
aoqi@0 163 // such objects: the memregion will be from the bottom of the region to the
aoqi@0 164 // saved mark. Otherwise, the "obj_allocated_since_save_marks" method of
aoqi@0 165 // the space must distiguish between objects in the region allocated before
aoqi@0 166 // and after the call to save marks.
aoqi@0 167 virtual MemRegion used_region_at_save_marks() const {
aoqi@0 168 return MemRegion(bottom(), saved_mark_word());
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 // Initialization.
aoqi@0 172 // "initialize" should be called once on a space, before it is used for
aoqi@0 173 // any purpose. The "mr" arguments gives the bounds of the space, and
aoqi@0 174 // the "clear_space" argument should be true unless the memory in "mr" is
aoqi@0 175 // known to be zeroed.
aoqi@0 176 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
aoqi@0 177
aoqi@0 178 // The "clear" method must be called on a region that may have
aoqi@0 179 // had allocation performed in it, but is now to be considered empty.
aoqi@0 180 virtual void clear(bool mangle_space);
aoqi@0 181
aoqi@0 182 // For detecting GC bugs. Should only be called at GC boundaries, since
aoqi@0 183 // some unused space may be used as scratch space during GC's.
aoqi@0 184 // Default implementation does nothing. We also call this when expanding
aoqi@0 185 // a space to satisfy an allocation request. See bug #4668531
aoqi@0 186 virtual void mangle_unused_area() {}
aoqi@0 187 virtual void mangle_unused_area_complete() {}
aoqi@0 188 virtual void mangle_region(MemRegion mr) {}
aoqi@0 189
aoqi@0 190 // Testers
aoqi@0 191 bool is_empty() const { return used() == 0; }
aoqi@0 192 bool not_empty() const { return used() > 0; }
aoqi@0 193
aoqi@0 194 // Returns true iff the given the space contains the
aoqi@0 195 // given address as part of an allocated object. For
aoqi@0 196 // ceratin kinds of spaces, this might be a potentially
aoqi@0 197 // expensive operation. To prevent performance problems
aoqi@0 198 // on account of its inadvertent use in product jvm's,
aoqi@0 199 // we restrict its use to assertion checks only.
aoqi@0 200 virtual bool is_in(const void* p) const = 0;
aoqi@0 201
aoqi@0 202 // Returns true iff the given reserved memory of the space contains the
aoqi@0 203 // given address.
aoqi@0 204 bool is_in_reserved(const void* p) const { return _bottom <= p && p < _end; }
aoqi@0 205
aoqi@0 206 // Returns true iff the given block is not allocated.
aoqi@0 207 virtual bool is_free_block(const HeapWord* p) const = 0;
aoqi@0 208
aoqi@0 209 // Test whether p is double-aligned
aoqi@0 210 static bool is_aligned(void* p) {
aoqi@0 211 return ((intptr_t)p & (sizeof(double)-1)) == 0;
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 // Size computations. Sizes are in bytes.
aoqi@0 215 size_t capacity() const { return byte_size(bottom(), end()); }
aoqi@0 216 virtual size_t used() const = 0;
aoqi@0 217 virtual size_t free() const = 0;
aoqi@0 218
aoqi@0 219 // Iterate over all the ref-containing fields of all objects in the
aoqi@0 220 // space, calling "cl.do_oop" on each. Fields in objects allocated by
aoqi@0 221 // applications of the closure are not included in the iteration.
aoqi@0 222 virtual void oop_iterate(ExtendedOopClosure* cl);
aoqi@0 223
aoqi@0 224 // Same as above, restricted to the intersection of a memory region and
aoqi@0 225 // the space. Fields in objects allocated by applications of the closure
aoqi@0 226 // are not included in the iteration.
aoqi@0 227 virtual void oop_iterate(MemRegion mr, ExtendedOopClosure* cl) = 0;
aoqi@0 228
aoqi@0 229 // Iterate over all objects in the space, calling "cl.do_object" on
aoqi@0 230 // each. Objects allocated by applications of the closure are not
aoqi@0 231 // included in the iteration.
aoqi@0 232 virtual void object_iterate(ObjectClosure* blk) = 0;
aoqi@0 233 // Similar to object_iterate() except only iterates over
aoqi@0 234 // objects whose internal references point to objects in the space.
aoqi@0 235 virtual void safe_object_iterate(ObjectClosure* blk) = 0;
aoqi@0 236
aoqi@0 237 // Iterate over all objects that intersect with mr, calling "cl->do_object"
aoqi@0 238 // on each. There is an exception to this: if this closure has already
aoqi@0 239 // been invoked on an object, it may skip such objects in some cases. This is
aoqi@0 240 // Most likely to happen in an "upwards" (ascending address) iteration of
aoqi@0 241 // MemRegions.
aoqi@0 242 virtual void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl);
aoqi@0 243
aoqi@0 244 // Iterate over as many initialized objects in the space as possible,
aoqi@0 245 // calling "cl.do_object_careful" on each. Return NULL if all objects
aoqi@0 246 // in the space (at the start of the iteration) were iterated over.
aoqi@0 247 // Return an address indicating the extent of the iteration in the
aoqi@0 248 // event that the iteration had to return because of finding an
aoqi@0 249 // uninitialized object in the space, or if the closure "cl"
aoqi@0 250 // signalled early termination.
aoqi@0 251 virtual HeapWord* object_iterate_careful(ObjectClosureCareful* cl);
aoqi@0 252 virtual HeapWord* object_iterate_careful_m(MemRegion mr,
aoqi@0 253 ObjectClosureCareful* cl);
aoqi@0 254
aoqi@0 255 // Create and return a new dirty card to oop closure. Can be
aoqi@0 256 // overriden to return the appropriate type of closure
aoqi@0 257 // depending on the type of space in which the closure will
aoqi@0 258 // operate. ResourceArea allocated.
aoqi@0 259 virtual DirtyCardToOopClosure* new_dcto_cl(ExtendedOopClosure* cl,
aoqi@0 260 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 261 HeapWord* boundary = NULL);
aoqi@0 262
aoqi@0 263 // If "p" is in the space, returns the address of the start of the
aoqi@0 264 // "block" that contains "p". We say "block" instead of "object" since
aoqi@0 265 // some heaps may not pack objects densely; a chunk may either be an
aoqi@0 266 // object or a non-object. If "p" is not in the space, return NULL.
aoqi@0 267 virtual HeapWord* block_start_const(const void* p) const = 0;
aoqi@0 268
aoqi@0 269 // The non-const version may have benevolent side effects on the data
aoqi@0 270 // structure supporting these calls, possibly speeding up future calls.
aoqi@0 271 // The default implementation, however, is simply to call the const
aoqi@0 272 // version.
aoqi@0 273 inline virtual HeapWord* block_start(const void* p);
aoqi@0 274
aoqi@0 275 // Requires "addr" to be the start of a chunk, and returns its size.
aoqi@0 276 // "addr + size" is required to be the start of a new chunk, or the end
aoqi@0 277 // of the active area of the heap.
aoqi@0 278 virtual size_t block_size(const HeapWord* addr) const = 0;
aoqi@0 279
aoqi@0 280 // Requires "addr" to be the start of a block, and returns "TRUE" iff
aoqi@0 281 // the block is an object.
aoqi@0 282 virtual bool block_is_obj(const HeapWord* addr) const = 0;
aoqi@0 283
aoqi@0 284 // Requires "addr" to be the start of a block, and returns "TRUE" iff
aoqi@0 285 // the block is an object and the object is alive.
aoqi@0 286 virtual bool obj_is_alive(const HeapWord* addr) const;
aoqi@0 287
aoqi@0 288 // Allocation (return NULL if full). Assumes the caller has established
aoqi@0 289 // mutually exclusive access to the space.
aoqi@0 290 virtual HeapWord* allocate(size_t word_size) = 0;
aoqi@0 291
aoqi@0 292 // Allocation (return NULL if full). Enforces mutual exclusion internally.
aoqi@0 293 virtual HeapWord* par_allocate(size_t word_size) = 0;
aoqi@0 294
aoqi@0 295 // Returns true if this object has been allocated since a
aoqi@0 296 // generation's "save_marks" call.
aoqi@0 297 virtual bool obj_allocated_since_save_marks(const oop obj) const = 0;
aoqi@0 298
aoqi@0 299 // Mark-sweep-compact support: all spaces can update pointers to objects
aoqi@0 300 // moving as a part of compaction.
aoqi@0 301 virtual void adjust_pointers();
aoqi@0 302
aoqi@0 303 // PrintHeapAtGC support
aoqi@0 304 virtual void print() const;
aoqi@0 305 virtual void print_on(outputStream* st) const;
aoqi@0 306 virtual void print_short() const;
aoqi@0 307 virtual void print_short_on(outputStream* st) const;
aoqi@0 308
aoqi@0 309
aoqi@0 310 // Accessor for parallel sequential tasks.
aoqi@0 311 SequentialSubTasksDone* par_seq_tasks() { return &_par_seq_tasks; }
aoqi@0 312
aoqi@0 313 // IF "this" is a ContiguousSpace, return it, else return NULL.
aoqi@0 314 virtual ContiguousSpace* toContiguousSpace() {
aoqi@0 315 return NULL;
aoqi@0 316 }
aoqi@0 317
aoqi@0 318 // Debugging
aoqi@0 319 virtual void verify() const = 0;
aoqi@0 320 };
aoqi@0 321
aoqi@0 322 // A MemRegionClosure (ResourceObj) whose "do_MemRegion" function applies an
aoqi@0 323 // OopClosure to (the addresses of) all the ref-containing fields that could
aoqi@0 324 // be modified by virtue of the given MemRegion being dirty. (Note that
aoqi@0 325 // because of the imprecise nature of the write barrier, this may iterate
aoqi@0 326 // over oops beyond the region.)
aoqi@0 327 // This base type for dirty card to oop closures handles memory regions
aoqi@0 328 // in non-contiguous spaces with no boundaries, and should be sub-classed
aoqi@0 329 // to support other space types. See ContiguousDCTOC for a sub-class
aoqi@0 330 // that works with ContiguousSpaces.
aoqi@0 331
aoqi@0 332 class DirtyCardToOopClosure: public MemRegionClosureRO {
aoqi@0 333 protected:
aoqi@0 334 ExtendedOopClosure* _cl;
aoqi@0 335 Space* _sp;
aoqi@0 336 CardTableModRefBS::PrecisionStyle _precision;
aoqi@0 337 HeapWord* _boundary; // If non-NULL, process only non-NULL oops
aoqi@0 338 // pointing below boundary.
aoqi@0 339 HeapWord* _min_done; // ObjHeadPreciseArray precision requires
aoqi@0 340 // a downwards traversal; this is the
aoqi@0 341 // lowest location already done (or,
aoqi@0 342 // alternatively, the lowest address that
aoqi@0 343 // shouldn't be done again. NULL means infinity.)
aoqi@0 344 NOT_PRODUCT(HeapWord* _last_bottom;)
aoqi@0 345 NOT_PRODUCT(HeapWord* _last_explicit_min_done;)
aoqi@0 346
aoqi@0 347 // Get the actual top of the area on which the closure will
aoqi@0 348 // operate, given where the top is assumed to be (the end of the
aoqi@0 349 // memory region passed to do_MemRegion) and where the object
aoqi@0 350 // at the top is assumed to start. For example, an object may
aoqi@0 351 // start at the top but actually extend past the assumed top,
aoqi@0 352 // in which case the top becomes the end of the object.
aoqi@0 353 virtual HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj);
aoqi@0 354
aoqi@0 355 // Walk the given memory region from bottom to (actual) top
aoqi@0 356 // looking for objects and applying the oop closure (_cl) to
aoqi@0 357 // them. The base implementation of this treats the area as
aoqi@0 358 // blocks, where a block may or may not be an object. Sub-
aoqi@0 359 // classes should override this to provide more accurate
aoqi@0 360 // or possibly more efficient walking.
aoqi@0 361 virtual void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top);
aoqi@0 362
aoqi@0 363 public:
aoqi@0 364 DirtyCardToOopClosure(Space* sp, ExtendedOopClosure* cl,
aoqi@0 365 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 366 HeapWord* boundary) :
aoqi@0 367 _sp(sp), _cl(cl), _precision(precision), _boundary(boundary),
aoqi@0 368 _min_done(NULL) {
aoqi@0 369 NOT_PRODUCT(_last_bottom = NULL);
aoqi@0 370 NOT_PRODUCT(_last_explicit_min_done = NULL);
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 void do_MemRegion(MemRegion mr);
aoqi@0 374
aoqi@0 375 void set_min_done(HeapWord* min_done) {
aoqi@0 376 _min_done = min_done;
aoqi@0 377 NOT_PRODUCT(_last_explicit_min_done = _min_done);
aoqi@0 378 }
aoqi@0 379 #ifndef PRODUCT
aoqi@0 380 void set_last_bottom(HeapWord* last_bottom) {
aoqi@0 381 _last_bottom = last_bottom;
aoqi@0 382 }
aoqi@0 383 #endif
aoqi@0 384 };
aoqi@0 385
aoqi@0 386 // A structure to represent a point at which objects are being copied
aoqi@0 387 // during compaction.
aoqi@0 388 class CompactPoint : public StackObj {
aoqi@0 389 public:
aoqi@0 390 Generation* gen;
aoqi@0 391 CompactibleSpace* space;
aoqi@0 392 HeapWord* threshold;
aoqi@0 393 CompactPoint(Generation* _gen, CompactibleSpace* _space,
aoqi@0 394 HeapWord* _threshold) :
aoqi@0 395 gen(_gen), space(_space), threshold(_threshold) {}
aoqi@0 396 };
aoqi@0 397
aoqi@0 398
aoqi@0 399 // A space that supports compaction operations. This is usually, but not
aoqi@0 400 // necessarily, a space that is normally contiguous. But, for example, a
aoqi@0 401 // free-list-based space whose normal collection is a mark-sweep without
aoqi@0 402 // compaction could still support compaction in full GC's.
aoqi@0 403
aoqi@0 404 class CompactibleSpace: public Space {
aoqi@0 405 friend class VMStructs;
aoqi@0 406 friend class CompactibleFreeListSpace;
aoqi@0 407 private:
aoqi@0 408 HeapWord* _compaction_top;
aoqi@0 409 CompactibleSpace* _next_compaction_space;
aoqi@0 410
aoqi@0 411 public:
aoqi@0 412 CompactibleSpace() :
aoqi@0 413 _compaction_top(NULL), _next_compaction_space(NULL) {}
aoqi@0 414
aoqi@0 415 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
aoqi@0 416 virtual void clear(bool mangle_space);
aoqi@0 417
aoqi@0 418 // Used temporarily during a compaction phase to hold the value
aoqi@0 419 // top should have when compaction is complete.
aoqi@0 420 HeapWord* compaction_top() const { return _compaction_top; }
aoqi@0 421
aoqi@0 422 void set_compaction_top(HeapWord* value) {
aoqi@0 423 assert(value == NULL || (value >= bottom() && value <= end()),
aoqi@0 424 "should point inside space");
aoqi@0 425 _compaction_top = value;
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 // Perform operations on the space needed after a compaction
aoqi@0 429 // has been performed.
aoqi@0 430 virtual void reset_after_compaction() {}
aoqi@0 431
aoqi@0 432 // Returns the next space (in the current generation) to be compacted in
aoqi@0 433 // the global compaction order. Also is used to select the next
aoqi@0 434 // space into which to compact.
aoqi@0 435
aoqi@0 436 virtual CompactibleSpace* next_compaction_space() const {
aoqi@0 437 return _next_compaction_space;
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 void set_next_compaction_space(CompactibleSpace* csp) {
aoqi@0 441 _next_compaction_space = csp;
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 // MarkSweep support phase2
aoqi@0 445
aoqi@0 446 // Start the process of compaction of the current space: compute
aoqi@0 447 // post-compaction addresses, and insert forwarding pointers. The fields
aoqi@0 448 // "cp->gen" and "cp->compaction_space" are the generation and space into
aoqi@0 449 // which we are currently compacting. This call updates "cp" as necessary,
aoqi@0 450 // and leaves the "compaction_top" of the final value of
aoqi@0 451 // "cp->compaction_space" up-to-date. Offset tables may be updated in
aoqi@0 452 // this phase as if the final copy had occurred; if so, "cp->threshold"
aoqi@0 453 // indicates when the next such action should be taken.
aoqi@0 454 virtual void prepare_for_compaction(CompactPoint* cp);
aoqi@0 455 // MarkSweep support phase3
aoqi@0 456 virtual void adjust_pointers();
aoqi@0 457 // MarkSweep support phase4
aoqi@0 458 virtual void compact();
aoqi@0 459
aoqi@0 460 // The maximum percentage of objects that can be dead in the compacted
aoqi@0 461 // live part of a compacted space ("deadwood" support.)
aoqi@0 462 virtual size_t allowed_dead_ratio() const { return 0; };
aoqi@0 463
aoqi@0 464 // Some contiguous spaces may maintain some data structures that should
aoqi@0 465 // be updated whenever an allocation crosses a boundary. This function
aoqi@0 466 // returns the first such boundary.
aoqi@0 467 // (The default implementation returns the end of the space, so the
aoqi@0 468 // boundary is never crossed.)
aoqi@0 469 virtual HeapWord* initialize_threshold() { return end(); }
aoqi@0 470
aoqi@0 471 // "q" is an object of the given "size" that should be forwarded;
aoqi@0 472 // "cp" names the generation ("gen") and containing "this" (which must
aoqi@0 473 // also equal "cp->space"). "compact_top" is where in "this" the
aoqi@0 474 // next object should be forwarded to. If there is room in "this" for
aoqi@0 475 // the object, insert an appropriate forwarding pointer in "q".
aoqi@0 476 // If not, go to the next compaction space (there must
aoqi@0 477 // be one, since compaction must succeed -- we go to the first space of
aoqi@0 478 // the previous generation if necessary, updating "cp"), reset compact_top
aoqi@0 479 // and then forward. In either case, returns the new value of "compact_top".
aoqi@0 480 // If the forwarding crosses "cp->threshold", invokes the "cross_threhold"
aoqi@0 481 // function of the then-current compaction space, and updates "cp->threshold
aoqi@0 482 // accordingly".
aoqi@0 483 virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
aoqi@0 484 HeapWord* compact_top);
aoqi@0 485
aoqi@0 486 // Return a size with adjusments as required of the space.
aoqi@0 487 virtual size_t adjust_object_size_v(size_t size) const { return size; }
aoqi@0 488
aoqi@0 489 protected:
aoqi@0 490 // Used during compaction.
aoqi@0 491 HeapWord* _first_dead;
aoqi@0 492 HeapWord* _end_of_live;
aoqi@0 493
aoqi@0 494 // Minimum size of a free block.
aoqi@0 495 virtual size_t minimum_free_block_size() const = 0;
aoqi@0 496
aoqi@0 497 // This the function is invoked when an allocation of an object covering
aoqi@0 498 // "start" to "end occurs crosses the threshold; returns the next
aoqi@0 499 // threshold. (The default implementation does nothing.)
aoqi@0 500 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* the_end) {
aoqi@0 501 return end();
aoqi@0 502 }
aoqi@0 503
aoqi@0 504 // Requires "allowed_deadspace_words > 0", that "q" is the start of a
aoqi@0 505 // free block of the given "word_len", and that "q", were it an object,
aoqi@0 506 // would not move if forwared. If the size allows, fill the free
aoqi@0 507 // block with an object, to prevent excessive compaction. Returns "true"
aoqi@0 508 // iff the free region was made deadspace, and modifies
aoqi@0 509 // "allowed_deadspace_words" to reflect the number of available deadspace
aoqi@0 510 // words remaining after this operation.
aoqi@0 511 bool insert_deadspace(size_t& allowed_deadspace_words, HeapWord* q,
aoqi@0 512 size_t word_len);
aoqi@0 513 };
aoqi@0 514
aoqi@0 515 #define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
aoqi@0 516 /* Compute the new addresses for the live objects and store it in the mark \
aoqi@0 517 * Used by universe::mark_sweep_phase2() \
aoqi@0 518 */ \
aoqi@0 519 HeapWord* compact_top; /* This is where we are currently compacting to. */ \
aoqi@0 520 \
aoqi@0 521 /* We're sure to be here before any objects are compacted into this \
aoqi@0 522 * space, so this is a good time to initialize this: \
aoqi@0 523 */ \
aoqi@0 524 set_compaction_top(bottom()); \
aoqi@0 525 \
aoqi@0 526 if (cp->space == NULL) { \
aoqi@0 527 assert(cp->gen != NULL, "need a generation"); \
aoqi@0 528 assert(cp->threshold == NULL, "just checking"); \
aoqi@0 529 assert(cp->gen->first_compaction_space() == this, "just checking"); \
aoqi@0 530 cp->space = cp->gen->first_compaction_space(); \
aoqi@0 531 compact_top = cp->space->bottom(); \
aoqi@0 532 cp->space->set_compaction_top(compact_top); \
aoqi@0 533 cp->threshold = cp->space->initialize_threshold(); \
aoqi@0 534 } else { \
aoqi@0 535 compact_top = cp->space->compaction_top(); \
aoqi@0 536 } \
aoqi@0 537 \
aoqi@0 538 /* We allow some amount of garbage towards the bottom of the space, so \
aoqi@0 539 * we don't start compacting before there is a significant gain to be made.\
aoqi@0 540 * Occasionally, we want to ensure a full compaction, which is determined \
aoqi@0 541 * by the MarkSweepAlwaysCompactCount parameter. \
aoqi@0 542 */ \
aoqi@0 543 uint invocations = MarkSweep::total_invocations(); \
aoqi@0 544 bool skip_dead = ((invocations % MarkSweepAlwaysCompactCount) != 0); \
aoqi@0 545 \
aoqi@0 546 size_t allowed_deadspace = 0; \
aoqi@0 547 if (skip_dead) { \
aoqi@0 548 const size_t ratio = allowed_dead_ratio(); \
aoqi@0 549 allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize; \
aoqi@0 550 } \
aoqi@0 551 \
aoqi@0 552 HeapWord* q = bottom(); \
aoqi@0 553 HeapWord* t = scan_limit(); \
aoqi@0 554 \
aoqi@0 555 HeapWord* end_of_live= q; /* One byte beyond the last byte of the last \
aoqi@0 556 live object. */ \
aoqi@0 557 HeapWord* first_dead = end();/* The first dead object. */ \
aoqi@0 558 LiveRange* liveRange = NULL; /* The current live range, recorded in the \
aoqi@0 559 first header of preceding free area. */ \
aoqi@0 560 _first_dead = first_dead; \
aoqi@0 561 \
aoqi@0 562 const intx interval = PrefetchScanIntervalInBytes; \
aoqi@0 563 \
aoqi@0 564 while (q < t) { \
aoqi@0 565 assert(!block_is_obj(q) || \
aoqi@0 566 oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() || \
aoqi@0 567 oop(q)->mark()->has_bias_pattern(), \
aoqi@0 568 "these are the only valid states during a mark sweep"); \
aoqi@0 569 if (block_is_obj(q) && oop(q)->is_gc_marked()) { \
aoqi@0 570 /* prefetch beyond q */ \
aoqi@0 571 Prefetch::write(q, interval); \
aoqi@0 572 size_t size = block_size(q); \
aoqi@0 573 compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
aoqi@0 574 q += size; \
aoqi@0 575 end_of_live = q; \
aoqi@0 576 } else { \
aoqi@0 577 /* run over all the contiguous dead objects */ \
aoqi@0 578 HeapWord* end = q; \
aoqi@0 579 do { \
aoqi@0 580 /* prefetch beyond end */ \
aoqi@0 581 Prefetch::write(end, interval); \
aoqi@0 582 end += block_size(end); \
aoqi@0 583 } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));\
aoqi@0 584 \
aoqi@0 585 /* see if we might want to pretend this object is alive so that \
aoqi@0 586 * we don't have to compact quite as often. \
aoqi@0 587 */ \
aoqi@0 588 if (allowed_deadspace > 0 && q == compact_top) { \
aoqi@0 589 size_t sz = pointer_delta(end, q); \
aoqi@0 590 if (insert_deadspace(allowed_deadspace, q, sz)) { \
aoqi@0 591 compact_top = cp->space->forward(oop(q), sz, cp, compact_top); \
aoqi@0 592 q = end; \
aoqi@0 593 end_of_live = end; \
aoqi@0 594 continue; \
aoqi@0 595 } \
aoqi@0 596 } \
aoqi@0 597 \
aoqi@0 598 /* otherwise, it really is a free region. */ \
aoqi@0 599 \
aoqi@0 600 /* for the previous LiveRange, record the end of the live objects. */ \
aoqi@0 601 if (liveRange) { \
aoqi@0 602 liveRange->set_end(q); \
aoqi@0 603 } \
aoqi@0 604 \
aoqi@0 605 /* record the current LiveRange object. \
aoqi@0 606 * liveRange->start() is overlaid on the mark word. \
aoqi@0 607 */ \
aoqi@0 608 liveRange = (LiveRange*)q; \
aoqi@0 609 liveRange->set_start(end); \
aoqi@0 610 liveRange->set_end(end); \
aoqi@0 611 \
aoqi@0 612 /* see if this is the first dead region. */ \
aoqi@0 613 if (q < first_dead) { \
aoqi@0 614 first_dead = q; \
aoqi@0 615 } \
aoqi@0 616 \
aoqi@0 617 /* move on to the next object */ \
aoqi@0 618 q = end; \
aoqi@0 619 } \
aoqi@0 620 } \
aoqi@0 621 \
aoqi@0 622 assert(q == t, "just checking"); \
aoqi@0 623 if (liveRange != NULL) { \
aoqi@0 624 liveRange->set_end(q); \
aoqi@0 625 } \
aoqi@0 626 _end_of_live = end_of_live; \
aoqi@0 627 if (end_of_live < first_dead) { \
aoqi@0 628 first_dead = end_of_live; \
aoqi@0 629 } \
aoqi@0 630 _first_dead = first_dead; \
aoqi@0 631 \
aoqi@0 632 /* save the compaction_top of the compaction space. */ \
aoqi@0 633 cp->space->set_compaction_top(compact_top); \
aoqi@0 634 }
aoqi@0 635
aoqi@0 636 #define SCAN_AND_ADJUST_POINTERS(adjust_obj_size) { \
aoqi@0 637 /* adjust all the interior pointers to point at the new locations of objects \
aoqi@0 638 * Used by MarkSweep::mark_sweep_phase3() */ \
aoqi@0 639 \
aoqi@0 640 HeapWord* q = bottom(); \
aoqi@0 641 HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */ \
aoqi@0 642 \
aoqi@0 643 assert(_first_dead <= _end_of_live, "Stands to reason, no?"); \
aoqi@0 644 \
aoqi@0 645 if (q < t && _first_dead > q && \
aoqi@0 646 !oop(q)->is_gc_marked()) { \
aoqi@0 647 /* we have a chunk of the space which hasn't moved and we've \
aoqi@0 648 * reinitialized the mark word during the previous pass, so we can't \
aoqi@0 649 * use is_gc_marked for the traversal. */ \
aoqi@0 650 HeapWord* end = _first_dead; \
aoqi@0 651 \
aoqi@0 652 while (q < end) { \
aoqi@0 653 /* I originally tried to conjoin "block_start(q) == q" to the \
aoqi@0 654 * assertion below, but that doesn't work, because you can't \
aoqi@0 655 * accurately traverse previous objects to get to the current one \
aoqi@0 656 * after their pointers have been \
aoqi@0 657 * updated, until the actual compaction is done. dld, 4/00 */ \
aoqi@0 658 assert(block_is_obj(q), \
aoqi@0 659 "should be at block boundaries, and should be looking at objs"); \
aoqi@0 660 \
aoqi@0 661 /* point all the oops to the new location */ \
aoqi@0 662 size_t size = oop(q)->adjust_pointers(); \
aoqi@0 663 size = adjust_obj_size(size); \
aoqi@0 664 \
aoqi@0 665 q += size; \
aoqi@0 666 } \
aoqi@0 667 \
aoqi@0 668 if (_first_dead == t) { \
aoqi@0 669 q = t; \
aoqi@0 670 } else { \
aoqi@0 671 /* $$$ This is funky. Using this to read the previously written \
aoqi@0 672 * LiveRange. See also use below. */ \
aoqi@0 673 q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
aoqi@0 674 } \
aoqi@0 675 } \
aoqi@0 676 \
aoqi@0 677 const intx interval = PrefetchScanIntervalInBytes; \
aoqi@0 678 \
aoqi@0 679 debug_only(HeapWord* prev_q = NULL); \
aoqi@0 680 while (q < t) { \
aoqi@0 681 /* prefetch beyond q */ \
aoqi@0 682 Prefetch::write(q, interval); \
aoqi@0 683 if (oop(q)->is_gc_marked()) { \
aoqi@0 684 /* q is alive */ \
aoqi@0 685 /* point all the oops to the new location */ \
aoqi@0 686 size_t size = oop(q)->adjust_pointers(); \
aoqi@0 687 size = adjust_obj_size(size); \
aoqi@0 688 debug_only(prev_q = q); \
aoqi@0 689 q += size; \
aoqi@0 690 } else { \
aoqi@0 691 /* q is not a live object, so its mark should point at the next \
aoqi@0 692 * live object */ \
aoqi@0 693 debug_only(prev_q = q); \
aoqi@0 694 q = (HeapWord*) oop(q)->mark()->decode_pointer(); \
aoqi@0 695 assert(q > prev_q, "we should be moving forward through memory"); \
aoqi@0 696 } \
aoqi@0 697 } \
aoqi@0 698 \
aoqi@0 699 assert(q == t, "just checking"); \
aoqi@0 700 }
aoqi@0 701
aoqi@0 702 #define SCAN_AND_COMPACT(obj_size) { \
aoqi@0 703 /* Copy all live objects to their new location \
aoqi@0 704 * Used by MarkSweep::mark_sweep_phase4() */ \
aoqi@0 705 \
aoqi@0 706 HeapWord* q = bottom(); \
aoqi@0 707 HeapWord* const t = _end_of_live; \
aoqi@0 708 debug_only(HeapWord* prev_q = NULL); \
aoqi@0 709 \
aoqi@0 710 if (q < t && _first_dead > q && \
aoqi@0 711 !oop(q)->is_gc_marked()) { \
aoqi@0 712 debug_only( \
aoqi@0 713 /* we have a chunk of the space which hasn't moved and we've reinitialized \
aoqi@0 714 * the mark word during the previous pass, so we can't use is_gc_marked for \
aoqi@0 715 * the traversal. */ \
aoqi@0 716 HeapWord* const end = _first_dead; \
aoqi@0 717 \
aoqi@0 718 while (q < end) { \
aoqi@0 719 size_t size = obj_size(q); \
aoqi@0 720 assert(!oop(q)->is_gc_marked(), \
aoqi@0 721 "should be unmarked (special dense prefix handling)"); \
aoqi@0 722 debug_only(prev_q = q); \
aoqi@0 723 q += size; \
aoqi@0 724 } \
aoqi@0 725 ) /* debug_only */ \
aoqi@0 726 \
aoqi@0 727 if (_first_dead == t) { \
aoqi@0 728 q = t; \
aoqi@0 729 } else { \
aoqi@0 730 /* $$$ Funky */ \
aoqi@0 731 q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
aoqi@0 732 } \
aoqi@0 733 } \
aoqi@0 734 \
aoqi@0 735 const intx scan_interval = PrefetchScanIntervalInBytes; \
aoqi@0 736 const intx copy_interval = PrefetchCopyIntervalInBytes; \
aoqi@0 737 while (q < t) { \
aoqi@0 738 if (!oop(q)->is_gc_marked()) { \
aoqi@0 739 /* mark is pointer to next marked oop */ \
aoqi@0 740 debug_only(prev_q = q); \
aoqi@0 741 q = (HeapWord*) oop(q)->mark()->decode_pointer(); \
aoqi@0 742 assert(q > prev_q, "we should be moving forward through memory"); \
aoqi@0 743 } else { \
aoqi@0 744 /* prefetch beyond q */ \
aoqi@0 745 Prefetch::read(q, scan_interval); \
aoqi@0 746 \
aoqi@0 747 /* size and destination */ \
aoqi@0 748 size_t size = obj_size(q); \
aoqi@0 749 HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
aoqi@0 750 \
aoqi@0 751 /* prefetch beyond compaction_top */ \
aoqi@0 752 Prefetch::write(compaction_top, copy_interval); \
aoqi@0 753 \
aoqi@0 754 /* copy object and reinit its mark */ \
aoqi@0 755 assert(q != compaction_top, "everything in this pass should be moving"); \
aoqi@0 756 Copy::aligned_conjoint_words(q, compaction_top, size); \
aoqi@0 757 oop(compaction_top)->init_mark(); \
aoqi@0 758 assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
aoqi@0 759 \
aoqi@0 760 debug_only(prev_q = q); \
aoqi@0 761 q += size; \
aoqi@0 762 } \
aoqi@0 763 } \
aoqi@0 764 \
aoqi@0 765 /* Let's remember if we were empty before we did the compaction. */ \
aoqi@0 766 bool was_empty = used_region().is_empty(); \
aoqi@0 767 /* Reset space after compaction is complete */ \
aoqi@0 768 reset_after_compaction(); \
aoqi@0 769 /* We do this clear, below, since it has overloaded meanings for some */ \
aoqi@0 770 /* space subtypes. For example, OffsetTableContigSpace's that were */ \
aoqi@0 771 /* compacted into will have had their offset table thresholds updated */ \
aoqi@0 772 /* continuously, but those that weren't need to have their thresholds */ \
aoqi@0 773 /* re-initialized. Also mangles unused area for debugging. */ \
aoqi@0 774 if (used_region().is_empty()) { \
aoqi@0 775 if (!was_empty) clear(SpaceDecorator::Mangle); \
aoqi@0 776 } else { \
aoqi@0 777 if (ZapUnusedHeapArea) mangle_unused_area(); \
aoqi@0 778 } \
aoqi@0 779 }
aoqi@0 780
aoqi@0 781 class GenSpaceMangler;
aoqi@0 782
aoqi@0 783 // A space in which the free area is contiguous. It therefore supports
aoqi@0 784 // faster allocation, and compaction.
aoqi@0 785 class ContiguousSpace: public CompactibleSpace {
aoqi@0 786 friend class OneContigSpaceCardGeneration;
aoqi@0 787 friend class VMStructs;
aoqi@0 788 protected:
aoqi@0 789 HeapWord* _top;
aoqi@0 790 HeapWord* _concurrent_iteration_safe_limit;
aoqi@0 791 // A helper for mangling the unused area of the space in debug builds.
aoqi@0 792 GenSpaceMangler* _mangler;
aoqi@0 793
aoqi@0 794 GenSpaceMangler* mangler() { return _mangler; }
aoqi@0 795
aoqi@0 796 // Allocation helpers (return NULL if full).
aoqi@0 797 inline HeapWord* allocate_impl(size_t word_size, HeapWord* end_value);
aoqi@0 798 inline HeapWord* par_allocate_impl(size_t word_size, HeapWord* end_value);
aoqi@0 799
aoqi@0 800 public:
aoqi@0 801 ContiguousSpace();
aoqi@0 802 ~ContiguousSpace();
aoqi@0 803
aoqi@0 804 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
aoqi@0 805 virtual void clear(bool mangle_space);
aoqi@0 806
aoqi@0 807 // Accessors
aoqi@0 808 HeapWord* top() const { return _top; }
aoqi@0 809 void set_top(HeapWord* value) { _top = value; }
aoqi@0 810
aoqi@0 811 virtual void set_saved_mark() { _saved_mark_word = top(); }
aoqi@0 812 void reset_saved_mark() { _saved_mark_word = bottom(); }
aoqi@0 813
aoqi@0 814 WaterMark bottom_mark() { return WaterMark(this, bottom()); }
aoqi@0 815 WaterMark top_mark() { return WaterMark(this, top()); }
aoqi@0 816 WaterMark saved_mark() { return WaterMark(this, saved_mark_word()); }
aoqi@0 817 bool saved_mark_at_top() const { return saved_mark_word() == top(); }
aoqi@0 818
aoqi@0 819 // In debug mode mangle (write it with a particular bit
aoqi@0 820 // pattern) the unused part of a space.
aoqi@0 821
aoqi@0 822 // Used to save the an address in a space for later use during mangling.
aoqi@0 823 void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN;
aoqi@0 824 // Used to save the space's current top for later use during mangling.
aoqi@0 825 void set_top_for_allocations() PRODUCT_RETURN;
aoqi@0 826
aoqi@0 827 // Mangle regions in the space from the current top up to the
aoqi@0 828 // previously mangled part of the space.
aoqi@0 829 void mangle_unused_area() PRODUCT_RETURN;
aoqi@0 830 // Mangle [top, end)
aoqi@0 831 void mangle_unused_area_complete() PRODUCT_RETURN;
aoqi@0 832 // Mangle the given MemRegion.
aoqi@0 833 void mangle_region(MemRegion mr) PRODUCT_RETURN;
aoqi@0 834
aoqi@0 835 // Do some sparse checking on the area that should have been mangled.
aoqi@0 836 void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN;
aoqi@0 837 // Check the complete area that should have been mangled.
aoqi@0 838 // This code may be NULL depending on the macro DEBUG_MANGLING.
aoqi@0 839 void check_mangled_unused_area_complete() PRODUCT_RETURN;
aoqi@0 840
aoqi@0 841 // Size computations: sizes in bytes.
aoqi@0 842 size_t capacity() const { return byte_size(bottom(), end()); }
aoqi@0 843 size_t used() const { return byte_size(bottom(), top()); }
aoqi@0 844 size_t free() const { return byte_size(top(), end()); }
aoqi@0 845
aoqi@0 846 // Override from space.
aoqi@0 847 bool is_in(const void* p) const;
aoqi@0 848
aoqi@0 849 virtual bool is_free_block(const HeapWord* p) const;
aoqi@0 850
aoqi@0 851 // In a contiguous space we have a more obvious bound on what parts
aoqi@0 852 // contain objects.
aoqi@0 853 MemRegion used_region() const { return MemRegion(bottom(), top()); }
aoqi@0 854
aoqi@0 855 MemRegion used_region_at_save_marks() const {
aoqi@0 856 return MemRegion(bottom(), saved_mark_word());
aoqi@0 857 }
aoqi@0 858
aoqi@0 859 // Allocation (return NULL if full)
aoqi@0 860 virtual HeapWord* allocate(size_t word_size);
aoqi@0 861 virtual HeapWord* par_allocate(size_t word_size);
aoqi@0 862
aoqi@0 863 virtual bool obj_allocated_since_save_marks(const oop obj) const {
aoqi@0 864 return (HeapWord*)obj >= saved_mark_word();
aoqi@0 865 }
aoqi@0 866
aoqi@0 867 // Iteration
aoqi@0 868 void oop_iterate(ExtendedOopClosure* cl);
aoqi@0 869 void oop_iterate(MemRegion mr, ExtendedOopClosure* cl);
aoqi@0 870 void object_iterate(ObjectClosure* blk);
aoqi@0 871 // For contiguous spaces this method will iterate safely over objects
aoqi@0 872 // in the space (i.e., between bottom and top) when at a safepoint.
aoqi@0 873 void safe_object_iterate(ObjectClosure* blk);
aoqi@0 874 void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl);
aoqi@0 875 // iterates on objects up to the safe limit
aoqi@0 876 HeapWord* object_iterate_careful(ObjectClosureCareful* cl);
aoqi@0 877 HeapWord* concurrent_iteration_safe_limit() {
aoqi@0 878 assert(_concurrent_iteration_safe_limit <= top(),
aoqi@0 879 "_concurrent_iteration_safe_limit update missed");
aoqi@0 880 return _concurrent_iteration_safe_limit;
aoqi@0 881 }
aoqi@0 882 // changes the safe limit, all objects from bottom() to the new
aoqi@0 883 // limit should be properly initialized
aoqi@0 884 void set_concurrent_iteration_safe_limit(HeapWord* new_limit) {
aoqi@0 885 assert(new_limit <= top(), "uninitialized objects in the safe range");
aoqi@0 886 _concurrent_iteration_safe_limit = new_limit;
aoqi@0 887 }
aoqi@0 888
aoqi@0 889
aoqi@0 890 #if INCLUDE_ALL_GCS
aoqi@0 891 // In support of parallel oop_iterate.
aoqi@0 892 #define ContigSpace_PAR_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 893 void par_oop_iterate(MemRegion mr, OopClosureType* blk);
aoqi@0 894
aoqi@0 895 ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DECL)
aoqi@0 896 #undef ContigSpace_PAR_OOP_ITERATE_DECL
aoqi@0 897 #endif // INCLUDE_ALL_GCS
aoqi@0 898
aoqi@0 899 // Compaction support
aoqi@0 900 virtual void reset_after_compaction() {
aoqi@0 901 assert(compaction_top() >= bottom() && compaction_top() <= end(), "should point inside space");
aoqi@0 902 set_top(compaction_top());
aoqi@0 903 // set new iteration safe limit
aoqi@0 904 set_concurrent_iteration_safe_limit(compaction_top());
aoqi@0 905 }
aoqi@0 906 virtual size_t minimum_free_block_size() const { return 0; }
aoqi@0 907
aoqi@0 908 // Override.
aoqi@0 909 DirtyCardToOopClosure* new_dcto_cl(ExtendedOopClosure* cl,
aoqi@0 910 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 911 HeapWord* boundary = NULL);
aoqi@0 912
aoqi@0 913 // Apply "blk->do_oop" to the addresses of all reference fields in objects
aoqi@0 914 // starting with the _saved_mark_word, which was noted during a generation's
aoqi@0 915 // save_marks and is required to denote the head of an object.
aoqi@0 916 // Fields in objects allocated by applications of the closure
aoqi@0 917 // *are* included in the iteration.
aoqi@0 918 // Updates _saved_mark_word to point to just after the last object
aoqi@0 919 // iterated over.
aoqi@0 920 #define ContigSpace_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
aoqi@0 921 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk);
aoqi@0 922
aoqi@0 923 ALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DECL)
aoqi@0 924 #undef ContigSpace_OOP_SINCE_SAVE_MARKS_DECL
aoqi@0 925
aoqi@0 926 // Same as object_iterate, but starting from "mark", which is required
aoqi@0 927 // to denote the start of an object. Objects allocated by
aoqi@0 928 // applications of the closure *are* included in the iteration.
aoqi@0 929 virtual void object_iterate_from(WaterMark mark, ObjectClosure* blk);
aoqi@0 930
aoqi@0 931 // Very inefficient implementation.
aoqi@0 932 virtual HeapWord* block_start_const(const void* p) const;
aoqi@0 933 size_t block_size(const HeapWord* p) const;
aoqi@0 934 // If a block is in the allocated area, it is an object.
aoqi@0 935 bool block_is_obj(const HeapWord* p) const { return p < top(); }
aoqi@0 936
aoqi@0 937 // Addresses for inlined allocation
aoqi@0 938 HeapWord** top_addr() { return &_top; }
aoqi@0 939 HeapWord** end_addr() { return &_end; }
aoqi@0 940
aoqi@0 941 // Overrides for more efficient compaction support.
aoqi@0 942 void prepare_for_compaction(CompactPoint* cp);
aoqi@0 943
aoqi@0 944 // PrintHeapAtGC support.
aoqi@0 945 virtual void print_on(outputStream* st) const;
aoqi@0 946
aoqi@0 947 // Checked dynamic downcasts.
aoqi@0 948 virtual ContiguousSpace* toContiguousSpace() {
aoqi@0 949 return this;
aoqi@0 950 }
aoqi@0 951
aoqi@0 952 // Debugging
aoqi@0 953 virtual void verify() const;
aoqi@0 954
aoqi@0 955 // Used to increase collection frequency. "factor" of 0 means entire
aoqi@0 956 // space.
aoqi@0 957 void allocate_temporary_filler(int factor);
aoqi@0 958
aoqi@0 959 };
aoqi@0 960
aoqi@0 961
aoqi@0 962 // A dirty card to oop closure that does filtering.
aoqi@0 963 // It knows how to filter out objects that are outside of the _boundary.
aoqi@0 964 class Filtering_DCTOC : public DirtyCardToOopClosure {
aoqi@0 965 protected:
aoqi@0 966 // Override.
aoqi@0 967 void walk_mem_region(MemRegion mr,
aoqi@0 968 HeapWord* bottom, HeapWord* top);
aoqi@0 969
aoqi@0 970 // Walk the given memory region, from bottom to top, applying
aoqi@0 971 // the given oop closure to (possibly) all objects found. The
aoqi@0 972 // given oop closure may or may not be the same as the oop
aoqi@0 973 // closure with which this closure was created, as it may
aoqi@0 974 // be a filtering closure which makes use of the _boundary.
aoqi@0 975 // We offer two signatures, so the FilteringClosure static type is
aoqi@0 976 // apparent.
aoqi@0 977 virtual void walk_mem_region_with_cl(MemRegion mr,
aoqi@0 978 HeapWord* bottom, HeapWord* top,
aoqi@0 979 ExtendedOopClosure* cl) = 0;
aoqi@0 980 virtual void walk_mem_region_with_cl(MemRegion mr,
aoqi@0 981 HeapWord* bottom, HeapWord* top,
aoqi@0 982 FilteringClosure* cl) = 0;
aoqi@0 983
aoqi@0 984 public:
aoqi@0 985 Filtering_DCTOC(Space* sp, ExtendedOopClosure* cl,
aoqi@0 986 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 987 HeapWord* boundary) :
aoqi@0 988 DirtyCardToOopClosure(sp, cl, precision, boundary) {}
aoqi@0 989 };
aoqi@0 990
aoqi@0 991 // A dirty card to oop closure for contiguous spaces
aoqi@0 992 // (ContiguousSpace and sub-classes).
aoqi@0 993 // It is a FilteringClosure, as defined above, and it knows:
aoqi@0 994 //
aoqi@0 995 // 1. That the actual top of any area in a memory region
aoqi@0 996 // contained by the space is bounded by the end of the contiguous
aoqi@0 997 // region of the space.
aoqi@0 998 // 2. That the space is really made up of objects and not just
aoqi@0 999 // blocks.
aoqi@0 1000
aoqi@0 1001 class ContiguousSpaceDCTOC : public Filtering_DCTOC {
aoqi@0 1002 protected:
aoqi@0 1003 // Overrides.
aoqi@0 1004 HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj);
aoqi@0 1005
aoqi@0 1006 virtual void walk_mem_region_with_cl(MemRegion mr,
aoqi@0 1007 HeapWord* bottom, HeapWord* top,
aoqi@0 1008 ExtendedOopClosure* cl);
aoqi@0 1009 virtual void walk_mem_region_with_cl(MemRegion mr,
aoqi@0 1010 HeapWord* bottom, HeapWord* top,
aoqi@0 1011 FilteringClosure* cl);
aoqi@0 1012
aoqi@0 1013 public:
aoqi@0 1014 ContiguousSpaceDCTOC(ContiguousSpace* sp, ExtendedOopClosure* cl,
aoqi@0 1015 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 1016 HeapWord* boundary) :
aoqi@0 1017 Filtering_DCTOC(sp, cl, precision, boundary)
aoqi@0 1018 {}
aoqi@0 1019 };
aoqi@0 1020
aoqi@0 1021
aoqi@0 1022 // Class EdenSpace describes eden-space in new generation.
aoqi@0 1023
aoqi@0 1024 class DefNewGeneration;
aoqi@0 1025
aoqi@0 1026 class EdenSpace : public ContiguousSpace {
aoqi@0 1027 friend class VMStructs;
aoqi@0 1028 private:
aoqi@0 1029 DefNewGeneration* _gen;
aoqi@0 1030
aoqi@0 1031 // _soft_end is used as a soft limit on allocation. As soft limits are
aoqi@0 1032 // reached, the slow-path allocation code can invoke other actions and then
aoqi@0 1033 // adjust _soft_end up to a new soft limit or to end().
aoqi@0 1034 HeapWord* _soft_end;
aoqi@0 1035
aoqi@0 1036 public:
aoqi@0 1037 EdenSpace(DefNewGeneration* gen) :
aoqi@0 1038 _gen(gen), _soft_end(NULL) {}
aoqi@0 1039
aoqi@0 1040 // Get/set just the 'soft' limit.
aoqi@0 1041 HeapWord* soft_end() { return _soft_end; }
aoqi@0 1042 HeapWord** soft_end_addr() { return &_soft_end; }
aoqi@0 1043 void set_soft_end(HeapWord* value) { _soft_end = value; }
aoqi@0 1044
aoqi@0 1045 // Override.
aoqi@0 1046 void clear(bool mangle_space);
aoqi@0 1047
aoqi@0 1048 // Set both the 'hard' and 'soft' limits (_end and _soft_end).
aoqi@0 1049 void set_end(HeapWord* value) {
aoqi@0 1050 set_soft_end(value);
aoqi@0 1051 ContiguousSpace::set_end(value);
aoqi@0 1052 }
aoqi@0 1053
aoqi@0 1054 // Allocation (return NULL if full)
aoqi@0 1055 HeapWord* allocate(size_t word_size);
aoqi@0 1056 HeapWord* par_allocate(size_t word_size);
aoqi@0 1057 };
aoqi@0 1058
aoqi@0 1059 // Class ConcEdenSpace extends EdenSpace for the sake of safe
aoqi@0 1060 // allocation while soft-end is being modified concurrently
aoqi@0 1061
aoqi@0 1062 class ConcEdenSpace : public EdenSpace {
aoqi@0 1063 public:
aoqi@0 1064 ConcEdenSpace(DefNewGeneration* gen) : EdenSpace(gen) { }
aoqi@0 1065
aoqi@0 1066 // Allocation (return NULL if full)
aoqi@0 1067 HeapWord* par_allocate(size_t word_size);
aoqi@0 1068 };
aoqi@0 1069
aoqi@0 1070
aoqi@0 1071 // A ContigSpace that Supports an efficient "block_start" operation via
aoqi@0 1072 // a BlockOffsetArray (whose BlockOffsetSharedArray may be shared with
aoqi@0 1073 // other spaces.) This is the abstract base class for old generation
aoqi@0 1074 // (tenured) spaces.
aoqi@0 1075
aoqi@0 1076 class OffsetTableContigSpace: public ContiguousSpace {
aoqi@0 1077 friend class VMStructs;
aoqi@0 1078 protected:
aoqi@0 1079 BlockOffsetArrayContigSpace _offsets;
aoqi@0 1080 Mutex _par_alloc_lock;
aoqi@0 1081
aoqi@0 1082 public:
aoqi@0 1083 // Constructor
aoqi@0 1084 OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray,
aoqi@0 1085 MemRegion mr);
aoqi@0 1086
aoqi@0 1087 void set_bottom(HeapWord* value);
aoqi@0 1088 void set_end(HeapWord* value);
aoqi@0 1089
aoqi@0 1090 void clear(bool mangle_space);
aoqi@0 1091
aoqi@0 1092 inline HeapWord* block_start_const(const void* p) const;
aoqi@0 1093
aoqi@0 1094 // Add offset table update.
aoqi@0 1095 virtual inline HeapWord* allocate(size_t word_size);
aoqi@0 1096 inline HeapWord* par_allocate(size_t word_size);
aoqi@0 1097
aoqi@0 1098 // MarkSweep support phase3
aoqi@0 1099 virtual HeapWord* initialize_threshold();
aoqi@0 1100 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
aoqi@0 1101
aoqi@0 1102 virtual void print_on(outputStream* st) const;
aoqi@0 1103
aoqi@0 1104 // Debugging
aoqi@0 1105 void verify() const;
aoqi@0 1106 };
aoqi@0 1107
aoqi@0 1108
aoqi@0 1109 // Class TenuredSpace is used by TenuredGeneration
aoqi@0 1110
aoqi@0 1111 class TenuredSpace: public OffsetTableContigSpace {
aoqi@0 1112 friend class VMStructs;
aoqi@0 1113 protected:
aoqi@0 1114 // Mark sweep support
aoqi@0 1115 size_t allowed_dead_ratio() const;
aoqi@0 1116 public:
aoqi@0 1117 // Constructor
aoqi@0 1118 TenuredSpace(BlockOffsetSharedArray* sharedOffsetArray,
aoqi@0 1119 MemRegion mr) :
aoqi@0 1120 OffsetTableContigSpace(sharedOffsetArray, mr) {}
aoqi@0 1121 };
aoqi@0 1122 #endif // SHARE_VM_MEMORY_SPACE_HPP

mercurial