Skip to content

Commit

Permalink
JACOBIN-345 Rewrote test for <clinit>() in instantiation to use metho…
Browse files Browse the repository at this point in the history
…d table
  • Loading branch information
platypusguy committed Sep 1, 2023
1 parent 7819158 commit 9c5c8b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/jvm/initializerBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// previously executed.
//
// CURR: Implement the superclass requirement.
func runInitializationBlock(k *classloader.Klass, idx int) error {
func runInitializationBlock(k *classloader.Klass) error {
// get list of the superclasses up to but not including java.lang.Object
var superclasses []string
// put the present class at the bottom of the list of superclasses
Expand Down
33 changes: 21 additions & 12 deletions src/jvm/instantiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,29 @@ func instantiateClass(classname string) (*object.Object, error) {

runInitializer:
// run intialization blocks
for i := 0; i < len(k.Data.Methods); i++ {
meth := k.Data.Methods[i]
methName := k.Data.CP.Utf8Refs[meth.Name]
if strings.HasPrefix(methName, "<clinit>") {
err := runInitializationBlock(k, i)
if err != nil {
errMsg := fmt.Sprintf("error encountered running %s<clinit>", classname)
_ = log.Log(errMsg, log.SEVERE)
return nil, err
} else {
break
}
_, ok := k.Data.MethodTable["<clinit>()V"]
if ok {
err := runInitializationBlock(k)
if err != nil {
errMsg := fmt.Sprintf("error encountered running %s.<clinit>()", classname)
_ = log.Log(errMsg, log.SEVERE)
return nil, err
}
}
// for i := 0; i < len(k.Data.Methods); i++ {
// meth := k.Data.Methods[i]
// methName := k.Data.CP.Utf8Refs[meth.Name]
// if strings.HasPrefix(methName, "<clinit>") {
// err := runInitializationBlock(k, i)
// if err != nil {
// errMsg := fmt.Sprintf("error encountered running %s<clinit>", classname)
// _ = log.Log(errMsg, log.SEVERE)
// return nil, err
// } else {
// break
// }
// }
// }
return &obj, nil
}

Expand Down

0 comments on commit 9c5c8b3

Please sign in to comment.