Mercurial > hg > graal-compiler
annotate src/share/vm/oops/constantPoolOop.hpp @ 1649:a528509c992b
6968336: VM crash guarantee(!nm->is_zombie()) failed: cannot lock a zombie method
Reviewed-by: twisti
author | never |
---|---|
date | Thu, 15 Jul 2010 08:54:48 -0700 |
parents | 136b78722a08 |
children | 083fde3b838e |
rev | line source |
---|---|
0 | 1 /* |
1579 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
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:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // A constantPool is an array containing class constants as described in the | |
26 // class file. | |
27 // | |
28 // Most of the constant pool entries are written during class parsing, which | |
29 // is safe. For klass and string types, the constant pool entry is | |
30 // modified when the entry is resolved. If a klass or string constant pool | |
31 // entry is read without a lock, only the resolved state guarantees that | |
32 // the entry in the constant pool is a klass or String object and | |
33 // not a symbolOop. | |
34 | |
35 class SymbolHashMap; | |
36 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
37 class constantPoolOopDesc : public oopDesc { |
0 | 38 friend class VMStructs; |
39 friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast | |
40 private: | |
41 typeArrayOop _tags; // the tag array describing the constant pool's contents | |
42 constantPoolCacheOop _cache; // the cache holding interpreter runtime information | |
43 klassOop _pool_holder; // the corresponding class | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
44 int _flags; // a few header bits to describe contents for GC |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
45 int _length; // number of elements in the array |
518
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
431
diff
changeset
|
46 volatile bool _is_conc_safe; // if true, safe for concurrent |
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
431
diff
changeset
|
47 // GC processing |
0 | 48 // only set to non-zero if constant pool is merged by RedefineClasses |
49 int _orig_length; | |
50 | |
51 void set_tags(typeArrayOop tags) { oop_store_without_check((oop*)&_tags, tags); } | |
52 void tag_at_put(int which, jbyte t) { tags()->byte_at_put(which, t); } | |
53 void release_tag_at_put(int which, jbyte t) { tags()->release_byte_at_put(which, t); } | |
54 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
55 enum FlagBit { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
56 FB_has_invokedynamic = 1, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
57 FB_has_pseudo_string = 2 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
58 }; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
59 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
60 int flags() const { return _flags; } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
61 void set_flags(int f) { _flags = f; } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
62 bool flag_at(FlagBit fb) const { return (_flags & (1 << (int)fb)) != 0; } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
63 void set_flag_at(FlagBit fb); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
64 // no clear_flag_at function; they only increase |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
65 |
0 | 66 private: |
67 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(constantPoolOopDesc)); } | |
68 oop* tags_addr() { return (oop*)&_tags; } | |
69 oop* cache_addr() { return (oop*)&_cache; } | |
70 | |
71 oop* obj_at_addr(int which) const { | |
72 assert(is_within_bounds(which), "index out of bounds"); | |
73 return (oop*) &base()[which]; | |
74 } | |
75 | |
76 jint* int_at_addr(int which) const { | |
77 assert(is_within_bounds(which), "index out of bounds"); | |
78 return (jint*) &base()[which]; | |
79 } | |
80 | |
81 jlong* long_at_addr(int which) const { | |
82 assert(is_within_bounds(which), "index out of bounds"); | |
83 return (jlong*) &base()[which]; | |
84 } | |
85 | |
86 jfloat* float_at_addr(int which) const { | |
87 assert(is_within_bounds(which), "index out of bounds"); | |
88 return (jfloat*) &base()[which]; | |
89 } | |
90 | |
91 jdouble* double_at_addr(int which) const { | |
92 assert(is_within_bounds(which), "index out of bounds"); | |
93 return (jdouble*) &base()[which]; | |
94 } | |
95 | |
96 public: | |
97 typeArrayOop tags() const { return _tags; } | |
98 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
99 bool has_pseudo_string() const { return flag_at(FB_has_pseudo_string); } |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
100 bool has_invokedynamic() const { return flag_at(FB_has_invokedynamic); } |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
101 void set_pseudo_string() { set_flag_at(FB_has_pseudo_string); } |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
102 void set_invokedynamic() { set_flag_at(FB_has_invokedynamic); } |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
103 |
0 | 104 // Klass holding pool |
105 klassOop pool_holder() const { return _pool_holder; } | |
106 void set_pool_holder(klassOop k) { oop_store_without_check((oop*)&_pool_holder, (oop) k); } | |
107 oop* pool_holder_addr() { return (oop*)&_pool_holder; } | |
108 | |
109 // Interpreter runtime support | |
110 constantPoolCacheOop cache() const { return _cache; } | |
111 void set_cache(constantPoolCacheOop cache){ oop_store((oop*)&_cache, cache); } | |
112 | |
113 // Assembly code support | |
114 static int tags_offset_in_bytes() { return offset_of(constantPoolOopDesc, _tags); } | |
115 static int cache_offset_in_bytes() { return offset_of(constantPoolOopDesc, _cache); } | |
116 static int pool_holder_offset_in_bytes() { return offset_of(constantPoolOopDesc, _pool_holder); } | |
117 | |
118 // Storing constants | |
119 | |
120 void klass_at_put(int which, klassOop k) { | |
121 oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); | |
122 // The interpreter assumes when the tag is stored, the klass is resolved | |
123 // and the klassOop is a klass rather than a symbolOop, so we need | |
124 // hardware store ordering here. | |
125 release_tag_at_put(which, JVM_CONSTANT_Class); | |
126 if (UseConcMarkSweepGC) { | |
127 // In case the earlier card-mark was consumed by a concurrent | |
128 // marking thread before the tag was updated, redirty the card. | |
129 oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); | |
130 } | |
131 } | |
132 | |
133 // For temporary use while constructing constant pool | |
134 void klass_index_at_put(int which, int name_index) { | |
135 tag_at_put(which, JVM_CONSTANT_ClassIndex); | |
136 *int_at_addr(which) = name_index; | |
137 } | |
138 | |
139 // Temporary until actual use | |
140 void unresolved_klass_at_put(int which, symbolOop s) { | |
141 // Overwrite the old index with a GC friendly value so | |
142 // that if GC looks during the transition it won't try | |
143 // to treat a small integer as oop. | |
144 *obj_at_addr(which) = NULL; | |
145 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); | |
146 oop_store_without_check(obj_at_addr(which), oop(s)); | |
147 } | |
148 | |
1602 | 149 void method_handle_index_at_put(int which, int ref_kind, int ref_index) { |
150 tag_at_put(which, JVM_CONSTANT_MethodHandle); | |
151 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind; | |
152 } | |
153 | |
154 void method_type_index_at_put(int which, int ref_index) { | |
155 tag_at_put(which, JVM_CONSTANT_MethodType); | |
156 *int_at_addr(which) = ref_index; | |
157 } | |
158 | |
0 | 159 // Temporary until actual use |
160 void unresolved_string_at_put(int which, symbolOop s) { | |
161 *obj_at_addr(which) = NULL; | |
162 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString); | |
163 oop_store_without_check(obj_at_addr(which), oop(s)); | |
164 } | |
165 | |
166 void int_at_put(int which, jint i) { | |
167 tag_at_put(which, JVM_CONSTANT_Integer); | |
168 *int_at_addr(which) = i; | |
169 } | |
170 | |
171 void long_at_put(int which, jlong l) { | |
172 tag_at_put(which, JVM_CONSTANT_Long); | |
173 // *long_at_addr(which) = l; | |
174 Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l)); | |
175 } | |
176 | |
177 void float_at_put(int which, jfloat f) { | |
178 tag_at_put(which, JVM_CONSTANT_Float); | |
179 *float_at_addr(which) = f; | |
180 } | |
181 | |
182 void double_at_put(int which, jdouble d) { | |
183 tag_at_put(which, JVM_CONSTANT_Double); | |
184 // *double_at_addr(which) = d; | |
185 // u8 temp = *(u8*) &d; | |
186 Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d)); | |
187 } | |
188 | |
189 void symbol_at_put(int which, symbolOop s) { | |
190 tag_at_put(which, JVM_CONSTANT_Utf8); | |
191 oop_store_without_check(obj_at_addr(which), oop(s)); | |
192 } | |
193 | |
194 void string_at_put(int which, oop str) { | |
195 oop_store((volatile oop*)obj_at_addr(which), str); | |
196 release_tag_at_put(which, JVM_CONSTANT_String); | |
197 if (UseConcMarkSweepGC) { | |
198 // In case the earlier card-mark was consumed by a concurrent | |
199 // marking thread before the tag was updated, redirty the card. | |
200 oop_store_without_check((volatile oop *)obj_at_addr(which), str); | |
201 } | |
202 } | |
203 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
204 void object_at_put(int which, oop str) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
205 oop_store((volatile oop*) obj_at_addr(which), str); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
206 release_tag_at_put(which, JVM_CONSTANT_Object); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
207 if (UseConcMarkSweepGC) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
208 // In case the earlier card-mark was consumed by a concurrent |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
209 // marking thread before the tag was updated, redirty the card. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
210 oop_store_without_check((volatile oop*) obj_at_addr(which), str); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
211 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
212 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
213 |
0 | 214 // For temporary use while constructing constant pool |
215 void string_index_at_put(int which, int string_index) { | |
216 tag_at_put(which, JVM_CONSTANT_StringIndex); | |
217 *int_at_addr(which) = string_index; | |
218 } | |
219 | |
220 void field_at_put(int which, int class_index, int name_and_type_index) { | |
221 tag_at_put(which, JVM_CONSTANT_Fieldref); | |
222 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; | |
223 } | |
224 | |
225 void method_at_put(int which, int class_index, int name_and_type_index) { | |
226 tag_at_put(which, JVM_CONSTANT_Methodref); | |
227 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; | |
228 } | |
229 | |
230 void interface_method_at_put(int which, int class_index, int name_and_type_index) { | |
231 tag_at_put(which, JVM_CONSTANT_InterfaceMethodref); | |
232 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice | |
233 } | |
234 | |
235 void name_and_type_at_put(int which, int name_index, int signature_index) { | |
236 tag_at_put(which, JVM_CONSTANT_NameAndType); | |
237 *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice | |
238 } | |
239 | |
240 // Tag query | |
241 | |
242 constantTag tag_at(int which) const { return (constantTag)tags()->byte_at_acquire(which); } | |
243 | |
244 // Whether the entry is a pointer that must be GC'd. | |
245 bool is_pointer_entry(int which) { | |
246 constantTag tag = tag_at(which); | |
247 return tag.is_klass() || | |
248 tag.is_unresolved_klass() || | |
249 tag.is_symbol() || | |
250 tag.is_unresolved_string() || | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
251 tag.is_string() || |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
252 tag.is_object(); |
0 | 253 } |
254 | |
255 // Fetching constants | |
256 | |
257 klassOop klass_at(int which, TRAPS) { | |
258 constantPoolHandle h_this(THREAD, this); | |
259 return klass_at_impl(h_this, which, CHECK_NULL); | |
260 } | |
261 | |
262 symbolOop klass_name_at(int which); // Returns the name, w/o resolving. | |
263 | |
264 klassOop resolved_klass_at(int which) { // Used by Compiler | |
265 guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); | |
266 // Must do an acquire here in case another thread resolved the klass | |
267 // behind our back, lest we later load stale values thru the oop. | |
268 return klassOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); | |
269 } | |
270 | |
271 // This method should only be used with a cpool lock or during parsing or gc | |
272 symbolOop unresolved_klass_at(int which) { // Temporary until actual use | |
273 symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); | |
274 // check that the klass is still unresolved. | |
275 assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool"); | |
276 return s; | |
277 } | |
278 | |
279 // RedefineClasses() API support: | |
280 symbolOop klass_at_noresolve(int which) { return klass_name_at(which); } | |
281 | |
282 jint int_at(int which) { | |
283 assert(tag_at(which).is_int(), "Corrupted constant pool"); | |
284 return *int_at_addr(which); | |
285 } | |
286 | |
287 jlong long_at(int which) { | |
288 assert(tag_at(which).is_long(), "Corrupted constant pool"); | |
289 // return *long_at_addr(which); | |
290 u8 tmp = Bytes::get_native_u8((address)&base()[which]); | |
291 return *((jlong*)&tmp); | |
292 } | |
293 | |
294 jfloat float_at(int which) { | |
295 assert(tag_at(which).is_float(), "Corrupted constant pool"); | |
296 return *float_at_addr(which); | |
297 } | |
298 | |
299 jdouble double_at(int which) { | |
300 assert(tag_at(which).is_double(), "Corrupted constant pool"); | |
301 u8 tmp = Bytes::get_native_u8((address)&base()[which]); | |
302 return *((jdouble*)&tmp); | |
303 } | |
304 | |
305 symbolOop symbol_at(int which) { | |
306 assert(tag_at(which).is_utf8(), "Corrupted constant pool"); | |
307 return symbolOop(*obj_at_addr(which)); | |
308 } | |
309 | |
310 oop string_at(int which, TRAPS) { | |
311 constantPoolHandle h_this(THREAD, this); | |
312 return string_at_impl(h_this, which, CHECK_NULL); | |
313 } | |
314 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
315 oop object_at(int which) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
316 assert(tag_at(which).is_object(), "Corrupted constant pool"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
317 return *obj_at_addr(which); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
318 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
319 |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
320 // A "pseudo-string" is an non-string oop that has found is way into |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
321 // a String entry. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
322 // Under AnonymousClasses this can happen if the user patches a live |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
323 // object into a CONSTANT_String entry of an anonymous class. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
324 // Method oops internally created for method handles may also |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
325 // use pseudo-strings to link themselves to related metaobjects. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
326 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
327 bool is_pseudo_string_at(int which); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
328 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
329 oop pseudo_string_at(int which) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
330 assert(tag_at(which).is_string(), "Corrupted constant pool"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
331 return *obj_at_addr(which); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
332 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
333 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
334 void pseudo_string_at_put(int which, oop x) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
335 assert(AnonymousClasses, ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
336 set_pseudo_string(); // mark header |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
337 assert(tag_at(which).is_string() || tag_at(which).is_unresolved_string(), "Corrupted constant pool"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
338 string_at_put(which, x); // this works just fine |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
339 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
340 |
0 | 341 // only called when we are sure a string entry is already resolved (via an |
342 // earlier string_at call. | |
343 oop resolved_string_at(int which) { | |
344 assert(tag_at(which).is_string(), "Corrupted constant pool"); | |
345 // Must do an acquire here in case another thread resolved the klass | |
346 // behind our back, lest we later load stale values thru the oop. | |
347 return (oop)OrderAccess::load_ptr_acquire(obj_at_addr(which)); | |
348 } | |
349 | |
350 // This method should only be used with a cpool lock or during parsing or gc | |
351 symbolOop unresolved_string_at(int which) { // Temporary until actual use | |
352 symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); | |
353 // check that the string is still unresolved. | |
354 assert(tag_at(which).is_unresolved_string(), "Corrupted constant pool"); | |
355 return s; | |
356 } | |
357 | |
358 // Returns an UTF8 for a CONSTANT_String entry at a given index. | |
359 // UTF8 char* representation was chosen to avoid conversion of | |
360 // java_lang_Strings at resolved entries into symbolOops | |
361 // or vice versa. | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
362 // Caller is responsible for checking for pseudo-strings. |
0 | 363 char* string_at_noresolve(int which); |
364 | |
365 jint name_and_type_at(int which) { | |
366 assert(tag_at(which).is_name_and_type(), "Corrupted constant pool"); | |
367 return *int_at_addr(which); | |
368 } | |
369 | |
1602 | 370 int method_handle_ref_kind_at(int which) { |
371 assert(tag_at(which).is_method_handle(), "Corrupted constant pool"); | |
372 return extract_low_short_from_int(*int_at_addr(which)); // mask out unwanted ref_index bits | |
373 } | |
374 int method_handle_index_at(int which) { | |
375 assert(tag_at(which).is_method_handle(), "Corrupted constant pool"); | |
376 return extract_high_short_from_int(*int_at_addr(which)); // shift out unwanted ref_kind bits | |
377 } | |
378 int method_type_index_at(int which) { | |
379 assert(tag_at(which).is_method_type(), "Corrupted constant pool"); | |
380 return *int_at_addr(which); | |
381 } | |
382 // Derived queries: | |
383 symbolOop method_handle_name_ref_at(int which) { | |
384 int member = method_handle_index_at(which); | |
385 return impl_name_ref_at(member, true); | |
386 } | |
387 symbolOop method_handle_signature_ref_at(int which) { | |
388 int member = method_handle_index_at(which); | |
389 return impl_signature_ref_at(member, true); | |
390 } | |
391 int method_handle_klass_index_at(int which) { | |
392 int member = method_handle_index_at(which); | |
393 return impl_klass_ref_index_at(member, true); | |
394 } | |
395 symbolOop method_type_signature_at(int which) { | |
396 int sym = method_type_index_at(which); | |
397 return symbol_at(sym); | |
398 } | |
399 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
400 // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve, |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
401 // name_and_type_ref_index_at) all expect to be passed indices obtained |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
402 // directly from the bytecode, and extracted according to java byte order. |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
403 // If the indices are meant to refer to fields or methods, they are |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
404 // actually potentially byte-swapped, rewritten constant pool cache indices. |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
405 // The routine remap_instruction_operand_from_cache manages the adjustment |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
406 // of these values back to constant pool indices. |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
407 |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
408 // There are also "uncached" versions which do not adjust the operand index; see below. |
0 | 409 |
410 // Lookup for entries consisting of (klass_index, name_and_type index) | |
411 klassOop klass_ref_at(int which, TRAPS); | |
412 symbolOop klass_ref_at_noresolve(int which); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
413 symbolOop name_ref_at(int which) { return impl_name_ref_at(which, false); } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
414 symbolOop signature_ref_at(int which) { return impl_signature_ref_at(which, false); } |
0 | 415 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
416 int klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, false); } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
417 int name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, false); } |
0 | 418 |
419 // Lookup for entries consisting of (name_index, signature_index) | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
420 int name_ref_index_at(int which_nt); // == low-order jshort of name_and_type_at(which_nt) |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
421 int signature_ref_index_at(int which_nt); // == high-order jshort of name_and_type_at(which_nt) |
0 | 422 |
423 BasicType basic_type_for_signature_at(int which); | |
424 | |
425 // Resolve string constants (to prevent allocation during compilation) | |
426 void resolve_string_constants(TRAPS) { | |
427 constantPoolHandle h_this(THREAD, this); | |
428 resolve_string_constants_impl(h_this, CHECK); | |
429 } | |
430 | |
1602 | 431 // Resolve late bound constants. |
432 oop resolve_constant_at(int index, TRAPS) { | |
433 constantPoolHandle h_this(THREAD, this); | |
434 return resolve_constant_at_impl(h_this, index, -1, THREAD); | |
435 } | |
436 | |
437 oop resolve_cached_constant_at(int cache_index, TRAPS) { | |
438 constantPoolHandle h_this(THREAD, this); | |
439 return resolve_constant_at_impl(h_this, -1, cache_index, THREAD); | |
440 } | |
441 | |
0 | 442 // Klass name matches name at offset |
443 bool klass_name_at_matches(instanceKlassHandle k, int which); | |
444 | |
445 // Sizing | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
446 int length() const { return _length; } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
447 void set_length(int length) { _length = length; } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
448 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
449 // Tells whether index is within bounds. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
450 bool is_within_bounds(int index) const { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
451 return 0 <= index && index < length(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
452 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
453 |
0 | 454 static int header_size() { return sizeof(constantPoolOopDesc)/HeapWordSize; } |
455 static int object_size(int length) { return align_object_size(header_size() + length); } | |
456 int object_size() { return object_size(length()); } | |
457 | |
518
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
431
diff
changeset
|
458 bool is_conc_safe() { return _is_conc_safe; } |
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
431
diff
changeset
|
459 void set_is_conc_safe(bool v) { _is_conc_safe = v; } |
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
431
diff
changeset
|
460 |
0 | 461 friend class constantPoolKlass; |
462 friend class ClassFileParser; | |
463 friend class SystemDictionary; | |
464 | |
465 // Used by compiler to prevent classloading. | |
466 static klassOop klass_at_if_loaded (constantPoolHandle this_oop, int which); | |
467 static klassOop klass_ref_at_if_loaded (constantPoolHandle this_oop, int which); | |
468 // Same as above - but does LinkResolving. | |
469 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); | |
470 | |
471 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the | |
472 // future by other Java code. These take constant pool indices rather than possibly-byte-swapped | |
473 // constant pool cache indices as do the peer methods above. | |
1602 | 474 symbolOop uncached_klass_ref_at_noresolve(int which); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
475 symbolOop uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
476 symbolOop uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
477 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
478 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); } |
0 | 479 |
480 // Sharing | |
481 int pre_resolve_shared_klasses(TRAPS); | |
482 void shared_symbols_iterate(OopClosure* closure0); | |
483 void shared_tags_iterate(OopClosure* closure0); | |
484 void shared_strings_iterate(OopClosure* closure0); | |
485 | |
486 // Debugging | |
487 const char* printable_name_at(int which) PRODUCT_RETURN0; | |
488 | |
1565 | 489 #ifdef ASSERT |
490 enum { CPCACHE_INDEX_TAG = 0x10000 }; // helps keep CP cache indices distinct from CP indices | |
1602 | 491 #else |
492 enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op | |
1565 | 493 #endif //ASSERT |
494 | |
0 | 495 private: |
496 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
497 symbolOop impl_name_ref_at(int which, bool uncached); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
498 symbolOop impl_signature_ref_at(int which, bool uncached); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
499 int impl_klass_ref_index_at(int which, bool uncached); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
500 int impl_name_and_type_ref_index_at(int which, bool uncached); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
501 |
1565 | 502 int remap_instruction_operand_from_cache(int operand); // operand must be biased by CPCACHE_INDEX_TAG |
0 | 503 |
504 // Used while constructing constant pool (only by ClassFileParser) | |
505 jint klass_index_at(int which) { | |
506 assert(tag_at(which).is_klass_index(), "Corrupted constant pool"); | |
507 return *int_at_addr(which); | |
508 } | |
509 | |
510 jint string_index_at(int which) { | |
511 assert(tag_at(which).is_string_index(), "Corrupted constant pool"); | |
512 return *int_at_addr(which); | |
513 } | |
514 | |
515 // Performs the LinkResolver checks | |
516 static void verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle klass, TRAPS); | |
517 | |
518 // Implementation of methods that needs an exposed 'this' pointer, in order to | |
519 // handle GC while executing the method | |
520 static klassOop klass_at_impl(constantPoolHandle this_oop, int which, TRAPS); | |
521 static oop string_at_impl(constantPoolHandle this_oop, int which, TRAPS); | |
522 | |
523 // Resolve string constants (to prevent allocation during compilation) | |
524 static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS); | |
525 | |
1602 | 526 static oop resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS); |
527 | |
0 | 528 public: |
529 // Merging constantPoolOop support: | |
530 bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS); | |
531 void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i, | |
532 TRAPS); | |
533 void copy_entry_to(int from_i, constantPoolHandle to_cp, int to_i, TRAPS); | |
534 int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS); | |
535 int orig_length() const { return _orig_length; } | |
536 void set_orig_length(int orig_length) { _orig_length = orig_length; } | |
537 | |
538 | |
539 // JVMTI accesss - GetConstantPool, RetransformClasses, ... | |
540 friend class JvmtiConstantPoolReconstituter; | |
541 | |
542 private: | |
543 jint cpool_entry_size(jint idx); | |
544 jint hash_entries_to(SymbolHashMap *symmap, SymbolHashMap *classmap); | |
545 | |
546 // Copy cpool bytes into byte array. | |
547 // Returns: | |
548 // int > 0, count of the raw cpool bytes that have been copied | |
549 // 0, OutOfMemory error | |
550 // -1, Internal error | |
551 int copy_cpool_bytes(int cpool_size, | |
552 SymbolHashMap* tbl, | |
553 unsigned char *bytes); | |
554 }; | |
555 | |
556 class SymbolHashMapEntry : public CHeapObj { | |
557 private: | |
558 unsigned int _hash; // 32-bit hash for item | |
559 SymbolHashMapEntry* _next; // Next element in the linked list for this bucket | |
560 symbolOop _symbol; // 1-st part of the mapping: symbol => value | |
561 u2 _value; // 2-nd part of the mapping: symbol => value | |
562 | |
563 public: | |
564 unsigned int hash() const { return _hash; } | |
565 void set_hash(unsigned int hash) { _hash = hash; } | |
566 | |
567 SymbolHashMapEntry* next() const { return _next; } | |
568 void set_next(SymbolHashMapEntry* next) { _next = next; } | |
569 | |
570 symbolOop symbol() const { return _symbol; } | |
571 void set_symbol(symbolOop sym) { _symbol = sym; } | |
572 | |
573 u2 value() const { return _value; } | |
574 void set_value(u2 value) { _value = value; } | |
575 | |
576 SymbolHashMapEntry(unsigned int hash, symbolOop symbol, u2 value) | |
577 : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {} | |
578 | |
579 }; // End SymbolHashMapEntry class | |
580 | |
581 | |
582 class SymbolHashMapBucket : public CHeapObj { | |
583 | |
584 private: | |
585 SymbolHashMapEntry* _entry; | |
586 | |
587 public: | |
588 SymbolHashMapEntry* entry() const { return _entry; } | |
589 void set_entry(SymbolHashMapEntry* entry) { _entry = entry; } | |
590 void clear() { _entry = NULL; } | |
591 | |
592 }; // End SymbolHashMapBucket class | |
593 | |
594 | |
595 class SymbolHashMap: public CHeapObj { | |
596 | |
597 private: | |
598 // Default number of entries in the table | |
599 enum SymbolHashMap_Constants { | |
600 _Def_HashMap_Size = 256 | |
601 }; | |
602 | |
603 int _table_size; | |
604 SymbolHashMapBucket* _buckets; | |
605 | |
606 void initialize_table(int table_size) { | |
607 _table_size = table_size; | |
608 _buckets = NEW_C_HEAP_ARRAY(SymbolHashMapBucket, table_size); | |
609 for (int index = 0; index < table_size; index++) { | |
610 _buckets[index].clear(); | |
611 } | |
612 } | |
613 | |
614 public: | |
615 | |
616 int table_size() const { return _table_size; } | |
617 | |
618 SymbolHashMap() { initialize_table(_Def_HashMap_Size); } | |
619 SymbolHashMap(int table_size) { initialize_table(table_size); } | |
620 | |
621 // hash P(31) from Kernighan & Ritchie | |
622 static unsigned int compute_hash(const char* str, int len) { | |
623 unsigned int hash = 0; | |
624 while (len-- > 0) { | |
625 hash = 31*hash + (unsigned) *str; | |
626 str++; | |
627 } | |
628 return hash; | |
629 } | |
630 | |
631 SymbolHashMapEntry* bucket(int i) { | |
632 return _buckets[i].entry(); | |
633 } | |
634 | |
635 void add_entry(symbolOop sym, u2 value); | |
636 SymbolHashMapEntry* find_entry(symbolOop sym); | |
637 | |
638 u2 symbol_to_value(symbolOop sym) { | |
639 SymbolHashMapEntry *entry = find_entry(sym); | |
640 return (entry == NULL) ? 0 : entry->value(); | |
641 } | |
642 | |
643 ~SymbolHashMap() { | |
644 SymbolHashMapEntry* next; | |
645 for (int i = 0; i < _table_size; i++) { | |
646 for (SymbolHashMapEntry* cur = bucket(i); cur != NULL; cur = next) { | |
647 next = cur->next(); | |
648 delete(cur); | |
649 } | |
650 } | |
651 delete _buckets; | |
652 } | |
653 }; // End SymbolHashMap class |