|
1 /* |
|
2 * Copyright 2001-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 CompactibleSpace* DefNewGeneration::first_compaction_space() const { |
|
26 return eden(); |
|
27 } |
|
28 |
|
29 HeapWord* DefNewGeneration::allocate(size_t word_size, |
|
30 bool is_tlab) { |
|
31 // This is the slow-path allocation for the DefNewGeneration. |
|
32 // Most allocations are fast-path in compiled code. |
|
33 // We try to allocate from the eden. If that works, we are happy. |
|
34 // Note that since DefNewGeneration supports lock-free allocation, we |
|
35 // have to use it here, as well. |
|
36 HeapWord* result = eden()->par_allocate(word_size); |
|
37 if (result != NULL) { |
|
38 return result; |
|
39 } |
|
40 do { |
|
41 HeapWord* old_limit = eden()->soft_end(); |
|
42 if (old_limit < eden()->end()) { |
|
43 // Tell the next generation we reached a limit. |
|
44 HeapWord* new_limit = |
|
45 next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size); |
|
46 if (new_limit != NULL) { |
|
47 Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit); |
|
48 } else { |
|
49 assert(eden()->soft_end() == eden()->end(), |
|
50 "invalid state after allocation_limit_reached returned null"); |
|
51 } |
|
52 } else { |
|
53 // The allocation failed and the soft limit is equal to the hard limit, |
|
54 // there are no reasons to do an attempt to allocate |
|
55 assert(old_limit == eden()->end(), "sanity check"); |
|
56 break; |
|
57 } |
|
58 // Try to allocate until succeeded or the soft limit can't be adjusted |
|
59 result = eden()->par_allocate(word_size); |
|
60 } while (result == NULL); |
|
61 |
|
62 // If the eden is full and the last collection bailed out, we are running |
|
63 // out of heap space, and we try to allocate the from-space, too. |
|
64 // allocate_from_space can't be inlined because that would introduce a |
|
65 // circular dependency at compile time. |
|
66 if (result == NULL) { |
|
67 result = allocate_from_space(word_size); |
|
68 } |
|
69 return result; |
|
70 } |
|
71 |
|
72 HeapWord* DefNewGeneration::par_allocate(size_t word_size, |
|
73 bool is_tlab) { |
|
74 return eden()->par_allocate(word_size); |
|
75 } |
|
76 |
|
77 void DefNewGeneration::gc_prologue(bool full) { |
|
78 // Ensure that _end and _soft_end are the same in eden space. |
|
79 eden()->set_soft_end(eden()->end()); |
|
80 } |
|
81 |
|
82 size_t DefNewGeneration::tlab_capacity() const { |
|
83 return eden()->capacity(); |
|
84 } |
|
85 |
|
86 size_t DefNewGeneration::unsafe_max_tlab_alloc() const { |
|
87 return unsafe_max_alloc_nogc(); |
|
88 } |