Skip to content

Adds bytecode constants and utilities - #1097

Merged
popematt merged 3 commits into
amazon-ion:ion11from
popematt:bytecodeir
Oct 1, 2025
Merged

popematt merged 3 commits into
amazon-ion:ion11from
popematt:bytecodeir

Conversation

@popematt

Copy link
Copy Markdown
Contributor

Issue #, if available:

None

Description of changes:

This is the first step of production-izing the design that I prototyped in https://github.com/popematt/ion-java/tree/bytecode-generator-experiment.

This PR adds constants and utilities to define the intermediate representation bytecode. It looks like a huge PR, but it's 90% comments and constants.

I'm not certain that this the most logical way to set up the package structure, and I'm open to suggestions. For now, I was just going to do something like this to keep it separate from the many and varied existing reader/writer implementations.

com/
amazon/
ion
 |-- bytecode
 |   |-- ir
 |   |-- binary10
 |   |-- binary11
 |
 |-- impl
 |-- ...

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov

codecov Bot commented Sep 26, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.62189% with 49 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (ion11@1b68d1e). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...n/java/com/amazon/ion/bytecode/ir/OperationKind.kt 0.00% 26 Missing ⚠️
...c/main/java/com/amazon/ion/bytecode/ir/Debugger.kt 70.14% 12 Missing and 8 partials ⚠️
...java/com/amazon/ion/bytecode/ir/InstructionInfo.kt 99.02% 0 Missing and 1 partial ⚠️
...in/java/com/amazon/ion/bytecode/ir/Instructions.kt 75.00% 1 Missing ⚠️
.../main/java/com/amazon/ion/bytecode/ir/Operation.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             ion11    #1097   +/-   ##
========================================
  Coverage         ?   68.01%           
  Complexity       ?     5635           
========================================
  Files            ?      167           
  Lines            ?    23482           
  Branches         ?     4184           
========================================
  Hits             ?    15971           
  Misses           ?     6216           
  Partials         ?     1295           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

*
* See `com/amazon/ion/bytecode/ir/instruction_reference.md` for more details about the instruction set.
*/
internal object InstructionKind {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe this should be called OperationKind instead. If it would be more logical that way (or with any other name you can think of), please say so.

@@ -0,0 +1,83 @@
# Bytecode Reference Table

View the rendered version [on GitHub](https://github.com/amazon-ion/ion-java/tree/master/src/main/java/com/amazon/ion/bytecode/ir/instruction_reference.md).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This link will only work after the PR is merged.

| DIRECTIVE_MODULE | `0x8D` | `10001` | `101` | `00` | - | - | Must have END_CONTAINER instruction to delimit end of directive |
| DIRECTIVE_ENCODING | `0x8E` | `10001` | `110` | `00` | - | - | Must have END_CONTAINER instruction to delimit end of directive |
| PLACEHOLDER | `0x90` | `10010` | `000` | `00` | - | - | Required, tagged parameter. |
| PLACEHOLDER_OPT | `0x91` | `10010` | `001` | `00` | bytecode_length (u22) | - | Optional tagged macro parameter.[^0x91] |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This footnote syntax is part of GitHub Flavored MarkDown (GFMD). You can't have newlines inside the source of a markdown table, so I chose to use footnotes to avoid having some lines with 400+ characters because I wanted this to also be readable as plain text.

Comment thread src/main/java/com/amazon/ion/bytecode/ir/InstructionInfo.kt Outdated
Comment thread src/main/java/com/amazon/ion/bytecode/ir/InstructionKind.kt Outdated
Comment thread src/main/java/com/amazon/ion/bytecode/ir/Instructions.kt Outdated
Comment thread src/main/java/com/amazon/ion/bytecode/ir/Instructions.kt Outdated
Comment thread src/main/java/com/amazon/ion/bytecode/ir/Operation.kt Outdated
Comment thread src/main/java/com/amazon/ion/bytecode/ir/instruction_reference.md Outdated
Comment on lines +209 to +210
L0 STRING_CP 0 <Hello World>
L1 INT_CP 1 <12345>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice to have: column alignment for the constant pool values. Obviously not a blocker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. That would be nice to have. I'm going to leave it for now, though.

@popematt
popematt merged commit e94f00f into amazon-ion:ion11 Oct 1, 2025
19 of 36 checks passed
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.

2 participants