Handle Javac Optimisation of String Concatenations
See original GitHub issueDescription of the bug It appears that when I am trying to concatenate two Strings, when one is from the storage, then the compiler complains with the following message:
Inherited methods that are not specifically implemented are not supported. Implement the method 'toString' without a 'super' call to the class Object to use it.
io.neow3j.compiler.CompilerException: Inherited methods that are not specifically implemented are not supported. Implement the method 'toString' without a 'super' call to the class Object to use it.
at io.neow3j.compiler.Compiler.throwIfObjectIsOwner(Compiler.java:603)
at io.neow3j.compiler.Compiler.handleInsn(Compiler.java:584)
at io.neow3j.compiler.NeoMethod.convert(NeoMethod.java:481)
at io.neow3j.compiler.converters.MethodsConverter.handleUncachedMethodCall(MethodsConverter.java:224)
To Reproduce Steps to reproduce the behavior:
- create new smart contract
- try to concatenate two strings: map.getString(key) + “foo”;
- or: map.get(key).toString() + “foo”
- compile
Expected behavior It should be possible to concatenate two strings like this without compiling issues.
Platform and Software
- neow3j 3.17
Issue Analytics
- State:
- Created a year ago
- Comments:24 (14 by maintainers)
Top Results From Across the Web
java - Compile time optimization of String concatenation
In Java, most optimization is performed by the runtime's just in time compiler, so generally javac optimizations don't matter much.
Read more >Java Compiler Optimization for String Concatenation - Medium
StringConcatFactory offers different strategies to generate the CallSite divided in byte-code generator using ASM and MethodHandle-based one.
Read more >JEP 280: Indify String Concatenation - OpenJDK
This will enable future optimizations of String concatenation without requiring further changes to the bytecode emitted by javac .
Read more >We Don't Need StringBuilder for Simple Concatenation - DZone
Concatenating strings is useful, but expensive. Fortunately, you don't need to use StringBuilder anymore - the compiler can handle it for you.
Read more >String concatenation in Java 9 (part 1) - Guardsquare
In this blog, we will focus on a more low-level change to the handling of Strings, namely the “indified String concatenation”. We will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tested it, and it compiles just fine now @mialbu @gsmachado 😃
@ykoitzsch I could reproduce now. Javac is run with different compile options in VSCode than in Intellij. This includes an optimisation concerning the use of the
StringBuilder
class. It ultimately breaks the compilation to Neo byte code when an optimised concatenation was produced by the Java compiler.I’ll add this issue to our backlog for now and we’ll address it in the future. As for now, until we’ve fixed this, please use the gradle plugin to compile when developing with VSCode.
If you’re interested in more details, check out this and this.
Additional Info
The following contract class fails to compile using VSCode:
In the following I’ve listed the pattern of the compiled asm class when using either Intellij or VSCode.
Parts of the asmClass instructions based on compilation using Intellij IDE
Parts of the asmClass instructions based on compilation using VSCode IDE with RedHat Java extension