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