src/share/vm/gc_implementation/concurrentMarkSweep/cmsPermGen.cpp

changeset 435
a61af66fc99e
child 574
c0492d52d55b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsPermGen.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,109 @@
     1.4 +/*
     1.5 + * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_cmsPermGen.cpp.incl"
    1.30 +
    1.31 +CMSPermGen::CMSPermGen(ReservedSpace rs, size_t initial_byte_size,
    1.32 +             CardTableRS* ct,
    1.33 +             FreeBlockDictionary::DictionaryChoice dictionaryChoice) {
    1.34 +  CMSPermGenGen* g =
    1.35 +    new CMSPermGenGen(rs, initial_byte_size, -1, ct);
    1.36 +  if (g == NULL) {
    1.37 +    vm_exit_during_initialization("Could not allocate a CompactingPermGen");
    1.38 +  }
    1.39 +
    1.40 +  g->initialize_performance_counters();
    1.41 +
    1.42 +  _gen = g;
    1.43 +}
    1.44 +
    1.45 +HeapWord* CMSPermGen::mem_allocate(size_t size) {
    1.46 +  Mutex* lock = _gen->freelistLock();
    1.47 +  bool lock_owned = lock->owned_by_self();
    1.48 +  if (lock_owned) {
    1.49 +    MutexUnlocker mul(lock);
    1.50 +    return mem_allocate_work(size);
    1.51 +  } else {
    1.52 +    return mem_allocate_work(size);
    1.53 +  }
    1.54 +}
    1.55 +
    1.56 +HeapWord* CMSPermGen::mem_allocate_work(size_t size) {
    1.57 +  assert(!_gen->freelistLock()->owned_by_self(), "Potetntial deadlock");
    1.58 +
    1.59 +  MutexLocker ml(Heap_lock);
    1.60 +  HeapWord* obj = NULL;
    1.61 +
    1.62 +  obj = _gen->allocate(size, false);
    1.63 +  // Since we want to minimize pause times, we will prefer
    1.64 +  // expanding the perm gen rather than doing a stop-world
    1.65 +  // collection to satisfy the allocation request.
    1.66 +  if (obj == NULL) {
    1.67 +    // Try to expand the perm gen and allocate space.
    1.68 +    obj = _gen->expand_and_allocate(size, false, false);
    1.69 +    if (obj == NULL) {
    1.70 +      // Let's see if a normal stop-world full collection will
    1.71 +      // free up enough space.
    1.72 +      SharedHeap::heap()->collect_locked(GCCause::_permanent_generation_full);
    1.73 +      obj = _gen->allocate(size, false);
    1.74 +      if (obj == NULL) {
    1.75 +        // The collection above may have shrunk the space, so try
    1.76 +        // to expand again and allocate space.
    1.77 +        obj = _gen->expand_and_allocate(size, false, false);
    1.78 +      }
    1.79 +      if (obj == NULL) {
    1.80 +        // We have not been able to allocate space despite a
    1.81 +        // full stop-world collection. We now make a last-ditch collection
    1.82 +        // attempt (in which soft refs are all aggressively freed)
    1.83 +        // that will try to reclaim as much space as possible.
    1.84 +        SharedHeap::heap()->collect_locked(GCCause::_last_ditch_collection);
    1.85 +        obj = _gen->allocate(size, false);
    1.86 +        if (obj == NULL) {
    1.87 +          // Expand generation in case it was shrunk following the collection.
    1.88 +          obj = _gen->expand_and_allocate(size, false, false);
    1.89 +        }
    1.90 +      }
    1.91 +    }
    1.92 +  }
    1.93 +  return obj;
    1.94 +}
    1.95 +
    1.96 +void CMSPermGen::compute_new_size() {
    1.97 +  _gen->compute_new_size();
    1.98 +}
    1.99 +
   1.100 +void CMSPermGenGen::initialize_performance_counters() {
   1.101 +
   1.102 +  const char* gen_name = "perm";
   1.103 +
   1.104 +  // Generation Counters - generation 2, 1 subspace
   1.105 +  _gen_counters = new GenerationCounters(gen_name, 2, 1, &_virtual_space);
   1.106 +
   1.107 +  _gc_counters = NULL;
   1.108 +
   1.109 +  _space_counters = new GSpaceCounters(gen_name, 0,
   1.110 +                                       _virtual_space.reserved_size(),
   1.111 +                                       this, _gen_counters);
   1.112 +}

mercurial