hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
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-2006 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
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_psPromotionLAB.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    28
size_t PSPromotionLAB::filler_header_size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// This is the shared initialization code. It sets up the basic pointers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// and allows enough extra space for a filler object. We call a virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// method, "lab_is_valid()" to handle the different asserts the old/young
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// labs require.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
void PSPromotionLAB::initialize(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  assert(lab_is_valid(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  HeapWord* bottom = lab.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  HeapWord* end    = lab.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  set_bottom(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  set_top(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    44
  // Initialize after VM starts up because header_size depends on compressed
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    45
  // oops.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
  filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    47
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // We can be initialized to a zero size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if (free() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    if (ZapUnusedHeapArea) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    // NOTE! We need to allow space for a filler object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    assert(lab.word_size() >= filler_header_size, "lab is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    end = end - filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _state = needs_flush;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    _state = zero_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  assert(this->top() <= this->end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
void PSPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // If we were initialized to a zero sized lab, there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // nothing to flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // PLAB's never allocate the last aligned_header_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // so they can always fill with an array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  HeapWord* tlab_end = end() + filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  typeArrayOop filler_oop = (typeArrayOop) top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  filler_oop->set_mark(markOopDesc::prototype());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  filler_oop->set_klass(Universe::intArrayKlassObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  const size_t array_length =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Note that we actually DO NOT want to use the aligned header size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  set_bottom(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  set_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  set_top(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  _state = flushed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
bool PSPromotionLAB::unallocate_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  assert(Universe::heap()->is_in(obj), "Object outside heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (contains(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    HeapWord* object_end = (HeapWord*)obj + obj->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    assert(object_end <= top(), "Object crosses promotion LAB boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    if (object_end == top()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      set_top((HeapWord*)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void PSOldPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  PSPromotionLAB::flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  assert(_start_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _start_array->allocate_block(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  MemRegion used = to_space->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  assert(_start_array->covered_region().contains(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  PSOldGen* old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  MemRegion used = old_gen->object_space()->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#endif /* ASSERT */