Skip to content

Commit

Permalink
JACOBIN-592 Ported FASTORE and DASTORE bytecodes to new interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Oct 29, 2024
1 parent ab2343c commit c158e3f
Show file tree
Hide file tree
Showing 2 changed files with 59 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 = 3143
var BuildNo = 3144
60 changes: 58 additions & 2 deletions src/jvm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ var DispatchTable = [203]BytecodeFunc{
doIstore3, // ASTORE_3 0x4E
doIastore, // IASTORE 0x4F
doIastore, // LASTORE 0x50
notImplemented, // FASTORE 0x51
notImplemented, // DASTORE 0x52
doFastore, // FASTORE 0x51
doFastore, // DASTORE 0x52
doAastore, // AASTORE 0x53
notImplemented, // BASTORE 0x54
doIastore, // CASTORE 0x55
Expand Down Expand Up @@ -695,6 +695,62 @@ func doIastore(fr *frames.Frame, _ int64) int {
return 1
}

// 0x51, 0x52 FASTORE, DASTORE store a float, double in a float/doubles array
func doFastore(fr *frames.Frame, _ int64) int {
var array []float64
value := pop(fr).(float64)
index := pop(fr).(int64)
ref := pop(fr)
switch ref.(type) {
case *object.Object:
obj := ref.(*object.Object)
if object.IsNull(obj) {
globals.GetGlobalRef().ErrorGoStack = string(debug.Stack())
errMsg := fmt.Sprintf("in %s.%s, F/DASTORE: Invalid (null) reference to an array",
util.ConvertInternalClassNameToUserFormat(fr.ClName), fr.MethName)
status := exceptions.ThrowEx(excNames.NullPointerException, errMsg, fr)
if status != exceptions.Caught {
return exceptions.ERROR_OCCURRED // applies only if in test
}
}
fld := obj.FieldTable["value"]
if fld.Ftype != types.FloatArray {
globals.GetGlobalRef().ErrorGoStack = string(debug.Stack())
errMsg := fmt.Sprintf("in %s.%s, D/FASTORE: field type expected=[F, observed=%s",
util.ConvertInternalClassNameToUserFormat(fr.ClName), fr.MethName, fld.Ftype)
status := exceptions.ThrowEx(excNames.ArrayStoreException, errMsg, fr)
if status != exceptions.Caught {
return exceptions.ERROR_OCCURRED // applies only if in test
}
}
array = fld.Fvalue.([]float64)
case []float64:
array = ref.([]float64)
default:
globals.GetGlobalRef().ErrorGoStack = string(debug.Stack())
errMsg := fmt.Sprintf("in %s.%s, D/FASTORE: unexpected reference type: %T",
util.ConvertInternalClassNameToUserFormat(fr.ClName), fr.MethName, ref)
status := exceptions.ThrowEx(excNames.ArrayStoreException, errMsg, fr)
if status != exceptions.Caught {
return exceptions.ERROR_OCCURRED // applies only if in test
}
}

size := int64(len(array))
if index >= size {
globals.GetGlobalRef().ErrorGoStack = string(debug.Stack())
errMsg := fmt.Sprintf("in %s.%s, D/FASTORE: array size is %d but array index is %d",
util.ConvertInternalClassNameToUserFormat(fr.ClName), fr.MethName, size, index)
status := exceptions.ThrowEx(excNames.ArrayIndexOutOfBoundsException, errMsg, fr)
if status != exceptions.Caught {
return exceptions.ERROR_OCCURRED // applies only if in test
}
}

array[index] = value
return 1
}

// 0x53 AASTORE store a ref in a ref array
func doAastore(fr *frames.Frame, _ int64) int {
value := pop(fr).(*object.Object) // reference we're inserting
Expand Down

0 comments on commit c158e3f

Please sign in to comment.