8044171: Make optimistic exception handlers smaller
authorattila
Tue, 03 Jun 2014 11:31:06 +0200
changeset 24773 34c21f8464c5
parent 24772 0fc1013a1785
child 24774 da5a0201be9d
8044171: Make optimistic exception handlers smaller Reviewed-by: hannesw, lagergren
nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
nashorn/src/jdk/nashorn/internal/runtime/RewriteException.java
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jun 03 14:13:03 2014 +0530
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jun 03 11:31:06 2014 +0200
@@ -187,10 +187,10 @@
     private static final String SCRIPTFUNCTION_IMPL_NAME = Type.getInternalName(ScriptFunctionImpl.class);
     private static final Type   SCRIPTFUNCTION_IMPL_TYPE   = Type.typeFor(ScriptFunction.class);
 
-    private static final Call INIT_REWRITE_EXCEPTION = CompilerConstants.specialCallNoLookup(RewriteException.class,
-            "<init>", void.class, UnwarrantedOptimismException.class, Object[].class, String[].class);
-    private static final Call INIT_REWRITE_EXCEPTION_REST_OF = CompilerConstants.specialCallNoLookup(RewriteException.class,
-            "<init>", void.class, UnwarrantedOptimismException.class, Object[].class, String[].class, int[].class);
+    private static final Call CREATE_REWRITE_EXCEPTION = CompilerConstants.staticCallNoLookup(RewriteException.class,
+            "create", RewriteException.class, UnwarrantedOptimismException.class, Object[].class, String[].class);
+    private static final Call CREATE_REWRITE_EXCEPTION_REST_OF = CompilerConstants.staticCallNoLookup(RewriteException.class,
+            "create", RewriteException.class, UnwarrantedOptimismException.class, Object[].class, String[].class, int[].class);
 
     private static final Call ENSURE_INT = CompilerConstants.staticCallNoLookup(OptimisticReturnFilters.class,
             "ensureInt", int.class, Object.class, int.class);
@@ -4952,16 +4952,12 @@
                 // At this point we have the UnwarrantedOptimismException and the Object[] with local variables on
                 // stack. We need to create a RewriteException, push two references to it below the constructor
                 // arguments, invoke the constructor, and throw the exception.
-                method._new(RewriteException.class);
-                method.dup(2);
-                method.dup(2);
-                method.pop();
                 loadConstant(getByteCodeSymbolNames(fn));
                 if (isRestOf()) {
                     loadConstant(getContinuationEntryPoints());
-                    method.invoke(INIT_REWRITE_EXCEPTION_REST_OF);
+                    method.invoke(CREATE_REWRITE_EXCEPTION_REST_OF);
                 } else {
-                    method.invoke(INIT_REWRITE_EXCEPTION);
+                    method.invoke(CREATE_REWRITE_EXCEPTION);
                 }
                 method.athrow();
             }
--- a/nashorn/src/jdk/nashorn/internal/runtime/RewriteException.java	Tue Jun 03 14:13:03 2014 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/RewriteException.java	Tue Jun 03 11:31:06 2014 +0200
@@ -82,6 +82,17 @@
     /** Call for asserting the length of an array. */
     public static final Call ASSERT_ARRAY_LENGTH = staticCallNoLookup(RewriteException.class, "assertArrayLength", void.class, Object[].class, int.class);
 
+    private RewriteException(
+            final UnwarrantedOptimismException e,
+            final Object[] byteCodeSlots,
+            final String[] byteCodeSymbolNames,
+            final int[] previousContinuationEntryPoints) {
+        super("", e, false, Context.DEBUG);
+        this.byteCodeSlots = byteCodeSlots;
+        this.runtimeScope = mergeSlotsWithScope(byteCodeSlots, byteCodeSymbolNames);
+        this.previousContinuationEntryPoints = previousContinuationEntryPoints;
+    }
+
     /**
      * Constructor for a rewrite exception thrown from an optimistic function.
      * @param e the {@link UnwarrantedOptimismException} that triggered this exception.
@@ -91,12 +102,12 @@
      * effort to assist evaluation of expressions for their types by the compiler doing the deoptimizing recompilation,
      * and can thus be incomplete - the more complete it is, the more expressions can be evaluated by the compiler, and
      * the more unnecessary deoptimizing compilations can be avoided.
+     * @return a new rewrite exception
      */
-    public RewriteException(
-            final UnwarrantedOptimismException e,
+    public static RewriteException create(final UnwarrantedOptimismException e,
             final Object[] byteCodeSlots,
             final String[] byteCodeSymbolNames) {
-        this(e, byteCodeSlots, byteCodeSymbolNames, null);
+        return create(e, byteCodeSlots, byteCodeSymbolNames, null);
     }
 
     /**
@@ -110,16 +121,13 @@
      * the more unnecessary deoptimizing compilations can be avoided.
      * @param previousContinuationEntryPoints an array of continuation entry points that were already executed during
      * one logical invocation of the function (a rest-of triggering a rest-of triggering a...)
+     * @return a new rewrite exception
      */
-    public RewriteException(
-            final UnwarrantedOptimismException e,
+    public static RewriteException create(final UnwarrantedOptimismException e,
             final Object[] byteCodeSlots,
             final String[] byteCodeSymbolNames,
             final int[] previousContinuationEntryPoints) {
-        super("", e, false, Context.DEBUG);
-        this.byteCodeSlots = byteCodeSlots;
-        this.runtimeScope = mergeSlotsWithScope(byteCodeSlots, byteCodeSymbolNames);
-        this.previousContinuationEntryPoints = previousContinuationEntryPoints;
+        return new RewriteException(e, byteCodeSlots, byteCodeSymbolNames, previousContinuationEntryPoints);
     }
 
     /**