From cf6a09483362174446855ed56984b2819617a0fd Mon Sep 17 00:00:00 2001 From: Andrew Binstock <920630+platypusguy@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:33:48 -0700 Subject: [PATCH] JACOBIN-345 Added code to update the class's ClInit flag --- src/classloader/classloader.go | 7 +++++++ src/jvm/initializerBlock.go | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/classloader/classloader.go b/src/classloader/classloader.go index ee572881..ce8c1662 100644 --- a/src/classloader/classloader.go +++ b/src/classloader/classloader.go @@ -540,6 +540,13 @@ func convertToPostableClass(fullyParsedClass *ParsedClass) ClData { } } + _, clInitPresent := kd.MethodTable["()V"] + if clInitPresent { + kd.ClInit = 0x1 // there is a clinit, but it's not been run + } else { + kd.ClInit = 0x0 // there is no clinit + } + if len(fullyParsedClass.attributes) > 0 { for i := 0; i < len(fullyParsedClass.attributes); i++ { kda := Attr{ diff --git a/src/jvm/initializerBlock.go b/src/jvm/initializerBlock.go index 35cf39b5..8dcdb461 100644 --- a/src/jvm/initializerBlock.go +++ b/src/jvm/initializerBlock.go @@ -56,15 +56,21 @@ func runInitializationBlock(k *classloader.Klass) error { if err == nil { switch me.MType { case 'J': // it's a Java initializer (the most common case) - runJavaInitializer(me.Meth, k) + _ = runJavaInitializer(me.Meth, k) case 'G': // it's a native (that is, golang) initializer - runNativeInitializer(me.Meth, k) + _ = runNativeInitializer(me.Meth, k) } } } return nil } +// Run the () initializer code as a Java method. This effectively duplicates +// the code in run.go that creates a new frame and runs the method. Note that this +// code creates its own frame stack, which is distinct from the applications frame +// stack. The reason is that this is computing that's in most ways apart from the +// bytecode of the app. (This design might be revised at a later point and the two +// frame stacks combined into one.) func runJavaInitializer(m classloader.MData, k *classloader.Klass) error { meth := m.(classloader.JmEntry) f := frames.CreateFrame(meth.MaxStack) // create a new frame @@ -102,12 +108,15 @@ func runJavaInitializer(m classloader.MData, k *classloader.Klass) error { } err := runThread(&clInitThread) + k.Data.ClInit = 0x02 // flag showing we've run this class's if err != nil { return err } return nil } +// TODO: fill this in func runNativeInitializer(meth classloader.MData, k *classloader.Klass) error { + k.Data.ClInit = 0x02 // flag showing we've run this class's return nil }