jdk/src/share/classes/sun/dyn/CallSiteImpl.java
changeset 4537 7c3c7f8d5195
parent 2707 5a17df307cbc
child 5722 4ada807383c8
child 5506 202f599c92aa
equal deleted inserted replaced
4536:0f6ec6364a69 4537:7c3c7f8d5195
    24  */
    24  */
    25 
    25 
    26 package sun.dyn;
    26 package sun.dyn;
    27 
    27 
    28 import java.dyn.*;
    28 import java.dyn.*;
       
    29 import java.util.logging.Level;
       
    30 import java.util.logging.Logger;
    29 
    31 
    30 /**
    32 /**
    31  * The CallSite privately created by the JVM at every invokedynamic instruction.
    33  * Parts of CallSite known to the JVM.
       
    34  * FIXME: Merge all this into CallSite proper.
    32  * @author jrose
    35  * @author jrose
    33  */
    36  */
    34 class CallSiteImpl extends CallSite {
    37 public class CallSiteImpl {
    35     // Fields used only by the JVM.  Do not use or change.
    38     // Field used only by the JVM.  Do not use or change.
    36     private Object vmmethod;
    39     private Object vmmethod;
    37 
    40 
    38     // Values supplied by the JVM:
    41     // Values supplied by the JVM:
    39     int callerMID, callerBCI;
    42     protected int callerMID, callerBCI;
    40 
    43 
    41     private CallSiteImpl(Class<?> caller, String name, MethodType type) {
    44     private MethodHandle target;
    42         super(caller, name, type);
    45     protected final Object caller;  // usually a class
       
    46     protected final String name;
       
    47     protected final MethodType type;
       
    48 
       
    49     /** called only directly from CallSite() */
       
    50     protected CallSiteImpl(Access token, Object caller, String name, MethodType type) {
       
    51         Access.check(token);
       
    52         this.caller = caller;
       
    53         this.name = name;
       
    54         this.type = type;
    43     }
    55     }
    44 
    56 
    45     @Override
    57     /** native version of setTarget */
    46     public void setTarget(MethodHandle mh) {
    58     protected void setTarget(MethodHandle mh) {
    47         checkTarget(mh);
    59         //System.out.println("setTarget "+this+" := "+mh);
    48         if (MethodHandleNatives.JVM_SUPPORT)
    60         // XXX I don't know how to fix this properly.
    49             MethodHandleNatives.linkCallSite(this, (MethodHandle) mh);
    61 //         if (false && MethodHandleNatives.JVM_SUPPORT) // FIXME: enable this
    50         else
    62 //             MethodHandleNatives.linkCallSite(this, mh);
    51             super.setTarget(mh);
    63 //         else
       
    64             this.target = mh;
       
    65     }
       
    66 
       
    67     protected MethodHandle getTarget() {
       
    68         return target;
    52     }
    69     }
    53 
    70 
    54     private static final MethodHandle PRIVATE_INITIALIZE_CALL_SITE =
    71     private static final MethodHandle PRIVATE_INITIALIZE_CALL_SITE =
    55             MethodHandleImpl.IMPL_LOOKUP.findStatic(CallSite.class, "privateInitializeCallSite",
    72             MethodHandleImpl.IMPL_LOOKUP.findStatic(CallSite.class, "privateInitializeCallSite",
    56                 MethodType.make(void.class, CallSite.class, int.class, int.class));
    73                 MethodType.methodType(void.class, CallSite.class, int.class, int.class));
    57 
    74 
    58     // this is the up-call from the JVM:
    75     // this is the up-call from the JVM:
    59     static CallSite makeSite(Class<?> caller, String name, MethodType type,
    76     static CallSite makeSite(Class<?> caller, String name, MethodType type,
    60                              int callerMID, int callerBCI) {
    77                              int callerMID, int callerBCI) {
    61         MethodHandle bsm = Linkage.getBootstrapMethod(caller);
    78         MethodHandle bsm = Linkage.getBootstrapMethod(caller);
    62         if (bsm == null)
    79         if (bsm == null)
    63             throw new InvokeDynamicBootstrapError("class has no bootstrap method: "+caller);
    80             throw new InvokeDynamicBootstrapError("class has no bootstrap method: "+caller);
    64         CallSite site = bsm.<CallSite>invoke(caller, name, type);
    81         CallSite site;
       
    82         try {
       
    83             site = bsm.<CallSite>invoke(caller, name, type);
       
    84         } catch (Throwable ex) {
       
    85             throw new InvokeDynamicBootstrapError("exception thrown while linking", ex);
       
    86         }
    65         if (site == null)
    87         if (site == null)
    66             throw new InvokeDynamicBootstrapError("class bootstrap method failed to create a call site: "+caller);
    88             throw new InvokeDynamicBootstrapError("class bootstrap method failed to create a call site: "+caller);
    67         PRIVATE_INITIALIZE_CALL_SITE.<void>invoke(site, callerMID, callerBCI);
    89         if (site.type() != type)
       
    90             throw new InvokeDynamicBootstrapError("call site type not initialized correctly: "+site);
       
    91         if (site.callerClass() != caller)
       
    92             throw new InvokeDynamicBootstrapError("call site caller not initialized correctly: "+site);
       
    93         if ((Object)site.name() != name)
       
    94             throw new InvokeDynamicBootstrapError("call site name not initialized correctly: "+site);
       
    95         try {
       
    96             PRIVATE_INITIALIZE_CALL_SITE.<void>invoke(site, callerMID, callerBCI);
       
    97         } catch (Throwable ex) {
       
    98             throw new InvokeDynamicBootstrapError("call site initialization exception", ex);
       
    99         }
    68         return site;
   100         return site;
    69     }
   101     }
    70 }
   102 }