1
|
1 |
/*
|
|
2 |
* Copyright 1997-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/_klassKlass.cpp.incl"
|
|
27 |
|
|
28 |
int klassKlass::oop_size(oop obj) const {
|
|
29 |
assert (obj->is_klass(), "must be a klassOop");
|
|
30 |
return klassOop(obj)->klass_part()->klass_oop_size();
|
|
31 |
}
|
|
32 |
|
|
33 |
klassOop klassKlass::create_klass(TRAPS) {
|
|
34 |
KlassHandle h_this_klass;
|
|
35 |
klassKlass o;
|
|
36 |
// for bootstrapping, handles may not be available yet.
|
|
37 |
klassOop k = base_create_klass_oop(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
|
|
38 |
k->set_klass(k); // point to thyself
|
|
39 |
// Do not try to allocate mirror, java.lang.Class not loaded at this point.
|
|
40 |
// See Universe::fixup_mirrors()
|
|
41 |
return k;
|
|
42 |
}
|
|
43 |
|
|
44 |
void klassKlass::oop_follow_contents(oop obj) {
|
|
45 |
Klass* k = Klass::cast(klassOop(obj));
|
|
46 |
// If we are alive it is valid to keep our superclass and subtype caches alive
|
|
47 |
MarkSweep::mark_and_push(k->adr_super());
|
|
48 |
for (juint i = 0; i < Klass::primary_super_limit(); i++)
|
|
49 |
MarkSweep::mark_and_push(k->adr_primary_supers()+i);
|
|
50 |
MarkSweep::mark_and_push(k->adr_secondary_super_cache());
|
|
51 |
MarkSweep::mark_and_push(k->adr_secondary_supers());
|
|
52 |
MarkSweep::mark_and_push(k->adr_java_mirror());
|
|
53 |
MarkSweep::mark_and_push(k->adr_name());
|
|
54 |
// We follow the subklass and sibling links at the end of the
|
|
55 |
// marking phase, since otherwise following them will prevent
|
|
56 |
// class unloading (all classes are transitively linked from
|
|
57 |
// java.lang.Object).
|
|
58 |
MarkSweep::revisit_weak_klass_link(k);
|
|
59 |
obj->follow_header();
|
|
60 |
}
|
|
61 |
|
|
62 |
#ifndef SERIALGC
|
|
63 |
void klassKlass::oop_follow_contents(ParCompactionManager* cm,
|
|
64 |
oop obj) {
|
|
65 |
Klass* k = Klass::cast(klassOop(obj));
|
|
66 |
// If we are alive it is valid to keep our superclass and subtype caches alive
|
|
67 |
PSParallelCompact::mark_and_push(cm, k->adr_super());
|
|
68 |
for (juint i = 0; i < Klass::primary_super_limit(); i++)
|
|
69 |
PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
|
|
70 |
PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
|
|
71 |
PSParallelCompact::mark_and_push(cm, k->adr_secondary_supers());
|
|
72 |
PSParallelCompact::mark_and_push(cm, k->adr_java_mirror());
|
|
73 |
PSParallelCompact::mark_and_push(cm, k->adr_name());
|
|
74 |
// We follow the subklass and sibling links at the end of the
|
|
75 |
// marking phase, since otherwise following them will prevent
|
|
76 |
// class unloading (all classes are transitively linked from
|
|
77 |
// java.lang.Object).
|
|
78 |
PSParallelCompact::revisit_weak_klass_link(cm, k);
|
|
79 |
obj->follow_header(cm);
|
|
80 |
}
|
|
81 |
#endif // SERIALGC
|
|
82 |
|
|
83 |
int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
|
|
84 |
// Get size before changing pointers
|
|
85 |
int size = oop_size(obj);
|
|
86 |
Klass* k = Klass::cast(klassOop(obj));
|
|
87 |
blk->do_oop(k->adr_super());
|
|
88 |
for (juint i = 0; i < Klass::primary_super_limit(); i++)
|
|
89 |
blk->do_oop(k->adr_primary_supers()+i);
|
|
90 |
blk->do_oop(k->adr_secondary_super_cache());
|
|
91 |
blk->do_oop(k->adr_secondary_supers());
|
|
92 |
blk->do_oop(k->adr_java_mirror());
|
|
93 |
blk->do_oop(k->adr_name());
|
|
94 |
// The following are in the perm gen and are treated
|
|
95 |
// specially in a later phase of a perm gen collection; ...
|
|
96 |
assert(oop(k)->is_perm(), "should be in perm");
|
|
97 |
assert(oop(k->subklass())->is_perm_or_null(), "should be in perm");
|
|
98 |
assert(oop(k->next_sibling())->is_perm_or_null(), "should be in perm");
|
|
99 |
// ... don't scan them normally, but remember this klassKlass
|
|
100 |
// for later (see, for instance, oop_follow_contents above
|
|
101 |
// for what MarkSweep does with it.
|
|
102 |
if (blk->should_remember_klasses()) {
|
|
103 |
blk->remember_klass(k);
|
|
104 |
}
|
|
105 |
obj->oop_iterate_header(blk);
|
|
106 |
return size;
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
|
|
111 |
// Get size before changing pointers
|
|
112 |
int size = oop_size(obj);
|
|
113 |
Klass* k = Klass::cast(klassOop(obj));
|
|
114 |
oop* adr;
|
|
115 |
adr = k->adr_super();
|
|
116 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
117 |
for (juint i = 0; i < Klass::primary_super_limit(); i++) {
|
|
118 |
adr = k->adr_primary_supers()+i;
|
|
119 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
120 |
}
|
|
121 |
adr = k->adr_secondary_super_cache();
|
|
122 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
123 |
adr = k->adr_secondary_supers();
|
|
124 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
125 |
adr = k->adr_java_mirror();
|
|
126 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
127 |
adr = k->adr_name();
|
|
128 |
if (mr.contains(adr)) blk->do_oop(adr);
|
|
129 |
// The following are "weak links" in the perm gen and are
|
|
130 |
// treated specially in a later phase of a perm gen collection.
|
|
131 |
assert(oop(k)->is_perm(), "should be in perm");
|
|
132 |
assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
|
|
133 |
assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
|
|
134 |
if (blk->should_remember_klasses()
|
|
135 |
&& (mr.contains(k->adr_subklass())
|
|
136 |
|| mr.contains(k->adr_next_sibling()))) {
|
|
137 |
blk->remember_klass(k);
|
|
138 |
}
|
|
139 |
obj->oop_iterate_header(blk, mr);
|
|
140 |
return size;
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
int klassKlass::oop_adjust_pointers(oop obj) {
|
|
145 |
// Get size before changing pointers
|
|
146 |
int size = oop_size(obj);
|
|
147 |
obj->adjust_header();
|
|
148 |
|
|
149 |
Klass* k = Klass::cast(klassOop(obj));
|
|
150 |
|
|
151 |
MarkSweep::adjust_pointer(k->adr_super());
|
|
152 |
for (juint i = 0; i < Klass::primary_super_limit(); i++)
|
|
153 |
MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
|
|
154 |
MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
|
|
155 |
MarkSweep::adjust_pointer(k->adr_secondary_supers());
|
|
156 |
MarkSweep::adjust_pointer(k->adr_java_mirror());
|
|
157 |
MarkSweep::adjust_pointer(k->adr_name());
|
|
158 |
MarkSweep::adjust_pointer(k->adr_subklass());
|
|
159 |
MarkSweep::adjust_pointer(k->adr_next_sibling());
|
|
160 |
return size;
|
|
161 |
}
|
|
162 |
|
|
163 |
#ifndef SERIALGC
|
|
164 |
void klassKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
|
|
165 |
}
|
|
166 |
|
|
167 |
void klassKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
|
|
168 |
}
|
|
169 |
|
|
170 |
int klassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
|
|
171 |
Klass* k = Klass::cast(klassOop(obj));
|
|
172 |
|
|
173 |
oop* const beg_oop = k->oop_block_beg();
|
|
174 |
oop* const end_oop = k->oop_block_end();
|
|
175 |
for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
|
|
176 |
PSParallelCompact::adjust_pointer(cur_oop);
|
|
177 |
}
|
|
178 |
|
|
179 |
return oop_size(obj);
|
|
180 |
}
|
|
181 |
|
|
182 |
int klassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
|
|
183 |
HeapWord* beg_addr, HeapWord* end_addr) {
|
|
184 |
Klass* k = Klass::cast(klassOop(obj));
|
|
185 |
|
|
186 |
oop* const beg_oop = MAX2((oop*)beg_addr, k->oop_block_beg());
|
|
187 |
oop* const end_oop = MIN2((oop*)end_addr, k->oop_block_end());
|
|
188 |
for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
|
|
189 |
PSParallelCompact::adjust_pointer(cur_oop);
|
|
190 |
}
|
|
191 |
|
|
192 |
return oop_size(obj);
|
|
193 |
}
|
|
194 |
#endif // SERIALGC
|
|
195 |
|
|
196 |
|
|
197 |
#ifndef PRODUCT
|
|
198 |
|
|
199 |
// Printing
|
|
200 |
|
|
201 |
void klassKlass::oop_print_on(oop obj, outputStream* st) {
|
|
202 |
Klass::oop_print_on(obj, st);
|
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
void klassKlass::oop_print_value_on(oop obj, outputStream* st) {
|
|
207 |
Klass::oop_print_value_on(obj, st);
|
|
208 |
}
|
|
209 |
|
|
210 |
#endif
|
|
211 |
|
|
212 |
const char* klassKlass::internal_name() const {
|
|
213 |
return "{other class}";
|
|
214 |
}
|
|
215 |
|
|
216 |
|
|
217 |
// Verification
|
|
218 |
|
|
219 |
void klassKlass::oop_verify_on(oop obj, outputStream* st) {
|
|
220 |
Klass::oop_verify_on(obj, st);
|
|
221 |
guarantee(obj->is_perm(), "should be in permspace");
|
|
222 |
guarantee(obj->is_klass(), "should be klass");
|
|
223 |
|
|
224 |
Klass* k = Klass::cast(klassOop(obj));
|
|
225 |
if (k->super() != NULL) {
|
|
226 |
guarantee(k->super()->is_perm(), "should be in permspace");
|
|
227 |
guarantee(k->super()->is_klass(), "should be klass");
|
|
228 |
}
|
|
229 |
klassOop ko = k->secondary_super_cache();
|
|
230 |
if( ko != NULL ) {
|
|
231 |
guarantee(ko->is_perm(), "should be in permspace");
|
|
232 |
guarantee(ko->is_klass(), "should be klass");
|
|
233 |
}
|
|
234 |
for( uint i = 0; i < primary_super_limit(); i++ ) {
|
|
235 |
oop ko = k->adr_primary_supers()[i]; // Cannot use normal accessor because it asserts
|
|
236 |
if( ko != NULL ) {
|
|
237 |
guarantee(ko->is_perm(), "should be in permspace");
|
|
238 |
guarantee(ko->is_klass(), "should be klass");
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
if (k->java_mirror() != NULL || (k->oop_is_instance() && instanceKlass::cast(klassOop(obj))->is_loaded())) {
|
|
243 |
guarantee(k->java_mirror() != NULL, "should be allocated");
|
|
244 |
guarantee(k->java_mirror()->is_perm(), "should be in permspace");
|
|
245 |
guarantee(k->java_mirror()->is_instance(), "should be instance");
|
|
246 |
}
|
|
247 |
if (k->name() != NULL) {
|
|
248 |
guarantee(Universe::heap()->is_in_permanent(k->name()),
|
|
249 |
"should be in permspace");
|
|
250 |
guarantee(k->name()->is_symbol(), "should be symbol");
|
|
251 |
}
|
|
252 |
}
|