annotate src/share/vm/oops/symbolKlass.cpp @ 974:26b774d693aa

Merge
author acorn
date Wed, 16 Sep 2009 09:10:57 -0400
parents 2a1a77d3458f
children 4e6abf09f540
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_symbolKlass.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 symbolOop symbolKlass::allocate_symbol(u1* name, int len, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Don't allow symbol oops to be created which cannot fit in a symbolOop.
a61af66fc99e Initial load
duke
parents:
diff changeset
30 if (len > symbolOopDesc::max_length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 THROW_MSG_0(vmSymbols::java_lang_InternalError(),
a61af66fc99e Initial load
duke
parents:
diff changeset
32 "name is too long to represent");
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int size = symbolOopDesc::object_size(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
35 symbolKlassHandle h_k(THREAD, as_klassOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
36 symbolOop sym = (symbolOop)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(!sym->is_parsable(), "not expecting parsability yet.");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 No_Safepoint_Verifier no_safepoint;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 sym->set_utf8_length(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 sym->byte_at_put(i, name[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Let the first emptySymbol be created and
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // ensure only one is ever created.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 assert(sym->is_parsable() || Universe::emptySymbol() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 "should be parsable here.");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return sym;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 bool symbolKlass::allocate_symbols(int names_count, const char** names,
a61af66fc99e Initial load
duke
parents:
diff changeset
52 int* lengths, symbolOop* sym_oops, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (UseConcMarkSweepGC || UseParallelGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Concurrent GC needs to mark all the allocated symbol oops after
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // the remark phase which isn't done below (except the first symbol oop).
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // So return false which will let the symbols be allocated one by one.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // The parallel collector uses an object start array to find the
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // start of objects on a dirty card. The object start array is not
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // updated for the start of each symbol so is not precise. During
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // object array verification this causes a verification failure.
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // In a product build this causes extra searching for the start of
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // a symbol. As with the concurrent collector a return of false will
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // cause each symbol to be allocated separately and in the case
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // of the parallel collector will cause the object
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // start array to be updated.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(names_count > 0, "can't allocate 0 symbols");
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 int total_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int i, sizes[SymbolTable::symbol_alloc_batch_size];
a61af66fc99e Initial load
duke
parents:
diff changeset
73 for (i=0; i<names_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int len = lengths[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (len > symbolOopDesc::max_length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int sz = symbolOopDesc::object_size(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 sizes[i] = sz * HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 total_size += sz;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 symbolKlassHandle h_k(THREAD, as_klassOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 HeapWord* base = Universe::heap()->permanent_mem_allocate(total_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (base == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // CAN'T take any safepoint during the initialization of the symbol oops !
a61af66fc99e Initial load
duke
parents:
diff changeset
89 No_Safepoint_Verifier nosafepoint;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 klassOop sk = h_k();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 int pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 for (i=0; i<names_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 symbolOop s = (symbolOop) (((char*)base) + pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 s->set_mark(markOopDesc::prototype());
a61af66fc99e Initial load
duke
parents:
diff changeset
96 s->set_klass(sk);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 s->set_utf8_length(lengths[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 const char* name = names[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
99 for (int j=0; j<lengths[i]; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 s->byte_at_put(j, name[j]);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 assert(s->is_parsable(), "should be parsable here.");
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 sym_oops[i] = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 pos += sizes[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 klassOop symbolKlass::create_klass(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 symbolKlass o;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
114 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Make sure size calculation is right
a61af66fc99e Initial load
duke
parents:
diff changeset
116 assert(k()->size() == align_object_size(header_size()), "wrong size for object");
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return k();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int symbolKlass::oop_size(oop obj) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 assert(obj->is_symbol(),"must be a symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
123 symbolOop s = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int size = s->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 bool symbolKlass::oop_is_parsable(oop obj) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(obj->is_symbol(),"must be a symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 symbolOop s = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return s->object_is_parsable();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 void symbolKlass::oop_follow_contents(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 assert (obj->is_symbol(), "object must be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Performance tweak: We skip iterating over the klass pointer since we
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // know that Universe::symbolKlassObj never moves.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Note: do not follow next link here (see SymbolTable::follow_contents)
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #ifndef SERIALGC
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void symbolKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 assert (obj->is_symbol(), "object must be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Performance tweak: We skip iterating over the klass pointer since we
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // know that Universe::symbolKlassObj never moves.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Note: do not follow next link here (see SymbolTable::follow_contents)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 #endif // SERIALGC
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int symbolKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 assert(obj->is_symbol(), "object must be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 symbolOop s = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Get size before changing pointers.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Don't call size() or oop_size() since that is a virtual call.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 int size = s->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Performance tweak: We skip iterating over the klass pointer since we
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // know that Universe::symbolKlassObj never moves.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int symbolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert(obj->is_symbol(), "object must be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 symbolOop s = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Get size before changing pointers.
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Don't call size() or oop_size() since that is a virtual call.
a61af66fc99e Initial load
duke
parents:
diff changeset
167 int size = s->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Performance tweak: We skip iterating over the klass pointer since we
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // know that Universe::symbolKlassObj never moves.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 int symbolKlass::oop_adjust_pointers(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 assert(obj->is_symbol(), "should be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 symbolOop s = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Get size before changing pointers.
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Don't call size() or oop_size() since that is a virtual call.
a61af66fc99e Initial load
duke
parents:
diff changeset
179 int size = s->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Performance tweak: We skip iterating over the klass pointer since we
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // know that Universe::symbolKlassObj never moves.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 #ifndef SERIALGC
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void symbolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 assert(obj->is_symbol(), "should be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 void symbolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert(obj->is_symbol(), "should be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 assert(obj->is_symbol(), "should be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return symbolOop(obj)->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 HeapWord* beg_addr, HeapWord* end_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(obj->is_symbol(), "should be symbol");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return symbolOop(obj)->object_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 #endif // SERIALGC
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 void symbolKlass::oop_print_on(oop obj, outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 st->print("Symbol: '");
222
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
212 symbolOop(obj)->print_symbol_on(st);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
213 st->print("'");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void symbolKlass::oop_print_value_on(oop obj, outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 symbolOop sym = symbolOop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 st->print("'");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 for (int i = 0; i < sym->utf8_length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 st->print("%c", sym->byte_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 st->print("'");
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 #endif //PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 const char* symbolKlass::internal_name() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 return "{symbol}";
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }