func (x *JavaVMOption) PassRef() *C.JavaVMOption {
	if x == nil {
		x = (*JavaVMOption)(allocJavaVMOptionMemory(1))
	}
	return (*C.JavaVMOption)(unsafe.Pointer(x))
}
PassRef returns a reference to C object as it is or allocates a new C object of this type.
package android
import "C"
import (
	"sync"
	"unsafe"
)
func (x *AssetManager) Ref() *C.AAssetManager {
	if x == nil {
		return nil
	}
	return (*C.AAssetManager)(unsafe.Pointer(x))
}
func (x *AssetManager) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetManagerRef(ref unsafe.Pointer) *AssetManager {
	return (*AssetManager)(ref)
}
func NewAssetManager() *AssetManager {
	return (*AssetManager)(allocAssetManagerMemory(1))
}
func allocAssetManagerMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetManagerValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetManagerValue = unsafe.Sizeof([1]C.AAssetManager{})
type cgoAllocMap struct {
	mux sync.RWMutex
	m   map[unsafe.Pointer]struct{}
}
var cgoAllocsUnknown = new(cgoAllocMap)
func (a *cgoAllocMap) Add(ptr unsafe.Pointer) {
	a.mux.Lock()
	if a.m == nil {
		a.m = make(map[unsafe.Pointer]struct{})
	}
	a.m[ptr] = struct{}{}
	a.mux.Unlock()
}
func (a *cgoAllocMap) IsEmpty() bool {
	a.mux.RLock()
	isEmpty := len(a.m) == 0
	a.mux.RUnlock()
	return isEmpty
}
func (a *cgoAllocMap) Borrow(b *cgoAllocMap) {
	if b == nil || b.IsEmpty() {
		return
	}
	b.mux.Lock()
	a.mux.Lock()
	for ptr := range b.m {
		if a.m == nil {
			a.m = make(map[unsafe.Pointer]struct{})
		}
		a.m[ptr] = struct{}{}
		delete(b.m, ptr)
	}
	a.mux.Unlock()
	b.mux.Unlock()
}
func (a *cgoAllocMap) Free() {
	a.mux.Lock()
	for ptr := range a.m {
		C.free(ptr)
		delete(a.m, ptr)
	}
	a.mux.Unlock()
}
func (x *AssetManager) PassRef() *C.AAssetManager {
	if x == nil {
		x = (*AssetManager)(allocAssetManagerMemory(1))
	}
	return (*C.AAssetManager)(unsafe.Pointer(x))
}
func (x *AssetDir) Ref() *C.AAssetDir {
	if x == nil {
		return nil
	}
	return (*C.AAssetDir)(unsafe.Pointer(x))
}
func (x *AssetDir) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetDirRef(ref unsafe.Pointer) *AssetDir {
	return (*AssetDir)(ref)
}
func NewAssetDir() *AssetDir {
	return (*AssetDir)(allocAssetDirMemory(1))
}
func allocAssetDirMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetDirValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetDirValue = unsafe.Sizeof([1]C.AAssetDir{})
func (x *AssetDir) PassRef() *C.AAssetDir {
	if x == nil {
		x = (*AssetDir)(allocAssetDirMemory(1))
	}
	return (*C.AAssetDir)(unsafe.Pointer(x))
}
func (x *Asset) Ref() *C.AAsset {
	if x == nil {
		return nil
	}
	return (*C.AAsset)(unsafe.Pointer(x))
}
func (x *Asset) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetRef(ref unsafe.Pointer) *Asset {
	return (*Asset)(ref)
}
func NewAsset() *Asset {
	return (*Asset)(allocAssetMemory(1))
}
func allocAssetMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetValue = unsafe.Sizeof([1]C.AAsset{})
func (x *Asset) PassRef() *C.AAsset {
	if x == nil {
		x = (*Asset)(allocAssetMemory(1))
	}
	return (*C.AAsset)(unsafe.Pointer(x))
}
func (x *JNINativeMethod) Ref() *C.JNINativeMethod {
	if x == nil {
		return nil
	}
	return (*C.JNINativeMethod)(unsafe.Pointer(x))
}
func (x *JNINativeMethod) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewJNINativeMethodRef(ref unsafe.Pointer) *JNINativeMethod {
	return (*JNINativeMethod)(ref)
}
func NewJNINativeMethod() *JNINativeMethod {
	return (*JNINativeMethod)(allocJNINativeMethodMemory(1))
}
func allocJNINativeMethodMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJNINativeMethodValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJNINativeMethodValue = unsafe.Sizeof([1]C.JNINativeMethod{})
func (x *JNINativeMethod) PassRef() *C.JNINativeMethod {
	if x == nil {
		x = (*JNINativeMethod)(allocJNINativeMethodMemory(1))
	}
	return (*C.JNINativeMethod)(unsafe.Pointer(x))
}
func allocJavaVMAttachArgsMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJavaVMAttachArgsValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJavaVMAttachArgsValue = unsafe.Sizeof([1]C.JavaVMAttachArgs{})
func unpackPCharString(str string) (*C.char, *cgoAllocMap) {
	h := (*stringHeader)(unsafe.Pointer(&str))
	return (*C.char)(unsafe.Pointer(h.Data)), cgoAllocsUnknown
}
type stringHeader struct {
	Data uintptr
	Len  int
}
func packPCharString(p *C.char) (raw string) {
	if p != nil && *p != 0 {
		h := (*stringHeader)(unsafe.Pointer(&raw))
		h.Data = uintptr(unsafe.Pointer(p))
		for *p != 0 {
			p = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + 1))  
		}
		h.Len = int(uintptr(unsafe.Pointer(p)) - h.Data)
	}
	return
}
type RawString string
func (raw RawString) Copy() string {
	if len(raw) == 0 {
		return ""
	}
	h := (*stringHeader)(unsafe.Pointer(&raw))
	return C.GoStringN((*C.char)(unsafe.Pointer(h.Data)), C.int(h.Len))
}
func (x *JavaVMAttachArgs) Ref() *C.JavaVMAttachArgs {
	if x == nil {
		return nil
	}
	return x.refab42f020
}
func (x *JavaVMAttachArgs) Free() {
	if x != nil && x.allocsab42f020 != nil {
		x.allocsab42f020.(*cgoAllocMap).Free()
		x.refab42f020 = nil
	}
}
func NewJavaVMAttachArgsRef(ref unsafe.Pointer) *JavaVMAttachArgs {
	if ref == nil {
		return nil
	}
	obj := new(JavaVMAttachArgs)
	obj.refab42f020 = (*C.JavaVMAttachArgs)(unsafe.Pointer(ref))
	return obj
}
func (x *JavaVMAttachArgs) PassRef() (*C.JavaVMAttachArgs, *cgoAllocMap) {
	if x == nil {
		return nil, nil
	} else if x.refab42f020 != nil {
		return x.refab42f020, nil
	}
	memab42f020 := allocJavaVMAttachArgsMemory(1)
	refab42f020 := (*C.JavaVMAttachArgs)(memab42f020)
	allocsab42f020 := new(cgoAllocMap)
	allocsab42f020.Add(memab42f020)
	var cversion_allocs *cgoAllocMap
	refab42f020.version, cversion_allocs = (C.jint)(x.Version), cgoAllocsUnknown
	allocsab42f020.Borrow(cversion_allocs)
	var cname_allocs *cgoAllocMap
	refab42f020.name, cname_allocs = unpackPCharString(x.Name)
	allocsab42f020.Borrow(cname_allocs)
	var cgroup_allocs *cgoAllocMap
	refab42f020.group, cgroup_allocs = (C.jobject)(x.Group), cgoAllocsUnknown
	allocsab42f020.Borrow(cgroup_allocs)
	x.refab42f020 = refab42f020
	x.allocsab42f020 = allocsab42f020
	return refab42f020, allocsab42f020
}
func (x JavaVMAttachArgs) PassValue() (C.JavaVMAttachArgs, *cgoAllocMap) {
	if x.refab42f020 != nil {
		return *x.refab42f020, nil
	}
	ref, allocs := x.PassRef()
	return *ref, allocs
}
func (x *JavaVMAttachArgs) Deref() {
	if x.refab42f020 == nil {
		return
	}
	x.Version = (Jint)(x.refab42f020.version)
	x.Name = packPCharString(x.refab42f020.name)
	x.Group = (Jobject)(x.refab42f020.group)
}
func (x *JavaVMOption) Ref() *C.JavaVMOption {
	if x == nil {
		return nil
	}
	return (*C.JavaVMOption)(unsafe.Pointer(x))
}
func (x *JavaVMOption) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewJavaVMOptionRef(ref unsafe.Pointer) *JavaVMOption {
	return (*JavaVMOption)(ref)
}
func NewJavaVMOption() *JavaVMOption {
	return (*JavaVMOption)(allocJavaVMOptionMemory(1))
}
func allocJavaVMOptionMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJavaVMOptionValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJavaVMOptionValue = unsafe.Sizeof([1]C.JavaVMOption{})