annotate src/share/vm/memory/dump.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents ba764ed4b6f2
children 850fdf70db2b 6e76352f1f62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 113
diff changeset
2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
0
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 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_dump.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Closure to set up the fingerprint field for all methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 class FingerprintMethodsClosure: public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 methodOop mobj = (methodOop)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 (new Fingerprinter(mobj))->fingerprint();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40 };
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Closure to set the hash value (String.hash field) in all of the
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // String objects in the heap. Setting the hash value is not required.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // However, setting the value in advance prevents the value from being
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // written later, increasing the likelihood that the shared page contain
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // the hash can be shared.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 //
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // NOTE THAT the algorithm in StringTable::hash_string() MUST MATCH the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // algorithm in java.lang.String.hashCode().
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 class StringHashCodeClosure: public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
55 Thread* THREAD;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int hash_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 StringHashCodeClosure(Thread* t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 THREAD = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 hash_offset = java_lang_String::hash_offset_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
63 void do_oop(oop* p) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
64 if (p != NULL) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
65 oop obj = *p;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (obj->klass() == SystemDictionary::string_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int hash;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 typeArrayOop value = java_lang_String::value(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 int length = java_lang_String::length(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (length == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 hash = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int offset = java_lang_String::offset(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 jchar* s = value->char_at_addr(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 hash = StringTable::hash_string(s, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 obj->int_field_put(hash_offset, hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
82 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
83 };
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Remove data from objects which should not appear in the shared file
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // (as it pertains only to the current JVM).
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 class RemoveUnshareableInfoClosure : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Zap data from the objects which is pertains only to this JVM. We
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // want that data recreated in new JVMs when the shared file is used.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 ((methodOop)obj)->remove_unshareable_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 Klass::cast((klassOop)obj)->remove_unshareable_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Don't save compiler related special oops (shouldn't be any yet).
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (obj->is_methodData() || obj->is_compiledICHolder()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 };
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 static bool mark_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (obj != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
111 !obj->is_shared() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
112 !obj->is_forwarded() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
113 !obj->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 obj->set_mark(markOopDesc::prototype()->set_marked());
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Closure: mark objects closure.
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 class MarkObjectsOopClosure : public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public:
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
125 void do_oop(oop* p) { mark_object(*p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
126 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 };
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 class MarkObjectsSkippingKlassesOopClosure : public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void do_oop(oop* pobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 oop obj = *pobj;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (obj != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
135 !obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 mark_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
139 void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140 };
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 static void mark_object_recursive_skipping_klasses(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 mark_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (obj != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 MarkObjectsSkippingKlassesOopClosure mark_all;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 obj->oop_iterate(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Closure: mark common read-only objects, excluding symbols
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 class MarkCommonReadOnly : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 MarkObjectsOopClosure mark_all;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Mark all constMethod objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (obj->is_constMethod()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 mark_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 mark_object(constMethodOop(obj)->stackmap_data());
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Exception tables are needed by ci code during compilation.
a61af66fc99e Initial load
duke
parents:
diff changeset
166 mark_object(constMethodOop(obj)->exception_table());
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Mark objects referenced by klass objects which are read-only.
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 Klass* k = Klass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 mark_object(k->secondary_supers());
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // it is never modified. Otherwise, they will be pre-marked; the
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // GC marking phase will skip them; and by skipping them will fail
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // to mark the methods objects referenced by the array.
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if (obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 instanceKlass* ik = instanceKlass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 mark_object(ik->method_ordering());
a61af66fc99e Initial load
duke
parents:
diff changeset
183 mark_object(ik->local_interfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
184 mark_object(ik->transitive_interfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
185 mark_object(ik->fields());
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 mark_object(ik->class_annotations());
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 mark_object_recursive_skipping_klasses(ik->fields_annotations());
a61af66fc99e Initial load
duke
parents:
diff changeset
190 mark_object_recursive_skipping_klasses(ik->methods_annotations());
a61af66fc99e Initial load
duke
parents:
diff changeset
191 mark_object_recursive_skipping_klasses(ik->methods_parameter_annotations());
a61af66fc99e Initial load
duke
parents:
diff changeset
192 mark_object_recursive_skipping_klasses(ik->methods_default_annotations());
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 typeArrayOop inner_classes = ik->inner_classes();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (inner_classes != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 mark_object(inner_classes);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 };
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Closure: mark common symbols
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 class MarkCommonSymbols : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
208 MarkObjectsOopClosure mark_all;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
210 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // Mark symbols refered to by method objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 methodOop m = methodOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 mark_object(m->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
217 mark_object(m->signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Mark symbols referenced by klass objects which are read-only.
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 if (obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 instanceKlass* ik = instanceKlass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 mark_object(ik->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
227 mark_object(ik->generic_signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
228 mark_object(ik->source_file_name());
a61af66fc99e Initial load
duke
parents:
diff changeset
229 mark_object(ik->source_debug_extension());
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 typeArrayOop inner_classes = ik->inner_classes();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 if (inner_classes != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 int length = inner_classes->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 for (int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 i < length;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 i += instanceKlass::inner_class_next_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 int ioff = i + instanceKlass::inner_class_inner_name_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 int index = inner_classes->ushort_at(ioff);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (index != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 mark_object(ik->constants()->symbol_at(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 ik->field_names_and_sigs_iterate(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // Mark symbols referenced by other constantpool entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 constantPoolOop(obj)->shared_symbols_iterate(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 };
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // Closure: mark char arrays used by strings
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 class MarkStringValues : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
261 MarkObjectsOopClosure mark_all;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
263 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Character arrays referenced by String objects are read-only.
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (java_lang_String::is_instance(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 mark_object(java_lang_String::value(obj));
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 };
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 #ifdef DEBUG
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Closure: Check for objects left in the heap which have not been moved.
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 class CheckRemainingObjects : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
279 int count;
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
282 CheckRemainingObjects() {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (!obj->is_shared() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
288 !obj->is_forwarded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 ++count;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 tty->print("Unreferenced object: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
292 obj->print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 void status() {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 tty->print_cr("%d objects no longer referenced, not shared.", count);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 };
a61af66fc99e Initial load
duke
parents:
diff changeset
301 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Closure: Mark remaining objects read-write, except Strings.
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 class MarkReadWriteObjects : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
308 MarkObjectsOopClosure mark_objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
310 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // it is never modified. Otherwise, they will be pre-marked; the
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // GC marking phase will skip them; and by skipping them will fail
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // to mark the methods objects referenced by the array.
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 mark_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 Klass* k = klassOop(obj)->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 mark_object(k->java_mirror());
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 instanceKlass* ik = (instanceKlass*)k;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 mark_object(ik->methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
324 mark_object(ik->constants());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (obj->blueprint()->oop_is_javaArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 arrayKlass* ak = (arrayKlass*)k;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 mark_object(ak->component_mirror());
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Mark constantPool tags and the constantPoolCache.
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 else if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 constantPoolOop pool = constantPoolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 mark_object(pool->cache());
a61af66fc99e Initial load
duke
parents:
diff changeset
338 pool->shared_tags_iterate(&mark_objects);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // Mark all method objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 mark_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 };
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 // Closure: Mark String objects read-write.
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 class MarkStringObjects : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
355 MarkObjectsOopClosure mark_objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
357 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Mark String objects referenced by constant pool entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 constantPoolOop pool = constantPoolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 pool->shared_strings_iterate(&mark_objects);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367 };
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // Move objects matching specified type (ie. lock_bits) to the specified
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // space.
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 class MoveMarkedObjects : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
375 OffsetTableContigSpace* _space;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 bool _read_only;
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
379 MoveMarkedObjects(OffsetTableContigSpace* space, bool read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 _space = space;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 _read_only = read_only;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (obj->is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 if (obj->is_gc_marked() && obj->forwardee() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 int s = obj->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
390 oop sh_obj = (oop)_space->allocate(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 if (sh_obj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (_read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 warning("\nThe permanent generation read only space is not large "
a61af66fc99e Initial load
duke
parents:
diff changeset
394 "enough to \npreload requested classes. Use "
a61af66fc99e Initial load
duke
parents:
diff changeset
395 "-XX:SharedReadOnlySize= to increase \nthe initial "
a61af66fc99e Initial load
duke
parents:
diff changeset
396 "size of the read only space.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
397 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 warning("\nThe permanent generation read write space is not large "
a61af66fc99e Initial load
duke
parents:
diff changeset
399 "enough to \npreload requested classes. Use "
a61af66fc99e Initial load
duke
parents:
diff changeset
400 "-XX:SharedReadWriteSize= to increase \nthe initial "
a61af66fc99e Initial load
duke
parents:
diff changeset
401 "size of the read write space.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 exit(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (PrintSharedSpaces && Verbose && WizardMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 tty->print_cr("\nMoveMarkedObjects: " PTR_FORMAT " -> " PTR_FORMAT " %s", obj, sh_obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
407 (_read_only ? "ro" : "rw"));
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409 Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)sh_obj, s);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 obj->forward_to(sh_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 if (_read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // Readonly objects: set hash value to self pointer and make gc_marked.
a61af66fc99e Initial load
duke
parents:
diff changeset
413 sh_obj->forward_to(sh_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 sh_obj->init_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419 };
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 static void mark_and_move(oop obj, MoveMarkedObjects* move) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (mark_object(obj)) move->do_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 enum order_policy {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 OP_favor_startup = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
427 OP_balanced = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
428 OP_favor_runtime = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
429 };
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 static void mark_and_move_for_policy(order_policy policy, oop obj, MoveMarkedObjects* move) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 if (SharedOptimizeColdStartPolicy >= policy) mark_and_move(obj, move);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 class MarkAndMoveOrderedReadOnly : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
437 MoveMarkedObjects *_move_ro;
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
440 MarkAndMoveOrderedReadOnly(MoveMarkedObjects *move_ro) : _move_ro(move_ro) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 instanceKlass* ik = instanceKlass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
445 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 mark_and_move_for_policy(OP_favor_startup, ik->name(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (ik->super() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 do_object(ik->super());
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452
a61af66fc99e Initial load
duke
parents:
diff changeset
453 objArrayOop interfaces = ik->local_interfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 mark_and_move_for_policy(OP_favor_startup, interfaces, _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 for(i = 0; i < interfaces->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 klassOop k = klassOop(interfaces->obj_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
457 mark_and_move_for_policy(OP_favor_startup, k->klass_part()->name(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 do_object(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 objArrayOop methods = ik->methods();
a61af66fc99e Initial load
duke
parents:
diff changeset
462 for(i = 0; i < methods->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 methodOop m = methodOop(methods->obj_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
464 mark_and_move_for_policy(OP_favor_startup, m->constMethod(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->exception_table(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
466 mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->stackmap_data(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // We don't move the name symbolOop here because it may invalidate
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // method ordering, which is dependent on the address of the name
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // symbolOop. It will get promoted later with the other symbols.
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // Method name is rarely accessed during classloading anyway.
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // mark_and_move_for_policy(OP_balanced, m->name(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 mark_and_move_for_policy(OP_favor_startup, m->signature(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 mark_and_move_for_policy(OP_favor_startup, ik->transitive_interfaces(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 mark_and_move_for_policy(OP_favor_startup, ik->fields(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
481 mark_and_move_for_policy(OP_favor_runtime, ik->method_ordering(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
482 mark_and_move_for_policy(OP_favor_runtime, ik->class_annotations(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 mark_and_move_for_policy(OP_favor_runtime, ik->fields_annotations(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 mark_and_move_for_policy(OP_favor_runtime, ik->methods_annotations(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
485 mark_and_move_for_policy(OP_favor_runtime, ik->methods_parameter_annotations(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 mark_and_move_for_policy(OP_favor_runtime, ik->methods_default_annotations(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 mark_and_move_for_policy(OP_favor_runtime, ik->inner_classes(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(), _move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491 };
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 class MarkAndMoveOrderedReadWrite: public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
495 MoveMarkedObjects *_move_rw;
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
498 MarkAndMoveOrderedReadWrite(MoveMarkedObjects *move_rw) : _move_rw(move_rw) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 instanceKlass* ik = instanceKlass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
503 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop(), _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (ik->super() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 do_object(ik->super());
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 objArrayOop interfaces = ik->local_interfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
512 for(i = 0; i < interfaces->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 klassOop k = klassOop(interfaces->obj_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
514 mark_and_move_for_policy(OP_favor_startup, k, _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 do_object(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 objArrayOop methods = ik->methods();
a61af66fc99e Initial load
duke
parents:
diff changeset
519 mark_and_move_for_policy(OP_favor_startup, methods, _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
520 for(i = 0; i < methods->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 methodOop m = methodOop(methods->obj_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
522 mark_and_move_for_policy(OP_favor_startup, m, _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
523 mark_and_move_for_policy(OP_favor_startup, ik->constants(), _move_rw); // idempotent
a61af66fc99e Initial load
duke
parents:
diff changeset
524 mark_and_move_for_policy(OP_balanced, ik->constants()->cache(), _move_rw); // idempotent
a61af66fc99e Initial load
duke
parents:
diff changeset
525 mark_and_move_for_policy(OP_balanced, ik->constants()->tags(), _move_rw); // idempotent
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop()->klass(), _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 mark_and_move_for_policy(OP_favor_startup, ik->constants()->klass(), _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // Although Java mirrors are marked in MarkReadWriteObjects,
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // apparently they were never moved into shared spaces since
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // MoveMarkedObjects skips marked instance oops. This may
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // be a bug in the original implementation or simply the vestige
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // of an abandoned experiment. Nevertheless we leave a hint
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // here in case this capability is ever correctly implemented.
a61af66fc99e Initial load
duke
parents:
diff changeset
537 //
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // mark_and_move_for_policy(OP_favor_runtime, ik->java_mirror(), _move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 };
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // Adjust references in oops to refer to shared spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 class ResolveForwardingClosure: public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
548 void do_oop(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 oop obj = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 if (!obj->is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (obj != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 oop f = obj->forwardee();
a61af66fc99e Initial load
duke
parents:
diff changeset
553 guarantee(f->is_shared(), "Oop doesn't refer to shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
554 *p = f;
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
558 void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
559 };
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 void sort_methods(instanceKlass* ik, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
563 klassOop super = ik->super();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 if (super != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 sort_methods(instanceKlass::cast(super), THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
567
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // The methods array must be ordered by symbolOop address. (See
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // classFileParser.cpp where methods in a class are originally
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // sorted.) Since objects have just be reordered, this must be
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // corrected.
a61af66fc99e Initial load
duke
parents:
diff changeset
572 methodOopDesc::sort_methods(ik->methods(),
a61af66fc99e Initial load
duke
parents:
diff changeset
573 ik->methods_annotations(),
a61af66fc99e Initial load
duke
parents:
diff changeset
574 ik->methods_parameter_annotations(),
a61af66fc99e Initial load
duke
parents:
diff changeset
575 ik->methods_default_annotations(),
a61af66fc99e Initial load
duke
parents:
diff changeset
576 true /* idempotent, slow */);
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // Itable indices are calculated based on methods array order
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // (see klassItable::compute_itable_index()). Must reinitialize.
a61af66fc99e Initial load
duke
parents:
diff changeset
580 // We assume that since checkconstraints is false, this method
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // cannot throw an exception. An exception here would be
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // problematic since this is the VMThread, not a JavaThread.
a61af66fc99e Initial load
duke
parents:
diff changeset
583 ik->itable()->initialize_itable(false, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // Sort methods if the oop is an instanceKlass.
a61af66fc99e Initial load
duke
parents:
diff changeset
587
a61af66fc99e Initial load
duke
parents:
diff changeset
588 class SortMethodsClosure: public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
589 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
590 Thread* _thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
593 SortMethodsClosure(Thread* thread) : _thread(thread) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // instanceKlass objects need some adjustment.
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (obj->blueprint()->oop_is_instanceKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 instanceKlass* ik = instanceKlass::cast((klassOop)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 sort_methods(ik, _thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602 }
a61af66fc99e Initial load
duke
parents:
diff changeset
603 };
a61af66fc99e Initial load
duke
parents:
diff changeset
604
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 // Adjust references in oops to refer to shared spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 class PatchOopsClosure: public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
610 Thread* _thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
611 ResolveForwardingClosure resolve;
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
614 PatchOopsClosure(Thread* thread) : _thread(thread) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 obj->oop_iterate_header(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 obj->oop_iterate(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 assert(obj->klass()->is_shared(), "Klass not pointing into shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // If the object is a Java object or class which might (in the
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // future) contain a reference to a young gen object, add it to the
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // list.
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 if (obj->is_klass() || obj->is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
627 if (obj->is_klass() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
628 obj->is_a(SystemDictionary::class_klass()) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
629 obj->is_a(SystemDictionary::throwable_klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // Do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632 else if (obj->is_a(SystemDictionary::string_klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // immutable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
634 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // someone added an object we hadn't accounted for.
a61af66fc99e Initial load
duke
parents:
diff changeset
636 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640 };
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // Empty the young and old generations.
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 class ClearSpaceClosure : public SpaceClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
647 void do_space(Space* s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 s->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 };
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // Closure for serializing initialization data out to a data area to be
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // written to the shared file.
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656 class WriteClosure : public SerializeOopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
657 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
658 oop* top;
a61af66fc99e Initial load
duke
parents:
diff changeset
659 char* end;
a61af66fc99e Initial load
duke
parents:
diff changeset
660
a61af66fc99e Initial load
duke
parents:
diff changeset
661 void out_of_space() {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 warning("\nThe shared miscellaneous data space is not large "
a61af66fc99e Initial load
duke
parents:
diff changeset
663 "enough to \npreload requested classes. Use "
a61af66fc99e Initial load
duke
parents:
diff changeset
664 "-XX:SharedMiscDataSize= to increase \nthe initial "
a61af66fc99e Initial load
duke
parents:
diff changeset
665 "size of the miscellaneous data space.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
666 exit(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668
a61af66fc99e Initial load
duke
parents:
diff changeset
669
a61af66fc99e Initial load
duke
parents:
diff changeset
670 inline void check_space() {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 if ((char*)top + sizeof(oop) > end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 out_of_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
678 WriteClosure(char* md_top, char* md_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 top = (oop*)md_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 end = md_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683 char* get_top() { return (char*)top; }
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 void do_oop(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 check_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
687 oop obj = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
688 assert(obj->is_oop_or_null(), "invalid oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
689 assert(obj == NULL || obj->is_shared(),
a61af66fc99e Initial load
duke
parents:
diff changeset
690 "Oop in shared space not pointing into shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
691 *top = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
692 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
695 void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
696
0
a61af66fc99e Initial load
duke
parents:
diff changeset
697 void do_int(int* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 check_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
699 *top = (oop)(intptr_t)*p;
a61af66fc99e Initial load
duke
parents:
diff changeset
700 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702
a61af66fc99e Initial load
duke
parents:
diff changeset
703 void do_size_t(size_t* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 check_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
705 *top = (oop)(intptr_t)*p;
a61af66fc99e Initial load
duke
parents:
diff changeset
706 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 void do_ptr(void** p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 check_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
711 *top = (oop)*p;
a61af66fc99e Initial load
duke
parents:
diff changeset
712 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714
a61af66fc99e Initial load
duke
parents:
diff changeset
715 void do_ptr(HeapWord** p) { do_ptr((void **) p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 void do_tag(int tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
718 check_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
719 *top = (oop)(intptr_t)tag;
a61af66fc99e Initial load
duke
parents:
diff changeset
720 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 void do_region(u_char* start, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 if ((char*)top + size > end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 out_of_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
726 }
a61af66fc99e Initial load
duke
parents:
diff changeset
727 assert((intptr_t)start % sizeof(oop) == 0, "bad alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
728 assert(size % sizeof(oop) == 0, "bad size");
a61af66fc99e Initial load
duke
parents:
diff changeset
729 do_tag((int)size);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 while (size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 *top = *(oop*)start;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 ++top;
a61af66fc99e Initial load
duke
parents:
diff changeset
733 start += sizeof(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
734 size -= sizeof(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 bool reading() const { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
739 };
a61af66fc99e Initial load
duke
parents:
diff changeset
740
a61af66fc99e Initial load
duke
parents:
diff changeset
741
a61af66fc99e Initial load
duke
parents:
diff changeset
742 class ResolveConstantPoolsClosure : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
744 TRAPS;
a61af66fc99e Initial load
duke
parents:
diff changeset
745 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
746 ResolveConstantPoolsClosure(Thread *t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 __the_thread__ = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 constantPoolOop cpool = (constantPoolOop)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
752 int unresolved = cpool->pre_resolve_shared_klasses(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 };
a61af66fc99e Initial load
duke
parents:
diff changeset
756
a61af66fc99e Initial load
duke
parents:
diff changeset
757
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // Print a summary of the contents of the read/write spaces to help
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // identify objects which might be able to be made read-only. At this
a61af66fc99e Initial load
duke
parents:
diff changeset
760 // point, the objects have been written, and we can trash them as
a61af66fc99e Initial load
duke
parents:
diff changeset
761 // needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 static void print_contents() {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
765 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
766 CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
a61af66fc99e Initial load
duke
parents:
diff changeset
767
a61af66fc99e Initial load
duke
parents:
diff changeset
768 // High level summary of the read-only space:
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 ClassifyObjectClosure coc;
a61af66fc99e Initial load
duke
parents:
diff changeset
771 tty->cr(); tty->print_cr("ReadOnly space:");
a61af66fc99e Initial load
duke
parents:
diff changeset
772 gen->ro_space()->object_iterate(&coc);
a61af66fc99e Initial load
duke
parents:
diff changeset
773 coc.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 // High level summary of the read-write space:
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 coc.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
778 tty->cr(); tty->print_cr("ReadWrite space:");
a61af66fc99e Initial load
duke
parents:
diff changeset
779 gen->rw_space()->object_iterate(&coc);
a61af66fc99e Initial load
duke
parents:
diff changeset
780 coc.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 // Reset counters
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 ClearAllocCountClosure cacc;
a61af66fc99e Initial load
duke
parents:
diff changeset
785 gen->ro_space()->object_iterate(&cacc);
a61af66fc99e Initial load
duke
parents:
diff changeset
786 gen->rw_space()->object_iterate(&cacc);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 coc.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 // Lower level summary of the read-only space:
a61af66fc99e Initial load
duke
parents:
diff changeset
790
a61af66fc99e Initial load
duke
parents:
diff changeset
791 gen->ro_space()->object_iterate(&coc);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 tty->cr(); tty->print_cr("ReadOnly space:");
a61af66fc99e Initial load
duke
parents:
diff changeset
793 ClassifyInstanceKlassClosure cikc;
a61af66fc99e Initial load
duke
parents:
diff changeset
794 gen->rw_space()->object_iterate(&cikc);
a61af66fc99e Initial load
duke
parents:
diff changeset
795 cikc.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // Reset counters
a61af66fc99e Initial load
duke
parents:
diff changeset
798
a61af66fc99e Initial load
duke
parents:
diff changeset
799 gen->ro_space()->object_iterate(&cacc);
a61af66fc99e Initial load
duke
parents:
diff changeset
800 gen->rw_space()->object_iterate(&cacc);
a61af66fc99e Initial load
duke
parents:
diff changeset
801 coc.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
802
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // Lower level summary of the read-write space:
a61af66fc99e Initial load
duke
parents:
diff changeset
804
a61af66fc99e Initial load
duke
parents:
diff changeset
805 gen->rw_space()->object_iterate(&coc);
a61af66fc99e Initial load
duke
parents:
diff changeset
806 cikc.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
807 tty->cr(); tty->print_cr("ReadWrite space:");
a61af66fc99e Initial load
duke
parents:
diff changeset
808 gen->rw_space()->object_iterate(&cikc);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 cikc.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813
a61af66fc99e Initial load
duke
parents:
diff changeset
814 // Patch C++ vtable pointer in klass oops.
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 // Klass objects contain references to c++ vtables in the JVM library.
a61af66fc99e Initial load
duke
parents:
diff changeset
817 // Fix them to point to our constructed vtables. However, don't iterate
a61af66fc99e Initial load
duke
parents:
diff changeset
818 // across the space while doing this, as that causes the vtables to be
a61af66fc99e Initial load
duke
parents:
diff changeset
819 // patched, undoing our useful work. Instead, iterate to make a list,
a61af66fc99e Initial load
duke
parents:
diff changeset
820 // then use the list to do the fixing.
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 class PatchKlassVtables: public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
823 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
824 void* _vtbl_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
825 VirtualSpace* _md_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
826 GrowableArray<klassOop>* _klass_objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 PatchKlassVtables(void* vtbl_ptr, VirtualSpace* md_vs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 _vtbl_ptr = vtbl_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
832 _md_vs = md_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
833 _klass_objects = new GrowableArray<klassOop>();
a61af66fc99e Initial load
duke
parents:
diff changeset
834 }
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836
a61af66fc99e Initial load
duke
parents:
diff changeset
837 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
838 if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 _klass_objects->append(klassOop(obj));
a61af66fc99e Initial load
duke
parents:
diff changeset
840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 void patch(void** vtbl_list, int vtbl_list_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 for (int i = 0; i < _klass_objects->length(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 klassOop obj = (klassOop)_klass_objects->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 Klass* k = obj->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
848 void* v = *(void**)k;
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 int n;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 for (n = 0; n < vtbl_list_size; ++n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 *(void**)k = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (vtbl_list[n] == v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 *(void**)k = (void**)_vtbl_ptr +
a61af66fc99e Initial load
duke
parents:
diff changeset
855 (n * CompactingPermGenGen::num_virtuals);
a61af66fc99e Initial load
duke
parents:
diff changeset
856 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859 guarantee(n < vtbl_list_size, "unable to find matching vtbl pointer");
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 };
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864
a61af66fc99e Initial load
duke
parents:
diff changeset
865 // Populate the shared space.
a61af66fc99e Initial load
duke
parents:
diff changeset
866
a61af66fc99e Initial load
duke
parents:
diff changeset
867 class VM_PopulateDumpSharedSpace: public VM_Operation {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
869 GrowableArray<oop> *_class_promote_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
870 OffsetTableContigSpace* _ro_space;
a61af66fc99e Initial load
duke
parents:
diff changeset
871 OffsetTableContigSpace* _rw_space;
a61af66fc99e Initial load
duke
parents:
diff changeset
872 VirtualSpace* _md_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
873 VirtualSpace* _mc_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
874
a61af66fc99e Initial load
duke
parents:
diff changeset
875 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
876 VM_PopulateDumpSharedSpace(GrowableArray<oop> *class_promote_order,
a61af66fc99e Initial load
duke
parents:
diff changeset
877 OffsetTableContigSpace* ro_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
878 OffsetTableContigSpace* rw_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
879 VirtualSpace* md_vs, VirtualSpace* mc_vs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 _class_promote_order = class_promote_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
881 _ro_space = ro_space;
a61af66fc99e Initial load
duke
parents:
diff changeset
882 _rw_space = rw_space;
a61af66fc99e Initial load
duke
parents:
diff changeset
883 _md_vs = md_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
884 _mc_vs = mc_vs;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 }
a61af66fc99e Initial load
duke
parents:
diff changeset
886
a61af66fc99e Initial load
duke
parents:
diff changeset
887 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
a61af66fc99e Initial load
duke
parents:
diff changeset
888 void doit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
889 Thread* THREAD = VMThread::vm_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
890 NOT_PRODUCT(SystemDictionary::verify();)
a61af66fc99e Initial load
duke
parents:
diff changeset
891 // The following guarantee is meant to ensure that no loader constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
892 // exist yet, since the constraints table is not shared. This becomes
a61af66fc99e Initial load
duke
parents:
diff changeset
893 // more important now that we don't re-initialize vtables/itables for
a61af66fc99e Initial load
duke
parents:
diff changeset
894 // shared classes at runtime, where constraints were previously created.
a61af66fc99e Initial load
duke
parents:
diff changeset
895 guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
896 "loader constraints are not saved");
a61af66fc99e Initial load
duke
parents:
diff changeset
897 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
898
a61af66fc99e Initial load
duke
parents:
diff changeset
899 // At this point, many classes have been loaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
900
a61af66fc99e Initial load
duke
parents:
diff changeset
901 // Update all the fingerprints in the shared methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 tty->print("Calculating fingerprints ... ");
a61af66fc99e Initial load
duke
parents:
diff changeset
904 FingerprintMethodsClosure fpmc;
a61af66fc99e Initial load
duke
parents:
diff changeset
905 gch->object_iterate(&fpmc);
a61af66fc99e Initial load
duke
parents:
diff changeset
906 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 // Remove all references outside the heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
909
a61af66fc99e Initial load
duke
parents:
diff changeset
910 tty->print("Removing unshareable information ... ");
a61af66fc99e Initial load
duke
parents:
diff changeset
911 RemoveUnshareableInfoClosure ruic;
a61af66fc99e Initial load
duke
parents:
diff changeset
912 gch->object_iterate(&ruic);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // Move the objects in three passes.
a61af66fc99e Initial load
duke
parents:
diff changeset
916
a61af66fc99e Initial load
duke
parents:
diff changeset
917 MarkObjectsOopClosure mark_all;
a61af66fc99e Initial load
duke
parents:
diff changeset
918 MarkCommonReadOnly mark_common_ro;
a61af66fc99e Initial load
duke
parents:
diff changeset
919 MarkCommonSymbols mark_common_symbols;
a61af66fc99e Initial load
duke
parents:
diff changeset
920 MarkStringValues mark_string_values;
a61af66fc99e Initial load
duke
parents:
diff changeset
921 MarkReadWriteObjects mark_rw;
a61af66fc99e Initial load
duke
parents:
diff changeset
922 MarkStringObjects mark_strings;
a61af66fc99e Initial load
duke
parents:
diff changeset
923 MoveMarkedObjects move_ro(_ro_space, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 MoveMarkedObjects move_rw(_rw_space, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
925
a61af66fc99e Initial load
duke
parents:
diff changeset
926 // The SharedOptimizeColdStart VM option governs the new layout
a61af66fc99e Initial load
duke
parents:
diff changeset
927 // algorithm for promoting classes into the shared archive.
a61af66fc99e Initial load
duke
parents:
diff changeset
928 // The general idea is to minimize cold start time by laying
a61af66fc99e Initial load
duke
parents:
diff changeset
929 // out the objects in the order they are accessed at startup time.
a61af66fc99e Initial load
duke
parents:
diff changeset
930 // By doing this we are trying to eliminate out-of-order accesses
a61af66fc99e Initial load
duke
parents:
diff changeset
931 // in the shared archive. This benefits cold startup time by making
a61af66fc99e Initial load
duke
parents:
diff changeset
932 // disk reads as sequential as possible during class loading and
a61af66fc99e Initial load
duke
parents:
diff changeset
933 // bootstrapping activities. There may also be a small secondary
a61af66fc99e Initial load
duke
parents:
diff changeset
934 // effect of better "packing" of more commonly used data on a smaller
a61af66fc99e Initial load
duke
parents:
diff changeset
935 // number of pages, although no direct benefit has been measured from
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // this effect.
a61af66fc99e Initial load
duke
parents:
diff changeset
937 //
a61af66fc99e Initial load
duke
parents:
diff changeset
938 // At the class level of granularity, the promotion order is dictated
a61af66fc99e Initial load
duke
parents:
diff changeset
939 // by the classlist file whose generation is discussed elsewhere.
a61af66fc99e Initial load
duke
parents:
diff changeset
940 //
a61af66fc99e Initial load
duke
parents:
diff changeset
941 // At smaller granularity, optimal ordering was determined by an
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // offline analysis of object access order in the shared archive.
a61af66fc99e Initial load
duke
parents:
diff changeset
943 // The dbx watchpoint facility, combined with SA post-processing,
a61af66fc99e Initial load
duke
parents:
diff changeset
944 // was used to observe common access patterns primarily during
a61af66fc99e Initial load
duke
parents:
diff changeset
945 // classloading. This information was used to craft the promotion
a61af66fc99e Initial load
duke
parents:
diff changeset
946 // order seen in the following closures.
a61af66fc99e Initial load
duke
parents:
diff changeset
947 //
a61af66fc99e Initial load
duke
parents:
diff changeset
948 // The observed access order is mostly governed by what happens
a61af66fc99e Initial load
duke
parents:
diff changeset
949 // in SystemDictionary::load_shared_class(). NOTE WELL - care
a61af66fc99e Initial load
duke
parents:
diff changeset
950 // should be taken when making changes to this method, because it
a61af66fc99e Initial load
duke
parents:
diff changeset
951 // may invalidate assumptions made about access order!
a61af66fc99e Initial load
duke
parents:
diff changeset
952 //
a61af66fc99e Initial load
duke
parents:
diff changeset
953 // (Ideally, there would be a better way to manage changes to
a61af66fc99e Initial load
duke
parents:
diff changeset
954 // the access order. Unfortunately a generic in-VM solution for
a61af66fc99e Initial load
duke
parents:
diff changeset
955 // dynamically observing access order and optimizing shared
a61af66fc99e Initial load
duke
parents:
diff changeset
956 // archive layout is pretty difficult. We go with the static
a61af66fc99e Initial load
duke
parents:
diff changeset
957 // analysis because the code is fairly mature at this point
a61af66fc99e Initial load
duke
parents:
diff changeset
958 // and we're betting that the access order won't change much.)
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 MarkAndMoveOrderedReadOnly mark_and_move_ordered_ro(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
961 MarkAndMoveOrderedReadWrite mark_and_move_ordered_rw(&move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 // Phase 1a: move commonly used read-only objects to the read-only space.
a61af66fc99e Initial load
duke
parents:
diff changeset
964
a61af66fc99e Initial load
duke
parents:
diff changeset
965 if (SharedOptimizeColdStart) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 tty->print("Moving pre-ordered read-only objects to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
967 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
968 for (int i = 0; i < _class_promote_order->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
969 oop obj = _class_promote_order->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
970 mark_and_move_ordered_ro.do_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
971 }
a61af66fc99e Initial load
duke
parents:
diff changeset
972 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
973 }
a61af66fc99e Initial load
duke
parents:
diff changeset
974
a61af66fc99e Initial load
duke
parents:
diff changeset
975 tty->print("Moving read-only objects to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
976 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
977 gch->object_iterate(&mark_common_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
978 gch->object_iterate(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
979 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
980
a61af66fc99e Initial load
duke
parents:
diff changeset
981 // Phase 1b: move commonly used symbols to the read-only space.
a61af66fc99e Initial load
duke
parents:
diff changeset
982
a61af66fc99e Initial load
duke
parents:
diff changeset
983 tty->print("Moving common symbols to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
984 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
985 gch->object_iterate(&mark_common_symbols);
a61af66fc99e Initial load
duke
parents:
diff changeset
986 gch->object_iterate(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
987 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 // Phase 1c: move remaining symbols to the read-only space
a61af66fc99e Initial load
duke
parents:
diff changeset
990 // (e.g. String initializers).
a61af66fc99e Initial load
duke
parents:
diff changeset
991
a61af66fc99e Initial load
duke
parents:
diff changeset
992 tty->print("Moving remaining symbols to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
993 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
994 vmSymbols::oops_do(&mark_all, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
995 gch->object_iterate(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
996 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 // Phase 1d: move String character arrays to the read-only space.
a61af66fc99e Initial load
duke
parents:
diff changeset
999
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 tty->print("Moving string char arrays to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 gch->object_iterate(&mark_string_values);
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 gch->object_iterate(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1005
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 // Phase 2: move all remaining symbols to the read-only space. The
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 // remaining symbols are assumed to be string initializers no longer
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 // referenced.
a61af66fc99e Initial load
duke
parents:
diff changeset
1009
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 void* extra_symbols = _ro_space->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 tty->print("Moving additional symbols to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 _ro_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 SymbolTable::oops_do(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 gch->object_iterate(&move_ro);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 tty->print_cr("Read-only space ends at " PTR_FORMAT ", %d bytes.",
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 _ro_space->top(), _ro_space->used());
a61af66fc99e Initial load
duke
parents:
diff changeset
1018
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 // Phase 3: move read-write objects to the read-write space, except
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 // Strings.
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (SharedOptimizeColdStart) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 tty->print("Moving pre-ordered read-write objects to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 _rw_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 for (int i = 0; i < _class_promote_order->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 oop obj = _class_promote_order->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 mark_and_move_ordered_rw.do_object(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 tty->print("Moving read-write objects to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 _rw_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 Universe::oops_do(&mark_all, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 SystemDictionary::oops_do(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 oop tmp = Universe::arithmetic_exception_instance();
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 mark_object(java_lang_Throwable::message(tmp));
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 gch->object_iterate(&mark_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 gch->object_iterate(&move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1040
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 // Phase 4: move String objects to the read-write space.
a61af66fc99e Initial load
duke
parents:
diff changeset
1042
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 tty->print("Moving String objects to shared space at " PTR_FORMAT " ... ",
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 _rw_space->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 StringTable::oops_do(&mark_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 gch->object_iterate(&mark_strings);
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 gch->object_iterate(&move_rw);
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 tty->print_cr("Read-write space ends at " PTR_FORMAT ", %d bytes.",
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 _rw_space->top(), _rw_space->used());
a61af66fc99e Initial load
duke
parents:
diff changeset
1051
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 #ifdef DEBUG
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 // Check: scan for objects which were not moved.
a61af66fc99e Initial load
duke
parents:
diff changeset
1054
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 CheckRemainingObjects check_objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 gch->object_iterate(&check_objects);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 check_objects.status();
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1059
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 // Resolve forwarding in objects and saved C++ structures
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 tty->print("Updating references to shared objects ... ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 ResolveForwardingClosure resolve;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 Universe::oops_do(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 SystemDictionary::oops_do(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 StringTable::oops_do(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 SymbolTable::oops_do(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 vmSymbols::oops_do(&resolve);
a61af66fc99e Initial load
duke
parents:
diff changeset
1068
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 // Set up the share data and shared code segments.
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 char* md_top = _md_vs->low();
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 char* md_end = _md_vs->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 char* mc_top = _mc_vs->low();
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 char* mc_end = _mc_vs->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
1075
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 // Reserve space for the list of klassOops whose vtables are used
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 // for patching others as needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1078
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 void** vtbl_list = (void**)md_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 int vtbl_list_size = CompactingPermGenGen::vtbl_list_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1082
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 md_top += vtbl_list_size * sizeof(void*);
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 void* vtable = md_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 // Reserve space for a new dummy vtable for klass objects in the
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 // heap. Generate self-patching vtable entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
1088
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 CompactingPermGenGen::generate_vtable_methods(vtbl_list,
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 &vtable,
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 &md_top, md_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 &mc_top, mc_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1093
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 // Fix (forward) all of the references in these shared objects (which
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 // are required to point ONLY to objects in the shared spaces).
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 // Also, create a list of all objects which might later contain a
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // reference to a younger generation object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1098
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 PatchOopsClosure patch(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 gen->ro_space()->object_iterate(&patch);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 gen->rw_space()->object_iterate(&patch);
a61af66fc99e Initial load
duke
parents:
diff changeset
1103
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 // Previously method sorting was done concurrently with forwarding
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 // pointer resolution in the shared spaces. This imposed an ordering
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 // restriction in that methods were required to be promoted/patched
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 // before their holder classes. (Because constant pool pointers in
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 // methodKlasses are required to be resolved before their holder class
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 // is visited for sorting, otherwise methods are sorted by incorrect,
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 // pre-forwarding addresses.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 // Now, we reorder methods as a separate step after ALL forwarding
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 // pointer resolution, so that methods can be promoted in any order
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 // with respect to their holder classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1115
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 SortMethodsClosure sort(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 gen->ro_space()->object_iterate(&sort);
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 gen->rw_space()->object_iterate(&sort);
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1121
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 // Reorder the system dictionary. (Moving the symbols opps affects
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 // how the hash table indices are calculated.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1124
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 SystemDictionary::reorder_dictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
1126
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 // Empty the non-shared heap (because most of the objects were
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 // copied out, and the remainder cannot be considered valid oops).
a61af66fc99e Initial load
duke
parents:
diff changeset
1129
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 ClearSpaceClosure csc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 for (int i = 0; i < gch->n_gens(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 gch->get_gen(i)->space_iterate(&csc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 csc.do_space(gen->the_space());
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 NOT_PRODUCT(SystemDictionary::verify();)
a61af66fc99e Initial load
duke
parents:
diff changeset
1136
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 // Copy the String table, the symbol table, and the system
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 // dictionary to the shared space in usable form. Copy the hastable
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 // buckets first [read-write], then copy the linked lists of entries
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 // [read-only].
a61af66fc99e Initial load
duke
parents:
diff changeset
1141
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 SymbolTable::reverse(extra_symbols);
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 NOT_PRODUCT(SymbolTable::verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 SymbolTable::copy_buckets(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 StringTable::reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 NOT_PRODUCT(StringTable::verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 StringTable::copy_buckets(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 SystemDictionary::reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 SystemDictionary::copy_buckets(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1152
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 ClassLoader::verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 ClassLoader::copy_package_info_buckets(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 ClassLoader::verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
1156
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 SymbolTable::copy_table(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 StringTable::copy_table(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 SystemDictionary::copy_table(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 ClassLoader::verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 ClassLoader::copy_package_info_table(&md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 ClassLoader::verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 // Print debug data.
a61af66fc99e Initial load
duke
parents:
diff changeset
1165
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 const char* fmt = "%s space: " PTR_FORMAT " out of " PTR_FORMAT " bytes allocated at " PTR_FORMAT ".";
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 tty->print_cr(fmt, "ro", _ro_space->used(), _ro_space->capacity(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 _ro_space->bottom());
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 tty->print_cr(fmt, "rw", _rw_space->used(), _rw_space->capacity(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 _rw_space->bottom());
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1173
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 // Write the oop data to the output array.
a61af66fc99e Initial load
duke
parents:
diff changeset
1175
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 WriteClosure wc(md_top, md_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 CompactingPermGenGen::serialize_oops(&wc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 md_top = wc.get_top();
a61af66fc99e Initial load
duke
parents:
diff changeset
1179
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 // Update the vtable pointers in all of the Klass objects in the
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 // heap. They should point to newly generated vtable.
a61af66fc99e Initial load
duke
parents:
diff changeset
1182
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 PatchKlassVtables pkvt(vtable, _md_vs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 _rw_space->object_iterate(&pkvt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 pkvt.patch(vtbl_list, vtbl_list_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1186
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 char* saved_vtbl = (char*)malloc(vtbl_list_size * sizeof(void*));
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
a61af66fc99e Initial load
duke
parents:
diff changeset
1190
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 // Create and write the archive file that maps the shared spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
1192
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 FileMapInfo* mapinfo = new FileMapInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 mapinfo->populate_header(gch->gen_policy()->max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
1195
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 // Pass 1 - update file offsets in header.
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 mapinfo->write_header();
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 _ro_space->set_saved_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 _rw_space->set_saved_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 md_top - _md_vs->low(), SharedMiscDataSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 false, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 mc_top - _mc_vs->low(), SharedMiscCodeSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1208
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 // Pass 2 - write data.
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 mapinfo->open_for_write();
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 mapinfo->write_header();
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 md_top - _md_vs->low(), SharedMiscDataSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 false, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 mc_top - _mc_vs->low(), SharedMiscCodeSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 mapinfo->close();
a61af66fc99e Initial load
duke
parents:
diff changeset
1221
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // Summarize heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 print_contents();
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 }; // class VM_PopulateDumpSharedSpace
a61af66fc99e Initial load
duke
parents:
diff changeset
1227
a61af66fc99e Initial load
duke
parents:
diff changeset
1228
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 // Populate the shared spaces and dump to a file.
a61af66fc99e Initial load
duke
parents:
diff changeset
1230
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 jint CompactingPermGenGen::dump_shared(GrowableArray<oop>* class_promote_order, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1233
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 // Calculate hash values for all of the (interned) strings to avoid
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 // writes to shared pages in the future.
a61af66fc99e Initial load
duke
parents:
diff changeset
1236
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 tty->print("Calculating hash values for String objects .. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 StringHashCodeClosure shcc(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 StringTable::oops_do(&shcc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1241
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 VM_PopulateDumpSharedSpace op(class_promote_order,
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 gen->ro_space(), gen->rw_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 gen->md_space(), gen->mc_space());
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 VMThread::execute(&op);
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1249
a61af66fc99e Initial load
duke
parents:
diff changeset
1250
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 class LinkClassesClosure : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 Thread* THREAD;
a61af66fc99e Initial load
duke
parents:
diff changeset
1254
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 LinkClassesClosure(Thread* thread) : THREAD(thread) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
1257
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 void do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 Klass* k = Klass::cast((klassOop) obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 if (k->oop_is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 instanceKlass* ik = (instanceKlass*) k;
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 // Link the class to cause the bytecodes to be rewritten and the
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 // cpcache to be created.
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 if (ik->get_init_state() < instanceKlass::linked) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 ik->link_class(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting");
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1269
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 // Create String objects from string initializer symbols.
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 ik->constants()->resolve_string_constants(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 guarantee(!HAS_PENDING_EXCEPTION, "exception resolving string constants");
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1277
a61af66fc99e Initial load
duke
parents:
diff changeset
1278
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 // Support for a simple checksum of the contents of the class list
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 // file to prevent trivial tampering. The algorithm matches that in
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 // the MakeClassList program used by the J2SE build process.
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 #define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe))
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 static jlong
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 jsum(jlong start, const char *buf, const int len)
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 jlong h = start;
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 char *p = (char *)buf, *e = p + len;
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 while (p < e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 char c = *p++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 if (c <= ' ') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 /* Skip spaces and control characters */
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 h = 31 * h + c;
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 return h;
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1298
a61af66fc99e Initial load
duke
parents:
diff changeset
1299
a61af66fc99e Initial load
duke
parents:
diff changeset
1300
a61af66fc99e Initial load
duke
parents:
diff changeset
1301
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 // Preload classes from a list, populate the shared spaces and dump to a
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // file.
a61af66fc99e Initial load
duke
parents:
diff changeset
1305
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 void GenCollectedHeap::preload_and_dump(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1309
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 // Preload classes to be shared.
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 // Should use some hpi:: method rather than fopen() here. aB.
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 // Construct the path to the class list (in jre/lib)
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 // Walk up two directories from the location of the VM and
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 // optionally tack on "lib" (depending on platform)
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 char class_list_path[JVM_MAXPATHLEN];
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 os::jvm_path(class_list_path, sizeof(class_list_path));
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 for (int i = 0; i < 3; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 char *end = strrchr(class_list_path, *os::file_separator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 if (end != NULL) *end = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 int class_list_path_len = (int)strlen(class_list_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 if (class_list_path_len >= 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 strcat(class_list_path, os::file_separator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 strcat(class_list_path, "lib");
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 strcat(class_list_path, os::file_separator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 strcat(class_list_path, "classlist");
a61af66fc99e Initial load
duke
parents:
diff changeset
1330
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 FILE* file = fopen(class_list_path, "r");
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 if (file != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 jlong computed_jsum = JSUM_SEED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 jlong file_jsum = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1335
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 char class_name[256];
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 int class_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 gch->_preloading_shared_classes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 GrowableArray<oop>* class_promote_order = new GrowableArray<oop>();
a61af66fc99e Initial load
duke
parents:
diff changeset
1341
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 // Preload (and intern) strings which will be used later.
a61af66fc99e Initial load
duke
parents:
diff changeset
1343
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 StringTable::intern("main", THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 StringTable::intern("([Ljava/lang/String;)V", THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 StringTable::intern("Ljava/lang/Class;", THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1347
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 StringTable::intern("I", THREAD); // Needed for StringBuffer persistence?
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 StringTable::intern("Z", THREAD); // Needed for StringBuffer persistence?
a61af66fc99e Initial load
duke
parents:
diff changeset
1350
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 // sun.io.Converters
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 SymbolTable::lookup(obj_array_sig, (int)strlen(obj_array_sig), THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1354
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 // java.util.HashMap
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 SymbolTable::lookup(map_entry_array_sig, (int)strlen(map_entry_array_sig),
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1359
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 tty->print("Loading classes to share ... ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 if (*class_name == '#') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 jint fsh, fsl;
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff);
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1367
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 // Remove trailing newline
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 size_t name_len = strlen(class_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 class_name[name_len-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
1373
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1375
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 // Got a class name - load it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 symbolHandle class_name_symbol = oopFactory::new_symbol(class_name,
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 klassOop klass = SystemDictionary::resolve_or_null(class_name_symbol,
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 if (klass != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 tty->print_cr("Shared spaces preloaded: %s", class_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1387
a61af66fc99e Initial load
duke
parents:
diff changeset
1388
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 instanceKlass* ik = instanceKlass::cast(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
1390
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 // Should be class load order as per -XX:+TraceClassLoadingPreorder
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 class_promote_order->append(ik->as_klassOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
1393
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 // Link the class to cause the bytecodes to be rewritten and the
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 // cpcache to be created. The linking is done as soon as classes
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 // are loaded in order that the related data structures (klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 // cpCache, Sting constants) are located together.
a61af66fc99e Initial load
duke
parents:
diff changeset
1398
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 if (ik->get_init_state() < instanceKlass::linked) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 ik->link_class(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting");
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1403
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 // Create String objects from string initializer symbols.
a61af66fc99e Initial load
duke
parents:
diff changeset
1405
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 ik->constants()->resolve_string_constants(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1407
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 class_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 tty->print_cr(" Preload failed: %s", class_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 file_jsum = 0; // Checksum must be on last line of file
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 if (computed_jsum != file_jsum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 tty->print_cr("Preload failed: checksum of class list was incorrect.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1422
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1424
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1428
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 // Rewrite and unlink classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 tty->print("Rewriting and unlinking classes ... ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 // Make heap parsable
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 ensure_parsability(false); // arg is actually don't care
a61af66fc99e Initial load
duke
parents:
diff changeset
1433
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 // Link any classes which got missed. (It's not quite clear why
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 // they got missed.) This iteration would be unsafe if we weren't
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 // single-threaded at this point; however we can't do it on the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 // thread because it requires object allocation.
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 LinkClassesClosure lcc(Thread::current());
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 object_iterate(&lcc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 tty->print_cr("done. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1441
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 // Create and dump the shared spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 jint err = CompactingPermGenGen::dump_shared(class_promote_order, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 if (err != JNI_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 fatal("Dumping shared spaces failed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1447
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 char errmsg[JVM_MAXPATHLEN];
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 hpi::lasterror(errmsg, JVM_MAXPATHLEN);
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 tty->print_cr("Loading classlist failed: %s", errmsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1454
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 // Since various initialization steps have been undone by this process,
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 // it is not reasonable to continue running a java process.
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 }