Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 28, 2024
2 parents b40b466 + 3d26fff commit 944c2a6
Show file tree
Hide file tree
Showing 74 changed files with 3,576 additions and 320 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
target
target-failed
target-failed*
target-standard*
!src/it/decompile-compile/target
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ SOFTWARE.
-->
<pomExcludes>
<exclude>spring-fat/pom.xml</exclude>
<!--
@todo #229:90min Enable the fuse integration test.
The 'fuse' integration test is disabled in the default profile.
It uses outdated format of XMIR representation of bytecode.
We should either update the representation generated or just remove the test.
-->
<exclude>fuse/pom.xml</exclude>
</pomExcludes>
</configuration>
<dependencies>
Expand Down
50 changes: 45 additions & 5 deletions src/it/spring-fat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,53 @@ This might be helpful to exclude an optimization influence.

Here is the summary of the first results of the `spring-fat` integration test:

### Total

- The application starts and runs successfully.
- The average test time is approximately **826 seconds (13 minutes)**.
- Time is **11:08 min**.
- The total number of classes is **19511**.
- Phases: **disassemble**, **decompile**, **optimize**, **phi**, **compile**, *
*assemble**.

### Disassemble

- All classes are successfully disassembled.
- The total number of classes is **19511**.
- The Disassembly phase takes approximately **1 minute**.
- The Decompile phase takes approximately **K minutes**.
- The Compile phase takes approximately **L minutes**.
- The Assembly phase takes approximately **56 seconds**.
- The Disassembly phase takes **50s**.

### Decompile

- Some classes are not decompiled due to unsupported instructions. We skip a
file if it contains at least one instruction we don't support yet. Skipped
files are copied as is from the disassembled directory to the decompiled.
- The total number of truly decompiled classes is **4672**.
- The Decompile phase takes **? min**.

### Optimize

- We used the "staticize" optimization from the `ineo-maven-plugin`.
- The total number of optimized classes is **1**.
- The Optimize phase takes **? min**.

### Phi

- We print PHI expressions for all truly decompiled classes.
- Some classes are not printed due to some issues with the XMIR representation.
We skip a file if it contains at least one issue.
- The total number of classes with PHI expressions is **4153**.
- The Phi phase takes **? min**.

### Compile

- We compile all the classes from different XMIR representations.
- The total number of compiled classes is **19511**.
- The Compile phase takes **? min**.

### Assemble

- We assemble all the classes back to the bytecode.
- The total number of assembled classes is **19511**.
- The Assembly phase takes **57s**.

## Developer Notes

Expand Down
2 changes: 1 addition & 1 deletion src/it/spring-fat/invoker.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
invoker.goals=clean test -e
invoker.profiles=disassemble,decompile,ineo,compile,assemble
invoker.profiles=disassemble,decompile,ineo,phi,compile,assemble
4 changes: 3 additions & 1 deletion src/main/java/org/eolang/opeo/SelectiveDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public void decompile() {
final XmirEntry res;
final List<String> found = entry.xpath(this.xpath());
if (found.isEmpty()) {
res = entry.transform(xml -> new JeoDecompiler(xml).decompile());
res = entry.transform(
xml -> new JeoDecompiler(xml, entry.relative()).decompile()
);
this.modified.save(res);
} else {
Logger.info(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/opeo/ast/ArrayConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ArrayConstructor(final AstNode size, final String type) {
public Iterable<Directive> toXmir() {
final Directives directives = new Directives();
directives.add("o")
.attr("base", ".array")
.attr("base", ".array-node")
.append(new DirectivesData(this.type))
.append(this.size.toXmir());
return directives.up();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/eolang/opeo/ast/AstNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*/
package org.eolang.opeo.ast;

import java.util.Collections;
import java.util.List;
import org.xembly.Directive;

/**
* Abstract syntax tree node.
Expand All @@ -36,4 +38,21 @@ public interface AstNode extends Xmir {
* @return List of opcodes.
*/
List<AstNode> opcodes();

/**
* Empty node that does nothing.
* @since 0.2
*/
final class Empty implements AstNode {

@Override
public List<AstNode> opcodes() {
return Collections.emptyList();
}

@Override
public Iterable<Directive> toXmir() {
return Collections.emptyList();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/opeo/ast/ClassField.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ClassField(final Attributes attributes) {
public Iterable<Directive> toXmir() {
return new Directives()
.add("o")
.attr("base", "staticfield")
.attr("base", "static-field")
.attr("scope", this.attributes)
.up();
}
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/org/eolang/opeo/ast/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 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.opeo.ast;

import java.util.Collections;
import java.util.List;
import org.eolang.jeo.representation.DataType;
import org.eolang.jeo.representation.directives.DirectivesData;
import org.eolang.jeo.representation.xmir.XmlNode;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.xembly.Directive;
import org.xembly.Directives;

/**
* Constant.
* This class represents LDC instruction in the JVM bytecode.
* @since 0.2
* @todo #229:90min Do we need {@link Constant} class?
* It seems that this class is rather similar to {@link Literal} class.
* We need to investigate if we can remove this class and use {@link Literal} instead.
* If we can't remove this class, we need to add more tests to cover all the cases
* where {@link Constant} is used.
*/
public final class Constant implements AstNode, Typed {

/**
* The constant value.
*/
private final Object value;

/**
* Constructor.
* @param node The XMIR node with value to parse.
*/
public Constant(final XmlNode node) {
this(Constant.parse(node));
}

/**
* Constructor.
* @param value The constant value.
*/
public Constant(final Object value) {
this.value = value;
}

@Override
public List<AstNode> opcodes() {
return Collections.singletonList(new Opcode(Opcodes.LDC, this.value));
}

@Override
public Iterable<Directive> toXmir() {
return new Directives().add("o")
.attr("base", "load-constant")
.append(new DirectivesData(this.value))
.up();
}

@Override
public Type type() {
final Type result;
if (this.value instanceof Type) {
result = (Type) this.value;
} else {
result = Type.getType(this.value.getClass());
}
return result;
}

/**
* Parse the Constant value from XMIR representation.
* @param node The node to parse.
* @return The parsed value.
*/
private static Object parse(final XmlNode node) {
final XmlNode child = node.firstChild();
return DataType.find(child.attribute("base").orElseThrow())
.decode(child.text());
}
}
57 changes: 46 additions & 11 deletions src/main/java/org/eolang/opeo/ast/Constructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class Constructor implements AstNode, Typed {
/**
* Constructor type.
*/
private final String ctype;
private final AstNode ctype;

/**
* Constructor attributes.
Expand Down Expand Up @@ -98,9 +98,23 @@ public Constructor(
final Attributes attrs,
final List<AstNode> args
) {
this.ctype = type;
this.attributes = attrs;
this.arguments = args;
this(new NewAddress(type), attrs, args);
}

/**
* Constructor.
* @param ctype Constructor type
* @param attributes Constructor attributes
* @param arguments Constructor arguments
*/
public Constructor(
final AstNode ctype,
final Attributes attributes,
final List<AstNode> arguments
) {
this.ctype = ctype;
this.attributes = attributes;
this.arguments = arguments;
}

@Override
Expand All @@ -109,23 +123,20 @@ public Iterable<Directive> toXmir() {
directives.add("o")
.attr("base", ".new")
.attr("scope", this.attributes)
.add("o")
.attr("base", this.ctype)
.up();
.append(this.ctype.toXmir());
this.arguments.stream().map(AstNode::toXmir).forEach(directives::append);
return directives.up();
}

@Override
public List<AstNode> opcodes() {
final List<AstNode> res = new ArrayList<>(0);
res.add(new Opcode(Opcodes.NEW, this.ctype));
res.add(new Opcode(Opcodes.DUP));
res.addAll(this.ctype.opcodes());
this.arguments.stream().map(AstNode::opcodes).forEach(res::addAll);
res.add(
new Opcode(
Opcodes.INVOKESPECIAL,
this.ctype,
this.type(this.ctype),
"<init>",
this.attributes.descriptor(),
this.attributes.interfaced()
Expand All @@ -136,6 +147,30 @@ public List<AstNode> opcodes() {

@Override
public Type type() {
return Type.getObjectType(this.ctype);
return ((Typed) this.ctype).type();
}

/**
* Get a type of constructor.
* @param node Constructor node.
* @return Type of constructor.
*/
private String type(final AstNode node) {
final String result;
if (node instanceof NewAddress) {
result = ((NewAddress) node).typeAsString();
} else if (node instanceof Reference) {
result = this.type(((Reference) node).object());
} else if (node instanceof Duplicate) {
result = this.type(((Duplicate) node).origin());
} else {
throw new IllegalStateException(
String.format(
"Unexpected node type: %s",
node.getClass().getCanonicalName()
)
);
}
return result;
}
}
Loading

10 comments on commit 944c2a6

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-b419f9db discovered in pom.xml) and submitted as #274. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-f7413085 discovered in src/main/java/org/eolang/opeo/ast/Constant.java) and submitted as #275. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-1fb106a9 discovered in src/main/java/org/eolang/opeo/ast/ConstructorDescriptor.java) and submitted as #276. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-7fc7abda discovered in src/main/java/org/eolang/opeo/ast/Duplicate.java) and submitted as #277. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-4ff35b41 discovered in src/main/java/org/eolang/opeo/ast/Invocation.java) and submitted as #278. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-cd34d827 discovered in src/main/java/org/eolang/opeo/ast/Popped.java) and submitted as #279. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-a73992aa discovered in src/main/java/org/eolang/opeo/compilation/JeoCompiler.java) and submitted as #280. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-e1115bff discovered in src/main/java/org/eolang/opeo/compilation/JeoCompiler.java) and submitted as #281. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-b768fbb7 discovered in src/main/java/org/eolang/opeo/compilation/JeoCompiler.java) and submitted as #282. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 944c2a6 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 229-5bb45fdb discovered in src/test/java/it/JeoAndOpeoTest.java) and submitted as #283. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.