151 // This routine is called only in corner cases where the CPCE is not yet initialized.
152 // See AbstractInterpreter::deopt_continue_after_entry.
153 assert(_flags == 0 || parameter_size() == 0 || parameter_size() == value,
154 "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
155 // Setting the parameter size by itself is only safe if the
156 // current value of _flags is 0, otherwise another thread may have
157 // updated it and we don't want to overwrite that value. Don't
158 // bother trying to update it once it's nonzero but always make
159 // sure that the final parameter size agrees with what was passed.
160 if (_flags == 0) {
161 intx newflags = (value & parameter_size_mask);
162 Atomic::cmpxchg(newflags, &_flags, (intx)0);
163 }
164 guarantee(parameter_size() == value,
165 "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
166 }
167
168 void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
169 const methodHandle& method,
170 int vtable_index,
171 bool sender_is_interface,
172 InstanceKlass* pool_holder) {
173 bool is_vtable_call = (vtable_index >= 0); // FIXME: split this method on this boolean
174 assert(method->interpreter_entry() != NULL, "should have been set at this point");
175 assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
176
177 int byte_no = -1;
178 bool change_to_virtual = false;
179 InstanceKlass* holder = NULL; // have to declare this outside the switch
180 switch (invoke_code) {
181 case Bytecodes::_invokeinterface:
182 holder = method->method_holder();
183 // check for private interface method invocations
184 if (vtable_index == Method::nonvirtual_vtable_index && holder->is_interface() ) {
185 assert(method->is_private(), "unexpected non-private method");
186 assert(method->can_be_statically_bound(), "unexpected non-statically-bound method");
187 // set_f2_as_vfinal_method checks if is_vfinal flag is true.
188 set_method_flags(as_TosState(method->result_type()),
189 ( 1 << is_vfinal_shift) |
190 ((method->is_final_method() ? 1 : 0) << is_final_shift),
191 method()->size_of_parameters());
192 set_f2_as_vfinal_method(method());
247 break;
248 default:
249 ShouldNotReachHere();
250 break;
251 }
252
253 // Note: byte_no also appears in TemplateTable::resolve.
254 if (byte_no == 1) {
255 assert(invoke_code != Bytecodes::_invokevirtual &&
256 invoke_code != Bytecodes::_invokeinterface, "");
257 bool do_resolve = true;
258 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
259 // has to be checked that it is a subclass of the current class every time this bytecode
260 // is executed.
261 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
262 method->name() != vmSymbols::object_initializer_name()) {
263 do_resolve = false;
264 }
265 // Don't mark invokestatic to method as resolved if the holder class has not yet completed
266 // initialization. An invokestatic must only proceed if the class is initialized, but if
267 // we resolve it before then that class initialization check is skipped. However if the call
268 // is from the same class we can resolve as we must be executing with <clinit> on our call stack.
269 if (invoke_code == Bytecodes::_invokestatic &&
270 !method->method_holder()->is_initialized() &&
271 method->method_holder() != pool_holder) {
272 do_resolve = false;
273 }
274 if (do_resolve) {
275 assert(method->method_holder()->is_initialized() ||
276 method->method_holder()->is_reentrant_initialization(Thread::current()),
277 "invalid class initalization state");
278 set_bytecode_1(invoke_code);
279 }
280 } else if (byte_no == 2) {
281 if (change_to_virtual) {
282 assert(invoke_code == Bytecodes::_invokeinterface, "");
283 // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
284 //
285 // Workaround for the case where we encounter an invokeinterface, but we
286 // should really have an _invokevirtual since the resolved method is a
287 // virtual method in java.lang.Object. This is a corner case in the spec
288 // but is presumably legal. javac does not generate this code.
289 //
290 // We do not set bytecode_1() to _invokeinterface, because that is the
291 // bytecode # used by the interpreter to see if it is resolved. In this
292 // case, the method gets reresolved with caller for each interface call
293 // because the actual selected method may not be public.
294 //
295 // We set bytecode_2() to _invokevirtual.
296 // See also interpreterRuntime.cpp. (8/25/2000)
297 } else {
300 ((method->is_private() ||
301 (method->is_final() && method->method_holder() == SystemDictionary::Object_klass())))),
302 "unexpected invocation mode");
303 if (invoke_code == Bytecodes::_invokeinterface &&
304 (method->is_private() || method->is_final())) {
305 // We set bytecode_1() to _invokeinterface, because that is the
306 // bytecode # used by the interpreter to see if it is resolved.
307 // We set bytecode_2() to _invokevirtual.
308 set_bytecode_1(invoke_code);
309 }
310 }
311 // set up for invokevirtual, even if linking for invokeinterface also:
312 set_bytecode_2(Bytecodes::_invokevirtual);
313 } else {
314 ShouldNotReachHere();
315 }
316 NOT_PRODUCT(verify(tty));
317 }
318
319 void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, const methodHandle& method,
320 bool sender_is_interface, InstanceKlass* pool_holder) {
321 int index = Method::nonvirtual_vtable_index;
322 // index < 0; FIXME: inline and customize set_direct_or_vtable_call
323 set_direct_or_vtable_call(invoke_code, method, index, sender_is_interface, pool_holder);
324 }
325
326 void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, const methodHandle& method, int index) {
327 // either the method is a miranda or its holder should accept the given index
328 assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
329 // index >= 0; FIXME: inline and customize set_direct_or_vtable_call
330 set_direct_or_vtable_call(invoke_code, method, index, false, NULL /* not used */);
331 }
332
333 void ConstantPoolCacheEntry::set_itable_call(Bytecodes::Code invoke_code,
334 Klass* referenced_klass,
335 const methodHandle& method, int index) {
336 assert(method->method_holder()->verify_itable_index(index), "");
337 assert(invoke_code == Bytecodes::_invokeinterface, "");
338 InstanceKlass* interf = method->method_holder();
339 assert(interf->is_interface(), "must be an interface");
340 assert(!method->is_final_method(), "interfaces do not have final methods; cannot link to one here");
341 set_f1(referenced_klass);
342 set_f2((intx)method());
343 set_method_flags(as_TosState(method->result_type()),
344 0, // no option bits
345 method()->size_of_parameters());
346 set_bytecode_1(Bytecodes::_invokeinterface);
347 }
348
349
350 void ConstantPoolCacheEntry::set_method_handle(const constantPoolHandle& cpool, const CallInfo &call_info) {
|
151 // This routine is called only in corner cases where the CPCE is not yet initialized.
152 // See AbstractInterpreter::deopt_continue_after_entry.
153 assert(_flags == 0 || parameter_size() == 0 || parameter_size() == value,
154 "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
155 // Setting the parameter size by itself is only safe if the
156 // current value of _flags is 0, otherwise another thread may have
157 // updated it and we don't want to overwrite that value. Don't
158 // bother trying to update it once it's nonzero but always make
159 // sure that the final parameter size agrees with what was passed.
160 if (_flags == 0) {
161 intx newflags = (value & parameter_size_mask);
162 Atomic::cmpxchg(newflags, &_flags, (intx)0);
163 }
164 guarantee(parameter_size() == value,
165 "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
166 }
167
168 void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
169 const methodHandle& method,
170 int vtable_index,
171 bool sender_is_interface) {
172 bool is_vtable_call = (vtable_index >= 0); // FIXME: split this method on this boolean
173 assert(method->interpreter_entry() != NULL, "should have been set at this point");
174 assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
175
176 int byte_no = -1;
177 bool change_to_virtual = false;
178 InstanceKlass* holder = NULL; // have to declare this outside the switch
179 switch (invoke_code) {
180 case Bytecodes::_invokeinterface:
181 holder = method->method_holder();
182 // check for private interface method invocations
183 if (vtable_index == Method::nonvirtual_vtable_index && holder->is_interface() ) {
184 assert(method->is_private(), "unexpected non-private method");
185 assert(method->can_be_statically_bound(), "unexpected non-statically-bound method");
186 // set_f2_as_vfinal_method checks if is_vfinal flag is true.
187 set_method_flags(as_TosState(method->result_type()),
188 ( 1 << is_vfinal_shift) |
189 ((method->is_final_method() ? 1 : 0) << is_final_shift),
190 method()->size_of_parameters());
191 set_f2_as_vfinal_method(method());
246 break;
247 default:
248 ShouldNotReachHere();
249 break;
250 }
251
252 // Note: byte_no also appears in TemplateTable::resolve.
253 if (byte_no == 1) {
254 assert(invoke_code != Bytecodes::_invokevirtual &&
255 invoke_code != Bytecodes::_invokeinterface, "");
256 bool do_resolve = true;
257 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
258 // has to be checked that it is a subclass of the current class every time this bytecode
259 // is executed.
260 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
261 method->name() != vmSymbols::object_initializer_name()) {
262 do_resolve = false;
263 }
264 // Don't mark invokestatic to method as resolved if the holder class has not yet completed
265 // initialization. An invokestatic must only proceed if the class is initialized, but if
266 // we resolve it before then that class initialization check is skipped.
267 if (invoke_code == Bytecodes::_invokestatic && !method->method_holder()->is_initialized()) {
268 do_resolve = false;
269 }
270 if (do_resolve) {
271 set_bytecode_1(invoke_code);
272 }
273 } else if (byte_no == 2) {
274 if (change_to_virtual) {
275 assert(invoke_code == Bytecodes::_invokeinterface, "");
276 // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
277 //
278 // Workaround for the case where we encounter an invokeinterface, but we
279 // should really have an _invokevirtual since the resolved method is a
280 // virtual method in java.lang.Object. This is a corner case in the spec
281 // but is presumably legal. javac does not generate this code.
282 //
283 // We do not set bytecode_1() to _invokeinterface, because that is the
284 // bytecode # used by the interpreter to see if it is resolved. In this
285 // case, the method gets reresolved with caller for each interface call
286 // because the actual selected method may not be public.
287 //
288 // We set bytecode_2() to _invokevirtual.
289 // See also interpreterRuntime.cpp. (8/25/2000)
290 } else {
293 ((method->is_private() ||
294 (method->is_final() && method->method_holder() == SystemDictionary::Object_klass())))),
295 "unexpected invocation mode");
296 if (invoke_code == Bytecodes::_invokeinterface &&
297 (method->is_private() || method->is_final())) {
298 // We set bytecode_1() to _invokeinterface, because that is the
299 // bytecode # used by the interpreter to see if it is resolved.
300 // We set bytecode_2() to _invokevirtual.
301 set_bytecode_1(invoke_code);
302 }
303 }
304 // set up for invokevirtual, even if linking for invokeinterface also:
305 set_bytecode_2(Bytecodes::_invokevirtual);
306 } else {
307 ShouldNotReachHere();
308 }
309 NOT_PRODUCT(verify(tty));
310 }
311
312 void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, const methodHandle& method,
313 bool sender_is_interface) {
314 int index = Method::nonvirtual_vtable_index;
315 // index < 0; FIXME: inline and customize set_direct_or_vtable_call
316 set_direct_or_vtable_call(invoke_code, method, index, sender_is_interface);
317 }
318
319 void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, const methodHandle& method, int index) {
320 // either the method is a miranda or its holder should accept the given index
321 assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
322 // index >= 0; FIXME: inline and customize set_direct_or_vtable_call
323 set_direct_or_vtable_call(invoke_code, method, index, false);
324 }
325
326 void ConstantPoolCacheEntry::set_itable_call(Bytecodes::Code invoke_code,
327 Klass* referenced_klass,
328 const methodHandle& method, int index) {
329 assert(method->method_holder()->verify_itable_index(index), "");
330 assert(invoke_code == Bytecodes::_invokeinterface, "");
331 InstanceKlass* interf = method->method_holder();
332 assert(interf->is_interface(), "must be an interface");
333 assert(!method->is_final_method(), "interfaces do not have final methods; cannot link to one here");
334 set_f1(referenced_klass);
335 set_f2((intx)method());
336 set_method_flags(as_TosState(method->result_type()),
337 0, // no option bits
338 method()->size_of_parameters());
339 set_bytecode_1(Bytecodes::_invokeinterface);
340 }
341
342
343 void ConstantPoolCacheEntry::set_method_handle(const constantPoolHandle& cpool, const CallInfo &call_info) {
|