annotate src/share/vm/memory/permGen.cpp @ 1839:e41cd7fd68a6

6794422: Perm gen expansion policy for concurrent collectors Summary: Concurrent collectors should expand the perm gen without a full STW GC, but possibly by triggering a concurrent collection. Temporary band-aid for G1 where no concurrent collection is kicked off since the perm gen is not collected concurrently. Reviewed-by: johnc
author ysr
date Fri, 01 Oct 2010 16:12:54 -0700
parents c18cbe5936b8
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1839
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_permGen.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
1839
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
28 HeapWord* PermGen::request_expand_and_allocate(Generation* gen, size_t size,
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
29 GCCause::Cause prev_cause) {
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
30 if (gen->capacity() < _capacity_expansion_limit ||
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
31 prev_cause != GCCause::_no_gc || UseG1GC) { // last disjunct is a temporary hack for G1
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
32 return gen->expand_and_allocate(size, false);
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
33 }
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
34 // We have reached the limit of capacity expansion where
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
35 // we will not expand further until a GC is done; request denied.
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
36 return NULL;
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
37 }
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
38
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
39 HeapWord* PermGen::mem_allocate_in_gen(size_t size, Generation* gen) {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
40 GCCause::Cause next_cause = GCCause::_permanent_generation_full;
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
41 GCCause::Cause prev_cause = GCCause::_no_gc;
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
42 unsigned int gc_count_before, full_gc_count_before;
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
43 HeapWord* obj;
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
44
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
45 for (;;) {
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
46 {
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
47 MutexLocker ml(Heap_lock);
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
48 if ((obj = gen->allocate(size, false)) != NULL) {
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
49 return obj;
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
50 }
1839
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
51 // Attempt to expand and allocate the requested space:
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
52 // specific subtypes may use specific policy to either expand
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
53 // or not. The default policy (see above) is to expand until
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
54 // _capacity_expansion_limit, and no further unless a GC is done.
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
55 // Concurrent collectors may decide to kick off a concurrent
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
56 // collection under appropriate conditions.
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
57 obj = request_expand_and_allocate(gen, size, prev_cause);
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
58
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
59 if (obj != NULL || prev_cause == GCCause::_last_ditch_collection) {
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
60 return obj;
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
61 }
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
62 if (GC_locker::is_active_and_needs_gc()) {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
63 // If this thread is not in a jni critical section, we stall
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
64 // the requestor until the critical section has cleared and
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
65 // GC allowed. When the critical section clears, a GC is
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
66 // initiated by the last thread exiting the critical section; so
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
67 // we retry the allocation sequence from the beginning of the loop,
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
68 // rather than causing more, now probably unnecessary, GC attempts.
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
69 JavaThread* jthr = JavaThread::current();
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
70 if (!jthr->in_critical()) {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
71 MutexUnlocker mul(Heap_lock);
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
72 // Wait for JNI critical section to be exited
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
73 GC_locker::stall_until_clear();
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
74 continue;
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
75 } else {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
76 if (CheckJNICalls) {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
77 fatal("Possible deadlock due to allocating while"
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
78 " in jni critical section");
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
79 }
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
80 return NULL;
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
81 }
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
82 }
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
83 // Read the GC count while holding the Heap_lock
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
84 gc_count_before = SharedHeap::heap()->total_collections();
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
85 full_gc_count_before = SharedHeap::heap()->total_full_collections();
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
86 }
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
87
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
88 // Give up heap lock above, VMThread::execute below gets it back
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
89 VM_GenCollectForPermanentAllocation op(size, gc_count_before, full_gc_count_before,
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
90 next_cause);
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
91 VMThread::execute(&op);
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
92 if (!op.prologue_succeeded() || op.gc_locked()) {
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
93 assert(op.result() == NULL, "must be NULL if gc_locked() is true");
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
94 continue; // retry and/or stall as necessary
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
95 }
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
96 obj = op.result();
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
97 assert(obj == NULL || SharedHeap::heap()->is_in_reserved(obj),
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
98 "result not in heap");
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
99 if (obj != NULL) {
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
100 return obj;
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
101 }
480
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
102 prev_cause = next_cause;
d249b360e026 6782457: CMS: Livelock in CompactibleFreeListSpace::block_size()
ysr
parents: 196
diff changeset
103 next_cause = GCCause::_last_ditch_collection;
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
104 }
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
105 }
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
106
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 CompactingPermGen::CompactingPermGen(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
108 ReservedSpace shared_rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
109 size_t initial_byte_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
110 GenRemSet* remset,
a61af66fc99e Initial load
duke
parents:
diff changeset
111 PermanentGenerationSpec* perm_spec)
a61af66fc99e Initial load
duke
parents:
diff changeset
112 {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 CompactingPermGenGen* g =
a61af66fc99e Initial load
duke
parents:
diff changeset
114 new CompactingPermGenGen(rs, shared_rs, initial_byte_size, -1, remset,
a61af66fc99e Initial load
duke
parents:
diff changeset
115 NULL, perm_spec);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (g == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
117 vm_exit_during_initialization("Could not allocate a CompactingPermGen");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 _gen = g;
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 g->initialize_performance_counters();
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 _capacity_expansion_limit = g->capacity() + MaxPermHeapExpansion;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 HeapWord* CompactingPermGen::mem_allocate(size_t size) {
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
126 return mem_allocate_in_gen(size, _gen);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void CompactingPermGen::compute_new_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 size_t desired_capacity = align_size_up(_gen->used(), MinPermHeapExpansion);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (desired_capacity < PermSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 desired_capacity = PermSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (_gen->capacity() > desired_capacity) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _gen->shrink(_gen->capacity() - desired_capacity);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
1839
e41cd7fd68a6 6794422: Perm gen expansion policy for concurrent collectors
ysr
parents: 1552
diff changeset
137 set_capacity_expansion_limit(_gen->capacity() + MaxPermHeapExpansion);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }