Skip to content

Commit

Permalink
JACOBIN-345 Replaced several <clinit> routines with native methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Sep 3, 2023
1 parent da45820 commit d8a4f3e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/classloader/javaLangString.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@

package classloader

import (
"jacobin/log"
"jacobin/types"
)

/*
We don't run String's static initializer block because the initialization
is already handled in new String creation
We don't run String's static initializer block because the initialization
is already handled in String creation
*/

func Load_Lang_String() map[string]GMeth {
// need to replace eventually by enbling the Java intializer to run
MethodSignatures["java/lang/String.<clinit>()V"] =
GMeth{
ParamSlots: 0,
GFunction: justReturn,
GFunction: stringClinit,
}

return MethodSignatures
}

func stringClinit([]interface{}) interface{} {
klass := MethAreaFetch("java/lang/String")
if klass == nil {
errMsg := "In <clinit>, expected java/lang/String to be in the MethodArea, but it was not"
_ = log.Log(errMsg, log.SEVERE)
}
klass.Data.ClInit = types.ClInitRun // just mark that String.<clinit>() has been run
return nil
}
39 changes: 37 additions & 2 deletions src/classloader/javaLangSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ package classloader
import (
"fmt"
"jacobin/globals"
"jacobin/log"
"jacobin/object"
"jacobin/shutdown"
"jacobin/types"
"os"
"os/user"
"runtime"
Expand Down Expand Up @@ -66,16 +68,49 @@ func Load_Lang_System() map[string]GMeth {
GFunction: getProperty,
}

// need to replace eventually by enbling the Java intializer to run
MethodSignatures["java/lang/System.<clinit>()V"] =
MethodSignatures["java/lang/System.registerNatives()V"] =
GMeth{
ParamSlots: 0,
GFunction: justReturn,
}

MethodSignatures["java/lang/System.<clinit>()V"] =
GMeth{
ParamSlots: 0,
GFunction: clinit,
}

return MethodSignatures
}

/*
check whether this clinit() has been previously run. If not, have it duplicate the
following bytecodes from JDK 17 java/lang/System:
static {};
0: invokestatic #637 // Method registerNatives:()V
3: aconst_null
4: putstatic #640 // Field in:Ljava/io/InputStream;
7: aconst_null
8: putstatic #387 // Field out:Ljava/io/PrintStream;
11: aconst_null
12: putstatic #384 // Field err:Ljava/io/PrintStream;
15: return
*/
func clinit([]interface{}) interface{} {
klass := MethAreaFetch("java/lang/System")
if klass == nil {
errMsg := "In <clinit>, expected java/lang/System to be in the MethodArea, but it was not"
_ = log.Log(errMsg, log.SEVERE)
}
if klass.Data.ClInit != types.ClInitRun {
_ = AddStatic("java/lang/System.in", Static{Type: "L", Value: object.Null})
_ = AddStatic("java/lang/System.err", Static{Type: "L", Value: object.Null})
_ = AddStatic("java/lang/System.out", Static{Type: "L", Value: object.Null})
klass.Data.ClInit = types.ClInitRun
}
return nil
}

// Return time in milliseconds, measured since midnight of Jan 1, 1970
func currentTimeMillis([]interface{}) interface{} {
return time.Now().UnixMilli() // is int64
Expand Down

0 comments on commit d8a4f3e

Please sign in to comment.