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