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

Improvements #128

Merged
merged 10 commits into from Oct 17, 2022
Merged

Improvements #128

merged 10 commits into from Oct 17, 2022

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Oct 14, 2022

Several improvements:

  • make all getInputResultHandles() implementations consistent
  • fix addition of long values (typo in the type descriptor)
  • replace usage of LDC for loading common constants with specialized instructions (ICONST_0, ICONST_1 etc.)
  • add multiplication (IMUL etc.)
  • add long/float/double comparison (LCMP, FCMP*, DCMP*)
  • add reference inequality (IF_ACMPNE)
  • add returnBoolean, returnInt, returnNull and returnVoid to simplify common method exits
  • add utility for generating StringBuilder chains
  • add utilities for generating equals, hashCode and toString, similarly to what IDEs do
  • add documentation of high-level utilities in the Gizmo class to USAGE.adoc

Most implementations of the `Operation.getInputResultHandles()` method
return a `LinkedHashSet`, even if the interface demands just `Set`.
A few existing implementations returned just `HashSet`, and this
commit makes them consistent with the rest.
The code that emits LADD had a typo: the correct descriptor for the `long`
type is `J` and not `Z`.
@Ladicek
Copy link
Contributor Author

Ladicek commented Oct 14, 2022

Note it is probably easiest to review individual commits separately.

@Ladicek Ladicek force-pushed the improvements branch 2 times, most recently from ada1ba0 to 8af0225 Compare October 14, 2022 15:00
Previously, all constants were loaded from the constant pool and pushed
on the stack using the LDC instruction. This is less efficient than
necessary, because for some very commonly used constants, the JVM ISA
has dedicated instructions: ICONST_0, ICONST_1 etc. With this commit,
all the common constats are loaded using these instructions.
@Ladicek Ladicek force-pushed the improvements branch 3 times, most recently from ec56176 to b4e76f0 Compare October 17, 2022 08:30
Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

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

Awesome set of improments and fixes! Thanks a lot Ladislav.

@@ -1177,7 +1177,7 @@ void writeBytecode(MethodVisitor methodVisitor) {

@Override
Set<ResultHandle> getInputResultHandles() {
return new HashSet<>(Arrays.asList(a1, a2));
return new LinkedHashSet<>(Arrays.asList(a1, a2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, would it make sense to use HashSet everywhere instead? Or clarify the contract of BytecodeCreatorImpl.Operation.getInputResultHandles()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to do some experiments to improve the generated code, and as part of them, I'd probably make this a List, actually.

src/main/java/io/quarkus/gizmo/BytecodeCreator.java Outdated Show resolved Hide resolved
src/main/java/io/quarkus/gizmo/Gizmo.java Show resolved Hide resolved
USAGE.adoc Outdated Show resolved Hide resolved
Previously, the only arithmetic operation available through Gizmo API
was addition (IADD etc.). This commit adds multiplication (IMUL etc.),
as well as internal helper methods that will help implement more
arithmetic operations in the future.
As opposed to comparing `int` values, where the JVM ISA provides instructions
that branch directly, comparing `long`, `float` and `double` values is more
involved. The LCMP, FCMP* and DCMP* instructions push a comparison result
on the stack as an `int` and an `int` branching instruction must be used
afterwards.
The `ifReferencesEqual` method emits the IF_ACMPEQ instruction. This commit
adds `ifReferencesNotEqual`, which emits IF_ACMPNE. This is useful to generate
bytecode similar to what javac generates.
Notably, 4 methods are added to simplify common `returnValue` invocations.
The `returnBoolean` and `returnInt` methods simplify returning a constant,
`returnNull` simplifies returning the `null` reference, and `returnVoid`
makes return from a `void` method or constructor more obvious.
Most notably, `JdkMap.instance(ResultHandle)` is deprecated and replaced
by `JdkMap.on(ResultHandle)` to be consistent with other classes.
@mkouba mkouba merged commit 25e1f1f into quarkusio:main Oct 17, 2022
@Ladicek Ladicek deleted the improvements branch October 17, 2022 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants