src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp

Thu, 09 Apr 2015 15:58:49 +0200

author
mlarsson
date
Thu, 09 Apr 2015 15:58:49 +0200
changeset 7686
fb69749583e8
parent 7031
ee019285a52c
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

8072621: Clean up around VM_GC_Operations
Reviewed-by: brutisso, jmasa

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONLAB_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONLAB_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
jmasa@7031 29 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 30 #include "memory/allocation.hpp"
stefank@2314 31
duke@435 32 //
duke@435 33 // PSPromotionLAB is a parallel scavenge promotion lab. This class acts very
duke@435 34 // much like a MutableSpace. We couldn't embed a MutableSpace, though, as
duke@435 35 // it has a considerable number of asserts and invariants that are violated.
duke@435 36 //
duke@435 37
duke@435 38 class ObjectStartArray;
duke@435 39
zgu@3900 40 class PSPromotionLAB : public CHeapObj<mtGC> {
duke@435 41 protected:
coleenp@548 42 static size_t filler_header_size;
duke@435 43
duke@435 44 enum LabState {
duke@435 45 needs_flush,
duke@435 46 flushed,
duke@435 47 zero_size
duke@435 48 };
duke@435 49
duke@435 50 HeapWord* _top;
duke@435 51 HeapWord* _bottom;
duke@435 52 HeapWord* _end;
duke@435 53 LabState _state;
duke@435 54
duke@435 55 void set_top(HeapWord* value) { _top = value; }
duke@435 56 void set_bottom(HeapWord* value) { _bottom = value; }
duke@435 57 void set_end(HeapWord* value) { _end = value; }
duke@435 58
duke@435 59 // The shared initialize code invokes this.
duke@435 60 debug_only(virtual bool lab_is_valid(MemRegion lab) { return false; });
duke@435 61
duke@435 62 PSPromotionLAB() : _top(NULL), _bottom(NULL), _end(NULL) { }
duke@435 63
duke@435 64 public:
duke@435 65 // Filling and flushing.
duke@435 66 void initialize(MemRegion lab);
duke@435 67
duke@435 68 virtual void flush();
duke@435 69
duke@435 70 // Accessors
duke@435 71 HeapWord* bottom() const { return _bottom; }
duke@435 72 HeapWord* end() const { return _end; }
duke@435 73 HeapWord* top() const { return _top; }
duke@435 74
duke@435 75 bool is_flushed() { return _state == flushed; }
duke@435 76
stefank@3181 77 bool unallocate_object(HeapWord* obj, size_t obj_size);
duke@435 78
duke@435 79 // Returns a subregion containing all objects in this space.
duke@435 80 MemRegion used_region() { return MemRegion(bottom(), top()); }
duke@435 81
duke@435 82 // Boolean querries.
duke@435 83 bool is_empty() const { return used() == 0; }
duke@435 84 bool not_empty() const { return used() > 0; }
duke@435 85 bool contains(const void* p) const { return _bottom <= p && p < _end; }
duke@435 86
duke@435 87 // Size computations. Sizes are in bytes.
duke@435 88 size_t capacity() const { return byte_size(bottom(), end()); }
duke@435 89 size_t used() const { return byte_size(bottom(), top()); }
duke@435 90 size_t free() const { return byte_size(top(), end()); }
duke@435 91 };
duke@435 92
duke@435 93 class PSYoungPromotionLAB : public PSPromotionLAB {
duke@435 94 public:
duke@435 95 PSYoungPromotionLAB() { }
duke@435 96
duke@435 97 // Not MT safe
jmasa@7031 98 inline HeapWord* allocate(size_t size);
duke@435 99
jmasa@7031 100 debug_only(virtual bool lab_is_valid(MemRegion lab);)
duke@435 101 };
duke@435 102
duke@435 103 class PSOldPromotionLAB : public PSPromotionLAB {
duke@435 104 private:
duke@435 105 ObjectStartArray* _start_array;
duke@435 106
duke@435 107 public:
duke@435 108 PSOldPromotionLAB() : _start_array(NULL) { }
duke@435 109 PSOldPromotionLAB(ObjectStartArray* start_array) : _start_array(start_array) { }
duke@435 110
duke@435 111 void set_start_array(ObjectStartArray* start_array) { _start_array = start_array; }
duke@435 112
duke@435 113 void flush();
duke@435 114
duke@435 115 // Not MT safe
duke@435 116 HeapWord* allocate(size_t size) {
duke@435 117 // Cannot test for this now that we're doing promotion failures
duke@435 118 // assert(_state != flushed, "Sanity");
duke@435 119 assert(_start_array != NULL, "Sanity");
duke@435 120 HeapWord* obj = top();
duke@435 121 HeapWord* new_top = obj + size;
duke@435 122 // The 'new_top>obj' check is needed to detect overflow of obj+size.
duke@435 123 if (new_top > obj && new_top <= end()) {
duke@435 124 set_top(new_top);
duke@435 125 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
duke@435 126 "checking alignment");
duke@435 127 _start_array->allocate_block(obj);
duke@435 128 return obj;
duke@435 129 }
duke@435 130
duke@435 131 return NULL;
duke@435 132 }
duke@435 133
duke@435 134 debug_only(virtual bool lab_is_valid(MemRegion lab));
duke@435 135 };
stefank@2314 136
stefank@2314 137 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONLAB_HPP

mercurial