src/hotspot/share/ci/ciStreams.cpp
changeset 53746 bdccafc038a2
parent 53595 8462b295c08b
child 59056 15936b142f86
equal deleted inserted replaced
53745:a535ba736cab 53746:bdccafc038a2
   332   ciEnv* env = CURRENT_ENV;
   332   ciEnv* env = CURRENT_ENV;
   333   constantPoolHandle cpool(THREAD, _method->get_Method()->constants());
   333   constantPoolHandle cpool(THREAD, _method->get_Method()->constants());
   334   ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder);
   334   ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder);
   335   will_link = m->is_loaded();
   335   will_link = m->is_loaded();
   336 
   336 
   337   // Use the MethodType stored in the CP cache to create a signature
   337   // Use the signature stored in the CP cache to create a signature
   338   // with correct types (in respect to class loaders).
   338   // with correct types (in respect to class loaders).
   339   if (has_method_type()) {
   339   //
   340     ciSymbol*     sig_sym     = env->get_symbol(cpool->symbol_at(get_method_signature_index(cpool)));
   340   // In classic Java (before Java 7) there is never the slightest
   341     ciKlass*      pool_holder = env->get_klass(cpool->pool_holder());
   341   // difference between the signature at the call site and that of the
   342     ciMethodType* method_type = get_method_type();
   342   // method.  Such a difference would have been a type error in the
   343     ciSignature* declared_signature = new (env->arena()) ciSignature(pool_holder, sig_sym, method_type);
   343   // JVM.
   344     (*declared_signature_result) = declared_signature;
   344   //
       
   345   // Now there are a few circumstances where the signature of a call
       
   346   // site (which controls the outgoing stacked arguments) can differ
       
   347   // from the signature of the method (which controls the receipt of
       
   348   // those arguments at the method entry point).
       
   349   //
       
   350   // A. The signatures can differ if the callee is a static method and
       
   351   // the caller thinks it is calling a non-static method (VH.get).
       
   352   // This requires the method signature to have an explicit leading
       
   353   // argument for the implicit 'this', not present at the call site.
       
   354   //
       
   355   // B. The call site can have less specific parameter types than the
       
   356   // method, allowing loosely-typed code to handle strongly-typed
       
   357   // methods.  This happens with linkToStatic and related linker
       
   358   // commands.  Obviously the loosely-typed code has to ensure that
       
   359   // the strongly typed method's invariants are respected, and this is
       
   360   // done by issuing dynamic casts.
       
   361   //
       
   362   // C. The call site can have more specific parameter types than the
       
   363   // method, allowing loosely-typed methods to handle strongly-typed
       
   364   // requests.
       
   365   //
       
   366   // D. There are corresponding effects with return values, such as
       
   367   // boolean method returning an int to an int-receiving call site,
       
   368   // even though the method thought it returned just a boolean.
       
   369   //
       
   370   // E. The calling sequence at a particular call site may add an
       
   371   // "appendix" argument not mentioned in the call site signature.  It
       
   372   // is expected by the method signature, though, and this adds to the
       
   373   // method's arity, even after 'this' parameter effects (A) are
       
   374   // discounted.  Appendixes are used by invokehandle and
       
   375   // invokedynamic instructions.
       
   376   //
       
   377   // F. A linker method (linkToStatic, etc.) can also take an extra
       
   378   // argument, a MemberName which routes the call to a concrete
       
   379   // strongly-typed method.  In this case the linker method may also
       
   380   // differ in any of the ways A-D.  The eventual method will ignore
       
   381   // the presence of the extra argument.
       
   382   //
       
   383   // None of these changes to calling sequences requires an argument
       
   384   // to be moved or reformatted in any way.  This works because all
       
   385   // references look alike to the JVM, as do all primitives (except
       
   386   // float/long/double).  Another required property of the JVM is
       
   387   // that, if a trailing argument is added or dropped, the placement
       
   388   // of other arguments does not change.  This allows cases E and F to
       
   389   // work smoothly, against without any moving or reformatting,
       
   390   // despite the arity change.
       
   391   //
       
   392   if (has_local_signature()) {
       
   393     Symbol* local_signature = cpool->symbol_at(get_method_signature_index(cpool));
       
   394     ciSymbol* sig_sym  = env->get_symbol(local_signature);
       
   395     ciKlass* pool_holder = env->get_klass(cpool->pool_holder());
       
   396     ciSignature* call_site_sig = new (env->arena()) ciSignature(pool_holder, cpool, sig_sym);
       
   397     // Examples of how the call site signature can differ from the method's own signature:
       
   398     //
       
   399     //  meth = static jboolean java.lang.invoke.VarHandleGuards.guard_LII_Z(jobject, jobject, jint, jint, jobject)
       
   400     //  msig = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;IILjava/lang/invoke/VarHandle$AccessDescriptor;)Z
       
   401     //  call = (Ljava/util/concurrent/locks/AbstractQueuedSynchronizer;II)Z
       
   402     //
       
   403     //  meth = static jobject java.lang.invoke.LambdaForm$MH/0x0000000800066840.linkToTargetMethod(jobject, jobject)
       
   404     //  msig = (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       
   405     //  call = (Ljava/lang/String;)Ljava/util/function/Predicate;
       
   406     //
       
   407     (*declared_signature_result) = call_site_sig;
       
   408 
   345   } else {
   409   } else {
       
   410     // We can just use the method's own signature.  It may differ from the call site, but not by much.
       
   411     //
       
   412     // Examples of how the call site signature can differ from the method's signature:
       
   413     //
       
   414     // meth = static final native jint java.lang.invoke.MethodHandle.linkToStatic(jobject, jobject, jint, jint, jobject)
       
   415     // msig = (Ljava/lang/Object;Ljava/lang/Object;IILjava/lang/invoke/MemberName;)I
       
   416     // call = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;IILjava/lang/invoke/MemberName;)Z
       
   417     //
       
   418     // meth = final native jint java.lang.invoke.MethodHandle.invokeBasic(jobject, jobject, jint, jint)
       
   419     // msig = (Ljava/lang/Object;Ljava/lang/Object;II)I
       
   420     // call = (Ljava/lang/invoke/VarHandle;Ljava/lang/Object;II)Z
       
   421     //
   346     (*declared_signature_result) = m->signature();
   422     (*declared_signature_result) = m->signature();
   347   }
   423   }
   348   return m;
   424   return m;
   349 }
   425 }
   350 
   426 
   370   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, get_method_index());
   446   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, get_method_index());
   371   return CURRENT_ENV->get_object(appendix_oop);
   447   return CURRENT_ENV->get_object(appendix_oop);
   372 }
   448 }
   373 
   449 
   374 // ------------------------------------------------------------------
   450 // ------------------------------------------------------------------
   375 // ciBytecodeStream::has_method_type
   451 // ciBytecodeStream::has_local_signature
   376 //
   452 //
   377 // Returns true if there is a MethodType argument stored in the
   453 // Returns true if the method stored in the constant
   378 // constant pool cache at the current bci.
   454 // pool cache at the current bci has a local signature.
   379 bool ciBytecodeStream::has_method_type() {
   455 bool ciBytecodeStream::has_local_signature() {
   380   GUARDED_VM_ENTRY(
   456   GUARDED_VM_ENTRY(
   381     constantPoolHandle cpool(_method->get_Method()->constants());
   457     constantPoolHandle cpool(_method->get_Method()->constants());
   382     return ConstantPool::has_method_type_at_if_loaded(cpool, get_method_index());
   458     return ConstantPool::has_local_signature_at_if_loaded(cpool, get_method_index());
   383   )
       
   384 }
       
   385 
       
   386 // ------------------------------------------------------------------
       
   387 // ciBytecodeStream::get_method_type
       
   388 //
       
   389 // Return the MethodType stored in the constant pool cache at
       
   390 // the current bci.
       
   391 ciMethodType* ciBytecodeStream::get_method_type() {
       
   392   GUARDED_VM_ENTRY(
       
   393     constantPoolHandle cpool(_method->get_Method()->constants());
       
   394     oop method_type_oop = ConstantPool::method_type_at_if_loaded(cpool, get_method_index());
       
   395     return CURRENT_ENV->get_object(method_type_oop)->as_method_type();
       
   396   )
   459   )
   397 }
   460 }
   398 
   461 
   399 // ------------------------------------------------------------------
   462 // ------------------------------------------------------------------
   400 // ciBytecodeStream::get_declared_method_holder
   463 // ciBytecodeStream::get_declared_method_holder