1

I'm aware of the fact that you can dump the local reference table using the method illustrated here.

jclass vm_class = env->FindClass("dalvik/system/VMDebug");
jmethodID dump_mid = env->GetStaticMethodID( vm_class, "dumpReferenceTables", "()V" );
env->CallStaticVoidMethod( vm_class, dump_mid );

However, this prints it to the log.

I'm wondering if there is a way to retrieve the current number of local references at any given moment in time programmatically.

Nathan F.
  • 3,250
  • 3
  • 35
  • 69
  • 1
    If you look at the native `dumpReferenceTables` method [here](https://android.googlesource.com/platform/art/+/refs/heads/master/runtime/native/dalvik_system_VMDebug.cc) it might help you out - it looks like you can get a `JNIEnvExt` from your `JNIEnv` and then possibly access the 'locals' reference table through that. (see the Dump method [here](https://android.googlesource.com/platform/art/+/master/runtime/indirect_reference_table.cc)) – rodit Jul 28 '20 at 17:44
  • @rodit I can't find the `JNIEnvExt` reference you're talking about in the first link you sent. On line 268 I do see the `dumpReferenceTables` method, however it doesn't have any instance of `JNIEnvExt`. After doing some more googling, I have found `JNIEnvExt`, but only in older versions of android under `jni_env_ext.h`. I can't find this in the `master` branch. – Nathan F. Jul 28 '20 at 21:50
  • I think i would need to do something like `size_t localRefCount = ((JNIEnvExt*)env)->locals->Capacity();` however, I can't figure out how to convert my `JNIEnv` into that `JNIEnvExt` since I can't include the required headers. I don't know if it's worth mentioning, but I'm working in C, not in C++. – Nathan F. Jul 28 '20 at 22:01
  • Well they seem to access it through using ScopedObjectAccess soa(env); and then soa->Env() gives you the reference to the JNIEnvExt. Using c rather than c++ might be a limitation - also I don't think Capacity is what you want - I think you'd need to iterate through the table and count the non-null entries as in the second link I sent. – rodit Jul 29 '20 at 12:24
  • Actually the reference table has a CountNullEntries method so you can just do Capacity() - CountNullEntries() - other than the ScopedObjectAcess thing I'm not sure how you'd get a JNIEnvExt reference – rodit Jul 29 '20 at 12:25

0 Answers0