Skip to content

Commit

Permalink
JACOBIN-345 Added code to update the class's ClInit flag
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Sep 1, 2023
1 parent 5e35629 commit cf6a094
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/classloader/classloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ func convertToPostableClass(fullyParsedClass *ParsedClass) ClData {
}
}

_, clInitPresent := kd.MethodTable["<clinit>()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{
Expand Down
13 changes: 11 additions & 2 deletions src/jvm/initializerBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <clinit>() 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
Expand Down Expand Up @@ -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 <clinit>
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 <clinit>
return nil
}

0 comments on commit cf6a094

Please sign in to comment.