changeset 33003:f1e00197031f

8139273: Small improvements to DynamicLinker and DynamicLinkerFactory Reviewed-by: lagergren, sundar
author attila
date Mon, 12 Oct 2015 10:27:32 +0200
parents 7db0663a5e96
children e4de5829b493
files nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java
diffstat 2 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java	Wed Jul 05 20:53:25 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java	Mon Oct 12 10:27:32 2015 +0200
@@ -150,12 +150,13 @@
  *
  * @author Attila Szegedi
  */
-public class DynamicLinker {
+public final class DynamicLinker {
     private static final String CLASS_NAME = DynamicLinker.class.getName();
     private static final String RELINK_METHOD_NAME = "relink";
 
     private static final String INITIAL_LINK_CLASS_NAME = "java.lang.invoke.MethodHandleNatives";
     private static final String INITIAL_LINK_METHOD_NAME = "linkCallSite";
+    private static final String INVOKE_PACKAGE_PREFIX = "java.lang.invoke.";
 
     private final LinkerServices linkerServices;
     private final GuardedInvocationFilter prelinkFilter;
@@ -305,26 +306,21 @@
         final StackTraceElement[] trace = new Throwable().getStackTrace();
         for(int i = 0; i < trace.length - 1; ++i) {
             final StackTraceElement frame = trace[i];
+            // If we found any of our linking entry points on the stack...
             if(isRelinkFrame(frame) || isInitialLinkFrame(frame)) {
-                return trace[i + 1];
+                // ... then look for the first thing calling it that isn't j.l.invoke
+                for (int j = i + 1; j < trace.length; ++j) {
+                    final StackTraceElement frame2 = trace[j];
+                    if (!frame2.getClassName().startsWith(INVOKE_PACKAGE_PREFIX)) {
+                        return frame2;
+                    }
+                }
             }
         }
         return null;
     }
 
     /**
-     * Deprecated because of imprecise name.
-     *
-     * @deprecated Use {@link #getLinkedCallSiteLocation()} instead.
-     *
-     * @return see non-deprecated method
-     */
-    @Deprecated
-    public static StackTraceElement getRelinkedCallSiteLocation() {
-        return getLinkedCallSiteLocation();
-    }
-
-    /**
      * Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()},
      * the frame immediately on top of the call site frame when the call site is
      * being linked for the first time.
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java	Wed Jul 05 20:53:25 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java	Mon Oct 12 10:27:32 2015 +0200
@@ -118,7 +118,7 @@
  *
  * @author Attila Szegedi
  */
-public class DynamicLinkerFactory {
+public final class DynamicLinkerFactory {
     /**
      * Default value for {@link #setUnstableRelinkThreshold(int) unstable relink threshold}.
      */