v.io/x/jni: support for perf improvements
MultiPart: 2/2
Change-Id: I2958240f49958cf7d971063d59ab332f1b692e09
diff --git a/impl/google/rpc/invoker.go b/impl/google/rpc/invoker.go
index 5b9400e..17cbae7 100644
--- a/impl/google/rpc/invoker.go
+++ b/impl/google/rpc/invoker.go
@@ -26,20 +26,7 @@
// #include "jni.h"
import "C"
-func goInvoker(env jutil.Env, obj jutil.Object) (rpc.Invoker, error) {
- // See if the Java object is an invoker.
- var jInvoker jutil.Object
- if jutil.IsInstanceOf(env, obj, jInvokerClass) {
- jInvoker = obj
- } else {
- // Create a new Java ReflectInvoker object.
- jReflectInvoker, err := jutil.NewObject(env, jReflectInvokerClass, []jutil.Sign{jutil.ObjectSign}, obj)
- if err != nil {
- return nil, fmt.Errorf("error creating Java ReflectInvoker object: %v", err)
- }
- jInvoker = jReflectInvoker
- }
-
+func goInvoker(env jutil.Env, jInvoker jutil.Object) (rpc.Invoker, error) {
// Reference Java invoker; it will be de-referenced when the go invoker
// created below is garbage-collected (through the finalizer callback we
// setup just below).
diff --git a/impl/google/rpc/jni.go b/impl/google/rpc/jni.go
index d9ae2ef..eec488e 100644
--- a/impl/google/rpc/jni.go
+++ b/impl/google/rpc/jni.go
@@ -512,9 +512,9 @@
}
//export Java_io_v_impl_google_rpc_ServerRPCHelper_nativeGoInvoker
-func Java_io_v_impl_google_rpc_ServerRPCHelper_nativeGoInvoker(jenv *C.JNIEnv, jServerRPCHelper C.jclass, jServiceObject C.jobject) C.jlong {
+func Java_io_v_impl_google_rpc_ServerRPCHelper_nativeGoInvoker(jenv *C.JNIEnv, jServerRPCHelper C.jclass, jInvoker C.jobject) C.jlong {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
- invoker, err := goInvoker(env, jutil.Object(uintptr(unsafe.Pointer(jServiceObject))))
+ invoker, err := goInvoker(env, jutil.Object(uintptr(unsafe.Pointer(jInvoker))))
if err != nil {
jutil.JThrowV(env, err)
return C.jlong(0)
diff --git a/v23/context/jni.go b/v23/context/jni.go
index 633ae95..b048eb1 100644
--- a/v23/context/jni.go
+++ b/v23/context/jni.go
@@ -110,9 +110,9 @@
}
//export Java_io_v_v23_context_VContext_nativeValue
-func Java_io_v_v23_context_VContext_nativeValue(jenv *C.JNIEnv, jVContext C.jobject, goPtr C.jlong, jKey C.jobject) C.jobject {
+func Java_io_v_v23_context_VContext_nativeValue(jenv *C.JNIEnv, jVContext C.jobject, goPtr C.jlong, jKeySign C.jstring) C.jobject {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
- key, err := GoContextKey(env, jutil.Object(uintptr(unsafe.Pointer(jKey))))
+ key := goContextKey(jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jKeySign)))))
value := (*(*context.T)(jutil.NativePtr(goPtr))).Value(key)
jValue, err := JavaContextValue(env, value)
if err != nil {
@@ -169,13 +169,9 @@
}
//export Java_io_v_v23_context_VContext_nativeWithValue
-func Java_io_v_v23_context_VContext_nativeWithValue(jenv *C.JNIEnv, jVContext C.jobject, goPtr C.jlong, goCancelPtr C.jlong, jKey C.jobject, jValue C.jobject) C.jobject {
+func Java_io_v_v23_context_VContext_nativeWithValue(jenv *C.JNIEnv, jVContext C.jobject, goPtr C.jlong, goCancelPtr C.jlong, jKeySign C.jstring, jValue C.jobject) C.jobject {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
- key, err := GoContextKey(env, jutil.Object(uintptr(unsafe.Pointer(jKey))))
- if err != nil {
- jutil.JThrowV(env, err)
- return nil
- }
+ key := goContextKey(jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jKeySign)))))
value, err := GoContextValue(env, jutil.Object(uintptr(unsafe.Pointer(jValue))))
if err != nil {
jutil.JThrowV(env, err)
diff --git a/v23/context/util.go b/v23/context/util.go
index 1b762f2..b87b23c 100644
--- a/v23/context/util.go
+++ b/v23/context/util.go
@@ -63,26 +63,6 @@
return (*context.T)(jutil.NativePtr(goCtxPtr)), cancel, nil
}
-// GoContextKey creates a Go Context key given the Java Context key. The
-// returned key guarantees that the two Java keys will be equal iff (1) they
-// belong to the same class, and (2) they have the same hashCode().
-func GoContextKey(env jutil.Env, jKey jutil.Object) (interface{}, error) {
- // Create a lookup key we use to map Java context keys to Go context keys.
- hashCode, err := jutil.CallIntMethod(env, jKey, "hashCode", nil)
- if err != nil {
- return nil, err
- }
- jClass, err := jutil.CallObjectMethod(env, jKey, "getClass", nil, classSign)
- if err != nil {
- return nil, err
- }
- className, err := jutil.CallStringMethod(env, jClass, "getName", nil)
- if err != nil {
- return nil, err
- }
- return goContextKey(fmt.Sprintf("%s:%d", className, hashCode)), nil
-}
-
// GoContextValue returns the Go Context value given the Java Context value.
func GoContextValue(env jutil.Env, jValue jutil.Object) (interface{}, error) {
// Reference Java object; it will be de-referenced when the Go wrapper