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