0
|
1 /*
|
|
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 #include "incls/_precompiled.incl"
|
|
26 #include "incls/_permGen.cpp.incl"
|
|
27
|
|
28 CompactingPermGen::CompactingPermGen(ReservedSpace rs,
|
|
29 ReservedSpace shared_rs,
|
|
30 size_t initial_byte_size,
|
|
31 GenRemSet* remset,
|
|
32 PermanentGenerationSpec* perm_spec)
|
|
33 {
|
|
34 CompactingPermGenGen* g =
|
|
35 new CompactingPermGenGen(rs, shared_rs, initial_byte_size, -1, remset,
|
|
36 NULL, perm_spec);
|
|
37 if (g == NULL)
|
|
38 vm_exit_during_initialization("Could not allocate a CompactingPermGen");
|
|
39 _gen = g;
|
|
40
|
|
41 g->initialize_performance_counters();
|
|
42
|
|
43 _capacity_expansion_limit = g->capacity() + MaxPermHeapExpansion;
|
|
44 }
|
|
45
|
|
46 HeapWord* CompactingPermGen::mem_allocate(size_t size) {
|
|
47 MutexLocker ml(Heap_lock);
|
|
48 HeapWord* obj = _gen->allocate(size, false);
|
|
49 bool tried_collection = false;
|
|
50 bool tried_expansion = false;
|
|
51 while (obj == NULL) {
|
|
52 if (_gen->capacity() >= _capacity_expansion_limit || tried_expansion) {
|
|
53 // Expansion limit reached, try collection before expanding further
|
|
54 // For now we force a full collection, this could be changed
|
|
55 SharedHeap::heap()->collect_locked(GCCause::_permanent_generation_full);
|
|
56 obj = _gen->allocate(size, false);
|
|
57 tried_collection = true;
|
|
58 tried_expansion = false; // ... following the collection:
|
|
59 // the collection may have shrunk the space.
|
|
60 }
|
|
61 if (obj == NULL && !tried_expansion) {
|
|
62 obj = _gen->expand_and_allocate(size, false);
|
|
63 tried_expansion = true;
|
|
64 }
|
|
65 if (obj == NULL && tried_collection && tried_expansion) {
|
|
66 // We have not been able to allocate despite a collection and
|
|
67 // an attempted space expansion. We now make a last-ditch collection
|
|
68 // attempt that will try to reclaim as much space as possible (for
|
|
69 // example by aggressively clearing all soft refs).
|
|
70 SharedHeap::heap()->collect_locked(GCCause::_last_ditch_collection);
|
|
71 obj = _gen->allocate(size, false);
|
|
72 if (obj == NULL) {
|
|
73 // An expansion attempt is necessary since the previous
|
|
74 // collection may have shrunk the space.
|
|
75 obj = _gen->expand_and_allocate(size, false);
|
|
76 }
|
|
77 break;
|
|
78 }
|
|
79 }
|
|
80 return obj;
|
|
81 }
|
|
82
|
|
83 void CompactingPermGen::compute_new_size() {
|
|
84 size_t desired_capacity = align_size_up(_gen->used(), MinPermHeapExpansion);
|
|
85 if (desired_capacity < PermSize) {
|
|
86 desired_capacity = PermSize;
|
|
87 }
|
|
88 if (_gen->capacity() > desired_capacity) {
|
|
89 _gen->shrink(_gen->capacity() - desired_capacity);
|
|
90 }
|
|
91 _capacity_expansion_limit = _gen->capacity() + MaxPermHeapExpansion;
|
|
92 }
|