Skip to content

Commit

Permalink
JACOBIN-563 Finished logic for handling arrays in CHECKCAST. Now need…
Browse files Browse the repository at this point in the history
…s testing.
  • Loading branch information
platypusguy committed Aug 11, 2024
1 parent 32e2585 commit 5cbb139
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/jvm/runUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,32 @@ func checkcastArray(obj *object.Object, className string) bool {
return className == "java/lang/Object"
}

return false
// If S (obj) is an array type SC[], that is, an array of components of type SC,
// if T is an array type TC[], that is, an array of components of type TC,
// then one of the following must be true:
// > TC and SC are the same primitive type.
objArrayType := object.GetArrayType(*sptr)
classArrayType := object.GetArrayType(className)
if !strings.HasPrefix(objArrayType, "L") && // if both array types are primitives
!strings.HasPrefix(classArrayType, "L") {
if objArrayType == classArrayType { // are they the same primitive?
return true
}
}

// we now know both types are arrays of references, so the objects
// referred to must be castable:
// If TC and SC are reference types, and type SC can be cast to TC by
// recursive application of these rules.
rawObjArrayType, _ := strings.CutPrefix(objArrayType, "L")
rawObjArrayType = strings.TrimSuffix(rawObjArrayType, ";")
rawClassArrayType, _ := strings.CutPrefix(classArrayType, "L")
rawClassArrayType = strings.TrimSuffix(rawClassArrayType, ";")
if rawObjArrayType == classArrayType || rawClassArrayType == "java/lang/Object" {
return true
} else {
return isClassAaSublclassOfB(obj.KlassName, stringPool.GetStringIndex(&className))
}
}

func checkcastInterface(obj *object.Object, className string) bool {
Expand Down

0 comments on commit 5cbb139

Please sign in to comment.