348 ShouldNotReachHere();
349 }
350 #endif
351 if (has_index_u4())
352 return get_index_u4(); // invokedynamic
353 return get_index_u2_cpcache();
354 }
355
356 // ------------------------------------------------------------------
357 // ciBytecodeStream::get_method
358 //
359 // If this is a method invocation bytecode, get the invoked method.
360 // Additionally return the declared signature to get more concrete
361 // type information if required (Cf. invokedynamic and invokehandle).
362 ciMethod* ciBytecodeStream::get_method(bool& will_link, ciSignature* *declared_signature_result) {
363 VM_ENTRY_MARK;
364 ciEnv* env = CURRENT_ENV;
365 constantPoolHandle cpool(THREAD, _method->get_Method()->constants());
366 ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder);
367 will_link = m->is_loaded();
368
369 // Use the MethodType stored in the CP cache to create a signature
370 // with correct types (in respect to class loaders).
371 if (has_method_type()) {
372 ciSymbol* sig_sym = env->get_symbol(cpool->symbol_at(get_method_signature_index(cpool)));
373 ciKlass* pool_holder = env->get_klass(cpool->pool_holder());
374 ciMethodType* method_type = get_method_type();
375 ciSignature* declared_signature = new (env->arena()) ciSignature(pool_holder, sig_sym, method_type);
376 (*declared_signature_result) = declared_signature;
377 } else {
378 (*declared_signature_result) = m->signature();
379 }
380 return m;
381 }
382
383 // ------------------------------------------------------------------
384 // ciBytecodeStream::has_appendix
385 //
386 // Returns true if there is an appendix argument stored in the
387 // constant pool cache at the current bci.
388 bool ciBytecodeStream::has_appendix() {
389 VM_ENTRY_MARK;
390 constantPoolHandle cpool(_method->get_Method()->constants());
391 return ConstantPool::has_appendix_at_if_loaded(cpool, get_method_index());
392 }
393
394 // ------------------------------------------------------------------
395 // ciBytecodeStream::get_appendix
396 //
397 // Return the appendix argument stored in the constant pool cache at
398 // the current bci.
399 ciObject* ciBytecodeStream::get_appendix() {
400 VM_ENTRY_MARK;
401 constantPoolHandle cpool(_method->get_Method()->constants());
402 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, get_method_index());
403 return CURRENT_ENV->get_object(appendix_oop);
404 }
405
406 // ------------------------------------------------------------------
407 // ciBytecodeStream::has_method_type
408 //
409 // Returns true if there is a MethodType argument stored in the
410 // constant pool cache at the current bci.
411 bool ciBytecodeStream::has_method_type() {
412 GUARDED_VM_ENTRY(
413 constantPoolHandle cpool(_method->get_Method()->constants());
414 return ConstantPool::has_method_type_at_if_loaded(cpool, get_method_index());
415 )
416 }
417
418 // ------------------------------------------------------------------
419 // ciBytecodeStream::get_method_type
420 //
421 // Return the MethodType stored in the constant pool cache at
422 // the current bci.
423 ciMethodType* ciBytecodeStream::get_method_type() {
424 GUARDED_VM_ENTRY(
425 constantPoolHandle cpool(_method->get_Method()->constants());
426 oop method_type_oop = ConstantPool::method_type_at_if_loaded(cpool, get_method_index());
427 return CURRENT_ENV->get_object(method_type_oop)->as_method_type();
428 )
429 }
430
431 // ------------------------------------------------------------------
432 // ciBytecodeStream::get_declared_method_holder
433 //
434 // Get the declared holder of the currently referenced method.
435 //
436 // Usage note: the holder() of a ciMethod class returns the canonical
437 // holder of the method, rather than the holder declared in the
438 // bytecodes.
439 //
440 // There is no "will_link" result passed back. The user is responsible
441 // for checking linkability when retrieving the associated method.
442 ciKlass* ciBytecodeStream::get_declared_method_holder() {
443 VM_ENTRY_MARK;
444 constantPoolHandle cpool(_method->get_Method()->constants());
445 bool ignore;
446 // report as MethodHandle for invokedynamic, which is syntactically classless
447 if (cur_bc() == Bytecodes::_invokedynamic)
|
348 ShouldNotReachHere();
349 }
350 #endif
351 if (has_index_u4())
352 return get_index_u4(); // invokedynamic
353 return get_index_u2_cpcache();
354 }
355
356 // ------------------------------------------------------------------
357 // ciBytecodeStream::get_method
358 //
359 // If this is a method invocation bytecode, get the invoked method.
360 // Additionally return the declared signature to get more concrete
361 // type information if required (Cf. invokedynamic and invokehandle).
362 ciMethod* ciBytecodeStream::get_method(bool& will_link, ciSignature* *declared_signature_result) {
363 VM_ENTRY_MARK;
364 ciEnv* env = CURRENT_ENV;
365 constantPoolHandle cpool(THREAD, _method->get_Method()->constants());
366 ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder);
367 will_link = m->is_loaded();
368 Symbol* local_signature = cpool->symbol_at(get_method_signature_index(cpool));
369
370 // Use the signature stored in the CP cache to create a signature
371 // with correct types (in respect to class loaders).
372 //
373 // In classic Java (before Java 7) there is never the slightest
374 // difference between the signature at the call site and that of the
375 // method. Such a difference would have been a type error in the
376 // JVM.
377 //
378 // Now there are a few circumstances where the signature of a call
379 // site (which controls the outgoing stacked arguments) can differ
380 // from the signature of the method (which controls the receipt of
381 // those arguments at the method entry point).
382 //
383 // A. The signatures can differ if the callee is a static method and
384 // the caller thinks it is calling a non-static method (VH.get).
385 // This requires the method signature to have an explicit leading
386 // argument for the implicit 'this', not present at the call site.
387 //
388 // B. The call site can have less specific parameter types than the
389 // method, allowing loosely-typed code to handle strongly-typed
390 // methods. This happens with linkToStatic and related linker
391 // commands. Obviously the loosely-typed code has to ensure that
392 // the strongly typed method's invariants are respected, and this is
393 // done by issuing dynamic casts.
394 //
395 // C. The call site can have more specific parameter types than the
396 // method, allowing loosely-typed methods to handle strongly-typed
397 // requests.
398 //
399 // D. There is are corresponding effects with return values, such as
400 // boolean method returning an int to an int-receiving call site,
401 // even though the method thought it returned just a boolean.
402 //
403 // E. The calling sequence at a particular call site may add an
404 // "appendix" argument not mentioned in the call site signature. It
405 // is expected by the method signature, though, and this adds to the
406 // method's arity, even after 'this' parameter effects (A) are
407 // discounted. Appendixes are used by invokehandle and
408 // invokedynamic instructions.
409 //
410 // F. A linker method (linkToStatic, etc.) can also take an extra
411 // argument, a MemberName which routes the call to a concrete
412 // strongly-typed method. In this case the linker method may also
413 // differ in any of the ways A-D. The eventual method will ignore
414 // the presence of the extra argument.
415 //
416 // None of these changes to calling sequences requires an argument
417 // to be moved or reformatted in any way. This works because all
418 // references look alike to the JVM, as do all primitives (except
419 // float/long/double). Another required property of the JVM is
420 // that, if a trailing argument is added or dropped, the placement
421 // of other arguments does not change. This allows cases E and F to
422 // work smoothly, against without any moving or reformatting,
423 // despite the arity change.
424 //
425 if (has_local_signature()) {
426 ciSymbol* sig_sym = env->get_symbol(local_signature);
427 ciKlass* pool_holder = env->get_klass(cpool->pool_holder());
428 ciSignature* call_site_sig = new (env->arena()) ciSignature(pool_holder, cpool, sig_sym);
429 // Examples of how the call site signature can differ from the method's own signature:
430 //
431 // meth = static jboolean java.lang.invoke.VarHandleGuards.guard_LII_Z(jobject, jobject, jint, jint, jobject)
432 // msig = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;IILjava/lang/invoke/VarHandle$AccessDescriptor;)Z
433 // call = (Ljava/util/concurrent/locks/AbstractQueuedSynchronizer;II)Z
434 //
435 // meth = static jobject java.lang.invoke.LambdaForm$MH/0x0000000800066840.linkToTargetMethod(jobject, jobject)
436 // msig = (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
437 // call = (Ljava/lang/String;)Ljava/util/function/Predicate;
438 //
439 (*declared_signature_result) = call_site_sig;
440
441 } else {
442 // We can just use the method's own signature. It may differ from the call site, but not by much.
443 //
444 // Examples of how the call site signature can differ from the method's signature:
445 //
446 // meth = static final native jint java.lang.invoke.MethodHandle.linkToStatic(jobject, jobject, jint, jint, jobject)
447 // msig = (Ljava/lang/Object;Ljava/lang/Object;IILjava/lang/invoke/MemberName;)I
448 // call = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;IILjava/lang/invoke/MemberName;)Z
449 //
450 // meth = final native jint java.lang.invoke.MethodHandle.invokeBasic(jobject, jobject, jint, jint)
451 // msig = (Ljava/lang/Object;Ljava/lang/Object;II)I
452 // call = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;II)Z
453 //
454 (*declared_signature_result) = m->signature();
455 }
456 return m;
457 }
458
459 // ------------------------------------------------------------------
460 // ciBytecodeStream::has_appendix
461 //
462 // Returns true if there is an appendix argument stored in the
463 // constant pool cache at the current bci.
464 bool ciBytecodeStream::has_appendix() {
465 VM_ENTRY_MARK;
466 constantPoolHandle cpool(_method->get_Method()->constants());
467 return ConstantPool::has_appendix_at_if_loaded(cpool, get_method_index());
468 }
469
470 // ------------------------------------------------------------------
471 // ciBytecodeStream::get_appendix
472 //
473 // Return the appendix argument stored in the constant pool cache at
474 // the current bci.
475 ciObject* ciBytecodeStream::get_appendix() {
476 VM_ENTRY_MARK;
477 constantPoolHandle cpool(_method->get_Method()->constants());
478 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, get_method_index());
479 return CURRENT_ENV->get_object(appendix_oop);
480 }
481
482 // ------------------------------------------------------------------
483 // ciBytecodeStream::has_method_type
484 //
485 // Returns true if there is a MethodType argument stored in the
486 // constant pool cache at the current bci.
487 bool ciBytecodeStream::has_local_signature() {
488 GUARDED_VM_ENTRY(
489 constantPoolHandle cpool(_method->get_Method()->constants());
490 return ConstantPool::has_local_signature_at_if_loaded(cpool, get_method_index());
491 )
492 }
493
494 // ------------------------------------------------------------------
495 // ciBytecodeStream::get_declared_method_holder
496 //
497 // Get the declared holder of the currently referenced method.
498 //
499 // Usage note: the holder() of a ciMethod class returns the canonical
500 // holder of the method, rather than the holder declared in the
501 // bytecodes.
502 //
503 // There is no "will_link" result passed back. The user is responsible
504 // for checking linkability when retrieving the associated method.
505 ciKlass* ciBytecodeStream::get_declared_method_holder() {
506 VM_ENTRY_MARK;
507 constantPoolHandle cpool(_method->get_Method()->constants());
508 bool ignore;
509 // report as MethodHandle for invokedynamic, which is syntactically classless
510 if (cur_bc() == Bytecodes::_invokedynamic)
|