annotate src/share/vm/memory/defNewGeneration.inline.hpp @ 79:82db0859acbe

6642862: Code cache allocation fails with large pages after 6588638 Reviewed-by: apetrusenko
author jcoomes
date Fri, 28 Mar 2008 23:35:42 -0700
parents a61af66fc99e
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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 CompactibleSpace* DefNewGeneration::first_compaction_space() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
26 return eden();
a61af66fc99e Initial load
duke
parents:
diff changeset
27 }
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 HeapWord* DefNewGeneration::allocate(size_t word_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
30 bool is_tlab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // This is the slow-path allocation for the DefNewGeneration.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Most allocations are fast-path in compiled code.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // We try to allocate from the eden. If that works, we are happy.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Note that since DefNewGeneration supports lock-free allocation, we
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // have to use it here, as well.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 HeapWord* result = eden()->par_allocate(word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
37 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 HeapWord* old_limit = eden()->soft_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 if (old_limit < eden()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Tell the next generation we reached a limit.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 HeapWord* new_limit =
a61af66fc99e Initial load
duke
parents:
diff changeset
45 next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 if (new_limit != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 assert(eden()->soft_end() == eden()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
50 "invalid state after allocation_limit_reached returned null");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // The allocation failed and the soft limit is equal to the hard limit,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // there are no reasons to do an attempt to allocate
a61af66fc99e Initial load
duke
parents:
diff changeset
55 assert(old_limit == eden()->end(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
56 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // Try to allocate until succeeded or the soft limit can't be adjusted
a61af66fc99e Initial load
duke
parents:
diff changeset
59 result = eden()->par_allocate(word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 } while (result == NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // If the eden is full and the last collection bailed out, we are running
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // out of heap space, and we try to allocate the from-space, too.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // allocate_from_space can't be inlined because that would introduce a
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // circular dependency at compile time.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (result == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 result = allocate_from_space(word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 HeapWord* DefNewGeneration::par_allocate(size_t word_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
73 bool is_tlab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return eden()->par_allocate(word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void DefNewGeneration::gc_prologue(bool full) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Ensure that _end and _soft_end are the same in eden space.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 eden()->set_soft_end(eden()->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 size_t DefNewGeneration::tlab_capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return eden()->capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 size_t DefNewGeneration::unsafe_max_tlab_alloc() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return unsafe_max_alloc_nogc();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }