Mercurial > hg > graal-compiler
annotate src/share/vm/oops/constantPoolOop.cpp @ 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:
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) { |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
267 if (constantPoolCacheOopDesc::is_secondary_index(which)) |
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. |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
270 return cache()->main_entry_at(which)->constant_pool_index(); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
271 // change byte-ordering and go via cache |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
272 i = remap_instruction_operand_from_cache(which); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
273 } else { |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
274 if (tag_at(which).is_name_and_type()) |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
275 // invokedynamic index is a simple name-and-type |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
276 return which; |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
277 } |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
278 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
|
279 jint ref_index = *int_at_addr(i); |
0 | 280 return extract_high_short_from_int(ref_index); |
281 } | |
282 | |
283 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
284 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
|
285 guarantee(!constantPoolCacheOopDesc::is_secondary_index(which), |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
286 "an invokedynamic instruction does not have a klass"); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
287 int i = which; |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
288 if (!uncached && cache() != NULL) { |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
289 // change byte-ordering and go via cache |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
290 i = remap_instruction_operand_from_cache(which); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
291 } |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
292 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
|
293 jint ref_index = *int_at_addr(i); |
0 | 294 return extract_low_short_from_int(ref_index); |
295 } | |
296 | |
297 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
298 |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
299 int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) { |
1565 | 300 int cpc_index = operand; |
301 DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG); | |
302 assert((int)(u2)cpc_index == cpc_index, "clean u2"); | |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
773
diff
changeset
|
303 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
|
304 return member_index; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
305 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
306 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
307 |
0 | 308 void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) { |
309 if (k->oop_is_instance() || k->oop_is_objArray()) { | |
310 instanceKlassHandle holder (THREAD, this_oop->pool_holder()); | |
311 klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass(); | |
312 KlassHandle element (THREAD, elem_oop); | |
313 | |
314 // The element type could be a typeArray - we only need the access check if it is | |
315 // an reference to another class | |
316 if (element->oop_is_instance()) { | |
317 LinkResolver::check_klass_accessability(holder, element, CHECK); | |
318 } | |
319 } | |
320 } | |
321 | |
322 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
323 int constantPoolOopDesc::name_ref_index_at(int which_nt) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
324 jint ref_index = name_and_type_at(which_nt); |
0 | 325 return extract_low_short_from_int(ref_index); |
326 } | |
327 | |
328 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
329 int constantPoolOopDesc::signature_ref_index_at(int which_nt) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
330 jint ref_index = name_and_type_at(which_nt); |
0 | 331 return extract_high_short_from_int(ref_index); |
332 } | |
333 | |
334 | |
335 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) { | |
336 return klass_at(klass_ref_index_at(which), CHECK_NULL); | |
337 } | |
338 | |
339 | |
340 symbolOop constantPoolOopDesc::klass_name_at(int which) { | |
341 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), | |
342 "Corrupted constant pool"); | |
343 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop. | |
344 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and | |
345 // tag is not updated atomicly. | |
346 oop entry = *(obj_at_addr(which)); | |
347 if (entry->is_klass()) { | |
348 // Already resolved - return entry's name. | |
349 return klassOop(entry)->klass_part()->name(); | |
350 } else { | |
351 assert(entry->is_symbol(), "must be either symbol or klass"); | |
352 return (symbolOop)entry; | |
353 } | |
354 } | |
355 | |
356 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) { | |
357 jint ref_index = klass_ref_index_at(which); | |
358 return klass_at_noresolve(ref_index); | |
359 } | |
360 | |
1602 | 361 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { |
362 jint ref_index = uncached_klass_ref_index_at(which); | |
363 return klass_at_noresolve(ref_index); | |
364 } | |
365 | |
0 | 366 char* constantPoolOopDesc::string_at_noresolve(int which) { |
367 // Test entry type in case string is resolved while in here. | |
368 oop entry = *(obj_at_addr(which)); | |
369 if (entry->is_symbol()) { | |
370 return ((symbolOop)entry)->as_C_string(); | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
371 } 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
|
372 return java_lang_String::as_utf8_string(entry); |
0 | 373 } else { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
374 return (char*)"<pseudo-string>"; |
0 | 375 } |
376 } | |
377 | |
378 | |
379 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) { | |
380 return FieldType::basic_type(symbol_at(which)); | |
381 } | |
382 | |
383 | |
384 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { | |
385 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused | |
386 if (this_oop->tag_at(index).is_unresolved_string()) { | |
387 this_oop->string_at(index, CHECK); | |
388 } | |
389 } | |
390 } | |
391 | |
1602 | 392 oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) { |
393 oop result_oop = NULL; | |
394 if (cache_index >= 0) { | |
395 assert(index < 0, "only one kind of index at a time"); | |
396 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
397 result_oop = cpc_entry->f1(); | |
398 if (result_oop != NULL) { | |
399 return result_oop; // that was easy... | |
400 } | |
401 index = cpc_entry->constant_pool_index(); | |
402 } | |
403 | |
404 int tag_value = this_oop->tag_at(index).value(); | |
405 switch (tag_value) { | |
406 | |
407 case JVM_CONSTANT_UnresolvedClass: | |
408 case JVM_CONSTANT_UnresolvedClassInError: | |
409 case JVM_CONSTANT_Class: | |
410 { | |
411 klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL); | |
412 // ldc wants the java mirror. | |
413 result_oop = resolved->klass_part()->java_mirror(); | |
414 break; | |
415 } | |
416 | |
417 case JVM_CONSTANT_String: | |
418 case JVM_CONSTANT_UnresolvedString: | |
419 if (this_oop->is_pseudo_string_at(index)) { | |
420 result_oop = this_oop->pseudo_string_at(index); | |
421 break; | |
422 } | |
423 result_oop = string_at_impl(this_oop, index, CHECK_NULL); | |
424 break; | |
425 | |
426 case JVM_CONSTANT_Object: | |
427 result_oop = this_oop->object_at(index); | |
428 break; | |
429 | |
430 case JVM_CONSTANT_MethodHandle: | |
431 { | |
432 int ref_kind = this_oop->method_handle_ref_kind_at(index); | |
433 int callee_index = this_oop->method_handle_klass_index_at(index); | |
434 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index)); | |
435 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index)); | |
436 if (PrintMiscellaneous) | |
437 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", | |
438 ref_kind, index, this_oop->method_handle_index_at(index), | |
439 callee_index, name->as_C_string(), signature->as_C_string()); | |
440 KlassHandle callee; | |
441 { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL); | |
442 callee = KlassHandle(THREAD, k); | |
443 } | |
444 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
445 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind, | |
446 callee, name, signature, | |
447 CHECK_NULL); | |
448 result_oop = value(); | |
449 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
450 break; | |
451 } | |
452 | |
453 case JVM_CONSTANT_MethodType: | |
454 { | |
455 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index)); | |
456 if (PrintMiscellaneous) | |
457 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", | |
458 index, this_oop->method_type_index_at(index), | |
459 signature->as_C_string()); | |
460 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
461 bool ignore_is_on_bcp = false; | |
462 Handle value = SystemDictionary::find_method_handle_type(signature, | |
463 klass, | |
464 ignore_is_on_bcp, | |
465 CHECK_NULL); | |
466 result_oop = value(); | |
467 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
468 break; | |
469 } | |
470 | |
471 /* maybe some day | |
472 case JVM_CONSTANT_Integer: | |
473 case JVM_CONSTANT_Float: | |
474 case JVM_CONSTANT_Long: | |
475 case JVM_CONSTANT_Double: | |
476 result_oop = java_lang_boxing_object::create(...); | |
477 break; | |
478 */ | |
479 | |
480 default: | |
481 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d", | |
482 this_oop(), index, cache_index, tag_value) ); | |
483 assert(false, "unexpected constant tag"); | |
484 break; | |
485 } | |
486 | |
487 if (cache_index >= 0) { | |
488 // Cache the oop here also. | |
489 Handle result(THREAD, result_oop); | |
490 result_oop = NULL; // safety | |
491 ObjectLocker ol(this_oop, THREAD); | |
492 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
493 oop result_oop2 = cpc_entry->f1(); | |
494 if (result_oop2 != NULL) { | |
495 // Race condition: May already be filled in while we were trying to lock. | |
496 return result_oop2; | |
497 } | |
498 cpc_entry->set_f1(result()); | |
499 return result(); | |
500 } else { | |
501 return result_oop; | |
502 } | |
503 } | |
504 | |
0 | 505 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
506 oop entry = *(this_oop->obj_at_addr(which)); | |
507 if (entry->is_symbol()) { | |
508 ObjectLocker ol(this_oop, THREAD); | |
509 if (this_oop->tag_at(which).is_unresolved_string()) { | |
510 // Intern string | |
511 symbolOop sym = this_oop->unresolved_string_at(which); | |
512 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL))); | |
513 this_oop->string_at_put(which, entry); | |
514 } else { | |
515 // Another thread beat us and interned string, read string from constant pool | |
516 entry = this_oop->resolved_string_at(which); | |
517 } | |
518 } | |
519 assert(java_lang_String::is_instance(entry), "must be string"); | |
520 return entry; | |
521 } | |
522 | |
523 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
524 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
|
525 oop entry = *(obj_at_addr(which)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
526 if (entry->is_symbol()) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
527 // 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
|
528 return false; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
529 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
|
530 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
|
531 else |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
532 // truly pseudo |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
533 return true; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
534 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
535 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
536 |
0 | 537 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k, |
538 int which) { | |
539 // Names are interned, so we can compare symbolOops directly | |
540 symbolOop cp_name = klass_name_at(which); | |
541 return (cp_name == k->name()); | |
542 } | |
543 | |
544 | |
545 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) { | |
546 ResourceMark rm; | |
547 int count = 0; | |
548 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused | |
549 if (tag_at(index).is_unresolved_string()) { | |
550 // Intern string | |
551 symbolOop sym = unresolved_string_at(index); | |
552 oop entry = StringTable::intern(sym, CHECK_(-1)); | |
553 string_at_put(index, entry); | |
554 } | |
555 } | |
556 return count; | |
557 } | |
558 | |
559 | |
560 // Iterate over symbols which are used as class, field, method names and | |
561 // signatures (in preparation for writing to the shared archive). | |
562 | |
563 void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) { | |
564 for (int index = 1; index < length(); index++) { // Index 0 is unused | |
565 switch (tag_at(index).value()) { | |
566 | |
567 case JVM_CONSTANT_UnresolvedClass: | |
568 closure->do_oop(obj_at_addr(index)); | |
569 break; | |
570 | |
571 case JVM_CONSTANT_NameAndType: | |
572 { | |
573 int i = *int_at_addr(index); | |
574 closure->do_oop(obj_at_addr((unsigned)i >> 16)); | |
575 closure->do_oop(obj_at_addr((unsigned)i & 0xffff)); | |
576 } | |
577 break; | |
578 | |
579 case JVM_CONSTANT_Class: | |
580 case JVM_CONSTANT_InterfaceMethodref: | |
581 case JVM_CONSTANT_Fieldref: | |
582 case JVM_CONSTANT_Methodref: | |
583 case JVM_CONSTANT_Integer: | |
584 case JVM_CONSTANT_Float: | |
585 // Do nothing! Not an oop. | |
586 // These constant types do not reference symbols at this point. | |
587 break; | |
588 | |
589 case JVM_CONSTANT_String: | |
590 // Do nothing! Not a symbol. | |
591 break; | |
592 | |
593 case JVM_CONSTANT_UnresolvedString: | |
594 case JVM_CONSTANT_Utf8: | |
595 // These constants are symbols, but unless these symbols are | |
596 // actually to be used for something, we don't want to mark them. | |
597 break; | |
598 | |
599 case JVM_CONSTANT_Long: | |
600 case JVM_CONSTANT_Double: | |
601 // Do nothing! Not an oop. (But takes two pool entries.) | |
602 ++index; | |
603 break; | |
604 | |
605 default: | |
606 ShouldNotReachHere(); | |
607 break; | |
608 } | |
609 } | |
610 } | |
611 | |
612 | |
613 // Iterate over the [one] tags array (in preparation for writing to the | |
614 // shared archive). | |
615 | |
616 void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) { | |
617 closure->do_oop(tags_addr()); | |
618 } | |
619 | |
620 | |
621 // Iterate over String objects (in preparation for writing to the shared | |
622 // archive). | |
623 | |
624 void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) { | |
625 for (int index = 1; index < length(); index++) { // Index 0 is unused | |
626 switch (tag_at(index).value()) { | |
627 | |
628 case JVM_CONSTANT_UnresolvedClass: | |
629 case JVM_CONSTANT_NameAndType: | |
630 // Do nothing! Not a String. | |
631 break; | |
632 | |
633 case JVM_CONSTANT_Class: | |
634 case JVM_CONSTANT_InterfaceMethodref: | |
635 case JVM_CONSTANT_Fieldref: | |
636 case JVM_CONSTANT_Methodref: | |
637 case JVM_CONSTANT_Integer: | |
638 case JVM_CONSTANT_Float: | |
639 // Do nothing! Not an oop. | |
640 // These constant types do not reference symbols at this point. | |
641 break; | |
642 | |
643 case JVM_CONSTANT_String: | |
644 closure->do_oop(obj_at_addr(index)); | |
645 break; | |
646 | |
647 case JVM_CONSTANT_UnresolvedString: | |
648 case JVM_CONSTANT_Utf8: | |
649 // These constants are symbols, but unless these symbols are | |
650 // actually to be used for something, we don't want to mark them. | |
651 break; | |
652 | |
653 case JVM_CONSTANT_Long: | |
654 case JVM_CONSTANT_Double: | |
655 // Do nothing! Not an oop. (But takes two pool entries.) | |
656 ++index; | |
657 break; | |
658 | |
659 default: | |
660 ShouldNotReachHere(); | |
661 break; | |
662 } | |
663 } | |
664 } | |
665 | |
666 | |
667 // Compare this constant pool's entry at index1 to the constant pool | |
668 // cp2's entry at index2. | |
669 bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2, | |
670 int index2, TRAPS) { | |
671 | |
672 jbyte t1 = tag_at(index1).value(); | |
673 jbyte t2 = cp2->tag_at(index2).value(); | |
674 | |
675 | |
676 // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass | |
677 // when comparing | |
678 if (t1 == JVM_CONSTANT_UnresolvedClassInError) { | |
679 t1 = JVM_CONSTANT_UnresolvedClass; | |
680 } | |
681 if (t2 == JVM_CONSTANT_UnresolvedClassInError) { | |
682 t2 = JVM_CONSTANT_UnresolvedClass; | |
683 } | |
684 | |
685 if (t1 != t2) { | |
686 // Not the same entry type so there is nothing else to check. Note | |
687 // that this style of checking will consider resolved/unresolved | |
688 // class pairs and resolved/unresolved string pairs as different. | |
689 // From the constantPoolOop API point of view, this is correct | |
690 // behavior. See constantPoolKlass::merge() to see how this plays | |
691 // out in the context of constantPoolOop merging. | |
692 return false; | |
693 } | |
694 | |
695 switch (t1) { | |
696 case JVM_CONSTANT_Class: | |
697 { | |
698 klassOop k1 = klass_at(index1, CHECK_false); | |
699 klassOop k2 = cp2->klass_at(index2, CHECK_false); | |
700 if (k1 == k2) { | |
701 return true; | |
702 } | |
703 } break; | |
704 | |
705 case JVM_CONSTANT_ClassIndex: | |
706 { | |
707 int recur1 = klass_index_at(index1); | |
708 int recur2 = cp2->klass_index_at(index2); | |
709 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
710 if (match) { | |
711 return true; | |
712 } | |
713 } break; | |
714 | |
715 case JVM_CONSTANT_Double: | |
716 { | |
717 jdouble d1 = double_at(index1); | |
718 jdouble d2 = cp2->double_at(index2); | |
719 if (d1 == d2) { | |
720 return true; | |
721 } | |
722 } break; | |
723 | |
724 case JVM_CONSTANT_Fieldref: | |
725 case JVM_CONSTANT_InterfaceMethodref: | |
726 case JVM_CONSTANT_Methodref: | |
727 { | |
728 int recur1 = uncached_klass_ref_index_at(index1); | |
729 int recur2 = cp2->uncached_klass_ref_index_at(index2); | |
730 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
731 if (match) { | |
732 recur1 = uncached_name_and_type_ref_index_at(index1); | |
733 recur2 = cp2->uncached_name_and_type_ref_index_at(index2); | |
734 match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
735 if (match) { | |
736 return true; | |
737 } | |
738 } | |
739 } break; | |
740 | |
741 case JVM_CONSTANT_Float: | |
742 { | |
743 jfloat f1 = float_at(index1); | |
744 jfloat f2 = cp2->float_at(index2); | |
745 if (f1 == f2) { | |
746 return true; | |
747 } | |
748 } break; | |
749 | |
750 case JVM_CONSTANT_Integer: | |
751 { | |
752 jint i1 = int_at(index1); | |
753 jint i2 = cp2->int_at(index2); | |
754 if (i1 == i2) { | |
755 return true; | |
756 } | |
757 } break; | |
758 | |
759 case JVM_CONSTANT_Long: | |
760 { | |
761 jlong l1 = long_at(index1); | |
762 jlong l2 = cp2->long_at(index2); | |
763 if (l1 == l2) { | |
764 return true; | |
765 } | |
766 } break; | |
767 | |
768 case JVM_CONSTANT_NameAndType: | |
769 { | |
770 int recur1 = name_ref_index_at(index1); | |
771 int recur2 = cp2->name_ref_index_at(index2); | |
772 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
773 if (match) { | |
774 recur1 = signature_ref_index_at(index1); | |
775 recur2 = cp2->signature_ref_index_at(index2); | |
776 match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
777 if (match) { | |
778 return true; | |
779 } | |
780 } | |
781 } break; | |
782 | |
783 case JVM_CONSTANT_String: | |
784 { | |
785 oop s1 = string_at(index1, CHECK_false); | |
786 oop s2 = cp2->string_at(index2, CHECK_false); | |
787 if (s1 == s2) { | |
788 return true; | |
789 } | |
790 } break; | |
791 | |
792 case JVM_CONSTANT_StringIndex: | |
793 { | |
794 int recur1 = string_index_at(index1); | |
795 int recur2 = cp2->string_index_at(index2); | |
796 bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false); | |
797 if (match) { | |
798 return true; | |
799 } | |
800 } break; | |
801 | |
802 case JVM_CONSTANT_UnresolvedClass: | |
803 { | |
804 symbolOop k1 = unresolved_klass_at(index1); | |
805 symbolOop k2 = cp2->unresolved_klass_at(index2); | |
806 if (k1 == k2) { | |
807 return true; | |
808 } | |
809 } break; | |
810 | |
1602 | 811 case JVM_CONSTANT_MethodType: |
812 { | |
813 int k1 = method_type_index_at(index1); | |
814 int k2 = cp2->method_type_index_at(index2); | |
815 if (k1 == k2) { | |
816 return true; | |
817 } | |
818 } break; | |
819 | |
820 case JVM_CONSTANT_MethodHandle: | |
821 { | |
822 int k1 = method_handle_ref_kind_at(index1); | |
823 int k2 = cp2->method_handle_ref_kind_at(index2); | |
824 if (k1 == k2) { | |
825 int i1 = method_handle_index_at(index1); | |
826 int i2 = cp2->method_handle_index_at(index2); | |
827 if (i1 == i2) { | |
828 return true; | |
829 } | |
830 } | |
831 } break; | |
832 | |
0 | 833 case JVM_CONSTANT_UnresolvedString: |
834 { | |
835 symbolOop s1 = unresolved_string_at(index1); | |
836 symbolOop s2 = cp2->unresolved_string_at(index2); | |
837 if (s1 == s2) { | |
838 return true; | |
839 } | |
840 } break; | |
841 | |
842 case JVM_CONSTANT_Utf8: | |
843 { | |
844 symbolOop s1 = symbol_at(index1); | |
845 symbolOop s2 = cp2->symbol_at(index2); | |
846 if (s1 == s2) { | |
847 return true; | |
848 } | |
849 } break; | |
850 | |
851 // Invalid is used as the tag for the second constant pool entry | |
852 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should | |
853 // not be seen by itself. | |
854 case JVM_CONSTANT_Invalid: // fall through | |
855 | |
856 default: | |
857 ShouldNotReachHere(); | |
858 break; | |
859 } | |
860 | |
861 return false; | |
862 } // end compare_entry_to() | |
863 | |
864 | |
865 // Copy this constant pool's entries at start_i to end_i (inclusive) | |
866 // to the constant pool to_cp's entries starting at to_i. A total of | |
867 // (end_i - start_i) + 1 entries are copied. | |
868 void constantPoolOopDesc::copy_cp_to(int start_i, int end_i, | |
869 constantPoolHandle to_cp, int to_i, TRAPS) { | |
870 | |
871 int dest_i = to_i; // leave original alone for debug purposes | |
872 | |
873 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) { | |
874 copy_entry_to(src_i, to_cp, dest_i, CHECK); | |
875 | |
876 switch (tag_at(src_i).value()) { | |
877 case JVM_CONSTANT_Double: | |
878 case JVM_CONSTANT_Long: | |
879 // double and long take two constant pool entries | |
880 src_i += 2; | |
881 dest_i += 2; | |
882 break; | |
883 | |
884 default: | |
885 // all others take one constant pool entry | |
886 src_i++; | |
887 dest_i++; | |
888 break; | |
889 } | |
890 } | |
891 } // end copy_cp_to() | |
892 | |
893 | |
894 // Copy this constant pool's entry at from_i to the constant pool | |
895 // to_cp's entry at to_i. | |
896 void constantPoolOopDesc::copy_entry_to(int from_i, constantPoolHandle to_cp, | |
897 int to_i, TRAPS) { | |
898 | |
899 switch (tag_at(from_i).value()) { | |
900 case JVM_CONSTANT_Class: | |
901 { | |
902 klassOop k = klass_at(from_i, CHECK); | |
903 to_cp->klass_at_put(to_i, k); | |
904 } break; | |
905 | |
906 case JVM_CONSTANT_ClassIndex: | |
907 { | |
908 jint ki = klass_index_at(from_i); | |
909 to_cp->klass_index_at_put(to_i, ki); | |
910 } break; | |
911 | |
912 case JVM_CONSTANT_Double: | |
913 { | |
914 jdouble d = double_at(from_i); | |
915 to_cp->double_at_put(to_i, d); | |
916 // double takes two constant pool entries so init second entry's tag | |
917 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); | |
918 } break; | |
919 | |
920 case JVM_CONSTANT_Fieldref: | |
921 { | |
922 int class_index = uncached_klass_ref_index_at(from_i); | |
923 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
924 to_cp->field_at_put(to_i, class_index, name_and_type_index); | |
925 } break; | |
926 | |
927 case JVM_CONSTANT_Float: | |
928 { | |
929 jfloat f = float_at(from_i); | |
930 to_cp->float_at_put(to_i, f); | |
931 } break; | |
932 | |
933 case JVM_CONSTANT_Integer: | |
934 { | |
935 jint i = int_at(from_i); | |
936 to_cp->int_at_put(to_i, i); | |
937 } break; | |
938 | |
939 case JVM_CONSTANT_InterfaceMethodref: | |
940 { | |
941 int class_index = uncached_klass_ref_index_at(from_i); | |
942 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
943 to_cp->interface_method_at_put(to_i, class_index, name_and_type_index); | |
944 } break; | |
945 | |
946 case JVM_CONSTANT_Long: | |
947 { | |
948 jlong l = long_at(from_i); | |
949 to_cp->long_at_put(to_i, l); | |
950 // long takes two constant pool entries so init second entry's tag | |
951 to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid); | |
952 } break; | |
953 | |
954 case JVM_CONSTANT_Methodref: | |
955 { | |
956 int class_index = uncached_klass_ref_index_at(from_i); | |
957 int name_and_type_index = uncached_name_and_type_ref_index_at(from_i); | |
958 to_cp->method_at_put(to_i, class_index, name_and_type_index); | |
959 } break; | |
960 | |
961 case JVM_CONSTANT_NameAndType: | |
962 { | |
963 int name_ref_index = name_ref_index_at(from_i); | |
964 int signature_ref_index = signature_ref_index_at(from_i); | |
965 to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index); | |
966 } break; | |
967 | |
968 case JVM_CONSTANT_String: | |
969 { | |
970 oop s = string_at(from_i, CHECK); | |
971 to_cp->string_at_put(to_i, s); | |
972 } break; | |
973 | |
974 case JVM_CONSTANT_StringIndex: | |
975 { | |
976 jint si = string_index_at(from_i); | |
977 to_cp->string_index_at_put(to_i, si); | |
978 } break; | |
979 | |
980 case JVM_CONSTANT_UnresolvedClass: | |
981 { | |
982 symbolOop k = unresolved_klass_at(from_i); | |
983 to_cp->unresolved_klass_at_put(to_i, k); | |
984 } break; | |
985 | |
986 case JVM_CONSTANT_UnresolvedClassInError: | |
987 { | |
988 symbolOop k = unresolved_klass_at(from_i); | |
989 to_cp->unresolved_klass_at_put(to_i, k); | |
990 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError); | |
991 } break; | |
992 | |
993 | |
994 case JVM_CONSTANT_UnresolvedString: | |
995 { | |
996 symbolOop s = unresolved_string_at(from_i); | |
997 to_cp->unresolved_string_at_put(to_i, s); | |
998 } break; | |
999 | |
1000 case JVM_CONSTANT_Utf8: | |
1001 { | |
1002 symbolOop s = symbol_at(from_i); | |
1003 to_cp->symbol_at_put(to_i, s); | |
1004 } break; | |
1005 | |
1602 | 1006 case JVM_CONSTANT_MethodType: |
1007 { | |
1008 jint k = method_type_index_at(from_i); | |
1009 to_cp->method_type_index_at_put(to_i, k); | |
1010 } break; | |
1011 | |
1012 case JVM_CONSTANT_MethodHandle: | |
1013 { | |
1014 int k1 = method_handle_ref_kind_at(from_i); | |
1015 int k2 = method_handle_index_at(from_i); | |
1016 to_cp->method_handle_index_at_put(to_i, k1, k2); | |
1017 } break; | |
1018 | |
0 | 1019 // Invalid is used as the tag for the second constant pool entry |
1020 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should | |
1021 // not be seen by itself. | |
1022 case JVM_CONSTANT_Invalid: // fall through | |
1023 | |
1024 default: | |
1025 { | |
1026 jbyte bad_value = tag_at(from_i).value(); // leave a breadcrumb | |
1027 ShouldNotReachHere(); | |
1028 } break; | |
1029 } | |
1030 } // end copy_entry_to() | |
1031 | |
1032 | |
1033 // Search constant pool search_cp for an entry that matches this | |
1034 // constant pool's entry at pattern_i. Returns the index of a | |
1035 // matching entry or zero (0) if there is no matching entry. | |
1036 int constantPoolOopDesc::find_matching_entry(int pattern_i, | |
1037 constantPoolHandle search_cp, TRAPS) { | |
1038 | |
1039 // index zero (0) is not used | |
1040 for (int i = 1; i < search_cp->length(); i++) { | |
1041 bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0); | |
1042 if (found) { | |
1043 return i; | |
1044 } | |
1045 } | |
1046 | |
1047 return 0; // entry not found; return unused index zero (0) | |
1048 } // end find_matching_entry() | |
1049 | |
1050 | |
1051 #ifndef PRODUCT | |
1052 | |
1053 const char* constantPoolOopDesc::printable_name_at(int which) { | |
1054 | |
1055 constantTag tag = tag_at(which); | |
1056 | |
1057 if (tag.is_unresolved_string() || tag.is_string()) { | |
1058 return string_at_noresolve(which); | |
1059 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | |
1060 return klass_name_at(which)->as_C_string(); | |
1061 } else if (tag.is_symbol()) { | |
1062 return symbol_at(which)->as_C_string(); | |
1063 } | |
1064 return ""; | |
1065 } | |
1066 | |
1067 #endif // PRODUCT | |
1068 | |
1069 | |
1070 // JVMTI GetConstantPool support | |
1071 | |
1072 // For temporary use until code is stable. | |
1073 #define DBG(code) | |
1074 | |
1075 static const char* WARN_MSG = "Must not be such entry!"; | |
1076 | |
1077 static void print_cpool_bytes(jint cnt, u1 *bytes) { | |
1078 jint size = 0; | |
1079 u2 idx1, idx2; | |
1080 | |
1081 for (jint idx = 1; idx < cnt; idx++) { | |
1082 jint ent_size = 0; | |
1083 u1 tag = *bytes++; | |
1084 size++; // count tag | |
1085 | |
1086 printf("const #%03d, tag: %02d ", idx, tag); | |
1087 switch(tag) { | |
1088 case JVM_CONSTANT_Invalid: { | |
1089 printf("Invalid"); | |
1090 break; | |
1091 } | |
1092 case JVM_CONSTANT_Unicode: { | |
1093 printf("Unicode %s", WARN_MSG); | |
1094 break; | |
1095 } | |
1096 case JVM_CONSTANT_Utf8: { | |
1097 u2 len = Bytes::get_Java_u2(bytes); | |
1098 char str[128]; | |
1099 if (len > 127) { | |
1100 len = 127; | |
1101 } | |
1102 strncpy(str, (char *) (bytes+2), len); | |
1103 str[len] = '\0'; | |
1104 printf("Utf8 \"%s\"", str); | |
1105 ent_size = 2 + len; | |
1106 break; | |
1107 } | |
1108 case JVM_CONSTANT_Integer: { | |
1109 u4 val = Bytes::get_Java_u4(bytes); | |
1110 printf("int %d", *(int *) &val); | |
1111 ent_size = 4; | |
1112 break; | |
1113 } | |
1114 case JVM_CONSTANT_Float: { | |
1115 u4 val = Bytes::get_Java_u4(bytes); | |
1116 printf("float %5.3ff", *(float *) &val); | |
1117 ent_size = 4; | |
1118 break; | |
1119 } | |
1120 case JVM_CONSTANT_Long: { | |
1121 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
|
1122 printf("long "INT64_FORMAT, *(jlong *) &val); |
0 | 1123 ent_size = 8; |
1124 idx++; // Long takes two cpool slots | |
1125 break; | |
1126 } | |
1127 case JVM_CONSTANT_Double: { | |
1128 u8 val = Bytes::get_Java_u8(bytes); | |
1129 printf("double %5.3fd", *(jdouble *)&val); | |
1130 ent_size = 8; | |
1131 idx++; // Double takes two cpool slots | |
1132 break; | |
1133 } | |
1134 case JVM_CONSTANT_Class: { | |
1135 idx1 = Bytes::get_Java_u2(bytes); | |
1136 printf("class #%03d", idx1); | |
1137 ent_size = 2; | |
1138 break; | |
1139 } | |
1140 case JVM_CONSTANT_String: { | |
1141 idx1 = Bytes::get_Java_u2(bytes); | |
1142 printf("String #%03d", idx1); | |
1143 ent_size = 2; | |
1144 break; | |
1145 } | |
1146 case JVM_CONSTANT_Fieldref: { | |
1147 idx1 = Bytes::get_Java_u2(bytes); | |
1148 idx2 = Bytes::get_Java_u2(bytes+2); | |
1149 printf("Field #%03d, #%03d", (int) idx1, (int) idx2); | |
1150 ent_size = 4; | |
1151 break; | |
1152 } | |
1153 case JVM_CONSTANT_Methodref: { | |
1154 idx1 = Bytes::get_Java_u2(bytes); | |
1155 idx2 = Bytes::get_Java_u2(bytes+2); | |
1156 printf("Method #%03d, #%03d", idx1, idx2); | |
1157 ent_size = 4; | |
1158 break; | |
1159 } | |
1160 case JVM_CONSTANT_InterfaceMethodref: { | |
1161 idx1 = Bytes::get_Java_u2(bytes); | |
1162 idx2 = Bytes::get_Java_u2(bytes+2); | |
1163 printf("InterfMethod #%03d, #%03d", idx1, idx2); | |
1164 ent_size = 4; | |
1165 break; | |
1166 } | |
1167 case JVM_CONSTANT_NameAndType: { | |
1168 idx1 = Bytes::get_Java_u2(bytes); | |
1169 idx2 = Bytes::get_Java_u2(bytes+2); | |
1170 printf("NameAndType #%03d, #%03d", idx1, idx2); | |
1171 ent_size = 4; | |
1172 break; | |
1173 } | |
1174 case JVM_CONSTANT_ClassIndex: { | |
1175 printf("ClassIndex %s", WARN_MSG); | |
1176 break; | |
1177 } | |
1178 case JVM_CONSTANT_UnresolvedClass: { | |
1179 printf("UnresolvedClass: %s", WARN_MSG); | |
1180 break; | |
1181 } | |
1182 case JVM_CONSTANT_UnresolvedClassInError: { | |
1183 printf("UnresolvedClassInErr: %s", WARN_MSG); | |
1184 break; | |
1185 } | |
1186 case JVM_CONSTANT_StringIndex: { | |
1187 printf("StringIndex: %s", WARN_MSG); | |
1188 break; | |
1189 } | |
1190 case JVM_CONSTANT_UnresolvedString: { | |
1191 printf("UnresolvedString: %s", WARN_MSG); | |
1192 break; | |
1193 } | |
1194 } | |
1195 printf(";\n"); | |
1196 bytes += ent_size; | |
1197 size += ent_size; | |
1198 } | |
1199 printf("Cpool size: %d\n", size); | |
1200 fflush(0); | |
1201 return; | |
1202 } /* end print_cpool_bytes */ | |
1203 | |
1204 | |
1205 // Returns size of constant pool entry. | |
1206 jint constantPoolOopDesc::cpool_entry_size(jint idx) { | |
1207 switch(tag_at(idx).value()) { | |
1208 case JVM_CONSTANT_Invalid: | |
1209 case JVM_CONSTANT_Unicode: | |
1210 return 1; | |
1211 | |
1212 case JVM_CONSTANT_Utf8: | |
1213 return 3 + symbol_at(idx)->utf8_length(); | |
1214 | |
1215 case JVM_CONSTANT_Class: | |
1216 case JVM_CONSTANT_String: | |
1217 case JVM_CONSTANT_ClassIndex: | |
1218 case JVM_CONSTANT_UnresolvedClass: | |
1219 case JVM_CONSTANT_UnresolvedClassInError: | |
1220 case JVM_CONSTANT_StringIndex: | |
1221 case JVM_CONSTANT_UnresolvedString: | |
1602 | 1222 case JVM_CONSTANT_MethodType: |
0 | 1223 return 3; |
1224 | |
1602 | 1225 case JVM_CONSTANT_MethodHandle: |
1226 return 4; //tag, ref_kind, ref_index | |
1227 | |
0 | 1228 case JVM_CONSTANT_Integer: |
1229 case JVM_CONSTANT_Float: | |
1230 case JVM_CONSTANT_Fieldref: | |
1231 case JVM_CONSTANT_Methodref: | |
1232 case JVM_CONSTANT_InterfaceMethodref: | |
1233 case JVM_CONSTANT_NameAndType: | |
1234 return 5; | |
1235 | |
1236 case JVM_CONSTANT_Long: | |
1237 case JVM_CONSTANT_Double: | |
1238 return 9; | |
1239 } | |
1240 assert(false, "cpool_entry_size: Invalid constant pool entry tag"); | |
1241 return 1; | |
1242 } /* end cpool_entry_size */ | |
1243 | |
1244 | |
1245 // SymbolHashMap is used to find a constant pool index from a string. | |
1246 // This function fills in SymbolHashMaps, one for utf8s and one for | |
1247 // class names, returns size of the cpool raw bytes. | |
1248 jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap, | |
1249 SymbolHashMap *classmap) { | |
1250 jint size = 0; | |
1251 | |
1252 for (u2 idx = 1; idx < length(); idx++) { | |
1253 u2 tag = tag_at(idx).value(); | |
1254 size += cpool_entry_size(idx); | |
1255 | |
1256 switch(tag) { | |
1257 case JVM_CONSTANT_Utf8: { | |
1258 symbolOop sym = symbol_at(idx); | |
1259 symmap->add_entry(sym, idx); | |
1260 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx)); | |
1261 break; | |
1262 } | |
1263 case JVM_CONSTANT_Class: | |
1264 case JVM_CONSTANT_UnresolvedClass: | |
1265 case JVM_CONSTANT_UnresolvedClassInError: { | |
1266 symbolOop sym = klass_name_at(idx); | |
1267 classmap->add_entry(sym, idx); | |
1268 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx)); | |
1269 break; | |
1270 } | |
1271 case JVM_CONSTANT_Long: | |
1272 case JVM_CONSTANT_Double: { | |
1273 idx++; // Both Long and Double take two cpool slots | |
1274 break; | |
1275 } | |
1276 } | |
1277 } | |
1278 return size; | |
1279 } /* end hash_utf8_entries_to */ | |
1280 | |
1281 | |
1282 // Copy cpool bytes. | |
1283 // Returns: | |
1284 // 0, in case of OutOfMemoryError | |
1285 // -1, in case of internal error | |
1286 // > 0, count of the raw cpool bytes that have been copied | |
1287 int constantPoolOopDesc::copy_cpool_bytes(int cpool_size, | |
1288 SymbolHashMap* tbl, | |
1289 unsigned char *bytes) { | |
1290 u2 idx1, idx2; | |
1291 jint size = 0; | |
1292 jint cnt = length(); | |
1293 unsigned char *start_bytes = bytes; | |
1294 | |
1295 for (jint idx = 1; idx < cnt; idx++) { | |
1296 u1 tag = tag_at(idx).value(); | |
1297 jint ent_size = cpool_entry_size(idx); | |
1298 | |
1299 assert(size + ent_size <= cpool_size, "Size mismatch"); | |
1300 | |
1301 *bytes = tag; | |
1302 DBG(printf("#%03hd tag=%03hd, ", idx, tag)); | |
1303 switch(tag) { | |
1304 case JVM_CONSTANT_Invalid: { | |
1305 DBG(printf("JVM_CONSTANT_Invalid")); | |
1306 break; | |
1307 } | |
1308 case JVM_CONSTANT_Unicode: { | |
1309 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode"); | |
1310 DBG(printf("JVM_CONSTANT_Unicode")); | |
1311 break; | |
1312 } | |
1313 case JVM_CONSTANT_Utf8: { | |
1314 symbolOop sym = symbol_at(idx); | |
1315 char* str = sym->as_utf8(); | |
1316 // Warning! It's crashing on x86 with len = sym->utf8_length() | |
1317 int len = (int) strlen(str); | |
1318 Bytes::put_Java_u2((address) (bytes+1), (u2) len); | |
1319 for (int i = 0; i < len; i++) { | |
1320 bytes[3+i] = (u1) str[i]; | |
1321 } | |
1322 DBG(printf("JVM_CONSTANT_Utf8: %s ", str)); | |
1323 break; | |
1324 } | |
1325 case JVM_CONSTANT_Integer: { | |
1326 jint val = int_at(idx); | |
1327 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); | |
1328 break; | |
1329 } | |
1330 case JVM_CONSTANT_Float: { | |
1331 jfloat val = float_at(idx); | |
1332 Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val); | |
1333 break; | |
1334 } | |
1335 case JVM_CONSTANT_Long: { | |
1336 jlong val = long_at(idx); | |
1337 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); | |
1338 idx++; // Long takes two cpool slots | |
1339 break; | |
1340 } | |
1341 case JVM_CONSTANT_Double: { | |
1342 jdouble val = double_at(idx); | |
1343 Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val); | |
1344 idx++; // Double takes two cpool slots | |
1345 break; | |
1346 } | |
1347 case JVM_CONSTANT_Class: | |
1348 case JVM_CONSTANT_UnresolvedClass: | |
1349 case JVM_CONSTANT_UnresolvedClassInError: { | |
1350 *bytes = JVM_CONSTANT_Class; | |
1351 symbolOop sym = klass_name_at(idx); | |
1352 idx1 = tbl->symbol_to_value(sym); | |
1353 assert(idx1 != 0, "Have not found a hashtable entry"); | |
1354 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1355 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8())); | |
1356 break; | |
1357 } | |
1358 case JVM_CONSTANT_String: { | |
1359 unsigned int hash; | |
1360 char *str = string_at_noresolve(idx); | |
1361 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
|
1362 if (sym == NULL) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1363 // 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
|
1364 // 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
|
1365 oop string = *(obj_at_addr(idx)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1366 assert(java_lang_String::is_instance(string),"Not a String"); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1367 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1368 idx1 = 0; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1369 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
|
1370 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
|
1371 int length; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1372 sym = cur->symbol(); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1373 jchar* chars = sym->as_unicode(length); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1374 if (java_lang_String::equals(string, chars, length)) { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1375 idx1 = cur->value(); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1376 DBG(printf("Index found: %d\n",idx1)); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1377 break; |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1378 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1379 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1380 } |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1381 } else { |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1382 idx1 = tbl->symbol_to_value(sym); |
47ffceb239d0
6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents:
726
diff
changeset
|
1383 } |
0 | 1384 assert(idx1 != 0, "Have not found a hashtable entry"); |
1385 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1386 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str)); | |
1387 break; | |
1388 } | |
1389 case JVM_CONSTANT_UnresolvedString: { | |
1390 *bytes = JVM_CONSTANT_String; | |
1391 symbolOop sym = unresolved_string_at(idx); | |
1392 idx1 = tbl->symbol_to_value(sym); | |
1393 assert(idx1 != 0, "Have not found a hashtable entry"); | |
1394 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1395 DBG(char *str = sym->as_utf8()); | |
1396 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str)); | |
1397 break; | |
1398 } | |
1399 case JVM_CONSTANT_Fieldref: | |
1400 case JVM_CONSTANT_Methodref: | |
1401 case JVM_CONSTANT_InterfaceMethodref: { | |
1402 idx1 = uncached_klass_ref_index_at(idx); | |
1403 idx2 = uncached_name_and_type_ref_index_at(idx); | |
1404 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1405 Bytes::put_Java_u2((address) (bytes+3), idx2); | |
1406 DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2)); | |
1407 break; | |
1408 } | |
1409 case JVM_CONSTANT_NameAndType: { | |
1410 idx1 = name_ref_index_at(idx); | |
1411 idx2 = signature_ref_index_at(idx); | |
1412 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1413 Bytes::put_Java_u2((address) (bytes+3), idx2); | |
1414 DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2)); | |
1415 break; | |
1416 } | |
1417 case JVM_CONSTANT_ClassIndex: { | |
1418 *bytes = JVM_CONSTANT_Class; | |
1419 idx1 = klass_index_at(idx); | |
1420 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1421 DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1)); | |
1422 break; | |
1423 } | |
1424 case JVM_CONSTANT_StringIndex: { | |
1425 *bytes = JVM_CONSTANT_String; | |
1426 idx1 = string_index_at(idx); | |
1427 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1428 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); | |
1429 break; | |
1430 } | |
1602 | 1431 case JVM_CONSTANT_MethodHandle: { |
1432 *bytes = JVM_CONSTANT_MethodHandle; | |
1433 int kind = method_handle_ref_kind_at(idx); | |
1434 idx1 = method_handle_index_at(idx); | |
1435 *(bytes+1) = (unsigned char) kind; | |
1436 Bytes::put_Java_u2((address) (bytes+2), idx1); | |
1437 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); | |
1438 break; | |
1439 } | |
1440 case JVM_CONSTANT_MethodType: { | |
1441 *bytes = JVM_CONSTANT_MethodType; | |
1442 idx1 = method_type_index_at(idx); | |
1443 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1444 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); | |
1445 break; | |
1446 } | |
0 | 1447 } |
1448 DBG(printf("\n")); | |
1449 bytes += ent_size; | |
1450 size += ent_size; | |
1451 } | |
1452 assert(size == cpool_size, "Size mismatch"); | |
1453 | |
1454 // Keep temorarily for debugging until it's stable. | |
1455 DBG(print_cpool_bytes(cnt, start_bytes)); | |
1456 return (int)(bytes - start_bytes); | |
1457 } /* end copy_cpool_bytes */ | |
1458 | |
1459 | |
1460 void SymbolHashMap::add_entry(symbolOop sym, u2 value) { | |
1461 char *str = sym->as_utf8(); | |
1462 unsigned int hash = compute_hash(str, sym->utf8_length()); | |
1463 unsigned int index = hash % table_size(); | |
1464 | |
1465 // check if already in map | |
1466 // we prefer the first entry since it is more likely to be what was used in | |
1467 // the class file | |
1468 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { | |
1469 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1470 if (en->hash() == hash && en->symbol() == sym) { | |
1471 return; // already there | |
1472 } | |
1473 } | |
1474 | |
1475 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); | |
1476 entry->set_next(bucket(index)); | |
1477 _buckets[index].set_entry(entry); | |
1478 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1479 } | |
1480 | |
1481 SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) { | |
1482 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL"); | |
1483 char *str = sym->as_utf8(); | |
1484 int len = sym->utf8_length(); | |
1485 unsigned int hash = SymbolHashMap::compute_hash(str, len); | |
1486 unsigned int index = hash % table_size(); | |
1487 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { | |
1488 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); | |
1489 if (en->hash() == hash && en->symbol() == sym) { | |
1490 return en; | |
1491 } | |
1492 } | |
1493 return NULL; | |
1494 } |