author | ysr |
Tue, 01 Jul 2008 11:59:44 -0700 | |
changeset 1383 | 3a216aa862b7 |
parent 386 | 7f121b1192f2 |
child 670 | ddf3e9583f2f |
permissions | -rw-r--r-- |
1 | 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 |
||
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 |
MutexLocker ml(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
|
30 |
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
|
31 |
GCCause::Cause prev_cause = GCCause::_no_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
|
32 |
|
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 |
for (;;) { |
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 |
HeapWord* obj = gen->allocate(size, false); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
35 |
if (obj != 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
|
36 |
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
|
37 |
} |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
38 |
if (gen->capacity() < _capacity_expansion_limit || |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
39 |
prev_cause != GCCause::_no_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
|
40 |
obj = gen->expand_and_allocate(size, false); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
41 |
} |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
42 |
if (obj == NULL && prev_cause != GCCause::_last_ditch_collection) { |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
43 |
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
|
44 |
// 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
|
45 |
// 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
|
46 |
// 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
|
47 |
// 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
|
48 |
// 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
|
49 |
// 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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
// 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
|
54 |
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
|
55 |
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
|
56 |
} 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
|
57 |
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
|
58 |
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
|
59 |
" 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
|
60 |
} |
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 |
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
|
62 |
} |
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 |
} |
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 |
// Read the GC count while holding the 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
|
66 |
unsigned int gc_count_before = SharedHeap::heap()->total_collections(); |
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 |
unsigned int full_gc_count_before = SharedHeap::heap()->total_full_collections(); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
68 |
{ |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
69 |
MutexUnlocker mu(Heap_lock); // give up heap lock, execute gets it back |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
70 |
VM_GenCollectForPermanentAllocation op(size, gc_count_before, full_gc_count_before, |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
71 |
next_cause); |
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 |
VMThread::execute(&op); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
73 |
if (!op.prologue_succeeded() || op.gc_locked()) { |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
74 |
assert(op.result() == NULL, "must be NULL if gc_locked() is true"); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
75 |
continue; // retry and/or stall as necessary |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
76 |
} |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
77 |
obj = op.result(); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
78 |
assert(obj == NULL || SharedHeap::heap()->is_in_reserved(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
|
79 |
"result not in heap"); |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
80 |
if (obj != 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
|
81 |
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
|
82 |
} |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
83 |
} |
7f121b1192f2
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
1
diff
changeset
|
84 |
prev_cause = next_cause; |
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 |
next_cause = GCCause::_last_ditch_collection; |
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 |
} 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
|
87 |
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
|
88 |
} |
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 | 92 |
CompactingPermGen::CompactingPermGen(ReservedSpace rs, |
93 |
ReservedSpace shared_rs, |
|
94 |
size_t initial_byte_size, |
|
95 |
GenRemSet* remset, |
|
96 |
PermanentGenerationSpec* perm_spec) |
|
97 |
{ |
|
98 |
CompactingPermGenGen* g = |
|
99 |
new CompactingPermGenGen(rs, shared_rs, initial_byte_size, -1, remset, |
|
100 |
NULL, perm_spec); |
|
101 |
if (g == NULL) |
|
102 |
vm_exit_during_initialization("Could not allocate a CompactingPermGen"); |
|
103 |
_gen = g; |
|
104 |
||
105 |
g->initialize_performance_counters(); |
|
106 |
||
107 |
_capacity_expansion_limit = g->capacity() + MaxPermHeapExpansion; |
|
108 |
} |
|
109 |
||
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 | 112 |
} |
113 |
||
114 |
void CompactingPermGen::compute_new_size() { |
|
115 |
size_t desired_capacity = align_size_up(_gen->used(), MinPermHeapExpansion); |
|
116 |
if (desired_capacity < PermSize) { |
|
117 |
desired_capacity = PermSize; |
|
118 |
} |
|
119 |
if (_gen->capacity() > desired_capacity) { |
|
120 |
_gen->shrink(_gen->capacity() - desired_capacity); |
|
121 |
} |
|
122 |
_capacity_expansion_limit = _gen->capacity() + MaxPermHeapExpansion; |
|
123 |
} |