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

get_env should accept JNI version as a parameter, like the C JNI function GetEnv does #500

Closed
rib opened this issue Sep 26, 2023 · 0 comments

Comments

@rib
Copy link
Contributor

rib commented Sep 26, 2023

          Should this method accept a JNI version as a parameter, like the C JNI function `GetEnv` does?

HotSpot seems to return the same JNIEnv regardless of requested version (as long as that version is supported), but other JVMs could in theory return a different JNIEnv depending on which version you ask for.

Originally posted by @argv-minus-one in #478 (comment)

rib added a commit that referenced this issue Nov 20, 2023
JavaVM::get_env now requires the caller to determine that the JavaVM
supports at least JNI 1.4 since there are two notable difficulties
with trying to check the version internally:

1. There is a chicken and egg problem with trying to use `GetEnv`
   to get a `JNIEnv` from a `JavaVM` without knowing that it supports JNI
   1.2
2. We require 1.4 as the minimum supported version but can't call
   `GetVersion` to validate a returned `JNIEnv` while there may be exceptions
   pending (since GetVersion is not in the list of JNI functions that are safe
   to call with pending exceptions).

This also documents how `::get_env()` must not be used to materialize
a (mutable) JNIEnv with a lifetime that doesn't correspond to the top JNI
stack frame for local object references.

Ref: #436 (reply in thread)

Fixes: #500
@rib rib closed this as completed in 450a164 Nov 20, 2023
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

No branches or pull requests

1 participant