Quantcast

RFR: 8178480: Wrong exception being thrown on an invalid MethodType

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RFR: 8178480: Wrong exception being thrown on an invalid MethodType

Claes Redestad
Hi,

JDK-8178387 subtly and inadvertently changed what exception was being
thrown by LambdaForm.compileToBytecode in
certain cases - this patch reverts this simplification and adds a
comment to warn against future attempts to
simplify too much..

Bug: https://bugs.openjdk.java.net/browse/JDK-8178480

diff -r 9363dd4a4fb9
src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
---
a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
Tue Apr 11 18:57:46 2017 +0200
+++
b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
Tue Apr 11 21:35:59 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

diff -r 9363dd4a4fb9
src/java.base/share/classes/java/lang/invoke/LambdaForm.java
--- a/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue
Apr 11 18:57:46 2017 +0200
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue
Apr 11 21:35:59 2017 +0200
@@ -847,9 +847,10 @@
          if (vmentry != null && isCompiled) {
              return;  // already compiled somehow
          }
-        assert(vmentry == null ||
vmentry.getMethodType().basicType().equals(methodType()));
+        MethodType invokerType = methodType(); // forces IAE to happen
outside try-catch block
+        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;


Thanks!

/Claes
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RFR: 8178480: Wrong exception being thrown on an invalid MethodType

Paul Sandoz
Tricky!

Would you mind making the comment a little more descriptive? e.g.

// 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

(IAE can be confused with Access or Argument)

Paul.

> On 11 Apr 2017, at 12:42, Claes Redestad <[hidden email]> wrote:
>
> Hi,
>
> JDK-8178387 subtly and inadvertently changed what exception was being thrown by LambdaForm.compileToBytecode in
> certain cases - this patch reverts this simplification and adds a comment to warn against future attempts to
> simplify too much..
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8178480
>
> diff -r 9363dd4a4fb9 src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
> --- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Tue Apr 11 18:57:46 2017 +0200
> +++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Tue Apr 11 21:35:59 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
>
> diff -r 9363dd4a4fb9 src/java.base/share/classes/java/lang/invoke/LambdaForm.java
> --- a/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue Apr 11 18:57:46 2017 +0200
> +++ b/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue Apr 11 21:35:59 2017 +0200
> @@ -847,9 +847,10 @@
>         if (vmentry != null && isCompiled) {
>             return;  // already compiled somehow
>         }
> -        assert(vmentry == null || vmentry.getMethodType().basicType().equals(methodType()));
> +        MethodType invokerType = methodType(); // forces IAE to happen outside try-catch block
> +        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;
>
>
> Thanks!
>
> /Claes

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RFR: 8178480: Wrong exception being thrown on an invalid MethodType

Claes Redestad
On 2017-04-11 22:15, Paul Sandoz wrote
> Would you mind making the comment a little more descriptive? e.g.
>
> // 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

Sure, I'll use that. Thanks for the quick review!

/Claes

Loading...