Is there a simple/standard way for dumping the contents of JNI types, such as jobject
or jclass
, to either console output or file, from the C++ environment? For example, printing the field names and types of a given jclass
? Is there an exising JNI facility or a library that could help to achieve this?
Asked
Active
Viewed 385 times
2

valiano
- 16,433
- 7
- 64
- 79
-
JNI allows access to the full introspection techniques available in Java. AFAIK, you'll have to code that yourself. What do you mean by "offsets"? – manuell Jun 20 '17 at 08:06
-
Thanks @manuell. Never mind the offsets, I confused it with something else. – valiano Jun 20 '17 at 08:25
-
Your question is confusing. Are you looking for [`javap -s`](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javap.html)? – Tom Blodget Jun 22 '17 at 23:17
-
@TomBlodget looking for an easy way to introspect/dump JNI classes during JVM runtime, from C++ code interacting with the JVM. Ideally, something like a function `dump_jobject(jobject* myObj)` (for example), that will nicely print the contents of the jobject, and could be called at runtime - either by adding a call in the C++ code itself, near the code to be debugged, or by adding it to IDE's variables watch view. – valiano Jun 23 '17 at 09:22
-
JNI doesn't have classes. (The C++ interface is a thin wrapper around the C interface.) It is far easier to do anything in Java than via JNI. I suggest you grab a reflection library that dumps objects like you need and simply call that at interesting points in your JNI code. (I've never used it but [XStream](https://stackoverflow.com/a/603055/2226988) looks like it might do the job.) – Tom Blodget Jun 23 '17 at 16:33
-
@TomBlodget thanks for clarifying and pointing towards XStream, I'll give this a try. – valiano Jun 23 '17 at 17:26