nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java
changeset 33003 f1e00197031f
parent 32534 b3ec7f3b3c2a
child 33007 03119bfefbbf
equal deleted inserted replaced
32954:7db0663a5e96 33003:f1e00197031f
   148  *
   148  *
   149  * </ul>
   149  * </ul>
   150  *
   150  *
   151  * @author Attila Szegedi
   151  * @author Attila Szegedi
   152  */
   152  */
   153 public class DynamicLinker {
   153 public final class DynamicLinker {
   154     private static final String CLASS_NAME = DynamicLinker.class.getName();
   154     private static final String CLASS_NAME = DynamicLinker.class.getName();
   155     private static final String RELINK_METHOD_NAME = "relink";
   155     private static final String RELINK_METHOD_NAME = "relink";
   156 
   156 
   157     private static final String INITIAL_LINK_CLASS_NAME = "java.lang.invoke.MethodHandleNatives";
   157     private static final String INITIAL_LINK_CLASS_NAME = "java.lang.invoke.MethodHandleNatives";
   158     private static final String INITIAL_LINK_METHOD_NAME = "linkCallSite";
   158     private static final String INITIAL_LINK_METHOD_NAME = "linkCallSite";
       
   159     private static final String INVOKE_PACKAGE_PREFIX = "java.lang.invoke.";
   159 
   160 
   160     private final LinkerServices linkerServices;
   161     private final LinkerServices linkerServices;
   161     private final GuardedInvocationFilter prelinkFilter;
   162     private final GuardedInvocationFilter prelinkFilter;
   162     private final int runtimeContextArgCount;
   163     private final int runtimeContextArgCount;
   163     private final boolean syncOnRelink;
   164     private final boolean syncOnRelink;
   303      */
   304      */
   304     public static StackTraceElement getLinkedCallSiteLocation() {
   305     public static StackTraceElement getLinkedCallSiteLocation() {
   305         final StackTraceElement[] trace = new Throwable().getStackTrace();
   306         final StackTraceElement[] trace = new Throwable().getStackTrace();
   306         for(int i = 0; i < trace.length - 1; ++i) {
   307         for(int i = 0; i < trace.length - 1; ++i) {
   307             final StackTraceElement frame = trace[i];
   308             final StackTraceElement frame = trace[i];
       
   309             // If we found any of our linking entry points on the stack...
   308             if(isRelinkFrame(frame) || isInitialLinkFrame(frame)) {
   310             if(isRelinkFrame(frame) || isInitialLinkFrame(frame)) {
   309                 return trace[i + 1];
   311                 // ... then look for the first thing calling it that isn't j.l.invoke
       
   312                 for (int j = i + 1; j < trace.length; ++j) {
       
   313                     final StackTraceElement frame2 = trace[j];
       
   314                     if (!frame2.getClassName().startsWith(INVOKE_PACKAGE_PREFIX)) {
       
   315                         return frame2;
       
   316                     }
       
   317                 }
   310             }
   318             }
   311         }
   319         }
   312         return null;
   320         return null;
   313     }
       
   314 
       
   315     /**
       
   316      * Deprecated because of imprecise name.
       
   317      *
       
   318      * @deprecated Use {@link #getLinkedCallSiteLocation()} instead.
       
   319      *
       
   320      * @return see non-deprecated method
       
   321      */
       
   322     @Deprecated
       
   323     public static StackTraceElement getRelinkedCallSiteLocation() {
       
   324         return getLinkedCallSiteLocation();
       
   325     }
   321     }
   326 
   322 
   327     /**
   323     /**
   328      * Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()},
   324      * Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()},
   329      * the frame immediately on top of the call site frame when the call site is
   325      * the frame immediately on top of the call site frame when the call site is