Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix case of JNIEnv::FindClass called from JNI_OnLoad #283

Merged
merged 3 commits into from
Jul 2, 2014

Conversation

dicej
Copy link
Member

@dicej dicej commented Jun 23, 2014

If an JNI_OnLoad implementation calls FindClass when using the OpenJDK
class library, the calling method on the Java stack will be
ClassLoader.loadLibrary. However, we must use the class loader of the
class attempting to load the library in this case, not the system
classloader.

Therefore, we now maintain a stack such that the latest class to load
a library in the current thread is at the top, and we use that class
whenever FindClass is called by ClassLoader.loadLibrary (via
JNI_OnLoad).

Note that this patch does not attempt to address the same problem for
the Avian or Android class libraries, but the same strategy should
work for them as well.

Fixes #277

If an JNI_OnLoad implementation calls FindClass when using the OpenJDK
class library, the calling method on the Java stack will be
ClassLoader.loadLibrary.  However, we must use the class loader of the
class attempting to load the library in this case, not the system
classloader.

Therefore, we now maintain a stack such that the latest class to load
a library in the current thread is at the top, and we use that class
whenever FindClass is called by ClassLoader.loadLibrary (via
JNI_OnLoad).

Note that this patch does not attempt to address the same problem for
the Avian or Android class libraries, but the same strategy should
work for them as well.
@joshuawarner32
Copy link
Collaborator

If it's not too hard, I'd like to see this expanded to the avian class library and a test added.

@dicej
Copy link
Member Author

dicej commented Jun 24, 2014

Yup, I'll work on that when I have a chance.

@dicej
Copy link
Member Author

dicej commented Jul 1, 2014

I've added a test and verified it passes with avian, android, openjdk, and openjdk-src builds.

…ibraries

This also fixes the some Android build rot and updates the version of
OpenSSL used.
joshuawarner32 added a commit that referenced this pull request Jul 2, 2014
fix case of JNIEnv::FindClass called from JNI_OnLoad
@joshuawarner32 joshuawarner32 merged commit 60df08d into ReadyTalk:master Jul 2, 2014
@dicej dicej deleted the findclass-onload branch May 4, 2015 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JNI methods cannot be attached inside clinit
2 participants