Skip to content

Commit 0b37fa1

Browse files
committed
Refactor native method registry
1 parent 0b8ab53 commit 0b37fa1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+217
-233
lines changed

cmd/java/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/zxh0/jvm.go/classpath"
1111
"github.com/zxh0/jvm.go/cpu"
1212
"github.com/zxh0/jvm.go/module"
13-
_ "github.com/zxh0/jvm.go/native"
13+
_ "github.com/zxh0/jvm.go/native/all"
1414
"github.com/zxh0/jvm.go/rtda"
1515
"github.com/zxh0/jvm.go/rtda/heap"
1616
"github.com/zxh0/jvm.go/vm"

instructions/reserved/invokenative.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import (
44
"fmt"
55

66
"github.com/zxh0/jvm.go/instructions/base"
7+
"github.com/zxh0/jvm.go/native"
78
"github.com/zxh0/jvm.go/rtda"
89
)
910

1011
// Invoke native method
1112
type InvokeNative struct{ base.NoOperandsInstruction }
1213

1314
func (instr *InvokeNative) Execute(frame *rtda.Frame) {
15+
method := frame.Method
1416
if frame.Thread.VMOptions.VerboseJNI {
1517
fmt.Printf("invokenative: %s.%s%s\n",
16-
frame.Method.Class.Name, frame.Method.Name, frame.Method.Descriptor)
18+
method.Class.Name, method.Name, method.Descriptor)
1719
}
1820

19-
nativeMethod := frame.Method.GetNativeMethod().(func(*rtda.Frame))
21+
// TODO: cache native method
22+
nativeMethod := native.FindNativeMethod(method)
2023
nativeMethod(frame)
2124
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package native
1+
package all
22

33
import (
44
_ "github.com/zxh0/jvm.go/native/java/awt"
@@ -19,14 +19,4 @@ import (
1919
_ "github.com/zxh0/jvm.go/native/sun/misc"
2020
_ "github.com/zxh0/jvm.go/native/sun/nio/ch"
2121
_ "github.com/zxh0/jvm.go/native/sun/reflect"
22-
"github.com/zxh0/jvm.go/rtda"
23-
"github.com/zxh0/jvm.go/rtda/heap"
2422
)
25-
26-
func init() {
27-
heap.SetEmptyNativeMethod(emptyNativeMethod)
28-
}
29-
30-
func emptyNativeMethod(frame *rtda.Frame) {
31-
// do nothing
32-
}

native/java/awt/Component.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

87
func init() {
98
}
109

11-
func _comp(method func(frame *rtda.Frame), name, desc string) {
12-
heap.RegisterNativeMethod("java/awt/Component", name, desc, method)
10+
func _comp(method native.Method, name, desc string) {
11+
native.Register("java/awt/Component", name, desc, method)
1312
}

native/java/awt/Container.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

87
func init() {
98
}
109

11-
func _container(method func(frame *rtda.Frame), name, desc string) {
12-
heap.RegisterNativeMethod("java/awt/Container", name, desc, method)
10+
func _container(method native.Method, name, desc string) {
11+
native.Register("java/awt/Container", name, desc, method)
1312
}

native/java/awt/Cursor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

87
func init() {
98
}
109

11-
func _cursor(method func(frame *rtda.Frame), name, desc string) {
12-
heap.RegisterNativeMethod("java/awt/Cursor", name, desc, method)
10+
func _cursor(method native.Method, name, desc string) {
11+
native.Register("java/awt/Cursor", name, desc, method)
1312
}

native/java/awt/Font.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

87
func init() {
98
}
109

11-
func _font(method func(frame *rtda.Frame), name, desc string) {
12-
heap.RegisterNativeMethod("java/awt/Font", name, desc, method)
10+
func _font(method native.Method, name, desc string) {
11+
native.Register("java/awt/Font", name, desc, method)
1312
}

native/java/awt/Frame.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

8-
func _frame(method func(frame *rtda.Frame), name, desc string) {
9-
heap.RegisterNativeMethod("java/awt/Frame", name, desc, method)
7+
func _frame(method native.Method, name, desc string) {
8+
native.Register("java/awt/Frame", name, desc, method)
109
}

native/java/awt/Toolkit.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

87
func init() {
98
}
109

11-
func _tk(method func(frame *rtda.Frame), name, desc string) {
12-
heap.RegisterNativeMethod("java/awt/Toolkit", name, desc, method)
10+
func _tk(method native.Method, name, desc string) {
11+
native.Register("java/awt/Toolkit", name, desc, method)
1312
}

native/java/awt/Window.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package awt
22

33
import (
4-
"github.com/zxh0/jvm.go/rtda"
5-
"github.com/zxh0/jvm.go/rtda/heap"
4+
"github.com/zxh0/jvm.go/native"
65
)
76

8-
func _window(method func(frame *rtda.Frame), name, desc string) {
9-
heap.RegisterNativeMethod("java/awt/Window", name, desc, method)
7+
func _window(method native.Method, name, desc string) {
8+
native.Register("java/awt/Window", name, desc, method)
109
}

0 commit comments

Comments
 (0)