hotspot/src/share/vm/memory/permGen.cpp
author twisti
Thu, 09 Sep 2010 05:24:11 -0700
changeset 6459 3d75ed40a975
parent 5547 f4b087cbb361
child 6765 f8d7d46aa4ff
permissions -rw-r--r--
6934483: GCC 4.5 errors "suggest parentheses around something..." when compiling with -Werror and -Wall Summary: These are minor changes fixing compile failure when -Wall -Werror flags are used under gcc 4.5. Reviewed-by: twisti, kvn, rasbold Contributed-by: Pavel Tisnovsky <ptisnovs@redhat.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
     2
 * Copyright (c) 2000, 2009, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1
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/_permGen.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    28
HeapWord* PermGen::mem_allocate_in_gen(size_t size, Generation* gen) {
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    29
  GCCause::Cause next_cause = GCCause::_permanent_generation_full;
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    30
  GCCause::Cause prev_cause = GCCause::_no_gc;
1667
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    31
  unsigned int gc_count_before, full_gc_count_before;
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    32
  HeapWord* obj;
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    33
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    34
  for (;;) {
1667
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    35
    {
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    36
      MutexLocker ml(Heap_lock);
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    37
      if ((obj = gen->allocate(size, false)) != NULL) {
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    38
        return obj;
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    39
      }
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    40
      if (gen->capacity() < _capacity_expansion_limit ||
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    41
          prev_cause != GCCause::_no_gc) {
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    42
        obj = gen->expand_and_allocate(size, false);
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    43
      }
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    44
      if (obj != NULL || prev_cause == GCCause::_last_ditch_collection) {
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    45
        return obj;
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    46
      }
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    47
      if (GC_locker::is_active_and_needs_gc()) {
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    48
        // If this thread is not in a jni critical section, we stall
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    49
        // the requestor until the critical section has cleared and
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    50
        // GC allowed. When the critical section clears, a GC is
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    51
        // initiated by the last thread exiting the critical section; so
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    52
        // we retry the allocation sequence from the beginning of the loop,
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    53
        // rather than causing more, now probably unnecessary, GC attempts.
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    54
        JavaThread* jthr = JavaThread::current();
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    55
        if (!jthr->in_critical()) {
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    56
          MutexUnlocker mul(Heap_lock);
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    57
          // Wait for JNI critical section to be exited
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    58
          GC_locker::stall_until_clear();
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    59
          continue;
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    60
        } else {
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    61
          if (CheckJNICalls) {
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    62
            fatal("Possible deadlock due to allocating while"
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    63
                  " in jni critical section");
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    64
          }
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    65
          return NULL;
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    66
        }
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    67
      }
1667
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    68
      // Read the GC count while holding the Heap_lock
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    69
      gc_count_before      = SharedHeap::heap()->total_collections();
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    70
      full_gc_count_before = SharedHeap::heap()->total_full_collections();
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    71
    }
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    72
1667
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    73
    // Give up heap lock above, VMThread::execute below gets it back
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    74
    VM_GenCollectForPermanentAllocation op(size, gc_count_before, full_gc_count_before,
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    75
                                           next_cause);
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    76
    VMThread::execute(&op);
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    77
    if (!op.prologue_succeeded() || op.gc_locked()) {
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    78
      assert(op.result() == NULL, "must be NULL if gc_locked() is true");
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    79
      continue;  // retry and/or stall as necessary
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    80
    }
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    81
    obj = op.result();
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    82
    assert(obj == NULL || SharedHeap::heap()->is_in_reserved(obj),
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    83
           "result not in heap");
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    84
    if (obj != NULL) {
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    85
      return obj;
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    86
    }
1667
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    87
    prev_cause = next_cause;
fc79935c3055 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 670
diff changeset
    88
    next_cause = GCCause::_last_ditch_collection;
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    89
  }
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    90
}
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
    91
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
CompactingPermGen::CompactingPermGen(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                                     ReservedSpace shared_rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                     size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                                     GenRemSet* remset,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                     PermanentGenerationSpec* perm_spec)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  CompactingPermGenGen* g =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    new CompactingPermGenGen(rs, shared_rs, initial_byte_size, -1, remset,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                             NULL, perm_spec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if (g == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    vm_exit_during_initialization("Could not allocate a CompactingPermGen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _gen = g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  g->initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _capacity_expansion_limit = g->capacity() + MaxPermHeapExpansion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
HeapWord* CompactingPermGen::mem_allocate(size_t size) {
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
   111
  return mem_allocate_in_gen(size, _gen);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
void CompactingPermGen::compute_new_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  size_t desired_capacity = align_size_up(_gen->used(), MinPermHeapExpansion);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  if (desired_capacity < PermSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    desired_capacity = PermSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if (_gen->capacity() > desired_capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    _gen->shrink(_gen->capacity() - desired_capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _capacity_expansion_limit = _gen->capacity() + MaxPermHeapExpansion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}