9
9
#include " dn_method_call.h"
10
10
#include " dn_signature_helper.h"
11
11
#include " dn_callback.h"
12
+ #include " jni_object_ref.h"
12
13
13
14
extern " C"
14
15
{
15
16
16
17
static JavaVM *gJvm = nullptr ;
17
- static jobject gClassLoader ;
18
+ static JavaGlobalRef< jobject> * gClassLoader = nullptr ;
18
19
static jmethodID gFindClassMethod ;
19
20
static pthread_key_t detachKey = 0 ;
20
21
21
22
// / for invoke result compare
22
- static jclass gStrCls ;
23
+ static JavaGlobalRef< jclass> * gStrCls = nullptr ;
23
24
24
- // / key is jobject, value is pai which contain jclass and reference count
25
+ // / key is jobject, value is pair which contain jclass and reference count
25
26
static std::map<jobject, std::pair<jclass, int > > objectGlobalReference;
26
27
27
28
// / protect objectGlobalReference
@@ -92,13 +93,13 @@ extern "C"
92
93
auto getClassLoaderMethod = env->GetMethodID (pluginClass, " getClassLoader" ,
93
94
" ()Ljava/lang/ClassLoader;" );
94
95
auto classLoader = env->CallObjectMethod (plugin, getClassLoaderMethod);
95
- gClassLoader = env->NewGlobalRef (classLoader);
96
+ gClassLoader = new JavaGlobalRef<jobject>( env->NewGlobalRef (classLoader), env );
96
97
gFindClassMethod = env->GetMethodID (classLoaderClass, " findClass" ,
97
98
" (Ljava/lang/String;)Ljava/lang/Class;" );
98
99
99
100
// / cache string class
100
101
jclass strCls = env->FindClass (" java/lang/String" );
101
- gStrCls = static_cast <jclass>(env->NewGlobalRef (strCls));
102
+ gStrCls = new JavaGlobalRef<jclass>( static_cast <jclass>(env->NewGlobalRef (strCls)), env );
102
103
103
104
env->DeleteLocalRef (classLoader);
104
105
env->DeleteLocalRef (plugin);
@@ -119,7 +120,7 @@ extern "C"
119
120
{
120
121
env->ExceptionClear ();
121
122
DNDebug (" findClass exception" );
122
- return static_cast <jclass>(env->CallObjectMethod (gClassLoader ,
123
+ return static_cast <jclass>(env->CallObjectMethod (gClassLoader -> Object () ,
123
124
gFindClassMethod ,
124
125
env->NewStringUTF (name)));
125
126
}
@@ -227,7 +228,7 @@ extern "C"
227
228
jobject obj = env->CallObjectMethodA (object, method, argValues);
228
229
if (obj != nullptr )
229
230
{
230
- if (env->IsInstanceOf (obj, gStrCls ))
231
+ if (env->IsInstanceOf (obj, gStrCls -> Object () ))
231
232
{
232
233
// / mark the last pointer as string
233
234
// / dart will check this pointer
0 commit comments