changeset 1457:59c36bec3c28

8139269: Do not expose prune method handles from ChainedCallSite Reviewed-by: hannesw, lagergren
author attila
date Fri, 09 Oct 2015 18:01:09 +0200
parents 446625d6e8cc
children e4283eeb182c
files src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java
diffstat 2 files changed, 10 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java	Wed Oct 07 15:02:15 2015 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java	Fri Oct 09 18:01:09 2015 +0200
@@ -103,27 +103,14 @@
  * handle is always at the start of the chain.
  */
 public class ChainedCallSite extends AbstractRelinkableCallSite {
-    private static final MethodHandle PRUNE_CATCHES =
-            MethodHandles.insertArguments(
-                    Lookup.findOwnSpecial(
-                            MethodHandles.lookup(),
-                            "prune",
-                            MethodHandle.class,
-                            MethodHandle.class,
-                            boolean.class),
-                    2,
-                    true);
-
-    private static final MethodHandle PRUNE_SWITCHPOINTS =
-            MethodHandles.insertArguments(
-                    Lookup.findOwnSpecial(
-                            MethodHandles.lookup(),
-                            "prune",
-                            MethodHandle.class,
-                            MethodHandle.class,
-                            boolean.class),
-                    2,
-                    false);
+    private static final MethodHandle PRUNE_CATCHES;
+    private static final MethodHandle PRUNE_SWITCHPOINTS;
+    static {
+        final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class,
+                MethodHandle.class, boolean.class);
+        PRUNE_CATCHES      = MethodHandles.insertArguments(PRUNE, 2, true);
+        PRUNE_SWITCHPOINTS = MethodHandles.insertArguments(PRUNE, 2, false);
+    }
 
     private final AtomicReference<LinkedList<GuardedInvocation>> invocations = new AtomicReference<>();
 
@@ -181,8 +168,8 @@
 
         // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
         // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
-        final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, getPruneSwitchpoints());
-        final MethodHandle pruneAndInvokeCatches      = makePruneAndInvokeMethod(relink, getPruneCatches());
+        final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, PRUNE_SWITCHPOINTS);
+        final MethodHandle pruneAndInvokeCatches      = makePruneAndInvokeMethod(relink, PRUNE_CATCHES);
 
         // Fold the new chain
         MethodHandle target = relink;
@@ -200,22 +187,6 @@
     }
 
     /**
-     * Get the switchpoint pruning function for a chained call site
-     * @return function that removes invalidated switchpoints tied to callsite guard chain and relinks
-     */
-    protected MethodHandle getPruneSwitchpoints() {
-        return PRUNE_SWITCHPOINTS;
-    }
-
-    /**
-     * Get the catch pruning function for a chained call site
-     * @return function that removes all catches tied to callsite guard chain and relinks
-     */
-    protected MethodHandle getPruneCatches() {
-        return PRUNE_CATCHES;
-    }
-
-    /**
      * Creates a method that rebuilds our call chain, pruning it of any invalidated switchpoints, and then invokes that
      * chain.
      * @param relink the ultimate fallback for the chain (the {@code DynamicLinker}'s relink).
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java	Wed Oct 07 15:02:15 2015 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java	Fri Oct 09 18:01:09 2015 +0200
@@ -64,9 +64,6 @@
     private static final String PROFILEFILE = Options.getStringProperty("nashorn.profilefile", "NashornProfile.txt");
 
     private static final MethodHandle INCREASE_MISS_COUNTER = MH.findStatic(MethodHandles.lookup(), LinkerCallSite.class, "increaseMissCount", MH.type(Object.class, String.class, Object.class));
-    private static final MethodHandle ON_CATCH_INVALIDATION = MH.findStatic(MethodHandles.lookup(), LinkerCallSite.class, "onCatchInvalidation", MH.type(ChainedCallSite.class, LinkerCallSite.class));
-
-    private int catchInvalidations;
 
     LinkerCallSite(final NashornCallSiteDescriptor descriptor) {
         super(descriptor);
@@ -75,34 +72,6 @@
         }
     }
 
-    @Override
-    protected MethodHandle getPruneCatches() {
-        return MH.filterArguments(super.getPruneCatches(), 0, ON_CATCH_INVALIDATION);
-    }
-
-    /**
-     * Action to perform when a catch guard around a callsite triggers. Increases
-     * catch invalidation counter
-     * @param callSite callsite
-     * @return the callsite, so this can be used as argument filter
-     */
-    @SuppressWarnings("unused")
-    private static ChainedCallSite onCatchInvalidation(final LinkerCallSite callSite) {
-        ++callSite.catchInvalidations;
-        return callSite;
-    }
-
-    /**
-     * Get the number of catch invalidations that have happened at this call site so far
-     * @param callSiteToken call site token, unique to the callsite.
-     * @return number of catch invalidations, i.e. thrown exceptions caught by the linker
-     */
-    public static int getCatchInvalidationCount(final Object callSiteToken) {
-        if (callSiteToken instanceof LinkerCallSite) {
-            return ((LinkerCallSite)callSiteToken).catchInvalidations;
-        }
-        return 0;
-    }
     /**
      * Construct a new linker call site.
      * @param name     Name of method.