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