Usage of native libraries in the core Java classes
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ritesh_kumar
Posted On:   Saturday, March 16, 2002 01:59 PM

Hi every body! I am doing a project in which I have to make additions to the current set of core libraries. This also includes changes to existing libraries (which I can do because the source code of the core classes are available). I must instantiate a class (java.lang.User which is my own addition) in every Thread object that I instantiate. However, the class java.lang.User uses some native methods (JNI). The problem is that the class just refuses to instantiate inside the Thread class! It some times gives me a segmentation fault and some times the jvm just hangs taking up a lot of kernel cpu cycles (I am using IBMJDK1.3 on Red Hat Linux 7.2). Even a System.out.println doesn't work inside in Thread object constructor (the init() method in java.lan   More>>

Hi every body!

I am doing a project in which I have to make additions to the current set of core libraries. This also includes changes to existing libraries (which I can do because the source code of the core classes are available). I must instantiate a class (java.lang.User which is my own addition) in every Thread object that I instantiate. However, the class java.lang.User uses some native methods (JNI). The problem is that the class just refuses to instantiate inside the Thread class! It some times gives me a segmentation fault and some times the jvm just hangs taking up a lot of kernel cpu cycles (I am using IBMJDK1.3 on Red Hat Linux 7.2). Even a System.out.println doesn't work inside in Thread object constructor (the init() method in java.lang.Thread). However, when I try to instantiate any class which does not use native methods inside the Thread class (I commented out the static{System.loadLibrary("user");} in my java.lang.User) then it sweetly initializes with every thing running fine (except when you actually use the native method; when an UnsatisfiedLinkError is thrown). What's going wrong? Is trying to load a native library in a class which is loaded due to the constructor of the java.lang.Thread class illegal? I tried to find out how does Thread itself load native libraries for its native methods... however in the whole jdk core clasees source I found statements like 'static{registerNatives()}' or 'static{initIDs()}' with registerNatives() and initIDs() themselves being native methods. What's the puzzle? Can somebody give me a clue into this. A million thanks if somebody answers this...

Ritesh Kumar

prefinal year B.Tech

IIT Kanpur.

   <<Less

Re: Usage of native libraries in the core Java classes

Posted By:   Alexander_Krapf  
Posted On:   Saturday, March 16, 2002 03:19 PM

Ritesh,


That sounds a lot like you're running into bugs in your JNI code. Are you doing any JNI_OnLoad processing that might blow up?


Irrespective of that, I hope you know that you're violating the Java license when you're creating classes in the java.lang package or any other java package. Why do you need to have classes in that package?


Good luck,


Alex

About | Sitemap | Contact