Skip to content

Commit

Permalink
JACOBIN-592 Ported IF_ACMPEQ and IF_ACMPNE bytecodes to new interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Oct 30, 2024
1 parent d97488c commit 0e625b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/config/buildno.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

package config

var BuildNo = 3155
var BuildNo = 3156
28 changes: 26 additions & 2 deletions src/jvm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ var DispatchTable = [203]BytecodeFunc{
doIficmpge, // IF_ICMPGE 0xA2
doIficmpgt, // IF_ICMPGT 0xA3
doIficmple, // IF_ICMPLE 0xA4
notImplemented, // IF_ACMPEQ 0xA5
notImplemented, // IF_ACMPNE 0xA6
doIfacmpeq, // IF_ACMPEQ 0xA5
doIfacmpne, // IF_ACMPNE 0xA6
doGoto, // GOTO 0xA7
notImplemented, // JSR 0xA8
notImplemented, // RET 0xA9
Expand Down Expand Up @@ -1304,6 +1304,30 @@ func doIficmple(fr *frames.Frame, _ int64) int {
}
}

// 0xA5 IF_ACMPEQ jump if two addresses are equal
func doIfacmpeq(fr *frames.Frame, _ int64) int {
val2 := pop(fr)
val1 := pop(fr)
if val1 == val2 { // if comp succeeds, next 2 bytes hold instruction index
jumpTo := (int16(fr.Meth[fr.PC+1]) * 256) + int16(fr.Meth[fr.PC+2])
return int(jumpTo)
} else {
return 3 // 2 for the jumpTo + 1 for next bytecode
}
}

// 0xA6 IF_ACMPNE jump if two addresses are equal
func doIfacmpne(fr *frames.Frame, _ int64) int {
val2 := pop(fr)
val1 := pop(fr)
if val1 != val2 { // if comp fails, next 2 bytes hold instruction index
jumpTo := (int16(fr.Meth[fr.PC+1]) * 256) + int16(fr.Meth[fr.PC+2])
return int(jumpTo)
} else {
return 3 // 2 for the jumpTo + 1 for next bytecode
}
}

// 0xA7 GOTO unconditional jump within method
func doGoto(fr *frames.Frame, _ int64) int {
jumpTo := (int16(fr.Meth[fr.PC+1]) * 256) + int16(fr.Meth[fr.PC+2])
Expand Down

0 comments on commit 0e625b5

Please sign in to comment.