10 #include <glog/logging.h> 24 *shouldDetach =
false;
27 auto status = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
28 CHECK(status == JNI_OK || status == JNI_EDETACHED);
30 if (status == JNI_EDETACHED) {
31 status = vm->AttachCurrentThread(
32 reinterpret_cast<void**>(&env),
nullptr );
33 CHECK_EQ(status, JNI_OK);
42 vm->DetachCurrentThread();
48 reinterpret_cast<jclass
>(env->NewGlobalRef(env->FindClass(name.c_str())));
58 auto methodId = env->GetMethodID(clazz, name.c_str(), signature.c_str());
64 if (!env->ExceptionCheck()) {
67 env->ExceptionDescribe();
69 throw std::runtime_error(
"JNI exception");
73 auto byteArray = env->NewByteArray(byteRange.
size());
74 env->SetByteArrayRegion(
78 reinterpret_cast<const jbyte*
>(byteRange.
data()));
jclass getClass(JNIEnv *env, const std::string &name)
constexpr size_type size() const
void maybeThrowException(JNIEnv *env, bool shouldDetach)
void releaseEnv(bool shouldDetach)
constexpr Iter data() const
JNIEnv * getEnv(bool *shouldDetach)
jmethodID getMethodID(JNIEnv *env, jclass clazz, const std::string &name, const std::string &signature)
std::unique_ptr< folly::IOBuf > Buf
jbyteArray createByteArray(JNIEnv *env, folly::ByteRange byteRange)