From 9c5c8b382955c6a04850dbdfde0d2b3be4020be7 Mon Sep 17 00:00:00 2001 From: Andrew Binstock <920630+platypusguy@users.noreply.github.com> Date: Thu, 31 Aug 2023 20:38:00 -0700 Subject: [PATCH] JACOBIN-345 Rewrote test for () in instantiation to use method table --- src/jvm/initializerBlock.go | 2 +- src/jvm/instantiate.go | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/jvm/initializerBlock.go b/src/jvm/initializerBlock.go index b2b13237..35cf39b5 100644 --- a/src/jvm/initializerBlock.go +++ b/src/jvm/initializerBlock.go @@ -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 diff --git a/src/jvm/instantiate.go b/src/jvm/instantiate.go index cdfc2a79..55cba967 100644 --- a/src/jvm/instantiate.go +++ b/src/jvm/instantiate.go @@ -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, "") { - err := runInitializationBlock(k, i) - if err != nil { - errMsg := fmt.Sprintf("error encountered running %s", classname) - _ = log.Log(errMsg, log.SEVERE) - return nil, err - } else { - break - } + _, ok := k.Data.MethodTable["()V"] + if ok { + err := runInitializationBlock(k) + if err != nil { + errMsg := fmt.Sprintf("error encountered running %s.()", 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, "") { + // err := runInitializationBlock(k, i) + // if err != nil { + // errMsg := fmt.Sprintf("error encountered running %s", classname) + // _ = log.Log(errMsg, log.SEVERE) + // return nil, err + // } else { + // break + // } + // } + // } return &obj, nil }