Skip to content

v4.0.0

Latest
Compare
Choose a tag to compare
@jfirebaugh jfirebaugh released this 07 Sep 00:08
· 8 commits to master since this release

This release contains many breaking changes in the high-level API, especially around ownership semantics.

  • Replaced UniqueObject and UniqueWeakObject with Global and Weak, and introduced Local. All high-level values must be one of these three types; high-level references (e.g. const jni::Object<>&) must now be used whenever borrowing, rather than ownership, is desired. In particular, native method implementations should accept non-primitive inputs via reference, rather than by value.
  • High-level JNI local refs are now always wrapped with the Local ownership type, which calls DeleteLocalRef when destroyed. You'll never need to worry about overflowing the local ref table.
  • Object, Class, and Array are no longer publicly constructible, destructible, movable, copyable, assignable, or implicitly convertible to raw pointers. Use Global, Weak, and Local for ownership. Use MakeGlobal, MakeWeak, and MakeLocal for explicit ref duplication. Use C++ references when borrowing, rather than ownership, is desired. Avoid using raw pointers when possible; use get() if you really need one.
  • If you tell jni.hpp about the Java inheritance tree, it'll build a parallel tree for Object, enabling convenient automatic conversions. To inform jni.hpp of Java inheritance, add a SuperTag typedef to a tag type naming the tag type for the Java superclass, e.g.:
    struct StringTag { using SuperTag = ObjectTag; ... };
  • As special cases of the above, String, Class, and Array now inherit from Object<>.
  • Introduced ArrayTag<T>, where T is a primitive or high-level type. This allows you to obtain array classes, e.g. Class<ArrayTag<jni::jlong>>::Singleton(env).
  • Swapped the argument order for Cast.
  • Removed an annoying parameter to Array::New.

Other new features:

  • Introduced Class<Tag>::Singleton(), providing a convenient way to obtain a reference to a Class instance.
  • Added wrappers for boxing and unboxing primitive types.
  • Support for Array<jbyte> <-> std::string conversions.
  • More efficient TypeSignature implementation.
  • Added deleters for Global and Weak that attach or get the JNIEnv. These are useful when the deletion will happen on an auxiliary thread, such as the finalizer thread.
  • Added a wrapper for java.lang.ref.WeakReference. This should almost always be used instead of JNI weak global refs, which have unsafe promotion semantics.

Bugfixes:

  • Cope with implementation inconsistencies in AttachCurrentThread
  • Improved compatibility with OpenJDK
  • Improved compatibility with GCC