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