hotspot/src/share/vm/gc_implementation/parallelScavenge/psPermGen.cpp
author kvn
Thu, 27 May 2010 18:01:56 -0700
changeset 5694 1e0532a6abff
parent 1623 a0dd9009e992
child 5547 f4b087cbb361
permissions -rw-r--r--
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb Summary: Added new product ObjectAlignmentInBytes flag to control object alignment. Reviewed-by: twisti, ysr, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
1623
a0dd9009e992 6785258: Update copyright year
xdono
parents: 1406
diff changeset
     2
 * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
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/_psPermGen.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
PSPermGen::PSPermGen(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                     size_t initial_size, size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
                     const char* gen_name, int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  PSOldGen(rs, alignment, initial_size, min_size, max_size, gen_name, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _last_used(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  assert(object_mark_sweep() != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  object_mark_sweep()->set_allowed_dead_ratio(PermMarkSweepDeadRatio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _avg_size = new AdaptivePaddedAverage(AdaptivePermSizeWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                                        PermGenPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
HeapWord* PSPermGen::allocate_permanent(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  HeapWord* obj = allocate_noexpand(size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    obj = expand_and_allocate(size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
void PSPermGen::compute_new_size(size_t used_before_collection) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Update our padded average of objects allocated in perm
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // gen between collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  assert(used_before_collection >= _last_used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                                "negative allocation amount since last GC?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  const size_t alloc_since_last_gc = used_before_collection - _last_used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _avg_size->sample(alloc_since_last_gc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  const size_t current_live = used_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Stash away the current amount live for the next call to this method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _last_used = current_live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // We have different alignment constraints than the rest of the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  const size_t alignment = MAX2(MinPermHeapExpansion,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                virtual_space()->alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Compute the desired size:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  //  The free space is the newly computed padded average,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  //  so the desired size is what's live + the free space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  size_t desired_size = current_live + (size_t)_avg_size->padded_average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  desired_size = align_size_up(desired_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // ...and no larger or smaller than our max and min allowed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  desired_size = MAX2(MIN2(desired_size, _max_gen_size), _min_gen_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  assert(desired_size <= _max_gen_size, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  const size_t size_before = _virtual_space->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (desired_size == size_before) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // no change, we're done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // We'll be growing or shrinking the heap:  in either case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    // we need to hold a lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    if (desired_size > size_before) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      const size_t change_bytes = desired_size - size_before;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      const size_t aligned_change_bytes =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        align_size_up(change_bytes, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      expand_by(aligned_change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      // Shrinking
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      const size_t change_bytes =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        size_before - desired_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      const size_t aligned_change_bytes = align_size_down(change_bytes, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      shrink(aligned_change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // While this code isn't controlled by AdaptiveSizePolicy, it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // convenient to see all resizing decsions under the same flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    gclog_or_tty->print_cr("AdaptiveSizePolicy::perm generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                           "collection: %d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                           "(" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
                           heap->total_collections(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                           size_before, _virtual_space->committed_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void PSPermGen::move_and_update(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  PSParallelCompact::move_and_update(cm, PSParallelCompact::perm_space_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
void PSPermGen::precompact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Reset start array first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  _start_array.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  object_mark_sweep()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}