Forum Stats

  • 3,853,777 Users
  • 2,264,267 Discussions
  • 7,905,444 Comments

Discussions

jclass lifecycle documentation

801075
801075 Member Posts: 1
edited Sep 28, 2010 3:24PM in Java Native Interface (JNI)
I am looking for some documentation that describes JNI in terms of the jclass lifecycle.

What I mean by this, is that if a singleton DLL/DSO was loaded but allows the creation of distinct Class types (for different ClassLoader), I'd like to understand better the interaction of that with JNI. For example can I attach an opaque pointer to a jclass/Class from JNI so allow the JNI part of the system to independantly track information relating to that specific instance of a Class.

Also the interaction with the DefineClass (and implied UndefineClass) mechanisms within Java, for example could a class be redefined or undefined (if no longer used by any existing Object), does JavaVM manage class unload callbacks to JNI, allowing the opaque pointer I stored in the jclass to be natively deallocated.

Of course I understand that usage of jclass is shared by multiple users, so the native code using the opaque point would be thread-safe and deadlock free.



I have looked as best I can at the old sun hosted foum and also skimmed through the JNI documentation but have been unable to find any reference to how ClassLoader/Class creation/destruction affect JNI.

Answers

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    798072 wrote:
    For example can I attach an opaque pointer to a jclass/Class from JNI so allow the JNI part of the system to independantly track information relating to that specific instance of a Class.
    Not a good idea, regardless. Classes are objects. As with any other object attempting to maintain a C/C++ pointer to it correctly handling the scope of java objects will not work.
    Also the interaction with the DefineClass (and implied UndefineClass) mechanisms within Java, for example could a class be redefined or undefined
    Again a matter of understanding the scope of objects in java.
This discussion has been closed.