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