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

feat(#344): Identify Problem With INVOKESPECIAL Instruction #360

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/it/streams/src/main/java/org/eolang/streams/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static void main(String... args) {
.filter(s -> Boolean.valueOf(s.equals("")).equals(false))
.mapToInt(s -> Integer.parseInt(s))
.sum();
System.out.printf("sum=%d time=%d\n", sum, System.currentTimeMillis() - start);
System.out.printf("sum=%d time=%d%n", sum, System.currentTimeMillis() - start);
// Here I test {@link Playground} class.
System.out.printf("Playground is available %b%n", new Playground(0).isAvailable());
}
}
44 changes: 44 additions & 0 deletions src/it/streams/src/main/java/org/eolang/streams/Playground.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.streams;

import java.util.Arrays;
import java.util.stream.IntStream;

public class Playground {

private final int d;

public Playground(final int d) {
this.d = d;
}

public boolean isAvailable() {
return isZero();
}

private boolean isZero() {
return new Integer(0).equals(this.d);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.util.Collections;
import java.util.List;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Constructor;
import org.eolang.opeo.ast.Labeled;
import org.eolang.opeo.ast.Super;
import org.eolang.opeo.ast.This;
Expand All @@ -44,10 +42,34 @@
* This is a clear sign that the class hierarchy is not well designed.
* The original problem lies in the {@link Labeled} class.
* We need to find more elegant solutions to handle labels in AST.
* @checkstyle NoJavadocForOverriddenMethodsCheck (500 lines)
* @checkstyle MultilineJavadocTagsCheck (500 lines)
*/
public final class InvokespecialHandler implements InstructionHandler {

/**
* Handle invokespecial instruction.
* @param state Current instruction to handle together with operand stack and variables.
* @todo #344:90min Super and Constructor classes ambiguity.
* Recently I removed the following code from this method:
* {@code
* state.stack().push(
* new Constructor(
* target,
* new Attributes().descriptor(descriptor).interfaced(interfaced),
* args
* )
* );
* }
* The reason behind this integration test with
* WebProperties$Resources$Chain$Strategy$Content.xmir class.
* See {@link JeoAndOpeoTest} for more info.
* We need to use both Super and This classes.
* Moreover, we might need to add some other representations.
* Don't forget to remove suppressions.
*/
@Override
@SuppressWarnings("PMD.UnusedLocalVariable")
public void handle(final DecompilerState state) {
final String type = (String) state.operand(0);
final String name = (String) state.operand(1);
Expand All @@ -64,11 +86,7 @@ public void handle(final DecompilerState state) {
);
} else {
state.stack().push(
new Constructor(
target,
new Attributes().descriptor(descriptor).interfaced(interfaced),
args
)
new Super(target, args, descriptor, type, name)
);
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/test/java/it/JeoAndOpeoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ void compilesAlreadyCompiledAndAssembles(final String path) {
);
}

@ParameterizedTest
@CsvSource("WebProperties$Resources$Chain$Strategy$Content.xmir")
@Disabled
void compilesDecompiled(final String path) {
Assertions.assertDoesNotThrow(
() -> new XmirRepresentation(
new JeoCompiler(
new XMLDocument(
new BytesOf(
new ResourceOf(String.format("xmir/decompiled/%s", path))
).asBytes()
)
).compile()
).toBytecode(),
"We expect that the pipeline 'already-decompiled-xmir' -> (compile) -> (assemble) ->'.class' will not throw any exceptions."
);
}

@ParameterizedTest
@CsvSource({
"xmir/disassembled/AsIsEscapeUtil.xmir",
Expand All @@ -108,7 +126,8 @@ void compilesAlreadyCompiledAndAssembles(final String path) {
"xmir/disassembled/Lambda.xmir",
"xmir/disassembled/Main.xmir",
"xmir/disassembled/UndertowWebServerFactoryCustomizer$ServerOptions.xmir",
"xmir/disassembled/MutableCoercionConfig.xmir"
"xmir/disassembled/MutableCoercionConfig.xmir",
"xmir/disassembled/WebProperties$Resources$Chain$Strategy$Content.xmir"
})
void decompilesCompilesAndKeepsTheSameInstructions(final String path) throws Exception {
final XMLDocument original = new XMLDocument(new BytesOf(new ResourceOf(path)).asBytes());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<program dob="2024-08-01T14:18:35.378920Z"
ms="1722521915378"
name="j$WebProperties$Resources$Chain$Strategy$Content"
revision="0.0.0"
time="2024-08-01T14:18:35.378920Z"
version="0.0.0">
<listing>yv66vgAAADQAOwoACAAtCgAJAC4JAAgALwcAMAgAMQkACAAyCQAIADMHADQHADUBAApjdXN0b21pemVkAQABWgEAB2VuYWJsZWQBAAVwYXRocwEAE1tMamF2YS9sYW5nL1N0cmluZzsBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQ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luZ2ZyYW1ld29yay9ib290L2F1dG9jb25maWd1cmUvd2ViL1dlYlByb3BlcnRpZXMkUmVzb3VyY2VzJENoYWluJFN0cmF0ZWd5AQA4b3JnL3NwcmluZ2ZyYW1ld29yay9ib290L2F1dG9jb25maWd1cmUvd2ViL1dlYlByb3BlcnRpZXMAIQAIAAkAAAADAAIACgALAAAAAgAMAAsAAAACAA0ADgAAAAcAAQAPABAAAQARAAAASQAFAAEAAAAXKrcAAioDtQADKgS9AARZAxIFU7UABrEAAAACABIAAAAOAAMAAAD0AAQA9gAJAQEAEwAAAAwAAQAAABcAFAAdAAAAAQAeAB8AAQARAAAALwABAAEAAAAFKrQAB6wAAAACABIAAAAGAAEAAAEEABMAAAAMAAEAAAAFABQAHQAAAAEAIAAhAAIAEQAAAEcAAgACAAAACyoEtQADKhu1AAexAAAAAgASAAAADgADAAABCAAFAQkACgEKABMAAAAWAAIAAAALABQAHQAAAAAACwAMAAsAAQAiAAAABQEADAAAAAEAIwAkAAEAEQAAAC8AAQABAAAABSq0AAawAAAAAgASAAAABgABAAABDQATAAAADAABAAAABQAUAB0AAAABACUAJgACABEAAABHAAIAAgAAAAsqBLUAAyortQAGsQAAAAIAEgAAAA4AAwAAAREABQESAAoBEwATAAAAFgACAAAACwAUAB0AAAAAAAsADQAOAAEAIgAAAAUBAA0AAAACACcAHwABABEAAAAvAAEAAQAAAAUqtAADrAAAAAIAEgAAAAYAAQAAARYAEwAAAAwAAQAAAAUAFAAdAAAQCAAoACkAAQARAAAALwABAAEAAAAFKrcAAawAAAACABIAAAAGAAEAAAD0ABMAAAAMAAEAAAAFACoAHQAAAAIAKwAAAAIALAAXAAAAIgAEABUANgAWAAkAGAAVABkACQAaABgAGwAJAAgAGgAcAAk=</listing>
<errors/>
<sheets/>
<license/>
<metas>
<meta>
<head>package</head>
<tail>org.springframework.boot.autoconfigure.web</tail>
<part>org.springframework.boot.autoconfigure.web</part>
</meta>
<meta>
<head>alias</head>
<tail>org.eolang.jeo.opcode</tail>
<part>org.eolang.jeo.opcode</part>
</meta>
<meta>
<head>alias</head>
<tail>org.eolang.jeo.label</tail>
<part>org.eolang.jeo.label</part>
</meta>
</metas>
<objects>
<o abstract="" name="j$WebProperties$Resources$Chain$Strategy$Content">
<o base="int" data="bytes" line="928042091" name="version">00 00 00 00 00 00 00 34</o>
<o base="int" data="bytes" line="170739509" name="access">00 00 00 00 00 00 00 21</o>
<o base="string" data="bytes" line="1094639065" name="supername">6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74</o>
<o base="tuple" line="1694433597" name="interfaces" star=""/>
<o base="field" line="999" name="j$customized">
<o base="int"
data="bytes"
line="2003148014"
name="access-j$customized">00 00 00 00 00 00 00 02</o>
<o base="string"
data="bytes"
line="1765145613"
name="descriptor-j$customized">5A</o>
<o base="string"
data="bytes"
line="256944047"
name="signature-j$customized"/>
<o base="bool"
data="bytes"
line="1603372374"
name="value-j$customized"
scope="nullable"/>
</o>
<o base="field" line="999" name="j$enabled">
<o base="int"
data="bytes"
line="1462359067"
name="access-j$enabled">00 00 00 00 00 00 00 02</o>
<o base="string"
data="bytes"
line="1201915791"
name="descriptor-j$enabled">5A</o>
<o base="string"
data="bytes"
line="1173528563"
name="signature-j$enabled"/>
<o base="bool"
data="bytes"
line="1643614846"
name="value-j$enabled"
scope="nullable"/>
</o>
<o base="field" line="999" name="j$paths">
<o base="int" data="bytes" line="806406194" name="access-j$paths">00 00 00 00 00 00 00 02</o>
<o base="string"
data="bytes"
line="1335432087"
name="descriptor-j$paths">5B 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B</o>
<o base="string"
data="bytes"
line="900080069"
name="signature-j$paths"/>
<o base="class"
data="bytes"
line="1560898856"
name="value-j$paths"
scope="nullable"/>
</o>
<o abstract=""
name="j$access$400-KExvcmcvc3ByaW5nZnJhbWV3b3JrL2Jvb3QvYXV0b2NvbmZpZ3VyZS93ZWIvV2ViUHJvcGVydGllcyRSZXNvdXJjZXMkQ2hhaW4kU3RyYXRlZ3kkQ29udGVudDspWg==">
<o base="int" data="bytes" line="2131650352" name="access">00 00 00 00 00 00 10 08</o>
<o base="string" data="bytes" line="1009717364" name="descriptor">28 4C 6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E 24 53 74 72 61 74 65 67 79 24 43 6F 6E 74 65 6E 74 3B 29 5A</o>
<o base="string" data="bytes" line="1118774926" name="signature"/>
<o base="tuple" line="801958815" name="exceptions" star=""/>
<o abstract="" line="710855168" name="maxs">
<o base="int" data="bytes" line="1872796232" name="stack">00 00 00 00 00 00 00 01</o>
<o base="int" data="bytes" line="1130272705" name="locals">00 00 00 00 00 00 00 01</o>
</o>
<o abstract=""
name="arg__Lorg/springframework/boot/autoconfigure/web/WebProperties$Resources$Chain$Strategy$Content;__0"/>
<o base="seq" name="@">
<o base="tuple" line="810311650" name="instructions" star="">
<o base="label" data="bytes" line="1806879108">31 36 32 63 33 30 61 65 2D 35 31 34 64 2D 34 35 62 39 2D 38 37 66 31 2D 31 66 36 33 61 30 63 38 66 38 33 66</o>
<o base="opcode" line="999" name="ALOAD-1A741E">
<o base="int" data="bytes" line="52102212">00 00 00 00 00 00 00 19</o>
<o base="int" data="bytes" line="186437085">00 00 00 00 00 00 00 00</o>
</o>
<o base="opcode" line="999" name="INVOKESPECIAL-1A741F">
<o base="int" data="bytes" line="1334278930">00 00 00 00 00 00 00 B7</o>
<o base="string" data="bytes" line="383310585">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E 24 53 74 72 61 74 65 67 79 24 43 6F 6E 74 65 6E 74</o>
<o base="string" data="bytes" line="1869430827">68 61 73 42 65 65 6E 43 75 73 74 6F 6D 69 7A 65 64</o>
<o base="string" data="bytes" line="185211417">28 29 5A</o>
<o base="bool" data="bytes" line="1398842008">00</o>
</o>
<o base="opcode" line="999" name="IRETURN-1A7420">
<o base="int" data="bytes" line="805987342">00 00 00 00 00 00 00 AC</o>
</o>
<o base="label" data="bytes" line="1582759068">31 39 65 66 32 34 63 37 2D 30 35 35 39 2D 34 39 30 30 2D 61 65 35 37 2D 35 65 38 65 36 63 37 31 61 61 65 38</o>
</o>
</o>
</o>
<o base="tuple" line="1626054283" name="attributes" star="">
<o base="InnerClass">
<o base="string" data="bytes" line="1006069326">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73</o>
<o base="string" data="bytes" line="1671364141">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73</o>
<o base="string" data="bytes" line="1426891726">52 65 73 6F 75 72 63 65 73</o>
<o base="int" data="bytes" line="1569828725">00 00 00 00 00 00 00 09</o>
</o>
<o base="InnerClass">
<o base="string" data="bytes" line="707811655">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E</o>
<o base="string" data="bytes" line="996791235">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73</o>
<o base="string" data="bytes" line="1331955450">43 68 61 69 6E</o>
<o base="int" data="bytes" line="103136145">00 00 00 00 00 00 00 09</o>
</o>
<o base="InnerClass">
<o base="string" data="bytes" line="1836980820">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E 24 53 74 72 61 74 65 67 79</o>
<o base="string" data="bytes" line="275680787">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E</o>
<o base="string" data="bytes" line="1066371195">53 74 72 61 74 65 67 79</o>
<o base="int" data="bytes" line="1261658688">00 00 00 00 00 00 00 09</o>
</o>
<o base="InnerClass">
<o base="string" data="bytes" line="1484193108">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E 24 53 74 72 61 74 65 67 79 24 43 6F 6E 74 65 6E 74</o>
<o base="string" data="bytes" line="379453110">6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 62 6F 6F 74 2F 61 75 74 6F 63 6F 6E 66 69 67 75 72 65 2F 77 65 62 2F 57 65 62 50 72 6F 70 65 72 74 69 65 73 24 52 65 73 6F 75 72 63 65 73 24 43 68 61 69 6E 24 53 74 72 61 74 65 67 79</o>
<o base="string" data="bytes" line="1808466354">43 6F 6E 74 65 6E 74</o>
<o base="int" data="bytes" line="1268059433">00 00 00 00 00 00 00 09</o>
</o>
</o>
</o>
</objects>
</program>
Loading