Mercurial > hg > truffle
comparison src/share/vm/interpreter/bytecode.cpp @ 1602:136b78722a08
6939203: JSR 292 needs method handle constants
Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode.
Reviewed-by: twisti, never
author | jrose |
---|---|
date | Wed, 09 Jun 2010 18:50:45 -0700 |
parents | e9ff18c4ace7 |
children | f95d63e2154a |
comparison
equal
deleted
inserted
replaced
1585:49fac4acd688 | 1602:136b78722a08 |
---|---|
134 | 134 |
135 | 135 |
136 // Implementation of Bytecode_invoke | 136 // Implementation of Bytecode_invoke |
137 | 137 |
138 void Bytecode_invoke::verify() const { | 138 void Bytecode_invoke::verify() const { |
139 Bytecodes::Code bc = adjusted_invoke_code(); | |
140 assert(is_valid(), "check invoke"); | 139 assert(is_valid(), "check invoke"); |
141 assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter"); | 140 assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter"); |
142 } | 141 } |
143 | 142 |
144 | 143 |
145 symbolOop Bytecode_invoke::signature() const { | 144 symbolOop Bytecode_member_ref::signature() const { |
146 constantPoolOop constants = method()->constants(); | 145 constantPoolOop constants = method()->constants(); |
147 return constants->signature_ref_at(index()); | 146 return constants->signature_ref_at(index()); |
148 } | 147 } |
149 | 148 |
150 | 149 |
151 symbolOop Bytecode_invoke::name() const { | 150 symbolOop Bytecode_member_ref::name() const { |
152 constantPoolOop constants = method()->constants(); | 151 constantPoolOop constants = method()->constants(); |
153 return constants->name_ref_at(index()); | 152 return constants->name_ref_at(index()); |
154 } | 153 } |
155 | 154 |
156 | 155 |
157 BasicType Bytecode_invoke::result_type(Thread *thread) const { | 156 BasicType Bytecode_member_ref::result_type(Thread *thread) const { |
158 symbolHandle sh(thread, signature()); | 157 symbolHandle sh(thread, signature()); |
159 ResultTypeFinder rts(sh); | 158 ResultTypeFinder rts(sh); |
160 rts.iterate(); | 159 rts.iterate(); |
161 return rts.type(); | 160 return rts.type(); |
162 } | 161 } |
165 methodHandle Bytecode_invoke::static_target(TRAPS) { | 164 methodHandle Bytecode_invoke::static_target(TRAPS) { |
166 methodHandle m; | 165 methodHandle m; |
167 KlassHandle resolved_klass; | 166 KlassHandle resolved_klass; |
168 constantPoolHandle constants(THREAD, _method->constants()); | 167 constantPoolHandle constants(THREAD, _method->constants()); |
169 | 168 |
170 if (adjusted_invoke_code() == Bytecodes::_invokedynamic) { | 169 if (java_code() == Bytecodes::_invokedynamic) { |
171 LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); | 170 LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
172 } else if (adjusted_invoke_code() != Bytecodes::_invokeinterface) { | 171 } else if (java_code() != Bytecodes::_invokeinterface) { |
173 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); | 172 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
174 } else { | 173 } else { |
175 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); | 174 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
176 } | 175 } |
177 return m; | 176 return m; |
178 } | 177 } |
179 | 178 |
180 | 179 |
181 int Bytecode_invoke::index() const { | 180 int Bytecode_member_ref::index() const { |
182 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, | 181 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
183 // at the same time it allocates per-call-site CP cache entries. | 182 // at the same time it allocates per-call-site CP cache entries. |
184 Bytecodes::Code stdc = Bytecodes::java_code(code()); | 183 Bytecodes::Code rawc = code(); |
185 Bytecode* invoke = Bytecode_at(bcp()); | 184 Bytecode* invoke = bytecode(); |
186 if (invoke->has_index_u4(stdc)) | 185 if (invoke->has_index_u4(rawc)) |
187 return invoke->get_index_u4(stdc); | 186 return invoke->get_index_u4(rawc); |
188 else | 187 else |
189 return invoke->get_index_u2_cpcache(stdc); | 188 return invoke->get_index_u2_cpcache(rawc); |
190 } | 189 } |
191 | 190 |
191 int Bytecode_member_ref::pool_index() const { | |
192 int index = this->index(); | |
193 DEBUG_ONLY({ | |
194 if (!bytecode()->has_index_u4(code())) | |
195 index -= constantPoolOopDesc::CPCACHE_INDEX_TAG; | |
196 }); | |
197 return _method->constants()->cache()->entry_at(index)->constant_pool_index(); | |
198 } | |
192 | 199 |
193 // Implementation of Bytecode_field | 200 // Implementation of Bytecode_field |
194 | 201 |
195 void Bytecode_field::verify() const { | 202 void Bytecode_field::verify() const { |
196 Bytecodes::Code stdc = Bytecodes::java_code(code()); | 203 assert(is_valid(), "check field"); |
197 assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic || | 204 } |
198 stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field"); | 205 |
199 } | 206 |
200 | 207 // Implementation of Bytecode_loadconstant |
201 | 208 |
202 bool Bytecode_field::is_static() const { | 209 int Bytecode_loadconstant::raw_index() const { |
203 Bytecodes::Code stdc = Bytecodes::java_code(code()); | 210 Bytecode* bcp = bytecode(); |
204 return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic; | 211 Bytecodes::Code rawc = bcp->code(); |
205 } | 212 assert(rawc != Bytecodes::_wide, "verifier prevents this"); |
206 | 213 if (Bytecodes::java_code(rawc) == Bytecodes::_ldc) |
207 | 214 return bcp->get_index_u1(rawc); |
208 int Bytecode_field::index() const { | 215 else |
209 Bytecode* invoke = Bytecode_at(bcp()); | 216 return bcp->get_index_u2(rawc, false); |
210 return invoke->get_index_u2_cpcache(Bytecodes::_getfield); | 217 } |
211 } | 218 |
212 | 219 int Bytecode_loadconstant::pool_index() const { |
213 | 220 int index = raw_index(); |
214 // Implementation of Bytecodes loac constant | 221 if (has_cache_index()) { |
215 | 222 return _method->constants()->cache()->entry_at(index)->constant_pool_index(); |
216 int Bytecode_loadconstant::index() const { | 223 } |
217 Bytecodes::Code stdc = Bytecodes::java_code(code()); | 224 return index; |
218 if (stdc != Bytecodes::_wide) { | 225 } |
219 if (Bytecodes::java_code(stdc) == Bytecodes::_ldc) | 226 |
220 return get_index_u1(stdc); | 227 BasicType Bytecode_loadconstant::result_type() const { |
221 else | 228 int index = pool_index(); |
222 return get_index_u2(stdc, false); | 229 constantTag tag = _method->constants()->tag_at(index); |
223 } | 230 return tag.basic_type(); |
224 stdc = Bytecodes::code_at(addr_at(1)); | 231 } |
225 return get_index_u2(stdc, true); | 232 |
233 oop Bytecode_loadconstant::resolve_constant(TRAPS) const { | |
234 assert(_method.not_null(), "must supply method to resolve constant"); | |
235 int index = raw_index(); | |
236 constantPoolOop constants = _method->constants(); | |
237 if (has_cache_index()) { | |
238 return constants->resolve_cached_constant_at(index, THREAD); | |
239 } else { | |
240 return constants->resolve_constant_at(index, THREAD); | |
241 } | |
226 } | 242 } |
227 | 243 |
228 //------------------------------------------------------------------------------ | 244 //------------------------------------------------------------------------------ |
229 // Non-product code | 245 // Non-product code |
230 | 246 |