예제 #1
0
파일: environ.c.go 프로젝트: timob/gojvm
// Refcounting is probably needed here, TODO: figure that out...
func (self *Environment) utf8() C.jstring {
	if self._UTF8 == nil {
		cs := C.CString("UTF8")
		defer C.free(unsafe.Pointer(cs))
		tf8 := C.envNewStringUTF(self.env, cs)
		self._UTF8 = C.jstring(C.envNewGlobalRef(self.env, tf8))
	}
	return self._UTF8
}
예제 #2
0
파일: environ.c.go 프로젝트: timob/gojvm
/*
	returns a new *Object of type *Class, using the constructor identified by []params
*/
func (self *Environment) NewInstance(c *Class, params ...interface{}) (o *Object, err error) {
	meth, alp, localStack, err := self.getClassMethod(c, false, "<init>", types.Basic(types.VoidKind), params...)
	//	meth, alp, err := self.getObjectMethod(newObject(self, c, C.jobject( c.class)), "<init>", BasicType(JavaVoidKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	obj := C.envNewObjectA(self.env, c.class, meth.method, alp.Ptr())
	if obj != nil {
		obj = C.envNewGlobalRef(self.env, obj)
		o = newObject(obj)
	} else {
		err = self.ExceptionOccurred()
	}
	return
}
예제 #3
0
파일: environ.c.go 프로젝트: timob/gojvm
// returns a Class object;  the object will first be looked up in cache,
// and if not found there, resolved via Java and stored in the cache path.
// classes returned via /THIS/ channel, need not be unrefed, as they all
// hold a global ref.
//
// TODO: in truth, they should probably ALL be local-refs of the cached one...
func (self *Environment) GetClass(klass types.Name) (c *Class, err error) {
	c, err = self.findCachedClass(klass)
	if err == nil {
		return
	}
	s := C.CString(klass.AsPath())
	defer C.free(unsafe.Pointer(s))
	// print("envFindClass ", klass,"\n")
	kl := C.envFindClass(self.env, s)
	if kl == nil {
		//print("GetClass missed ", klass.AsPath(), "\n\n")
		err = self.ExceptionOccurred()
	} else {
		err = nil // clear the cache error
		//print("found ", klass,"\n")
		kl = C.jclass(C.envNewGlobalRef(self.env, kl))
		c = newClass(kl)
		self.classes[klass.AsPath()] = c
	}
	return
}
예제 #4
0
파일: environ.c.go 프로젝트: timob/gojvm
// As gojvm is typically the /hosting/ context,
// a global reference in gojvm is more of a 'dont bother GC'ing this,
// I'm going to lose it somewhere in my stack',
// and as such should be use sparingly
func (self *Environment) NewGlobalRef(o *Object) *Object {
	return newObject(C.envNewGlobalRef(self.env, o.object))
}