Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jdk21/JEP456 ISSUE] jdk21/jep456 433 preview feature #34

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

cboudereau
Copy link
Owner

@cboudereau cboudereau commented Sep 27, 2023

It seems that the code compiles (locally only since github action for java does not support yet JDK21) with preview feature of JDK21 but fails when running unit tests:

jdk21:

openjdk 21 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

1. Issue

running clean compile works :

mvn clean compile

while clean test doesn't with the following error:

[ERROR]   SimpleTest.simple:17 ┬╗ Verify Bad local variable type
Exception Details:
  Location:
    io/github/cboudereau/dataseries/Union$Value.compareTo(Lio/github/cboudereau/dataseries/Union$Value;)I @297: aload
  Reason:
    Type top (current frame, locals[9]) is not assignable to reference type
  Current Frame:
    bci: @297
    flags: { }
    locals: { 'io/github/cboudereau/dataseries/Union$Value', 'io/github/cboudereau/dataseries/Union$Value', '[Z', 'io/github/cboudereau/dataseries/Union$Value$Tuple', integer, 'io/github/cboudereau/dataseries/Union$Value$Tuple', top, top, top, top, top, 'io/github/cboudereau/dataseries/Union$Value$Fixed', 'io/github/cboudereau/dataseries/Union$Value', integer, 'io/github/cboudereau/dataseries/Union$Value', integer } 
    stack: { }
  Bytecode:
    0000000: 1278 c000 7a4d bb00 0c59 2a2b b700 0e59
    0000010: b800 1157 4e03 3604 2c05 0454 2d15 04ba
    0000020: 0017 0000 ab00 0000 0000 0014 0000 0001
    0000030: 0000 0000 0000 0022 bb00 1b59 0101 b700
    0000040: 1d2c 0604 54bf 2d3a 0519 052c 0704 54b6
    0000050: 0020 c000 243a 0c2c 0804 5403 360d 2c10
    0000060: 0604 5419 0c15 0dba 0026 0000 aa00 0000
    0000070: 0000 00df ffff ffff 0000 0001 0000 00df
    0000080: 0000 001c 0000 006d 1905 2c10 0704 54b6
    0000090: 0027 c000 243a 0e03 360f 190e 150f ba00
    00000a0: 2600 00aa 0000 002b ffff ffff 0000 0001
    00000b0: 0000 002b 0000 0019 0000 0022 032c 1008
    00000c0: 0454 a700 9404 2c10 0904 54a7 008b 0436
    00000d0: 0d2c 100a 0454 a7ff 8d19 052c 100b 0454
    00000e0: b600 27c0 0024 3a0e 2c10 0c04 5403 360f
    00000f0: 190e 150f ba00 2600 00aa 0000 0000 0047
    0000100: ffff ffff 0000 0001 0000 0047 0000 001b
    0000110: 0000 0024 022c 100d 0454 a700 3c19 0ec0
    0000120: 0001 3a0b 2c10 0e04 5419 09b4 002a 190b
    0000130: b400 2ab9 002e 0200 2c10 0f04 54a7 0019
    0000140: 0536 0d2c 1010 0454 a7ff 1b04 3604 2c10
    0000150: 1104 54a7 fec9 2c10 1204 54ac 4ebb 001b
    0000160: 592d b600 362d b700 1d2c 1013 0454 bf
  Exception Handler Table:
    bci [75, 82] => handler: 348
    bci [138, 146] => handler: 348
    bci [219, 227] => handler: 348
  Stackmap Table:
    append_frame(@28,Object[#122],Object[#12],Integer)
    same_frame(@56)
    same_frame(@70)
    full_frame(@99,{Object[#36],Object[#36],Object[#122],Object[#12],Integer,Object[#12],Top,Top,Top,Top,Top,Top,Object[#36],Integer},{})   
    same_frame(@136)
    append_frame(@154,Object[#36],Integer)
    same_frame(@188)
    same_frame(@197)
    same_frame(@206)
    chop_frame(@217,2)
    append_frame(@240,Object[#36],Integer)
    same_frame(@276)
    same_frame(@285)
    same_frame(@320)
    chop_frame(@331,2)
    full_frame(@342,{Object[#36],Object[#36],Object[#122]},{Integer})
    same_locals_1_stack_item_frame(@348,Object[#52])

2. Workaround
The problem is at line 34:

        @Override
        default int compareTo(final Value<T> o) {
            return switch (new Tuple<>(this, o)) {
                case final Tuple<Value<T>, Value<T>>(Value.Infinite<T> _, Value.Infinite<T> _) -> 0;
                case final Tuple<Value<T>, Value<T>>(Value.Infinite<T> _, Value.Fixed<T> _) -> 1;
                case final Tuple<Value<T>, Value<T>>(Value.Fixed<T> _, Value.Infinite<T> _) -> -1;
                case final Tuple<Value<T>, Value<T>>(Value.Fixed<T> fst, Value.Fixed<T> snd) ->
                    fst.value.compareTo(snd.value);
            };
        }

By naming the first variable of the third case, everything is working

        @Override
        default int compareTo(final Value<T> o) {
            return switch (new Tuple<>(this, o)) {
                case final Tuple<Value<T>, Value<T>>(Value.Infinite<T> _, Value.Infinite<T> _) -> 0;
                case final Tuple<Value<T>, Value<T>>(Value.Infinite<T> _, Value.Fixed<T> _) -> 1;
                case final Tuple<Value<T>, Value<T>>(Value.Fixed<T> fst, Value.Infinite<T> _) -> -1;
                case final Tuple<Value<T>, Value<T>>(Value.Fixed<T> fst, Value.Fixed<T> snd) ->
                    fst.value.compareTo(snd.value);
            };
        }

@cboudereau
Copy link
Owner Author

openjdk issue: https://bugs.openjdk.org/browse/JDK-8317048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant