hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// PSPromotionLAB is a parallel scavenge promotion lab. This class acts very
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// much like a MutableSpace. We couldn't embed a MutableSpace, though, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// it has a considerable number of asserts and invariants that are violated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class ObjectStartArray;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class PSPromotionLAB : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  static const size_t filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  enum LabState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    needs_flush,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    flushed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    zero_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  HeapWord* _top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  HeapWord* _bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  HeapWord* _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  LabState _state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void set_top(HeapWord* value)    { _top = value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void set_bottom(HeapWord* value) { _bottom = value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  void set_end(HeapWord* value)    { _end = value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // The shared initialize code invokes this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  debug_only(virtual bool lab_is_valid(MemRegion lab) { return false; });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  PSPromotionLAB() : _top(NULL), _bottom(NULL), _end(NULL) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Filling and flushing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void initialize(MemRegion lab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  virtual void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  HeapWord* bottom() const           { return _bottom; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  HeapWord* end() const              { return _end;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  HeapWord* top() const              { return _top;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  bool is_flushed()                  { return _state == flushed; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  bool unallocate_object(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Returns a subregion containing all objects in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  MemRegion used_region()            { return MemRegion(bottom(), top()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Boolean querries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  bool is_empty() const              { return used() == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  bool not_empty() const             { return used() > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  bool contains(const void* p) const { return _bottom <= p && p < _end; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Size computations.  Sizes are in bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  size_t capacity() const            { return byte_size(bottom(), end()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  size_t used() const                { return byte_size(bottom(), top()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  size_t free() const                { return byte_size(top(),    end()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
class PSYoungPromotionLAB : public PSPromotionLAB {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  PSYoungPromotionLAB() { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Not MT safe
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  HeapWord* allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // Can't assert this, when young fills, we keep the LAB around, but flushed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // assert(_state != flushed, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    HeapWord* new_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // The 'new_top>obj' check is needed to detect overflow of obj+size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (new_top > obj && new_top <= end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      set_top(new_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
             "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  debug_only(virtual bool lab_is_valid(MemRegion lab));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
class PSOldPromotionLAB : public PSPromotionLAB {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  ObjectStartArray* _start_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  PSOldPromotionLAB() : _start_array(NULL) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  PSOldPromotionLAB(ObjectStartArray* start_array) : _start_array(start_array) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void set_start_array(ObjectStartArray* start_array) { _start_array = start_array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Not MT safe
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  HeapWord* allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // Cannot test for this now that we're doing promotion failures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // assert(_state != flushed, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    assert(_start_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    HeapWord* new_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    // The 'new_top>obj' check is needed to detect overflow of obj+size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    if (new_top > obj && new_top <= end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      set_top(new_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
             "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      _start_array->allocate_block(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  debug_only(virtual bool lab_is_valid(MemRegion lab));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
};