objectionary / jeo-maven-plugin

This Maven plugin converts Java Bytecode binary files to EOLANG programs that use the "opcode" atom
https://www.objectionary.com/jeo-maven-plugin/
MIT License
10 stars 2 forks source link

Disassembling. OutOfMemoryError: Java heap space #578

Closed volodya-lombrozo closed 2 months ago

volodya-lombrozo commented 2 months ago

When I run the spring-fat integration test in opeo-maven-plugin, I get the following exception during disassble phase:

[INFO] Disassembling 'target/classes/org/apache/catalina/startup/Tomcat.class' (24Kb)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  07:23 min
[INFO] Finished at: 2024-05-07T19:04:15+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Java heap space -> [Help 1]
java.lang.OutOfMemoryError: Java heap space
    at java.util.ArrayList.iterator (ArrayList.java:947)
    at java.util.Collections$UnmodifiableCollection$1.<init> (Collections.java:1051)
    at java.util.Collections$UnmodifiableCollection.iterator (Collections.java:1050)
    at org.xembly.DomCursor.iterator (DomCursor.java:66)
    at org.xembly.AttrDirective.exec (AttrDirective.java:78)
    at org.xembly.Xembler.apply (Xembler.java:159)
    at org.xembly.Xembler.dom (Xembler.java:214)
    at org.xembly.Xembler.xml (Xembler.java:248)
    at org.eolang.jeo.representation.BytecodeRepresentation.toEO (BytecodeRepresentation.java:147)
    at org.eolang.jeo.representation.BytecodeRepresentation.toEO (BytecodeRepresentation.java:132)
    at org.eolang.jeo.Disassemble.apply (Disassemble.java:69)
    at org.eolang.jeo.LoggedTranslation.apply (LoggedTranslation.java:84)
    at org.eolang.jeo.BachedTranslator$$Lambda$387/0x00000008013cd9f8.apply (Unknown Source)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1625)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:499)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:921)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:682)
    at org.eolang.jeo.BachedTranslator.apply (BachedTranslator.java:53)
    at org.eolang.jeo.LoggedTranslator.apply (LoggedTranslator.java:98)
    at org.eolang.jeo.Disassembler.disassemble (Disassembler.java:78)
    at org.eolang.jeo.DisassembleMojo.execute (DisassembleMojo.java:104)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)

It is a performance issue which we have to solve as soon as possible. Some profiling might be required to analyze where we have the problem with excessive object allocation.

volodya-lombrozo commented 2 months ago

The main problem with high memory consumption relates to XmirRepresentations and XmirRepresentation classes. When the plugin starts parsing bytecode, it opens all class files , parses them into XML and stores them in a List container, which is extremely suboptimal, of course. We should use a different approach with streams where the plugin will handle files one by one without storing large pieces in intermediate containers.