Thu, 11 Dec 2008 12:05:08 -0800
6578152: fill_region_with_object has usability and safety issues
Reviewed-by: apetrusenko, ysr
1 /*
2 * Copyright 2001-2008 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 */
25 // Methods of protected closure types
27 template <class T>
28 inline void DefNewGeneration::KeepAliveClosure::do_oop_work(T* p) {
29 #ifdef ASSERT
30 {
31 // We never expect to see a null reference being processed
32 // as a weak reference.
33 assert (!oopDesc::is_null(*p), "expected non-null ref");
34 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
35 assert (obj->is_oop(), "expected an oop while scanning weak refs");
36 }
37 #endif // ASSERT
39 _cl->do_oop_nv(p);
41 // Card marking is trickier for weak refs.
42 // This oop is a 'next' field which was filled in while we
43 // were discovering weak references. While we might not need
44 // to take a special action to keep this reference alive, we
45 // will need to dirty a card as the field was modified.
46 //
47 // Alternatively, we could create a method which iterates through
48 // each generation, allowing them in turn to examine the modified
49 // field.
50 //
51 // We could check that p is also in an older generation, but
52 // dirty cards in the youngest gen are never scanned, so the
53 // extra check probably isn't worthwhile.
54 if (Universe::heap()->is_in_reserved(p)) {
55 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
56 _rs->inline_write_ref_field_gc(p, obj);
57 }
58 }
60 template <class T>
61 inline void DefNewGeneration::FastKeepAliveClosure::do_oop_work(T* p) {
62 #ifdef ASSERT
63 {
64 // We never expect to see a null reference being processed
65 // as a weak reference.
66 assert (!oopDesc::is_null(*p), "expected non-null ref");
67 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
68 assert (obj->is_oop(), "expected an oop while scanning weak refs");
69 }
70 #endif // ASSERT
72 _cl->do_oop_nv(p);
74 // Optimized for Defnew generation if it's the youngest generation:
75 // we set a younger_gen card if we have an older->youngest
76 // generation pointer.
77 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
78 if (((HeapWord*)obj < _boundary) && Universe::heap()->is_in_reserved(p)) {
79 _rs->inline_write_ref_field_gc(p, obj);
80 }
81 }