Mercurial > hg > graal-compiler
annotate src/share/vm/oops/constantPoolOop.cpp @ 1711:a6bff45449bc
6973570: OrderAccess::storestore() scales poorly on multi-socket x64 and sparc: cache-line ping-ponging
Summary: volatile store to static variable removed in favour of a volatile store to stack to avoid excessive cache coherency traffic; verified that the volatile store is not elided by any of our current compilers.
Reviewed-by: dholmes, dice, jcoomes, kvn
author | ysr |
---|---|
date | Tue, 10 Aug 2010 14:53:35 -0700 |
parents | 083fde3b838e |
children | d257356e35f0 |
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:
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 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_constantPoolOop.cpp.incl" | |
27 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
28 void constantPoolOopDesc::set_flag_at(FlagBit fb) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
29 const int MAX_STATE_CHANGES = 2; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
30 for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
31 int oflags = _flags; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
32 int nflags = oflags | (1 << (int)fb); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
33 if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
34 return; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
35 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
36 assert(false, "failed to cmpxchg flags"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
37 _flags |= (1 << (int)fb); // better than nothing |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
38 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
39 |
0 | 40 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
41 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop. | |
42 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and | |
43 // tag is not updated atomicly. | |
44 oop entry = *(this_oop->obj_at_addr(which)); | |
45 if (entry->is_klass()) { | |
46 // Already resolved - return entry. | |
47 return (klassOop)entry; | |
48 } | |
49 | |
50 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object | |
51 // already has updated the object | |
52 assert(THREAD->is_Java_thread(), "must be a Java thread"); | |
53 bool do_resolve = false; | |
54 bool in_error = false; | |
55 | |
56 symbolHandle name; | |
57 Handle loader; | |
58 { ObjectLocker ol(this_oop, THREAD); | |
59 | |
60 if (this_oop->tag_at(which).is_unresolved_klass()) { | |
61 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) { | |
62 in_error = true; | |
63 } else { | |
64 do_resolve = true; | |
65 name = symbolHandle(THREAD, this_oop->unresolved_klass_at(which)); | |
66 loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader()); | |
67 } | |
68 } | |
69 } // unlocking constantPool | |
70 | |
71 | |
72 // The original attempt to resolve this constant pool entry failed so find the | |
73 // original error and throw it again (JVMS 5.4.3). | |
74 if (in_error) { | |
75 symbolOop error = SystemDictionary::find_resolution_error(this_oop, which); | |
76 guarantee(error != (symbolOop)NULL, "tag mismatch with resolution error table"); | |
77 ResourceMark rm; | |
78 // exception text will be the class name | |
79 const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); | |
80 THROW_MSG_0(error, className); | |
81 } | |
82 | |
83 if (do_resolve) { | |
84 // this_oop must be unlocked during resolve_or_fail | |
85 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); | |
86 Handle h_prot (THREAD, protection_domain); | |
87 klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD); | |
88 KlassHandle k; | |
89 if (!HAS_PENDING_EXCEPTION) { | |
90 k = KlassHandle(THREAD, k_oop); | |
91 // Do access check for klasses | |
92 verify_constant_pool_resolve(this_oop, k, THREAD); | |
93 } | |
94 | |
95 // Failed to resolve class. We must record the errors so that subsequent attempts | |
96 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3). | |
97 if (HAS_PENDING_EXCEPTION) { | |
98 ResourceMark rm; | |
99 symbolHandle error(PENDING_EXCEPTION->klass()->klass_part()->name()); | |
100 | |
101 bool throw_orig_error = false; | |
102 { | |
103 ObjectLocker ol (this_oop, THREAD); | |
104 | |
105 // some other thread has beaten us and has resolved the class. | |
106 if (this_oop->tag_at(which).is_klass()) { | |
107 CLEAR_PENDING_EXCEPTION; | |
108 entry = this_oop->resolved_klass_at(which); | |
109 return (klassOop)entry; | |
110 } | |
111 | |
112 if (!PENDING_EXCEPTION-> | |
1142 | 113 is_a(SystemDictionary::LinkageError_klass())) { |
0 | 114 // Just throw the exception and don't prevent these classes from |
115 // being loaded due to virtual machine errors like StackOverflow | |
116 // and OutOfMemoryError, etc, or if the thread was hit by stop() | |
117 // Needs clarification to section 5.4.3 of the VM spec (see 6308271) | |
118 } | |
119 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) { | |
120 SystemDictionary::add_resolution_error(this_oop, which, error); | |
121 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError); | |
122 } else { | |
123 // some other thread has put the class in error state. | |
124 error = symbolHandle(SystemDictionary::find_resolution_error(this_oop, which)); | |
125 assert(!error.is_null(), "checking"); | |
126 throw_orig_error = true; | |
127 } | |
128 } // unlocked | |
129 | |
130 if (throw_orig_error) { | |
131 CLEAR_PENDING_EXCEPTION; | |
132 ResourceMark rm; | |
133 const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); | |
134 THROW_MSG_0(error, className); | |
135 } | |
136 | |
137 return 0; | |
138 } | |
139 | |
140 if (TraceClassResolution && !k()->klass_part()->oop_is_array()) { | |
141 // skip resolving the constant pool so that this code get's | |
142 // called the next time some bytecodes refer to this class. | |
143 ResourceMark rm; | |
144 int line_number = -1; | |
145 const char * source_file = NULL; | |
146 if (JavaThread::current()->has_last_Java_frame()) { | |
147 // try to identify the method which called this function. | |
148 vframeStream vfst(JavaThread::current()); | |
149 if (!vfst.at_end()) { | |
150 line_number = vfst.method()->line_number_from_bci(vfst.bci()); | |
151 symbolOop s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name(); | |
152 if (s != NULL) { | |
153 source_file = s->as_C_string(); | |
154 } | |
155 } | |
156 } | |
157 if (k() != this_oop->pool_holder()) { | |
158 // only print something if the classes are different | |
159 if (source_file != NULL) { | |
160 tty->print("RESOLVE %s %s %s:%d\n", | |
161 instanceKlass::cast(this_oop->pool_holder())->external_name(), | |
162 instanceKlass::cast(k())->external_name(), source_file, line_number); | |
163 } else { | |
164 tty->print("RESOLVE %s %s\n", | |
165 instanceKlass::cast(this_oop->pool_holder())->external_name(), | |
166 instanceKlass::cast(k())->external_name()); | |
167 } | |
168 } | |
169 return k(); | |
170 } else { | |
171 ObjectLocker ol (this_oop, THREAD); | |
172 // Only updated constant pool - if it is resolved. | |
173 do_resolve = this_oop->tag_at(which).is_unresolved_klass(); | |
174 if (do_resolve) { | |
175 this_oop->klass_at_put(which, k()); | |
176 } | |
177 } | |
178 } | |
179 | |
180 entry = this_oop->resolved_klass_at(which); | |
181 assert(entry->is_klass(), "must be resolved at this point"); | |
182 return (klassOop)entry; | |
183 } | |
184 | |
185 | |
186 // Does not update constantPoolOop - to avoid any exception throwing. Used | |
187 // by compiler and exception handling. Also used to avoid classloads for | |
188 // instanceof operations. Returns NULL if the class has not been loaded or | |
189 // if the verification of constant pool failed | |
190 klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) { | |
191 oop entry = *this_oop->obj_at_addr(which); | |
192 if (entry->is_klass()) { | |
193 return (klassOop)entry; | |
194 } else { | |
195 assert(entry->is_symbol(), "must be either symbol or klass"); | |
196 Thread *thread = Thread::current(); | |
197 symbolHandle name (thread, (symbolOop)entry); | |
198 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); | |
199 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); | |
200 Handle h_prot (thread, protection_domain); | |
201 Handle h_loader (thread, loader); | |
202 klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread); | |
203 | |
204 if (k != NULL) { | |
205 // Make sure that resolving is legal | |
206 EXCEPTION_MARK; | |
207 KlassHandle klass(THREAD, k); | |
208 // return NULL if verification fails | |
209 verify_constant_pool_resolve(this_oop, klass, THREAD); | |
210 if (HAS_PENDING_EXCEPTION) { | |
211 CLEAR_PENDING_EXCEPTION; | |
212 return NULL; | |
213 } | |
214 return klass(); | |
215 } else { | |
216 return k; | |
217 } | |
218 } | |
219 } | |
220 | |
221 | |
222 klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) { | |
223 return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which)); | |
224 } | |
225 | |
226 | |
227 // This is an interface for the compiler that allows accessing non-resolved entries | |
228 // in the constant pool - but still performs the validations tests. Must be used | |
229 // in a pre-parse of the compiler - to determine what it can do and not do. | |
230 // Note: We cannot update the ConstantPool from the vm_thread. | |
231 klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { | |
232 int which = this_oop->klass_ref_index_at(index); | |
233 oop entry = *this_oop->obj_at_addr(which); | |
234 if (entry->is_klass()) { | |
235 return (klassOop)entry; | |
236 } else { | |
237 assert(entry->is_symbol(), "must be either symbol or klass"); | |
238 symbolHandle name (THREAD, (symbolOop)entry); | |
239 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); | |
240 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); | |
241 Handle h_loader(THREAD, loader); | |
242 Handle h_prot (THREAD, protection_domain); | |
243 KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); | |
244 | |
245 // Do access check for klasses | |
246 if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL); | |
247 return k(); | |
248 } | |
249 } | |
250 | |
251 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
252 symbolOop constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
253 int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); |
0 | 254 return symbol_at(name_index); |
255 } | |
256 | |
257 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
258 symbolOop constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
259 int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); |
0 | 260 return symbol_at(signature_index); |
261 } | |
262 | |
263 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
264 int constantPoolOopDesc::impl_name_and_type_ref_index_at(int which, bool uncached) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
265 int i = which; |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
266 if (!uncached && cache() != NULL) { |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
267 if (constantPoolCacheOopDesc::is_secondary_index(which)) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
268 // Invokedynamic indexes are always processed in native order |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
269 // so there is no question of reading a native u2 in Java order here. |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
270 int pool_index = cache()->main_entry_at(which)->constant_pool_index(); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
271 if (tag_at(pool_index).is_invoke_dynamic()) |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
272 pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
273 assert(tag_at(pool_index).is_name_and_type(), ""); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
274 return pool_index; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
275 } |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
276 // change byte-ordering and go via cache |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
277 i = remap_instruction_operand_from_cache(which); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
278 } else { |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
279 if (tag_at(which).is_name_and_type()) |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
280 // invokedynamic index is a simple name-and-type |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
281 return which; |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
282 } |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
283 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
284 jint ref_index = *int_at_addr(i); |
0 | 285 return extract_high_short_from_int(ref_index); |
286 } | |
287 | |
288 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
289 int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
290 guarantee(!constantPoolCacheOopDesc::is_secondary_index(which), |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
291 "an invokedynamic instruction does not have a klass"); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
292 int i = which; |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
293 if (!uncached && cache() != NULL) { |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
294 // change byte-ordering and go via cache |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
295 i = remap_instruction_operand_from_cache(which); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
296 } |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
297 assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
298 jint ref_index = *int_at_addr(i); |
0 | 299 return extract_low_short_from_int(ref_index); |
300 } | |
301 | |
302 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
303 |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
304 int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) { |
1565 | 305 int cpc_index = operand; |
306 DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG); | |
307 assert((int)(u2)cpc_index == cpc_index, "clean u2"); | |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
308 int member_index = cache()->entry_at(cpc_index)->constant_pool_index(); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
309 return member_index; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
310 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
311 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
312 |
0 | 313 void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) { |
314 if (k->oop_is_instance() || k->oop_is_objArray()) { | |
315 instanceKlassHandle holder (THREAD, this_oop->pool_holder()); | |
316 klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass(); | |
317 KlassHandle element (THREAD, elem_oop); | |
318 | |
319 // The element type could be a typeArray - we only need the access check if it is | |
320 // an reference to another class | |
321 if (element->oop_is_instance()) { | |
322 LinkResolver::check_klass_accessability(holder, element, CHECK); | |
323 } | |
324 } | |
325 } | |
326 | |
327 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
328 int constantPoolOopDesc::name_ref_index_at(int which_nt) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
329 jint ref_index = name_and_type_at(which_nt); |
0 | 330 return extract_low_short_from_int(ref_index); |
331 } | |
332 | |
333 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
334 int constantPoolOopDesc::signature_ref_index_at(int which_nt) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
335 jint ref_index = name_and_type_at(which_nt); |
0 | 336 return extract_high_short_from_int(ref_index); |
337 } | |
338 | |
339 | |
340 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) { | |
341 return klass_at(klass_ref_index_at(which), CHECK_NULL); | |
342 } | |
343 | |
344 | |
345 symbolOop constantPoolOopDesc::klass_name_at(int which) { | |
346 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), | |
347 "Corrupted constant pool"); | |
348 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop. | |
349 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and | |
350 // tag is not updated atomicly. | |
351 oop entry = *(obj_at_addr(which)); | |
352 if (entry->is_klass()) { | |
353 // Already resolved - return entry's name. | |
354 return klassOop(entry)->klass_part()->name(); | |
355 } else { | |
356 assert(entry->is_symbol(), "must be either symbol or klass"); | |
357 return (symbolOop)entry; | |
358 } | |
359 } | |
360 | |
361 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) { | |
362 jint ref_index = klass_ref_index_at(which); | |
363 return klass_at_noresolve(ref_index); | |
364 } | |
365 | |
1602 | 366 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { |
367 jint ref_index = uncached_klass_ref_index_at(which); | |
368 return klass_at_noresolve(ref_index); | |
369 } | |
370 | |
0 | 371 char* constantPoolOopDesc::string_at_noresolve(int which) { |
372 // Test entry type in case string is resolved while in here. | |
373 oop entry = *(obj_at_addr(which)); | |
374 if (entry->is_symbol()) { | |
375 return ((symbolOop)entry)->as_C_string(); | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
376 } else if (java_lang_String::is_instance(entry)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
377 return java_lang_String::as_utf8_string(entry); |
0 | 378 } else { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
379 return (char*)"<pseudo-string>"; |
0 | 380 } |
381 } | |
382 | |
383 | |
384 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) { | |
385 return FieldType::basic_type(symbol_at(which)); | |
386 } | |
387 | |
388 | |
389 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { | |
390 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused | |
391 if (this_oop->tag_at(index).is_unresolved_string()) { | |
392 this_oop->string_at(index, CHECK); | |
393 } | |
394 } | |
395 } | |
396 | |
1602 | 397 oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) { |
398 oop result_oop = NULL; | |
399 if (cache_index >= 0) { | |
400 assert(index < 0, "only one kind of index at a time"); | |
401 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
402 result_oop = cpc_entry->f1(); | |
403 if (result_oop != NULL) { | |
404 return result_oop; // that was easy... | |
405 } | |
406 index = cpc_entry->constant_pool_index(); | |
407 } | |
408 | |
409 int tag_value = this_oop->tag_at(index).value(); | |
410 switch (tag_value) { | |
411 | |
412 case JVM_CONSTANT_UnresolvedClass: | |
413 case JVM_CONSTANT_UnresolvedClassInError: | |
414 case JVM_CONSTANT_Class: | |
415 { | |
416 klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL); | |
417 // ldc wants the java mirror. | |
418 result_oop = resolved->klass_part()->java_mirror(); | |
419 break; | |
420 } | |
421 | |
422 case JVM_CONSTANT_String: | |
423 case JVM_CONSTANT_UnresolvedString: | |
424 if (this_oop->is_pseudo_string_at(index)) { | |
425 result_oop = this_oop->pseudo_string_at(index); | |
426 break; | |
427 } | |
428 result_oop = string_at_impl(this_oop, index, CHECK_NULL); | |
429 break; | |
430 | |
431 case JVM_CONSTANT_Object: | |
432 result_oop = this_oop->object_at(index); | |
433 break; | |
434 | |
435 case JVM_CONSTANT_MethodHandle: | |
436 { | |
437 int ref_kind = this_oop->method_handle_ref_kind_at(index); | |
438 int callee_index = this_oop->method_handle_klass_index_at(index); | |
439 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index)); | |
440 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index)); | |
441 if (PrintMiscellaneous) | |
442 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", | |
443 ref_kind, index, this_oop->method_handle_index_at(index), | |
444 callee_index, name->as_C_string(), signature->as_C_string()); | |
445 KlassHandle callee; | |
446 { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL); | |
447 callee = KlassHandle(THREAD, k); | |
448 } | |
449 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
450 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind, | |
451 callee, name, signature, | |
452 CHECK_NULL); | |
453 result_oop = value(); | |
454 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
455 break; | |
456 } | |
457 | |
458 case JVM_CONSTANT_MethodType: | |
459 { | |
460 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index)); | |
461 if (PrintMiscellaneous) | |
462 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", | |
463 index, this_oop->method_type_index_at(index), | |
464 signature->as_C_string()); | |
465 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
466 bool ignore_is_on_bcp = false; | |
467 Handle value = SystemDictionary::find_method_handle_type(signature, | |
468 klass, | |
469 ignore_is_on_bcp, | |
470 CHECK_NULL); | |
471 result_oop = value(); | |
472 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
473 break; | |
474 } | |
475 | |
476 /* maybe some day | |
477 case JVM_CONSTANT_Integer: | |
478 case JVM_CONSTANT_Float: | |
479 case JVM_CONSTANT_Long: | |
480 case JVM_CONSTANT_Double: | |
481 result_oop = java_lang_boxing_object::create(...); | |
482 break; | |
483 */ | |
484 | |
485 default: | |
486 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d", | |
487 this_oop(), index, cache_index, tag_value) ); | |
488 assert(false, "unexpected constant tag"); | |
489 break; | |
490 } | |
491 | |
492 if (cache_index >= 0) { | |
493 // Cache the oop here also. | |
494 Handle result(THREAD, result_oop); | |
495 result_oop = NULL; // safety | |
496 ObjectLocker ol(this_oop, THREAD); | |
497 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
498 oop result_oop2 = cpc_entry->f1(); | |
499 if (result_oop2 != NULL) { | |
500 // Race condition: May already be filled in while we were trying to lock. | |
501 return result_oop2; | |
502 } | |
503 cpc_entry->set_f1(result()); | |
504 return result(); | |
505 } else { | |
506 return result_oop; | |
507 } | |
508 } | |
509 | |
0 | 510 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
511 oop entry = *(this_oop->obj_at_addr(which)); | |
512 if (entry->is_symbol()) { | |
513 ObjectLocker ol(this_oop, THREAD); | |
514 if (this_oop->tag_at(which).is_unresolved_string()) { | |
515 // Intern string | |
516 symbolOop sym = this_oop->unresolved_string_at(which); | |
517 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL))); | |
518 this_oop->string_at_put(which, entry); | |
519 } else { | |
520 // Another thread beat us and interned string, read string from constant pool | |
521 entry = this_oop->resolved_string_at(which); | |
522 } | |
523 } | |
524 assert(java_lang_String::is_instance(entry), "must be string"); | |
525 return entry; | |
526 } | |
527 | |
528 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
529 bool constantPoolOopDesc::is_pseudo_string_at(int which) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
530 oop entry = *(obj_at_addr(which)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
531 if (entry->is_symbol()) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
532 // Not yet resolved, but it will resolve to a string. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
533 return false; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
534 else if (java_lang_String::is_instance(entry)) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
535 return false; // actually, it might be a non-interned or non-perm string |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
536 else |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
537 // truly pseudo |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
538 return true; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
539 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
540 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
541 |
0 | 542 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k, |
543 int which) { | |
544 // Names are interned, so we can compare symbolOops directly | |
545 symbolOop cp_name = klass_name_at(which); | |
546 return (cp_name == k->name()); | |
547 } | |
548 | |
549 | |
550 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) { | |
551 ResourceMark rm; | |
552 int count = 0; | |
553 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused | |
554 if (tag_at(index).is_unresolved_string()) { | |
555 // Intern string | |
556 symbolOop sym = unresolved_string_at(index); | |
557 oop entry = StringTable::intern(sym, CHECK_(-1)); | |
558 string_at_put(index, entry); | |
559 } | |
560 } | |
561 return count; | |
562 } | |
563 | |
564 | |
565 // Iterate over symbols which are used as class, field, method names and | |
566 // signatures (in preparation for writing to the shared archive). | |
567 | |
568 void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) { | |
569 for (int index = 1; index < length(); index++) { // Index 0 is unused | |
570 switch (tag_at(index).value()) { | |
571 | |
572 case JVM_CONSTANT_UnresolvedClass: | |
573 closure->do_oop(obj_at_addr(index)); | |
574 break; | |
575 | |
576 case JVM_CONSTANT_NameAndType: | |
577 { | |
578 int i = *int_at_addr(index); | |
579 closure->do_oop(obj_at_addr((unsigned)i >> 16)); | |
580 closure->do_oop(obj_at_addr((unsigned)i & 0xffff)); | |
581 } | |
582 break; | |
583 | |
584 case JVM_CONSTANT_Class: | |
585 case JVM_CONSTANT_InterfaceMethodref: | |
586 case JVM_CONSTANT_Fieldref: | |
587 case JVM_CONSTANT_Methodref: | |
588 case JVM_CONSTANT_Integer: | |
589 case JVM_CONSTANT_Float: | |
590 // Do nothing! Not an oop. | |
591 // These constant types do not reference symbols at this point. | |
592 break; | |
593 | |
594 case JVM_CONSTANT_String: | |
595 // Do nothing! Not a symbol. | |
596 break; | |
597 | |
598 case JVM_CONSTANT_UnresolvedString: | |
599 case JVM_CONSTANT_Utf8: | |
600 // These constants are symbols, but unless these symbols are | |
601 // actually to be used for something, we don't want to mark them. | |
602 break; | |
603 | |
604 case JVM_CONSTANT_Long: | |
605 case JVM_CONSTANT_Double: | |
606 // Do nothing! Not an oop. (But takes two pool entries.) | |
607 ++index; | |
608 break; | |
609 | |
610 default: | |
611 ShouldNotReachHere(); | |
612 break; | |
613 } | |
614 } | |
615 } | |
616 | |
617 | |
618 // Iterate over the [one] tags array (in preparation for writing to the | |
619 // shared archive). | |
620 | |
621 void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) { | |
622 closure->do_oop(tags_addr()); | |
623 } | |
624 | |
625 | |
626 // Iterate over String objects (in preparation for writing to the shared | |
627 // archive). | |
628 | |
629 void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) { | |
630 for (int index = 1; index < length(); index++) { // Index 0 is unused | |
631 switch (tag_at(index).value()) { | |
632 | |
633 case JVM_CONSTANT_UnresolvedClass: | |
634 case JVM_CONSTANT_NameAndType: | |
635 // Do nothing! Not a String. | |
636 break; | |
637 | |
638 case JVM_CONSTANT_Class: | |
639 case JVM_CONSTANT_InterfaceMethodref: | |
640 case JVM_CONSTANT_Fieldref: | |
641 case JVM_CONSTANT_Methodref: | |
642 case JVM_CONSTANT_Integer: | |
643 case JVM_CONSTANT_Float: | |
644 // Do nothing! Not an oop. | |
645 // These constant types do not reference symbols at this point. | |
646 break; | |
647 | |
648 case JVM_CONSTANT_String: | |
649 closure->do_oop(obj_at_addr(index)); | |
650 break; | |
651 | |
652 case JVM_CONSTANT_UnresolvedString: | |
653 case JVM_CONSTANT_Utf8: | |
654 // These constants are symbols, but unless these symbols are | |
655 // actually to be used for something, we don't want to mark them. | |
656 break; | |
657 | |
658 case JVM_CONSTANT_Long: | |
659 case JVM_CONSTANT_Double: | |
660 // Do nothing! Not an oop. (But takes two pool entries.) | |
661 ++index; | |
662 break; | |
663 | |
664 default: | |
665 ShouldNotReachHere(); | |
666 break; | |
667 } | |
668 } | |
669 } | |
670 | |
671 | |
672 // Compare this constant pool's entry at index1 to the constant pool | |
673 // cp2's entry at index2. | |
674 bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2, | |
675 int index2, TRAPS) { | |
676 | |
677 jbyte t1 = tag_at(index1).value(); | |
678 jbyte t2 = cp2->tag_at(index2).value(); | |
679 | |
680 | |
681 // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass | |
682 // when comparing | |
683 if (t1 == JVM_CONSTANT_UnresolvedClassInError) { | |
684 t1 = JVM_CONSTANT_UnresolvedClass; | |
685 } | |
686 if (t2 == JVM_CONSTANT_UnresolvedClassInError) { | |
687 t2 = JVM_CONSTANT_UnresolvedClass; | |
688 } | |
689 | |
690 if (t1 != t2) { | |
691 // Not the same entry type so there is nothing else to check. Note | |
692 // that this style of checking will consider resolved/unresolved | |
693 // class pairs and resolved/unresolved string pairs as different. | |
694 // From the constantPoolOop API point of view, this is correct | |
695 // behavior. See constantPoolKlass::merge() to see how this plays | |
696 // out in the context of constantPoolOop merging. | |
697 return false; | |
698 } | |
699 | |
700 switch (t1) { | |
701 case JVM_CONSTANT_Class: | |
702 { | |
703 klassOop k1 = klass_at(index1, CHECK_false); | |
704 klassOop k2 = cp2->klass_at(index2, CHECK_false); | |
705 if (k1 == k2) { | |
706 return true; | |
707 } | |
708 } break; | |
709 | |
710 case JVM_CONSTANT_ClassIndex: | |
711 { | |
712 int recur1 = klass_index_at(index1); | |
713 int recur2 = cp2->klass_index_at(index2); | |
714 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
715 if (match) { | |
716 return true; | |
717 } | |
718 } break; | |
719 | |
720 case JVM_CONSTANT_Double: | |
721 { | |
722 jdouble d1 = double_at(index1); | |
723 jdouble d2 = cp2->double_at(index2); | |
724 if (d1 == d2) { | |
725 return true; | |
726 } | |
727 } break; | |
728 | |
729 case JVM_CONSTANT_Fieldref: | |
730 case JVM_CONSTANT_InterfaceMethodref: | |
731 case JVM_CONSTANT_Methodref: | |
732 { | |
733 int recur1 = uncached_klass_ref_index_at(index1); | |
734 int recur2 = cp2->uncached_klass_ref_index_at(index2); | |
735 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
736 if (match) { | |
737 recur1 = uncached_name_and_type_ref_index_at(index1); | |
738 recur2 = cp2->uncached_name_and_type_ref_index_at(index2); | |
739 match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
740 if (match) { | |
741 return true; | |
742 } | |
743 } | |
744 } break; | |
745 | |
746 case JVM_CONSTANT_Float: | |
747 { | |
748 jfloat f1 = float_at(index1); | |
749 jfloat f2 = cp2->float_at(index2); | |
750 if (f1 == f2) { | |
751 return true; | |
752 } | |
753 } break; | |
754 | |
755 case JVM_CONSTANT_Integer: | |
756 { | |
757 jint i1 = int_at(index1); | |
758 jint i2 = cp2->int_at(index2); | |
759 if (i1 == i2) { | |
760 return true; | |
761 } | |
762 } break; | |
763 | |
764 case JVM_CONSTANT_Long: | |
765 { | |
766 jlong l1 = long_at(index1); | |
767 jlong l2 = cp2->long_at(index2); | |
768 if (l1 == l2) { | |
769 return true; | |
770 } | |
771 } break; | |
772 | |
773 case JVM_CONSTANT_NameAndType: | |
774 { | |
775 int recur1 = name_ref_index_at(index1); | |
776 int recur2 = cp2->name_ref_index_at(index2); | |
777 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
778 if (match) { | |
779 recur1 = signature_ref_index_at(index1); | |
780 recur2 = cp2->signature_ref_index_at(index2); | |
781 match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
782 if (match) { | |
783 return true; | |
784 } | |
785 } | |
786 } break; | |
787 | |
788 case JVM_CONSTANT_String: | |
789 { | |
790 oop s1 = string_at(index1, CHECK_false); | |
791 oop s2 = cp2->string_at(index2, CHECK_false); | |
792 if (s1 == s2) { | |
793 return true; | |
794 } | |
795 } break; | |
796 | |
797 case JVM_CONSTANT_StringIndex: | |
798 { | |
799 int recur1 = string_index_at(index1); | |
800 int recur2 = cp2->string_index_at(index2); | |
801 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
802 if (match) { | |
803 return true; | |
804 } | |
805 } break; | |
806 | |
807 case JVM_CONSTANT_UnresolvedClass: | |
808 { | |
809 symbolOop k1 = unresolved_klass_at(index1); | |
810 symbolOop k2 = cp2->unresolved_klass_at(index2); | |
811 if (k1 == k2) { | |
812 return true; | |
813 } | |
814 } break; | |
815 | |
1602 | 816 case JVM_CONSTANT_MethodType: |
817 { | |
818 int k1 = method_type_index_at(index1); | |
819 int k2 = cp2->method_type_index_at(index2); | |
820 if (k1 == k2) { | |
821 return true; | |
822 } | |
823 } break; | |
824 | |
825 case JVM_CONSTANT_MethodHandle: | |
826 { | |
827 int k1 = method_handle_ref_kind_at(index1); | |
828 int k2 = cp2->method_handle_ref_kind_at(index2); | |
829 if (k1 == k2) { | |
830 int i1 = method_handle_index_at(index1); | |
831 int i2 = cp2->method_handle_index_at(index2); | |
832 if (i1 == i2) { | |
833 return true; | |
834 } | |
835 } | |
836 } break; | |
837 | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
838 case JVM_CONSTANT_InvokeDynamic: |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
839 { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
840 int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
841 int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
842 if (k1 == k2) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
843 int i1 = invoke_dynamic_name_and_type_ref_index_at(index1); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
844 int i2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
845 if (i1 == i2) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
846 return true; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
847 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
848 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
849 } break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
850 |
0 | 851 case JVM_CONSTANT_UnresolvedString: |
852 { | |
853 symbolOop s1 = unresolved_string_at(index1); | |
854 symbolOop s2 = cp2->unresolved_string_at(index2); | |
855 if (s1 == s2) { | |
856 return true; | |
857 } | |
858 } break; | |
859 | |
860 case JVM_CONSTANT_Utf8: | |
861 { | |
862 symbolOop s1 = symbol_at(index1); | |
863 symbolOop s2 = cp2->symbol_at(index2); | |
864 if (s1 == s2) { | |
865 return true; | |
866 } | |
867 } break; | |
868 | |
869 // Invalid is used as the tag for the second constant pool entry | |
870 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should | |
871 // not be seen by itself. | |
872 case JVM_CONSTANT_Invalid: // fall through | |
873 | |
874 default: | |
875 ShouldNotReachHere(); | |
876 break; | |
877 } | |
878 | |
879 return false; | |
880 } // end compare_entry_to() | |
881 | |
882 | |
883 // Copy this constant pool's entries at start_i to end_i (inclusive) | |
884 // to the constant pool to_cp's entries starting at to_i. A total of | |
885 // (end_i - start_i) + 1 entries are copied. | |
886 void constantPoolOopDesc::copy_cp_to(int start_i, int end_i, | |
887 constantPoolHandle to_cp, int to_i, TRAPS) { | |
888 | |
889 int dest_i = to_i; // leave original alone for debug purposes | |
890 | |
891 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) { | |
892 copy_entry_to(src_i, to_cp, dest_i, CHECK); | |
893 | |
894 switch (tag_at(src_i).value()) { | |
895 case JVM_CONSTANT_Double: | |
896 case JVM_CONSTANT_Long: | |
897 // double and long take two constant pool entries | |
898 src_i += 2; | |
899 dest_i += 2; | |
900 break; | |
901 | |
902 default: | |
903 // all others take one constant pool entry | |
904 src_i++; | |
905 dest_i++; | |
906 break; | |
907 } | |
908 } | |
909 } // end copy_cp_to() | |
910 | |
911 | |
912 // Copy this constant pool's entry at from_i to the constant pool | |
913 // to_cp's entry at to_i. | |
914 void constantPoolOopDesc::copy_entry_to(int from_i, constantPoolHandle to_cp, | |
915 int to_i, TRAPS) { | |
916 | |
917 switch (tag_at(from_i).value()) { | |
918 case JVM_CONSTANT_Class: | |
919 { | |
920 klassOop k = klass_at(from_i, CHECK); | |
921 to_cp->klass_at_put(to_i, k); | |
922 } break; | |
923 | |
924 case JVM_CONSTANT_ClassIndex: | |
925 { | |
926 jint ki = klass_index_at(from_i); | |
927 to_cp->klass_index_at_put(to_i, ki); | |
928 } break; | |
929 | |
930 case JVM_CONSTANT_Double: | |
931 { | |
932 jdouble d = double_at(from_i); | |
933 to_cp->double_at_put(to_i, d); | |
934 // double takes two constant pool entries so init second entry's tag | |
935 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); | |
936 } break; | |
937 | |
938 case JVM_CONSTANT_Fieldref: | |
939 { | |
940 int class_index = uncached_klass_ref_index_at(from_i); | |
941 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
942 to_cp->field_at_put(to_i, class_index, name_and_type_index); | |
943 } break; | |
944 | |
945 case JVM_CONSTANT_Float: | |
946 { | |
947 jfloat f = float_at(from_i); | |
948 to_cp->float_at_put(to_i, f); | |
949 } break; | |
950 | |
951 case JVM_CONSTANT_Integer: | |
952 { | |
953 jint i = int_at(from_i); | |
954 to_cp->int_at_put(to_i, i); | |
955 } break; | |
956 | |
957 case JVM_CONSTANT_InterfaceMethodref: | |
958 { | |
959 int class_index = uncached_klass_ref_index_at(from_i); | |
960 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
961 to_cp->interface_method_at_put(to_i, class_index, name_and_type_index); | |
962 } break; | |
963 | |
964 case JVM_CONSTANT_Long: | |
965 { | |
966 jlong l = long_at(from_i); | |
967 to_cp->long_at_put(to_i, l); | |
968 // long takes two constant pool entries so init second entry's tag | |
969 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); | |
970 } break; | |
971 | |
972 case JVM_CONSTANT_Methodref: | |
973 { | |
974 int class_index = uncached_klass_ref_index_at(from_i); | |
975 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
976 to_cp->method_at_put(to_i, class_index, name_and_type_index); | |
977 } break; | |
978 | |
979 case JVM_CONSTANT_NameAndType: | |
980 { | |
981 int name_ref_index = name_ref_index_at(from_i); | |
982 int signature_ref_index = signature_ref_index_at(from_i); | |
983 to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index); | |
984 } break; | |
985 | |
986 case JVM_CONSTANT_String: | |
987 { | |
988 oop s = string_at(from_i, CHECK); | |
989 to_cp->string_at_put(to_i, s); | |
990 } break; | |
991 | |
992 case JVM_CONSTANT_StringIndex: | |
993 { | |
994 jint si = string_index_at(from_i); | |
995 to_cp->string_index_at_put(to_i, si); | |
996 } break; | |
997 | |
998 case JVM_CONSTANT_UnresolvedClass: | |
999 { | |
1000 symbolOop k = unresolved_klass_at(from_i); | |
1001 to_cp->unresolved_klass_at_put(to_i, k); | |
1002 } break; | |
1003 | |
1004 case JVM_CONSTANT_UnresolvedClassInError: | |
1005 { | |
1006 symbolOop k = unresolved_klass_at(from_i); | |
1007 to_cp->unresolved_klass_at_put(to_i, k); | |
1008 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError); | |
1009 } break; | |
1010 | |
1011 | |
1012 case JVM_CONSTANT_UnresolvedString: | |
1013 { | |
1014 symbolOop s = unresolved_string_at(from_i); | |
1015 to_cp->unresolved_string_at_put(to_i, s); | |
1016 } break; | |
1017 | |
1018 case JVM_CONSTANT_Utf8: | |
1019 { | |
1020 symbolOop s = symbol_at(from_i); | |
1021 to_cp->symbol_at_put(to_i, s); | |
1022 } break; | |
1023 | |
1602 | 1024 case JVM_CONSTANT_MethodType: |
1025 { | |
1026 jint k = method_type_index_at(from_i); | |
1027 to_cp->method_type_index_at_put(to_i, k); | |
1028 } break; | |
1029 | |
1030 case JVM_CONSTANT_MethodHandle: | |
1031 { | |
1032 int k1 = method_handle_ref_kind_at(from_i); | |
1033 int k2 = method_handle_index_at(from_i); | |
1034 to_cp->method_handle_index_at_put(to_i, k1, k2); | |
1035 } break; | |
1036 | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1037 case JVM_CONSTANT_InvokeDynamic: |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1038 { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1039 int k1 = invoke_dynamic_bootstrap_method_ref_index_at(from_i); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1040 int k2 = invoke_dynamic_name_and_type_ref_index_at(from_i); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1041 to_cp->invoke_dynamic_at_put(to_i, k1, k2); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1042 } break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1043 |
0 | 1044 // Invalid is used as the tag for the second constant pool entry |
1045 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should | |
1046 // not be seen by itself. | |
1047 case JVM_CONSTANT_Invalid: // fall through | |
1048 | |
1049 default: | |
1050 { | |
1051 jbyte bad_value = tag_at(from_i).value(); // leave a breadcrumb | |
1052 ShouldNotReachHere(); | |
1053 } break; | |
1054 } | |
1055 } // end copy_entry_to() | |
1056 | |
1057 | |
1058 // Search constant pool search_cp for an entry that matches this | |
1059 // constant pool's entry at pattern_i. Returns the index of a | |
1060 // matching entry or zero (0) if there is no matching entry. | |
1061 int constantPoolOopDesc::find_matching_entry(int pattern_i, | |
1062 constantPoolHandle search_cp, TRAPS) { | |
1063 | |
1064 // index zero (0) is not used | |
1065 for (int i = 1; i < search_cp->length(); i++) { | |
1066 bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0); | |
1067 if (found) { | |
1068 return i; | |
1069 } | |
1070 } | |
1071 | |
1072 return 0; // entry not found; return unused index zero (0) | |
1073 } // end find_matching_entry() | |
1074 | |
1075 | |
1076 #ifndef PRODUCT | |
1077 | |
1078 const char* constantPoolOopDesc::printable_name_at(int which) { | |
1079 | |
1080 constantTag tag = tag_at(which); | |
1081 | |
1082 if (tag.is_unresolved_string() || tag.is_string()) { | |
1083 return string_at_noresolve(which); | |
1084 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | |
1085 return klass_name_at(which)->as_C_string(); | |
1086 } else if (tag.is_symbol()) { | |
1087 return symbol_at(which)->as_C_string(); | |
1088 } | |
1089 return ""; | |
1090 } | |
1091 | |
1092 #endif // PRODUCT | |
1093 | |
1094 | |
1095 // JVMTI GetConstantPool support | |
1096 | |
1097 // For temporary use until code is stable. | |
1098 #define DBG(code) | |
1099 | |
1100 static const char* WARN_MSG = "Must not be such entry!"; | |
1101 | |
1102 static void print_cpool_bytes(jint cnt, u1 *bytes) { | |
1103 jint size = 0; | |
1104 u2 idx1, idx2; | |
1105 | |
1106 for (jint idx = 1; idx < cnt; idx++) { | |
1107 jint ent_size = 0; | |
1108 u1 tag = *bytes++; | |
1109 size++; // count tag | |
1110 | |
1111 printf("const #%03d, tag: %02d ", idx, tag); | |
1112 switch(tag) { | |
1113 case JVM_CONSTANT_Invalid: { | |
1114 printf("Invalid"); | |
1115 break; | |
1116 } | |
1117 case JVM_CONSTANT_Unicode: { | |
1118 printf("Unicode %s", WARN_MSG); | |
1119 break; | |
1120 } | |
1121 case JVM_CONSTANT_Utf8: { | |
1122 u2 len = Bytes::get_Java_u2(bytes); | |
1123 char str[128]; | |
1124 if (len > 127) { | |
1125 len = 127; | |
1126 } | |
1127 strncpy(str, (char *) (bytes+2), len); | |
1128 str[len] = '\0'; | |
1129 printf("Utf8 \"%s\"", str); | |
1130 ent_size = 2 + len; | |
1131 break; | |
1132 } | |
1133 case JVM_CONSTANT_Integer: { | |
1134 u4 val = Bytes::get_Java_u4(bytes); | |
1135 printf("int %d", *(int *) &val); | |
1136 ent_size = 4; | |
1137 break; | |
1138 } | |
1139 case JVM_CONSTANT_Float: { | |
1140 u4 val = Bytes::get_Java_u4(bytes); | |
1141 printf("float %5.3ff", *(float *) &val); | |
1142 ent_size = 4; | |
1143 break; | |
1144 } | |
1145 case JVM_CONSTANT_Long: { | |
1146 u8 val = Bytes::get_Java_u8(bytes); | |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
431
diff
changeset
|
1147 printf("long "INT64_FORMAT, *(jlong *) &val); |
0 | 1148 ent_size = 8; |
1149 idx++; // Long takes two cpool slots | |
1150 break; | |
1151 } | |
1152 case JVM_CONSTANT_Double: { | |
1153 u8 val = Bytes::get_Java_u8(bytes); | |
1154 printf("double %5.3fd", *(jdouble *)&val); | |
1155 ent_size = 8; | |
1156 idx++; // Double takes two cpool slots | |
1157 break; | |
1158 } | |
1159 case JVM_CONSTANT_Class: { | |
1160 idx1 = Bytes::get_Java_u2(bytes); | |
1161 printf("class #%03d", idx1); | |
1162 ent_size = 2; | |
1163 break; | |
1164 } | |
1165 case JVM_CONSTANT_String: { | |
1166 idx1 = Bytes::get_Java_u2(bytes); | |
1167 printf("String #%03d", idx1); | |
1168 ent_size = 2; | |
1169 break; | |
1170 } | |
1171 case JVM_CONSTANT_Fieldref: { | |
1172 idx1 = Bytes::get_Java_u2(bytes); | |
1173 idx2 = Bytes::get_Java_u2(bytes+2); | |
1174 printf("Field #%03d, #%03d", (int) idx1, (int) idx2); | |
1175 ent_size = 4; | |
1176 break; | |
1177 } | |
1178 case JVM_CONSTANT_Methodref: { | |
1179 idx1 = Bytes::get_Java_u2(bytes); | |
1180 idx2 = Bytes::get_Java_u2(bytes+2); | |
1181 printf("Method #%03d, #%03d", idx1, idx2); | |
1182 ent_size = 4; | |
1183 break; | |
1184 } | |
1185 case JVM_CONSTANT_InterfaceMethodref: { | |
1186 idx1 = Bytes::get_Java_u2(bytes); | |
1187 idx2 = Bytes::get_Java_u2(bytes+2); | |
1188 printf("InterfMethod #%03d, #%03d", idx1, idx2); | |
1189 ent_size = 4; | |
1190 break; | |
1191 } | |
1192 case JVM_CONSTANT_NameAndType: { | |
1193 idx1 = Bytes::get_Java_u2(bytes); | |
1194 idx2 = Bytes::get_Java_u2(bytes+2); | |
1195 printf("NameAndType #%03d, #%03d", idx1, idx2); | |
1196 ent_size = 4; | |
1197 break; | |
1198 } | |
1199 case JVM_CONSTANT_ClassIndex: { | |
1200 printf("ClassIndex %s", WARN_MSG); | |
1201 break; | |
1202 } | |
1203 case JVM_CONSTANT_UnresolvedClass: { | |
1204 printf("UnresolvedClass: %s", WARN_MSG); | |
1205 break; | |
1206 } | |
1207 case JVM_CONSTANT_UnresolvedClassInError: { | |
1208 printf("UnresolvedClassInErr: %s", WARN_MSG); | |
1209 break; | |
1210 } | |
1211 case JVM_CONSTANT_StringIndex: { | |
1212 printf("StringIndex: %s", WARN_MSG); | |
1213 break; | |
1214 } | |
1215 case JVM_CONSTANT_UnresolvedString: { | |
1216 printf("UnresolvedString: %s", WARN_MSG); | |
1217 break; | |
1218 } | |
1219 } | |
1220 printf(";\n"); | |
1221 bytes += ent_size; | |
1222 size += ent_size; | |
1223 } | |
1224 printf("Cpool size: %d\n", size); | |
1225 fflush(0); | |
1226 return; | |
1227 } /* end print_cpool_bytes */ | |
1228 | |
1229 | |
1230 // Returns size of constant pool entry. | |
1231 jint constantPoolOopDesc::cpool_entry_size(jint idx) { | |
1232 switch(tag_at(idx).value()) { | |
1233 case JVM_CONSTANT_Invalid: | |
1234 case JVM_CONSTANT_Unicode: | |
1235 return 1; | |
1236 | |
1237 case JVM_CONSTANT_Utf8: | |
1238 return 3 + symbol_at(idx)->utf8_length(); | |
1239 | |
1240 case JVM_CONSTANT_Class: | |
1241 case JVM_CONSTANT_String: | |
1242 case JVM_CONSTANT_ClassIndex: | |
1243 case JVM_CONSTANT_UnresolvedClass: | |
1244 case JVM_CONSTANT_UnresolvedClassInError: | |
1245 case JVM_CONSTANT_StringIndex: | |
1246 case JVM_CONSTANT_UnresolvedString: | |
1602 | 1247 case JVM_CONSTANT_MethodType: |
0 | 1248 return 3; |
1249 | |
1602 | 1250 case JVM_CONSTANT_MethodHandle: |
1251 return 4; //tag, ref_kind, ref_index | |
1252 | |
0 | 1253 case JVM_CONSTANT_Integer: |
1254 case JVM_CONSTANT_Float: | |
1255 case JVM_CONSTANT_Fieldref: | |
1256 case JVM_CONSTANT_Methodref: | |
1257 case JVM_CONSTANT_InterfaceMethodref: | |
1258 case JVM_CONSTANT_NameAndType: | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1259 case JVM_CONSTANT_InvokeDynamic: |
0 | 1260 return 5; |
1261 | |
1262 case JVM_CONSTANT_Long: | |
1263 case JVM_CONSTANT_Double: | |
1264 return 9; | |
1265 } | |
1266 assert(false, "cpool_entry_size: Invalid constant pool entry tag"); | |
1267 return 1; | |
1268 } /* end cpool_entry_size */ | |
1269 | |
1270 | |
1271 // SymbolHashMap is used to find a constant pool index from a string. | |
1272 // This function fills in SymbolHashMaps, one for utf8s and one for | |
1273 // class names, returns size of the cpool raw bytes. | |
1274 jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap, | |
1275 SymbolHashMap *classmap) { | |
1276 jint size = 0; | |
1277 | |
1278 for (u2 idx = 1; idx < length(); idx++) { | |
1279 u2 tag = tag_at(idx).value(); | |
1280 size += cpool_entry_size(idx); | |
1281 | |
1282 switch(tag) { | |
1283 case JVM_CONSTANT_Utf8: { | |
1284 symbolOop sym = symbol_at(idx); | |
1285 symmap->add_entry(sym, idx); | |
1286 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx)); | |
1287 break; | |
1288 } | |
1289 case JVM_CONSTANT_Class: | |
1290 case JVM_CONSTANT_UnresolvedClass: | |
1291 case JVM_CONSTANT_UnresolvedClassInError: { | |
1292 symbolOop sym = klass_name_at(idx); | |
1293 classmap->add_entry(sym, idx); | |
1294 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx)); | |
1295 break; | |
1296 } | |
1297 case JVM_CONSTANT_Long: | |
1298 case JVM_CONSTANT_Double: { | |
1299 idx++; // Both Long and Double take two cpool slots | |
1300 break; | |
1301 } | |
1302 } | |
1303 } | |
1304 return size; | |
1305 } /* end hash_utf8_entries_to */ | |
1306 | |
1307 | |
1308 // Copy cpool bytes. | |
1309 // Returns: | |
1310 // 0, in case of OutOfMemoryError | |
1311 // -1, in case of internal error | |
1312 // > 0, count of the raw cpool bytes that have been copied | |
1313 int constantPoolOopDesc::copy_cpool_bytes(int cpool_size, | |
1314 SymbolHashMap* tbl, | |
1315 unsigned char *bytes) { | |
1316 u2 idx1, idx2; | |
1317 jint size = 0; | |
1318 jint cnt = length(); | |
1319 unsigned char *start_bytes = bytes; | |
1320 | |
1321 for (jint idx = 1; idx < cnt; idx++) { | |
1322 u1 tag = tag_at(idx).value(); | |
1323 jint ent_size = cpool_entry_size(idx); | |
1324 | |
1325 assert(size + ent_size <= cpool_size, "Size mismatch"); | |
1326 | |
1327 *bytes = tag; | |
1328 DBG(printf("#%03hd tag=%03hd, ", idx, tag)); | |
1329 switch(tag) { | |
1330 case JVM_CONSTANT_Invalid: { | |
1331 DBG(printf("JVM_CONSTANT_Invalid")); | |
1332 break; | |
1333 } | |
1334 case JVM_CONSTANT_Unicode: { | |
1335 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode"); | |
1336 DBG(printf("JVM_CONSTANT_Unicode")); | |
1337 break; | |
1338 } | |
1339 case JVM_CONSTANT_Utf8: { | |
1340 symbolOop sym = symbol_at(idx); | |
1341 char* str = sym->as_utf8(); | |
1342 // Warning! It's crashing on x86 with len = sym->utf8_length() | |
1343 int len = (int) strlen(str); | |
1344 Bytes::put_Java_u2((address) (bytes+1), (u2) len); | |
1345 for (int i = 0; i < len; i++) { | |
1346 bytes[3+i] = (u1) str[i]; | |
1347 } | |
1348 DBG(printf("JVM_CONSTANT_Utf8: %s ", str)); | |
1349 break; | |
1350 } | |
1351 case JVM_CONSTANT_Integer: { | |
1352 jint val = int_at(idx); | |
1353 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); | |
1354 break; | |
1355 } | |
1356 case JVM_CONSTANT_Float: { | |
1357 jfloat val = float_at(idx); | |
1358 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); | |
1359 break; | |
1360 } | |
1361 case JVM_CONSTANT_Long: { | |
1362 jlong val = long_at(idx); | |
1363 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); | |
1364 idx++; // Long takes two cpool slots | |
1365 break; | |
1366 } | |
1367 case JVM_CONSTANT_Double: { | |
1368 jdouble val = double_at(idx); | |
1369 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); | |
1370 idx++; // Double takes two cpool slots | |
1371 break; | |
1372 } | |
1373 case JVM_CONSTANT_Class: | |
1374 case JVM_CONSTANT_UnresolvedClass: | |
1375 case JVM_CONSTANT_UnresolvedClassInError: { | |
1376 *bytes = JVM_CONSTANT_Class; | |
1377 symbolOop sym = klass_name_at(idx); | |
1378 idx1 = tbl->symbol_to_value(sym); | |
1379 assert(idx1 != 0, "Have not found a hashtable entry"); | |
1380 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1381 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8())); | |
1382 break; | |
1383 } | |
1384 case JVM_CONSTANT_String: { | |
1385 unsigned int hash; | |
1386 char *str = string_at_noresolve(idx); | |
1387 symbolOop sym = SymbolTable::lookup_only(str, (int) strlen(str), hash); | |
773
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1388 if (sym == NULL) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1389 // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8 |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1390 // this can happen with JVM TI; see CR 6839599 for more details |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1391 oop string = *(obj_at_addr(idx)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1392 assert(java_lang_String::is_instance(string),"Not a String"); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1393 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1394 idx1 = 0; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1395 for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1396 for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1397 int length; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1398 sym = cur->symbol(); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1399 jchar* chars = sym->as_unicode(length); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1400 if (java_lang_String::equals(string, chars, length)) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1401 idx1 = cur->value(); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1402 DBG(printf("Index found: %d\n",idx1)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1403 break; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1404 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1405 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1406 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1407 } else { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1408 idx1 = tbl->symbol_to_value(sym); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1409 } |
0 | 1410 assert(idx1 != 0, "Have not found a hashtable entry"); |
1411 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1412 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str)); | |
1413 break; | |
1414 } | |
1415 case JVM_CONSTANT_UnresolvedString: { | |
1416 *bytes = JVM_CONSTANT_String; | |
1417 symbolOop sym = unresolved_string_at(idx); | |
1418 idx1 = tbl->symbol_to_value(sym); | |
1419 assert(idx1 != 0, "Have not found a hashtable entry"); | |
1420 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1421 DBG(char *str = sym->as_utf8()); | |
1422 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str)); | |
1423 break; | |
1424 } | |
1425 case JVM_CONSTANT_Fieldref: | |
1426 case JVM_CONSTANT_Methodref: | |
1427 case JVM_CONSTANT_InterfaceMethodref: { | |
1428 idx1 = uncached_klass_ref_index_at(idx); | |
1429 idx2 = uncached_name_and_type_ref_index_at(idx); | |
1430 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1431 Bytes::put_Java_u2((address) (bytes+3), idx2); | |
1432 DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2)); | |
1433 break; | |
1434 } | |
1435 case JVM_CONSTANT_NameAndType: { | |
1436 idx1 = name_ref_index_at(idx); | |
1437 idx2 = signature_ref_index_at(idx); | |
1438 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1439 Bytes::put_Java_u2((address) (bytes+3), idx2); | |
1440 DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2)); | |
1441 break; | |
1442 } | |
1443 case JVM_CONSTANT_ClassIndex: { | |
1444 *bytes = JVM_CONSTANT_Class; | |
1445 idx1 = klass_index_at(idx); | |
1446 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1447 DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1)); | |
1448 break; | |
1449 } | |
1450 case JVM_CONSTANT_StringIndex: { | |
1451 *bytes = JVM_CONSTANT_String; | |
1452 idx1 = string_index_at(idx); | |
1453 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1454 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); | |
1455 break; | |
1456 } | |
1602 | 1457 case JVM_CONSTANT_MethodHandle: { |
1458 *bytes = JVM_CONSTANT_MethodHandle; | |
1459 int kind = method_handle_ref_kind_at(idx); | |
1460 idx1 = method_handle_index_at(idx); | |
1461 *(bytes+1) = (unsigned char) kind; | |
1462 Bytes::put_Java_u2((address) (bytes+2), idx1); | |
1463 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); | |
1464 break; | |
1465 } | |
1466 case JVM_CONSTANT_MethodType: { | |
1467 *bytes = JVM_CONSTANT_MethodType; | |
1468 idx1 = method_type_index_at(idx); | |
1469 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1470 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); | |
1471 break; | |
1472 } | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1473 case JVM_CONSTANT_InvokeDynamic: { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1474 *bytes = JVM_CONSTANT_InvokeDynamic; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1475 idx1 = invoke_dynamic_bootstrap_method_ref_index_at(idx); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1476 idx2 = invoke_dynamic_name_and_type_ref_index_at(idx); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1477 Bytes::put_Java_u2((address) (bytes+1), idx1); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1478 Bytes::put_Java_u2((address) (bytes+3), idx2); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1479 DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2)); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1480 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
1481 } |
0 | 1482 } |
1483 DBG(printf("\n")); | |
1484 bytes += ent_size; | |
1485 size += ent_size; | |
1486 } | |
1487 assert(size == cpool_size, "Size mismatch"); | |
1488 | |
1489 // Keep temorarily for debugging until it's stable. | |
1490 DBG(print_cpool_bytes(cnt, start_bytes)); | |
1491 return (int)(bytes - start_bytes); | |
1492 } /* end copy_cpool_bytes */ | |
1493 | |
1494 | |
1495 void SymbolHashMap::add_entry(symbolOop sym, u2 value) { | |
1496 char *str = sym->as_utf8(); | |
1497 unsigned int hash = compute_hash(str, sym->utf8_length()); | |
1498 unsigned int index = hash % table_size(); | |
1499 | |
1500 // check if already in map | |
1501 // we prefer the first entry since it is more likely to be what was used in | |
1502 // the class file | |
1503 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { | |
1504 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1505 if (en->hash() == hash && en->symbol() == sym) { | |
1506 return; // already there | |
1507 } | |
1508 } | |
1509 | |
1510 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); | |
1511 entry->set_next(bucket(index)); | |
1512 _buckets[index].set_entry(entry); | |
1513 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1514 } | |
1515 | |
1516 SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) { | |
1517 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL"); | |
1518 char *str = sym->as_utf8(); | |
1519 int len = sym->utf8_length(); | |
1520 unsigned int hash = SymbolHashMap::compute_hash(str, len); | |
1521 unsigned int index = hash % table_size(); | |
1522 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { | |
1523 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1524 if (en->hash() == hash && en->symbol() == sym) { | |
1525 return en; | |
1526 } | |
1527 } | |
1528 return NULL; | |
1529 } |