Skip to content

Commit 85ea140

Browse files
committed
Implement PR suggestions
1 parent 11bed3f commit 85ea140

8 files changed

Lines changed: 9 additions & 24 deletions

File tree

src/main/java/com/amazon/ion/bytecode/bin11/ByteArrayBytecodeGenerator11.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ internal class ByteArrayBytecodeGenerator11(
5050
symTab
5151
)
5252
} catch (e: StackOverflowError) {
53+
// TODO: implement recursion limit instead of catching StackOverflowError
5354
throw IonException("Ion data nested too deeply", e)
5455
}
5556
}

src/main/java/com/amazon/ion/bytecode/bin11/bytearray/AnnotationSIDOpcodeHandler.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ internal object AnnotationSIDOpcodeHandler : OpcodeToBytecodeHandler {
2222
macroIndices: IntArray,
2323
symbolTable: Array<String?>
2424
): Int {
25-
assert(opcode == 0x58) { "Handler cannot compile opcode ${opcode.toHexString()}" }
26-
2725
val sidValueAndLength = PrimitiveDecoder.readFlexUIntValueAndLength(source, position)
2826
val sid = sidValueAndLength.toInt()
2927
val length = sidValueAndLength.shr(Int.SIZE_BITS).toInt()

src/main/java/com/amazon/ion/bytecode/bin11/bytearray/IntOpcodeHandlers.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ internal object LongIntOpcodeHandler : OpcodeToBytecodeHandler {
152152
* */
153153
@OptIn(ExperimentalStdlibApi::class)
154154
internal val TAGLESS_FLEX_INT = OpcodeToBytecodeHandler { opcode, src, pos, dest, cp, _, _, _ ->
155-
assert(opcode == 0x60) { "Handler cannot compile opcode ${opcode.toHexString()}" }
156-
157155
val flexIntLength = PrimitiveDecoder.lengthOfFlexIntOrUIntAt(src, pos)
158156
when (flexIntLength) {
159157
// TODO(perf): See if there's any performance benefit to having a separate case for length=1|2 and using INT_I16 instruction

src/main/java/com/amazon/ion/bytecode/bin11/bytearray/ListOpcodeHandlers.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ internal object ShortLengthPrefixedListOpcodeHandler : OpcodeToBytecodeHandler {
2727
macroIndices: IntArray,
2828
symbolTable: Array<String?>
2929
): Int {
30-
assert(opcode in 0xb0..0xbf) { "Handler cannot compile opcode ${opcode.toHexString()}" }
31-
3230
val length = opcode and 0xF
3331
BytecodeEmitter.emitList(destination) {
3432
var p = position
@@ -66,8 +64,6 @@ internal object LongLengthPrefixedListOpcodeHandler : OpcodeToBytecodeHandler {
6664
macroIndices: IntArray,
6765
symbolTable: Array<String?>
6866
): Int {
69-
assert(opcode == 0xfa) { "Handler cannot compile opcode ${opcode.toHexString()}" }
70-
7167
val containerSizeUIntValueAndLength = PrimitiveDecoder.readFlexUIntValueAndLength(source, position)
7268
val containerLength = containerSizeUIntValueAndLength.toInt()
7369
val prefixLength = containerSizeUIntValueAndLength.shr(Int.SIZE_BITS).toInt()
@@ -107,8 +103,6 @@ internal object DelimitedListOpcodeHandler : OpcodeToBytecodeHandler {
107103
macroIndices: IntArray,
108104
symbolTable: Array<String?>
109105
): Int {
110-
assert(opcode == 0xf0) { "Handler cannot compile opcode ${opcode.toHexString()}" }
111-
112106
var p = position
113107
BytecodeEmitter.emitList(destination) {
114108
while (true) {
@@ -148,16 +142,14 @@ internal object TaglessElementListOpcodeHandler : OpcodeToBytecodeHandler {
148142
macroIndices: IntArray,
149143
symbolTable: Array<String?>
150144
): Int {
151-
assert(opcode == 0x5b) { "Handler cannot compile opcode ${opcode.toHexString()}" }
152-
153145
var p = position
154146
val childOpcode = source[p++].unsignedToInt()
155147
val macroAddress = when (childOpcode) {
156148
in 0x00..0x47 -> childOpcode
157149
in 0x48..0x4f -> {
158150
val flexUIntValueAndLength = PrimitiveDecoder.readFlexUIntValueAndLength(source, p)
159151
val addressLength = flexUIntValueAndLength.shr(Int.SIZE_BITS).toInt()
160-
p += flexUIntValueAndLength
152+
p += addressLength
161153
val lsb = childOpcode - 0x48
162154
val msb = flexUIntValueAndLength.toInt() * 8
163155
msb + lsb + 72
@@ -183,7 +175,7 @@ internal object TaglessElementListOpcodeHandler : OpcodeToBytecodeHandler {
183175
if (macroAddress < 0) {
184176
val handler = TaglessOpcodeHandlerTable.handler(childOpcode)
185177
BytecodeEmitter.emitList(destination) {
186-
for (i in 0 until containerLength) {
178+
for (i in 0 until childCount) {
187179
p += handler.convertOpcodeToBytecode(
188180
childOpcode,
189181
source,

src/main/java/com/amazon/ion/bytecode/bin11/bytearray/SymbolOpcodeHandlers.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ internal object SymbolSIDOpcodeHandler : OpcodeToBytecodeHandler {
2222
macroIndices: IntArray,
2323
symbolTable: Array<String?>
2424
): Int {
25-
assert(opcode in 0x50..0x57) { "Handler cannot compile opcode ${opcode.toHexString()}" }
26-
2725
val lsb = opcode and 0b111
2826
val msbValueAndLength = PrimitiveDecoder.readFlexUIntValueAndLength(source, position)
2927
val msb = msbValueAndLength.toInt().shl(3)
@@ -49,8 +47,6 @@ internal object SingleCharSymbolOpcodeHandler : OpcodeToBytecodeHandler {
4947
macroIndices: IntArray,
5048
symbolTable: Array<String?>
5149
): Int {
52-
assert(opcode == 0xa1) { "Handler cannot compile opcode ${opcode.toHexString()}" }
53-
5450
val char = source[position].toInt()
5551
destination.add(Instructions.I_SYMBOL_CHAR.packInstructionData(char))
5652
return 1

src/test/java/com/amazon/ion/bytecode/GeneratorTestUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object GeneratorTestUtil {
5454
* Asserts that the generator throws an [IonException] when compiling its input (as opposed to a [Throwable] of
5555
* an incorrect type).
5656
*/
57-
internal fun BytecodeGenerator.shouldThrowIonException() {
57+
internal fun BytecodeGenerator.refillShouldThrowIonException() {
5858
assertThrows<IonException> {
5959
val generator = this
6060
generator.refill(BytecodeBuffer(), ConstantPool(), EMPTY_MACRO_TABLE, intArrayOf(), DEFAULT_SYMBOL_TABLE)

src/test/java/com/amazon/ion/bytecode/bin11/ByteArrayBytecodeGenerator11Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package com.amazon.ion.bytecode.bin11
55
import com.amazon.ion.TextToBinaryUtils.cleanCommentedHexBytes
66
import com.amazon.ion.TextToBinaryUtils.hexStringToByteArray
77
import com.amazon.ion.Timestamp
8+
import com.amazon.ion.bytecode.GeneratorTestUtil.refillShouldThrowIonException
89
import com.amazon.ion.bytecode.GeneratorTestUtil.shouldGenerate
9-
import com.amazon.ion.bytecode.GeneratorTestUtil.shouldThrowIonException
1010
import com.amazon.ion.bytecode.PrimitiveUtils.generateFlexUIntBytes
1111
import com.amazon.ion.bytecode.ir.Instructions
1212
import com.amazon.ion.bytecode.ir.Instructions.packInstructionData
@@ -151,6 +151,6 @@ internal class ByteArrayBytecodeGenerator11Test {
151151
}
152152

153153
val generator = ByteArrayBytecodeGenerator11(bytes.toByteArray(), 0)
154-
generator.shouldThrowIonException()
154+
generator.refillShouldThrowIonException()
155155
}
156156
}

src/test/java/com/amazon/ion/bytecode/bin11/bytearray/ListOpcodeHandlerTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class ListOpcodeHandlerTests {
159159

160160
@Test
161161
fun `handler compiles large lists`() {
162-
val testLength = 10_000_000 // Much larger causes test crash
162+
val testLength = 10_000_000 // Much larger causes OutOfMemoryError in gradle test executor
163163
val bytes = byteArrayOf(
164164
OpCode.VARIABLE_LENGTH_LIST.toByte(),
165165
*generateFlexUIntBytes(testLength),
@@ -284,7 +284,7 @@ class ListOpcodeHandlerTests {
284284

285285
@Test
286286
fun `handler compiles large lists`() {
287-
val testLength = 10_000_000 // Much larger causes test crash
287+
val testLength = 10_000_000 // Much larger causes OutOfMemoryError in gradle test executor
288288
val bytes = byteArrayOf(
289289
OpCode.DELIMITED_LIST.toByte(),
290290
*Array<Byte>(testLength) { 0x6E /* true */ }.toByteArray(),
@@ -710,7 +710,7 @@ class ListOpcodeHandlerTests {
710710

711711
@Test
712712
fun `handler compiles large lists`() {
713-
val testLength = 10_000_000 // Much larger causes test crash
713+
val testLength = 10_000_000 // Much larger causes OutOfMemoryError in gradle test executor
714714
val bytes = byteArrayOf(
715715
OpCode.TAGLESS_ELEMENT_LIST.toByte(),
716716
OpCode.INT_8.toByte(),

0 commit comments

Comments
 (0)