2
0
mirror of synced 2025-02-24 07:18:15 +00:00
mobile/bind/java/testpkg/testpkg.go
David Crawshaw 5487fc8103 go.mobile/bind/java: tests of object reference tracking
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/112700044
2014-07-31 08:25:23 -04:00

59 lines
773 B
Go

// Package testpkg contains bound functions for testing the cgo-JNI interface.
package testpkg
import (
"fmt"
"runtime"
"time"
)
type I interface {
F()
}
func Call(i I) {
i.F()
}
var keep []I
func Keep(i I) {
keep = append(keep, i)
}
var numSCollected int
type S struct {
// *S already has a finalizer, so we need another object
// to count successful collections.
innerObj *int
}
func (*S) F() {
fmt.Println("called F on *S")
}
func finalizeInner(*int) {
numSCollected++
}
func New() *S {
s := &S{innerObj: new(int)}
runtime.SetFinalizer(s.innerObj, finalizeInner)
return s
}
func GC() {
runtime.GC()
time.Sleep(10 * time.Millisecond)
runtime.GC()
}
func Add(x, y int) int {
return x + y
}
func NumSCollected() int {
return numSCollected
}