8178480: Wrong exception being thrown on an invalid MethodType
authorredestad
Tue, 11 Apr 2017 22:32:49 +0200
changeset 44592 6b028630b652
parent 44591 b9bf065070fe
child 44594 273249225894
8178480: Wrong exception being thrown on an invalid MethodType Reviewed-by: psandoz
jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Tue Apr 11 18:57:46 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Tue Apr 11 22:32:49 2017 +0200
@@ -673,9 +673,7 @@
     /**
      * Generate customized bytecode for a given LambdaForm.
      */
-    static MemberName generateCustomizedCode(LambdaForm form) {
-        final MethodType invokerType = form.methodType();
-
+    static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
         MemberName pregenerated = lookupPregenerated(form, invokerType);
         if (pregenerated != null)  return pregenerated; // pre-generated bytecode
 
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Tue Apr 11 18:57:46 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Tue Apr 11 22:32:49 2017 +0200
@@ -847,9 +847,14 @@
         if (vmentry != null && isCompiled) {
             return;  // already compiled somehow
         }
-        assert(vmentry == null || vmentry.getMethodType().basicType().equals(methodType()));
+
+        // Obtain the invoker MethodType outside of the following try block.
+        // This ensures that an IllegalArgumentException is directly thrown if the
+        // type would have 256 or more parameters
+        MethodType invokerType = methodType();
+        assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType));
         try {
-            vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this);
+            vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this, invokerType);
             if (TRACE_INTERPRETER)
                 traceInterpreter("compileToBytecode", this);
             isCompiled = true;