29#ifndef JAU_JNIMEM__HPP_
30#define JAU_JNIMEM__HPP_
54 JNIEnv *env =
nullptr;
55 bool needsDetach =
false;
88 mutable std::mutex mtx;
92 static inline void check(jobject
object,
const char* file,
int line) {
93 if(
nullptr ==
object ) {
131 {
return !( *
this == rhs ); }
141template <
typename T,
typename U>
160 jboolean isCopy =
false;
182 if(
nullptr != narray ) {
183 env->ReleasePrimitiveArrayCritical(jarray, narray, mode);
184 this->jarray =
nullptr;
185 this->narray =
nullptr;
194 if(
nullptr == jarray_val ) {
197 T* _narray =
static_cast<T*
>( env->GetPrimitiveArrayCritical(jarray_val, &isCopy) );
198 if(
nullptr != _narray ) {
199 this->mode = mode_val;
200 this->jarray = jarray_val;
201 this->narray = _narray;
@ NO_UPDATE_AND_RELEASE
Like default JNI_ABORT: If 'isCopy': Do not update the java array data with the copy,...
@ UPDATE_NO_RELEASE
Like JNI_COMMIT: If 'isCopy': Update the java array data with the copy, but do not free the copy.
@ UPDATE_AND_RELEASE
Like default 0: If 'isCopy': Update the java array data with the copy and free the copy.
JNICriticalArray(const JNICriticalArray &o)=delete
JNICriticalArray & operator=(JNICriticalArray &&o)=delete
JNICriticalArray & operator=(const JNICriticalArray &o)=delete
void release()
Manual release of the acquired primitive array, usually one likes to simply do this via the destructo...
~JNICriticalArray()
Release the acquired primitive array, RAII style.
T * get(U jarray_val, Mode mode_val=UPDATE_AND_RELEASE)
Acquired the primitive array.
JNICriticalArray(JNIEnv *env_val)
JNICriticalArray(JNICriticalArray &&o)=delete
bool getIsCopy() const
Returns true if the primitive array had been acquired and the JVM utilizes a copy of the underlying j...
jobjectRefType getObjectRefType() const noexcept
Should return JNIGlobalRefType if the object is valid or JNIInvalidRefType if the object is nullptr.
jobject getObject() const noexcept
bool operator!=(const JNIGlobalRef &rhs) const noexcept
static void check(jobject object, const char *file, int line)
jobject operator*() noexcept
jclass getClass() const noexcept
bool isValidReference() const noexcept
bool operator==(const JNIGlobalRef &rhs) const noexcept
Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance.
thread_local JNIEnvContainer jni_env