8057019: Various problems with extra arguments to applies
authorlagergren
Thu, 04 Sep 2014 10:52:42 +0200
changeset 26375 a741f7808507
parent 26374 5bc67576b50e
child 26376 31155daecdc7
8057019: Various problems with extra arguments to applies Reviewed-by: attila, hannesw, jlaskey
nashorn/bin/dump_octane_code.sh
nashorn/bin/fixorphantests.sh
nashorn/bin/fixwhitespace.sh
nashorn/bin/jjsdebug.sh
nashorn/bin/rm-non-tracked.sh
nashorn/bin/run_octane.sh
nashorn/bin/rundiff.sh
nashorn/bin/runopt.sh
nashorn/bin/runopt_noassert.sh
nashorn/bin/runopt_nojfr.sh
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java
nashorn/test/script/basic/JDK-8057019-2.js
nashorn/test/script/basic/JDK-8057019-2.js.EXPECTED
nashorn/test/script/basic/JDK-8057019-payload.js
nashorn/test/script/basic/JDK-8057019.js
nashorn/test/script/basic/JDK-8057019.js.EXPECTED
nashorn/test/script/basic/apply_to_call/apply_to_call4.js.EXPECTED
--- a/nashorn/bin/dump_octane_code.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-#!/bin/bash
-# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#
-# The purpose of this script is to provide a large amount of IR/bytecode from a known
-# application to be diffed against the same output with a different Nashorn version.
-# That way we can quickly detect if a seemingly minute change modifies a lot of code,
-# which it most likely shouldn't. One example of this was when AccessSpecializer was
-# moved into Lower the first time, it worked fine, but as a lot of Scope information
-# at the time was finalized further down the code pipeline it did a lot fewer callsite
-# specializations. This would have been immediately detected with a before and after 
-# diff using the output from this script.
-#
-
-ITERS=$1
-if [ -z $ITERS ]; then 
-    ITERS=7
-fi
-NASHORN_JAR=dist/nashorn.jar
-JVM_FLAGS="-ea -esa -server -jar ${NASHORN_JAR}"
-
-BENCHMARKS=( "box2d.js" "code-load.js" "crypto.js" "deltablue.js" "earley-boyer.js" "gbemu.js" "mandreel.js" "navier-stokes.js" "pdfjs.js" "raytrace.js" "regexp.js" "richards.js" "splay.js" )
-
-for BENCHMARK in "${BENCHMARKS[@]}"
-do     
-    echo "START: ${BENCHMARK}"
-    CMD="${JAVA_HOME}/bin/java ${JVM_FLAGS} -co --print-lower-parse test/script/external/octane/${BENCHMARK}"
-    $CMD
-    echo "END: ${BENCHMARK}"
-    echo ""
-done
-
-echo "Done"
--- a/nashorn/bin/fixorphantests.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#ensure that all tests tagged with @test are also tagged with @run
-
-for f in $(find test/script/basic/*.js); do 
-    grep @test $f >/dev/null
-    TEST=$?
-    grep @run $f >/dev/null
-    RUN=$?    
-
-    if [ $TEST -eq 0 ] && [ ! $RUN -eq 0 ]; then		
-	echo "repairing ${f}..."
-	TEMP=$(mktemp /tmp/scratch.XXXXXX)
-
-	#IFS='', -raw flag to preserve white space
-	while IFS='' read -r line; do 	    
-	    echo $line | grep @test >/dev/null
-	    TEST=$?
-	    printf "%s\n" "$line" 
-	    if [ $TEST -eq 0 ]; then
-		printf "%s\n" "$line" | sed s/@test/@run/g 
-	    fi	   
-	done < $f >$TEMP
-
-	cp $TEMP $f
-
-	rm -fr $TEMP
-    fi
-
-done
--- a/nashorn/bin/fixwhitespace.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-fix() {
-    #convert tabs to spaces
-    find . -name $1 -exec sed -i "" 's/	/    /g' {} \;
-    #remove trailing whitespace
-    find . -name $1 -exec sed -i "" 's/[ 	]*$//' \{} \;
-}
-
-if [ ! -z $1 ]; then 
-    fix $1;
-else
-    fix "*.java"
-    fix "*.js"
-fi
--- a/nashorn/bin/jjsdebug.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-$JAVA_HOME/bin/jjs -J-Djava.ext.dirs=`dirname $0`/../dist -J-agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=y $*
--- a/nashorn/bin/rm-non-tracked.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-hg status|grep ^\?|awk '{print $2}'|xargs rm
--- a/nashorn/bin/run_octane.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-LOG="./octane_$(date|sed "s/ /_/g"|sed "s/:/_/g").log"
-
-run_one() {
-    sh ../bin/runopt.sh -scripting ../test/script/basic/run-octane.js -- $1 --verbose --iterations 25 | tee -a $LOG
-}
-
-if [ -z $1 ]; then 
-
-    run_one "box2d"
-    run_one "code-load"
-    run_one "crypto"
-    run_one "deltablue"
-    run_one "earley-boyer"
-    run_one "gbemu"
-    run_one "mandreel"
-    run_one "navier-stokes"
-    run_one "pdfjs"
-    run_one "raytrace"
-    run_one "regexp"
-    run_one "richards"
-    run_one "splay"
-    run_one "typescript"
-    run_one "zlib"
-
-else
-    run_one $1
-fi
--- a/nashorn/bin/rundiff.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-# do two runs of a script, one optimistic and one pessimistic, expect identical outputs
-# if not, display and error message and a diff
-
-which opendiff >/dev/null
-RES=$?
-if [ $RES = 0 ]; then
-    DIFFTOOL=opendiff
-else
-    DIFFTOOL=diff
-fi
-
-OPTIMISTIC=out_optimistic
-PESSIMISTIC=out_pessimistic
-$JAVA_HOME/bin/java -ea -jar ../dist/nashorn.jar ${@} >$PESSIMISTIC
-$JAVA_HOME/bin/java -ea -Dnashorn.optimistic -jar ../dist/nashorn.jar ${@} >$OPTIMISTIC
-
-if ! diff -q $PESSIMISTIC $OPTIMISTIC >/dev/null ; then
-    echo "Failure! Results are different"
-    echo ""
-    $DIFFTOOL $PESSIMISTIC $OPTIMISTIC
-else
-    echo "OK - Results are identical"
-fi
--- a/nashorn/bin/runopt.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-# 
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-# 
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-###########################################################################################
-# This is a helper script to evaluate nashorn with optimistic types
-# it produces a flight recording for every run, and uses the best 
-# known flags for performance for the current configration
-###########################################################################################
-
-# Flags to instrument lambdaform computation, caching, interpretation and compilation
-# Default compile threshold for lambdaforms is 30
-#FLAGS="-Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=3 -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -Djava.lang.invoke.MethodHandle.TRACE_INTERPRETER=true"
-
-
-# Flags to run trusted tests from the Nashorn test suite
-#FLAGS="-Djava.security.manager -Djava.security.policy=../build/nashorn.policy -Dnashorn.debug"
-
-
-# Unique timestamped file name for JFR recordings. For JFR, we also have to
-# crank up the stack cutoff depth to 1024, because of ridiculously long lambda form
-# stack traces.
-#
-# It is also recommended that you go into $JAVA_HOME/jre/lib/jfr/default.jfc and
-# set the "method-sampling-interval" Normal and Maximum sample time as low as you
-# can go (10 ms on most platforms). The default is normally higher. The increased
-# sampling overhead is usually negligible for Nashorn runs, but the data is better
-
-JFR_FILENAME="./nashorn_$(date|sed "s/ /_/g"|sed "s/:/_/g").jfr"
-
-
-# Directory where to look for nashorn.jar in a dist folder. The default is "..", assuming
-# that we run the script from the make dir
-DIR=..
-NASHORN_JAR=$DIR/dist/nashorn.jar
-
-
-# The built Nashorn jar is placed first in the bootclasspath to override the JDK
-# nashorn.jar in $JAVA_HOME/jre/lib/ext. Thus, we also need -esa, as assertions in
-# nashorn count as system assertions in this configuration
-
-# Type profiling default level is 111, 222 adds some compile time, but is faster
-
-$JAVA_HOME/bin/java \
-$FLAGS \
--ea \
--esa \
--Xbootclasspath/p:$NASHORN_JAR \
--Xms2G -Xmx2G \
--XX:TypeProfileLevel=222 \
--cp $CLASSPATH:../build/test/classes/ \
-jdk.nashorn.tools.Shell ${@}
-
-# Below are flags that may come in handy, but aren't used for default runs
-
-# Testing out new code optimizations using the generic hotspot "new code" parameter
-#-XX:+UnlockDiagnosticVMOptions \
-#-XX:+UseNewCode \
-
-# Flight recorder
-#-XX:+UnlockCommercialFeatures \
-#-XX:+FlightRecorder \
-#-XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=$JFR_FILENAME,stackdepth=1024 \
-
-
-# Type specialization and math intrinsic replacement should be enabled by default in 8u20 and nine,
-# keeping this flag around for experimental reasons. Replace + with - to switch it off
-#-XX:+UseTypeSpeculation \
-
-
-# Same with math intrinsics. They should be enabled by default in 8u20 and 9
-#-XX:+UseMathExactIntrinsics \
-
-
-# Add -Dnashorn.time to time the compilation phases.
-#-Dnashorn.time \
-
-
-# Add ShowHiddenFrames to get lambda form internals on the stack traces
-#-XX:+ShowHiddenFrames \
-
-
-# Add print optoassembly to get an asm dump. This requires 1) a debug build, not product,
-# That tired compilation is switched off, for C2 only output and that the number of
-# compiler threads is set to 1 for determinsm.
-#-XX:+PrintOptoAssembly -XX:-TieredCompilation -XX:CICompilerCount=1 \
-
-# Tier compile threasholds. Default value is 10. (1-100 is useful for experiments)
-# -XX:IncreaseFirstTierCompileThresholdAt=XX
-
--- a/nashorn/bin/runopt_noassert.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#!/bin/sh
-
-#FLAGS="-Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=3 -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -Djava.lang.invoke.MethodHandle.TRACE_INTERPRETER=true"
-
-FILENAME="./optimistic_noassert_$(date|sed "s/ /_/g"|sed "s/:/_/g").jfr"
-
-DIR=..
-NASHORN_JAR=$DIR/dist/nashorn.jar
-
-$JAVA_HOME/bin/java \
-$FLAGS \
--Xbootclasspath/p:$NASHORN_JAR \
--Xms2G -Xmx2G \
--XX:+UnlockCommercialFeatures \
--XX:+FlightRecorder \
--XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=$FILENAME,stackdepth=1024 \
--XX:TypeProfileLevel=222 \
--XX:+UnlockExperimentalVMOptions \
--XX:+UseTypeSpeculation \
--XX:+UseMathExactIntrinsics \
--XX:+UnlockDiagnosticVMOptions \
--cp $CLASSPATH:../build/test/classes/ \
-jdk.nashorn.tools.Shell ${@}
-
-#-XX:+ShowHiddenFrames \
-#-XX:+PrintOptoAssembly \
-#-XX:-TieredCompilation \
-#-XX:CICompilerCount=1 \
--- a/nashorn/bin/runopt_nojfr.sh	Wed Sep 03 14:33:34 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-#FLAGS="-Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=3 -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -Djava.lang.invoke.MethodHandle.TRACE_INTERPRETER=true"
-
-DIR=..
-NASHORN_JAR=$DIR/dist/nashorn.jar
-
-$JAVA_HOME/bin/java \
-$FLAGS \
--ea \
--esa \
--Xbootclasspath/p:$NASHORN_JAR \
--Xms2G -Xmx2G \
--XX:+UnlockCommercialFeatures \
--XX:TypeProfileLevel=222 \
--XX:+UnlockExperimentalVMOptions \
--XX:+UseTypeSpeculation \
--XX:+UseMathExactIntrinsics \
--XX:+UnlockDiagnosticVMOptions \
--XX:+UseNewCode \
--cp $CLASSPATH:../build/test/classes/ \
-jdk.nashorn.tools.Shell ${@}
-
-#-XX:+ShowHiddenFrames \
-#-XX:+PrintOptoAssembly \
-#-XX:-TieredCompilation \
-#-XX:CICompilerCount=1 \
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java	Wed Sep 03 14:33:34 2014 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java	Thu Sep 04 10:52:42 2014 +0200
@@ -36,6 +36,7 @@
 import java.lang.invoke.MethodType;
 import java.lang.invoke.SwitchPoint;
 import java.util.Collections;
+
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -44,6 +45,9 @@
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.objects.NativeFunction;
+import jdk.nashorn.internal.runtime.ScriptFunctionData;
+import jdk.nashorn.internal.runtime.ScriptObject;
+import jdk.nashorn.internal.runtime.ScriptRuntime;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
 
@@ -621,6 +625,23 @@
             appliedType = appliedType.changeParameterType(1, Object.class);
         }
 
+        /*
+         * dropArgs is a synthetic method handle that contains any args that we need to
+         * get rid of that come after the arguments array in the apply case. We adapt
+         * the callsite to ask for 3 args only and then dropArguments on the method handle
+         * to make it fit the extraneous args.
+         */
+        MethodType dropArgs = MH.type(void.class);
+        if (isApply && !isFailedApplyToCall) {
+            final int pc = appliedType.parameterCount();
+            for (int i = 3; i < pc; i++) {
+                dropArgs = dropArgs.appendParameterTypes(appliedType.parameterType(i));
+            }
+            if (pc > 3) {
+                appliedType = appliedType.dropParameterTypes(3, pc);
+            }
+        }
+
         if (isApply || isFailedApplyToCall) {
             if (passesArgs) {
                 // R(this, args) => R(this, Object[])
@@ -702,6 +723,15 @@
         }
         inv = MH.dropArguments(inv, 0, applyFnType);
 
+        /*
+         * Dropargs can only be non-()V in the case of isApply && !isFailedApplyToCall, which
+         * is when we need to add arguments to the callsite to catch and ignore the synthetic
+         * extra args that someone has added to the command line.
+         */
+        for (int i = 0; i < dropArgs.parameterCount(); i++) {
+            inv = MH.dropArguments(inv, 4 + i, dropArgs.parameterType(i));
+        }
+
         MethodHandle guard = appliedInvocation.getGuard();
         // If the guard checks the value of "this" but we aren't passing thisArg, insert the default one
         if (!passesThis && guard.type().parameterCount() > 1) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8057019-2.js	Thu Sep 04 10:52:42 2014 +0200
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * this apply with extra arguments
+ * (with apply to call enabled)
+ *
+ * @test
+ * @run
+ */
+
+load(__DIR__ + 'JDK-8057019-payload.js');
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8057019-2.js.EXPECTED	Thu Sep 04 10:52:42 2014 +0200
@@ -0,0 +1,24 @@
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+TypeError: Function.prototype.apply expects an Array for second argument
+TypeError: Function.prototype.apply expects an Array for second argument
+TypeError: Function.prototype.apply expects an Array for second argument
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8057019-payload.js	Thu Sep 04 10:52:42 2014 +0200
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * this apply with extra arguments
+ *
+ * @subtest
+ */
+
+function func(x, y, z) {
+    print(x, y, z);
+}
+
+function g() {
+    func.apply(this, arguments);
+}
+function h() {
+    func.apply(this, arguments, 23);
+}
+function i() {
+    func.apply(this, arguments, 23, 4711);
+}
+function j() {
+    func.apply(this, arguments, 23, 4711, "apa", "dingo", "gorilla");
+}
+function k() {
+    func.apply(this, arguments, 23);
+}
+function l() {
+    func.apply(this, [23, "apa", "gorilla", "dingo"], 17);
+}
+function m() {
+    func.apply(this, [23, "apa", "gorilla", "dingo"]);
+}
+function n() {
+    func.apply(this, "significant");
+}
+
+g(1,2);
+g(1,2,3);
+g(1,2,3,4);
+
+h(1,2);
+h(1,2,3);
+h(1,2,3,4);
+
+i(1,2);
+i(1,2,3);
+i(1,2,3,4);
+
+j(1,2);
+j(1,2,3);
+j(1,2,3,4);
+
+k(1,2);
+k(1,2,3);
+k(1,2,3,4);
+
+l(1,2);
+l(1,2,3);
+l(1,2,3,4);
+
+m(1,2);
+m(1,2,3);
+m(1,2,3,4);
+
+try {
+    n(1,2);
+} catch (e) {
+    print(e);
+}
+try {
+    n(1,2,3);
+} catch (e) {
+    print(e);    
+}
+
+try {
+    n(1,2,3,4);
+} catch (e) {
+    print(e);   
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8057019.js	Thu Sep 04 10:52:42 2014 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * this apply with extra arguments
+ * (turning off apply to call)
+ *
+ * @fork
+ * @option -Dnashorn.apply2call=false
+ * @test
+ * @run
+ */
+
+load(__DIR__ + 'JDK-8057019-payload.js');
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8057019.js.EXPECTED	Thu Sep 04 10:52:42 2014 +0200
@@ -0,0 +1,24 @@
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+1 2 undefined
+1 2 3
+1 2 3
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+23 apa gorilla
+TypeError: Function.prototype.apply expects an Array for second argument
+TypeError: Function.prototype.apply expects an Array for second argument
+TypeError: Function.prototype.apply expects an Array for second argument
--- a/nashorn/test/script/basic/apply_to_call/apply_to_call4.js.EXPECTED	Wed Sep 03 14:33:34 2014 +0200
+++ b/nashorn/test/script/basic/apply_to_call/apply_to_call4.js.EXPECTED	Thu Sep 04 10:52:42 2014 +0200
@@ -15,8 +15,8 @@
 2.3
 3.4
 test 5 done
-a=object
-17
+a=number
+22
 undefined
 Now it's time for transforms
 19