annotate src/share/vm/oops/constantPoolOop.cpp @ 516:fc7ab6287598

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