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

Decompile Java Streams to beautiful EO #329

Open
maxonfjvipon opened this issue Jun 26, 2024 · 11 comments
Open

Decompile Java Streams to beautiful EO #329

maxonfjvipon opened this issue Jun 26, 2024 · 11 comments
Assignees
Labels
enhancement New feature or request soon This issue will be solved soon

Comments

@maxonfjvipon
Copy link
Member

We have the next java code:

String[] strings = new String[10];
for (int i = 0; i < strings.length; i++) {
    strings[i] = String.valueOf(i);
}
int sum = Arrays.stream(strings)
    .filter(s -> !s.equals(""))
    .mapToInt(s -> Integer.parseInt(s))
    .sum();
System.out.println(sum);

After compilation, disassembling and decompiling it looks like this: decompiled.txt

In short - there are only opcodes, no decompilation is happening.

Ideally, the EO after decompilation should look something like this (I'm considering only working with Streams)

[] > factorial-application
  [] > new
    ... > @
  [] > main
    seq > @
      *
        ...
        java_util_Arrays.java_util_Arrays$stream
          java_lang_String[]-strings                         # I'm not sure if it's valid but we should mark that it's an array somehow
        .java_util_stream_Stream$filter
          [java_lang_String-s]
            seq > @
              *
                java_lang_String-s.java_lang_String$equals
                  ""
                .not
        .java_util_stream_Stream$mapToInt
          [java_lang_String-s]
            seq > @
              *
                java_lang_Integer.java_lang_Integer$parseInt
                  java_lang_String-s
        .java_util_stream_IntStream$sum > int_sum
        ...

Of course maybe it's not possible to get exactly such picture after decompilation because of bytecode restrictions. But the closer - the better

@volodya-lombrozo volodya-lombrozo self-assigned this Jun 26, 2024
@volodya-lombrozo volodya-lombrozo added the enhancement New feature or request label Jun 26, 2024
@volodya-lombrozo
Copy link
Member

@maxonfjvipon Thank you for the explanation.

@volodya-lombrozo volodya-lombrozo added the soon This issue will be solved soon label Jul 8, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
@volodya-lombrozo
Copy link
Member

@maxonfjvipon Can we change the code you provided in the description to the following:

long start = System.currentTimeMillis();
String[] strings = IntStream.range(0, 10)
    .mapToObj(i -> String.valueOf(i))
    .toArray(String[]::new);
int sum = Arrays.stream(strings)
    .filter(s -> Boolean.valueOf(s.equals("")).equals(false))
    .mapToInt(s -> Integer.parseInt(s))
    .sum();

?
Otherwise I will need to implement decompilation of many opcodes including arrays related opcodes and, what is the most important, GOTO instruction, which is the most problematic instruction (we will need to preserve the control-flow.)

@maxonfjvipon
Copy link
Member Author

@volodya-lombrozo sure, the creation of array of strings is not important step for us, we won't touch it in the optimizations

volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 9, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 10, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 10, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 10, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 10, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 11, 2024
@0pdd
Copy link

0pdd commented Jul 11, 2024

@maxonfjvipon 2 puzzles #341, #342 are still not solved.

volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
volodya-lombrozo added a commit to volodya-lombrozo/opeo-maven-plugin that referenced this issue Jul 12, 2024
@0pdd
Copy link

0pdd commented Jul 12, 2024

@maxonfjvipon 7 puzzles #341, #342, #344, #345, #346, #347, #348 are still not solved.

@0pdd
Copy link

0pdd commented Jul 29, 2024

@maxonfjvipon 6 puzzles #341, #342, #344, #345, #346, #347 are still not solved; solved: #348.

@0pdd
Copy link

0pdd commented Aug 1, 2024

@maxonfjvipon 7 puzzles #341, #342, #344, #345, #346, #347, #361 are still not solved; solved: #348.

@0pdd
Copy link

0pdd commented Aug 2, 2024

@maxonfjvipon 8 puzzles #341, #342, #344, #345, #346, #347, #361, #363 are still not solved; solved: #348.

@0pdd
Copy link

0pdd commented Aug 6, 2024

@maxonfjvipon 8 puzzles #341, #342, #345, #346, #347, #361, #363, #366 are still not solved; solved: #344, #348.

@0pdd
Copy link

0pdd commented Aug 13, 2024

@maxonfjvipon 8 puzzles #341, #342, #345, #346, #361, #363, #366, #385 are still not solved; solved: #344, #347, #348.

@0pdd
Copy link

0pdd commented Aug 14, 2024

@maxonfjvipon 7 puzzles #341, #342, #345, #346, #361, #363, #366 are still not solved; solved: #344, #347, #348, #385.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request soon This issue will be solved soon
Projects
None yet
Development

No branches or pull requests

3 participants