Small JNI improvements (#7371)

Summary:
* Avoid some unnecessary array copy operations on read/write
* Remove some duplicated code
* Don't leak arrays on some exceptions
* Fixed some doc comments

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7371

Reviewed By: jay-zhuang

Differential Revision: D24312932

Pulled By: pdillinger

fbshipit-source-id: 422fe6b98bbdb922a148922ac0d2d965c715176e
main
Adam Retter 4 years ago committed by Facebook GitHub Bot
parent 1a83f5a8ac
commit ccbf468cb1
  1. 19
      java/rocksjni/memory_util.cc
  2. 16
      java/rocksjni/options.cc
  3. 119
      java/rocksjni/portal.h
  4. 13
      java/rocksjni/rocksjni.cc
  5. 2
      java/rocksjni/transaction.cc
  6. 2
      java/rocksjni/ttl.cc

@ -22,21 +22,15 @@
* Signature: ([J[J)Ljava/util/Map; * Signature: ([J[J)Ljava/util/Map;
*/ */
jobject Java_org_rocksdb_MemoryUtil_getApproximateMemoryUsageByType( jobject Java_org_rocksdb_MemoryUtil_getApproximateMemoryUsageByType(
JNIEnv *env, jclass /*jclazz*/, jlongArray jdb_handles, jlongArray jcache_handles) { JNIEnv *env, jclass, jlongArray jdb_handles, jlongArray jcache_handles) {
std::vector<ROCKSDB_NAMESPACE::DB *> dbs; jboolean has_exception = JNI_FALSE;
jsize db_handle_count = env->GetArrayLength(jdb_handles); std::vector<ROCKSDB_NAMESPACE::DB *> dbs =
if(db_handle_count > 0) { ROCKSDB_NAMESPACE::JniUtil::fromJPointers<ROCKSDB_NAMESPACE::DB>(
jlong *ptr_jdb_handles = env->GetLongArrayElements(jdb_handles, nullptr); env, jdb_handles, &has_exception);
if (ptr_jdb_handles == nullptr) { if (has_exception == JNI_TRUE) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return nullptr; return nullptr;
} }
for (jsize i = 0; i < db_handle_count; i++) {
dbs.push_back(
reinterpret_cast<ROCKSDB_NAMESPACE::DB *>(ptr_jdb_handles[i]));
}
env->ReleaseLongArrayElements(jdb_handles, ptr_jdb_handles, JNI_ABORT);
}
std::unordered_set<const ROCKSDB_NAMESPACE::Cache *> cache_set; std::unordered_set<const ROCKSDB_NAMESPACE::Cache *> cache_set;
jsize cache_handle_count = env->GetArrayLength(jcache_handles); jsize cache_handle_count = env->GetArrayLength(jcache_handles);
@ -103,5 +97,4 @@ jobject Java_org_rocksdb_MemoryUtil_getApproximateMemoryUsageByType(
} }
return jusage_by_type; return jusage_by_type;
} }

@ -553,7 +553,8 @@ jlong Java_org_rocksdb_Options_dbPathsLen(
void Java_org_rocksdb_Options_dbPaths( void Java_org_rocksdb_Options_dbPaths(
JNIEnv* env, jobject, jlong jhandle, jobjectArray jpaths, JNIEnv* env, jobject, jlong jhandle, jobjectArray jpaths,
jlongArray jtarget_sizes) { jlongArray jtarget_sizes) {
jlong* ptr_jtarget_size = env->GetLongArrayElements(jtarget_sizes, nullptr); jboolean is_copy;
jlong* ptr_jtarget_size = env->GetLongArrayElements(jtarget_sizes, &is_copy);
if (ptr_jtarget_size == nullptr) { if (ptr_jtarget_size == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return; return;
@ -581,7 +582,8 @@ void Java_org_rocksdb_Options_dbPaths(
ptr_jtarget_size[i] = static_cast<jint>(db_path.target_size); ptr_jtarget_size[i] = static_cast<jint>(db_path.target_size);
} }
env->ReleaseLongArrayElements(jtarget_sizes, ptr_jtarget_size, JNI_COMMIT); env->ReleaseLongArrayElements(jtarget_sizes, ptr_jtarget_size,
is_copy == JNI_TRUE ? 0 : JNI_ABORT);
} }
/* /*
@ -5029,8 +5031,8 @@ void Java_org_rocksdb_ColumnFamilyOptions_setMaxBytesForLevelMultiplierAdditiona
JNIEnv* env, jobject, jlong jhandle, JNIEnv* env, jobject, jlong jhandle,
jintArray jmax_bytes_for_level_multiplier_additional) { jintArray jmax_bytes_for_level_multiplier_additional) {
jsize len = env->GetArrayLength(jmax_bytes_for_level_multiplier_additional); jsize len = env->GetArrayLength(jmax_bytes_for_level_multiplier_additional);
jint* additionals = jint* additionals = env->GetIntArrayElements(
env->GetIntArrayElements(jmax_bytes_for_level_multiplier_additional, 0); jmax_bytes_for_level_multiplier_additional, nullptr);
if (additionals == nullptr) { if (additionals == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return; return;
@ -5682,7 +5684,8 @@ jlong Java_org_rocksdb_DBOptions_dbPathsLen(
void Java_org_rocksdb_DBOptions_dbPaths( void Java_org_rocksdb_DBOptions_dbPaths(
JNIEnv* env, jobject, jlong jhandle, jobjectArray jpaths, JNIEnv* env, jobject, jlong jhandle, jobjectArray jpaths,
jlongArray jtarget_sizes) { jlongArray jtarget_sizes) {
jlong* ptr_jtarget_size = env->GetLongArrayElements(jtarget_sizes, nullptr); jboolean is_copy;
jlong* ptr_jtarget_size = env->GetLongArrayElements(jtarget_sizes, &is_copy);
if (ptr_jtarget_size == nullptr) { if (ptr_jtarget_size == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return; return;
@ -5710,7 +5713,8 @@ void Java_org_rocksdb_DBOptions_dbPaths(
ptr_jtarget_size[i] = static_cast<jint>(db_path.target_size); ptr_jtarget_size[i] = static_cast<jint>(db_path.target_size);
} }
env->ReleaseLongArrayElements(jtarget_sizes, ptr_jtarget_size, JNI_COMMIT); env->ReleaseLongArrayElements(jtarget_sizes, ptr_jtarget_size,
is_copy == JNI_TRUE ? 0 : JNI_ABORT);
} }
/* /*

@ -226,7 +226,7 @@ class CodeJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getValueMethod(JNIEnv* env) { static jmethodID getValueMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -264,7 +264,7 @@ class SubCodeJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getValueMethod(JNIEnv* env) { static jmethodID getValueMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -329,7 +329,7 @@ class StatusJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getCodeMethod(JNIEnv* env) { static jmethodID getCodeMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -350,7 +350,7 @@ class StatusJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getSubCodeMethod(JNIEnv* env) { static jmethodID getSubCodeMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -371,7 +371,7 @@ class StatusJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getStateMethod(JNIEnv* env) { static jmethodID getStateMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -941,7 +941,7 @@ class RocksDBExceptionJni :
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getStatusMethod(JNIEnv* env) { static jmethodID getStatusMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -1032,7 +1032,7 @@ class ListJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getIteratorMethod(JNIEnv* env) { static jmethodID getIteratorMethod(JNIEnv* env) {
jclass jlist_clazz = getListClass(env); jclass jlist_clazz = getListClass(env);
@ -1053,7 +1053,7 @@ class ListJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getHasNextMethod(JNIEnv* env) { static jmethodID getHasNextMethod(JNIEnv* env) {
jclass jiterator_clazz = getIteratorClass(env); jclass jiterator_clazz = getIteratorClass(env);
@ -1073,7 +1073,7 @@ class ListJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getNextMethod(JNIEnv* env) { static jmethodID getNextMethod(JNIEnv* env) {
jclass jiterator_clazz = getIteratorClass(env); jclass jiterator_clazz = getIteratorClass(env);
@ -1094,7 +1094,7 @@ class ListJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getArrayListConstructorMethodId(JNIEnv* env) { static jmethodID getArrayListConstructorMethodId(JNIEnv* env) {
jclass jarray_list_clazz = getArrayListClass(env); jclass jarray_list_clazz = getArrayListClass(env);
@ -1114,7 +1114,7 @@ class ListJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getListAddMethodId(JNIEnv* env) { static jmethodID getListAddMethodId(JNIEnv* env) {
jclass jlist_clazz = getListClass(env); jclass jlist_clazz = getListClass(env);
@ -1251,10 +1251,11 @@ class ByteBufferJni : public JavaClass {
* Get the Java Method: ByteBuffer#allocate * Get the Java Method: ByteBuffer#allocate
* *
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* @param jbytebuffer_clazz if you have a reference to a ByteBuffer class, or nullptr * @param jbytebuffer_clazz if you have a reference to a ByteBuffer class, or
* nullptr
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getAllocateMethodId(JNIEnv* env, static jmethodID getAllocateMethodId(JNIEnv* env,
jclass jbytebuffer_clazz = nullptr) { jclass jbytebuffer_clazz = nullptr) {
@ -1277,7 +1278,7 @@ class ByteBufferJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getArrayMethodId(JNIEnv* env, static jmethodID getArrayMethodId(JNIEnv* env,
jclass jbytebuffer_clazz = nullptr) { jclass jbytebuffer_clazz = nullptr) {
@ -1486,7 +1487,7 @@ class StringBuilderJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getListAddMethodId(JNIEnv* env) { static jmethodID getListAddMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -2373,7 +2374,7 @@ class MapJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMapPutMethodId(JNIEnv* env) { static jmethodID getMapPutMethodId(JNIEnv* env) {
jclass jlist_clazz = getJClass(env); jclass jlist_clazz = getJClass(env);
@ -2905,7 +2906,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getPutCfMethodId(JNIEnv* env) { static jmethodID getPutCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -2925,7 +2926,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getPutMethodId(JNIEnv* env) { static jmethodID getPutMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -2945,7 +2946,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMergeCfMethodId(JNIEnv* env) { static jmethodID getMergeCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -2965,7 +2966,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMergeMethodId(JNIEnv* env) { static jmethodID getMergeMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -2985,7 +2986,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getDeleteCfMethodId(JNIEnv* env) { static jmethodID getDeleteCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3005,7 +3006,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getDeleteMethodId(JNIEnv* env) { static jmethodID getDeleteMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3025,7 +3026,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getSingleDeleteCfMethodId(JNIEnv* env) { static jmethodID getSingleDeleteCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3045,7 +3046,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getSingleDeleteMethodId(JNIEnv* env) { static jmethodID getSingleDeleteMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3065,7 +3066,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getDeleteRangeCfMethodId(JNIEnv* env) { static jmethodID getDeleteRangeCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3085,7 +3086,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getDeleteRangeMethodId(JNIEnv* env) { static jmethodID getDeleteRangeMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3105,7 +3106,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getLogDataMethodId(JNIEnv* env) { static jmethodID getLogDataMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3125,7 +3126,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getPutBlobIndexCfMethodId(JNIEnv* env) { static jmethodID getPutBlobIndexCfMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3145,7 +3146,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMarkBeginPrepareMethodId(JNIEnv* env) { static jmethodID getMarkBeginPrepareMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3165,7 +3166,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMarkEndPrepareMethodId(JNIEnv* env) { static jmethodID getMarkEndPrepareMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3185,7 +3186,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMarkNoopMethodId(JNIEnv* env) { static jmethodID getMarkNoopMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3205,7 +3206,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMarkRollbackMethodId(JNIEnv* env) { static jmethodID getMarkRollbackMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3225,7 +3226,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getMarkCommitMethodId(JNIEnv* env) { static jmethodID getMarkCommitMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3245,7 +3246,7 @@ class WriteBatchHandlerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getContinueMethodId(JNIEnv* env) { static jmethodID getContinueMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3281,7 +3282,7 @@ class WriteBatchSavePointJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getConstructorMethodId(JNIEnv* env) { static jmethodID getConstructorMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3372,7 +3373,7 @@ class HistogramDataJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getConstructorMethodId(JNIEnv* env) { static jmethodID getConstructorMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3561,7 +3562,7 @@ class AbstractCompactionFilterFactoryJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getNameMethodId(JNIEnv* env) { static jmethodID getNameMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3582,7 +3583,7 @@ class AbstractCompactionFilterFactoryJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getCreateCompactionFilterMethodId(JNIEnv* env) { static jmethodID getCreateCompactionFilterMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -3649,7 +3650,7 @@ class AbstractComparatorJniBridge : public JavaClass {
* @param jclazz the AbstractComparatorJniBridge class * @param jclazz the AbstractComparatorJniBridge class
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getCompareInternalMethodId(JNIEnv* env, jclass jclazz) { static jmethodID getCompareInternalMethodId(JNIEnv* env, jclass jclazz) {
static jmethodID mid = static jmethodID mid =
@ -3666,7 +3667,7 @@ class AbstractComparatorJniBridge : public JavaClass {
* @param jclazz the AbstractComparatorJniBridge class * @param jclazz the AbstractComparatorJniBridge class
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getFindShortestSeparatorInternalMethodId(JNIEnv* env, jclass jclazz) { static jmethodID getFindShortestSeparatorInternalMethodId(JNIEnv* env, jclass jclazz) {
static jmethodID mid = static jmethodID mid =
@ -3683,7 +3684,7 @@ class AbstractComparatorJniBridge : public JavaClass {
* @param jclazz the AbstractComparatorJniBridge class * @param jclazz the AbstractComparatorJniBridge class
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getFindShortSuccessorInternalMethodId(JNIEnv* env, jclass jclazz) { static jmethodID getFindShortSuccessorInternalMethodId(JNIEnv* env, jclass jclazz) {
static jmethodID mid = static jmethodID mid =
@ -3719,7 +3720,7 @@ class AbstractComparatorJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getNameMethodId(JNIEnv* env) { static jmethodID getNameMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -4016,7 +4017,7 @@ class WBWIRocksIteratorJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Field ID or nullptr if the class or field id could not * @return The Java Field ID or nullptr if the class or field id could not
* be retieved * be retrieved
*/ */
static jfieldID getWriteEntryField(JNIEnv* env) { static jfieldID getWriteEntryField(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -4337,7 +4338,7 @@ class LoggerJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getLogMethodId(JNIEnv* env) { static jmethodID getLogMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -5718,7 +5719,8 @@ class TransactionJni : public JavaClass {
return nullptr; return nullptr;
} }
jlong *body = env->GetLongArrayElements(jtransaction_ids, nullptr); jboolean is_copy;
jlong* body = env->GetLongArrayElements(jtransaction_ids, &is_copy);
if(body == nullptr) { if(body == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
env->DeleteLocalRef(jkey); env->DeleteLocalRef(jkey);
@ -5728,7 +5730,8 @@ class TransactionJni : public JavaClass {
for(size_t i = 0; i < len; ++i) { for(size_t i = 0; i < len; ++i) {
body[i] = static_cast<jlong>(transaction_ids[i]); body[i] = static_cast<jlong>(transaction_ids[i]);
} }
env->ReleaseLongArrayElements(jtransaction_ids, body, 0); env->ReleaseLongArrayElements(jtransaction_ids, body,
is_copy == JNI_TRUE ? 0 : JNI_ABORT);
jobject jwaiting_transactions = env->CallObjectMethod(jtransaction, jobject jwaiting_transactions = env->CallObjectMethod(jtransaction,
mid, static_cast<jlong>(column_family_id), jkey, jtransaction_ids); mid, static_cast<jlong>(column_family_id), jkey, jtransaction_ids);
@ -5999,7 +6002,7 @@ class AbstractTableFilterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getFilterMethod(JNIEnv* env) { static jmethodID getFilterMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -6269,7 +6272,7 @@ class ColumnFamilyDescriptorJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getColumnFamilyNameMethod(JNIEnv* env) { static jmethodID getColumnFamilyNameMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -6289,7 +6292,7 @@ class ColumnFamilyDescriptorJni : public JavaClass {
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getColumnFamilyOptionsMethod(JNIEnv* env) { static jmethodID getColumnFamilyOptionsMethod(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -6783,7 +6786,8 @@ class ThreadStatusJni : public JavaClass {
env->DeleteLocalRef(jcf_name); env->DeleteLocalRef(jcf_name);
return nullptr; return nullptr;
} }
jlong *body = env->GetLongArrayElements(joperation_properties, nullptr); jboolean is_copy;
jlong* body = env->GetLongArrayElements(joperation_properties, &is_copy);
if (body == nullptr) { if (body == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
env->DeleteLocalRef(jdb_name); env->DeleteLocalRef(jdb_name);
@ -6794,7 +6798,8 @@ class ThreadStatusJni : public JavaClass {
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
body[i] = static_cast<jlong>(thread_status->op_properties[i]); body[i] = static_cast<jlong>(thread_status->op_properties[i]);
} }
env->ReleaseLongArrayElements(joperation_properties, body, 0); env->ReleaseLongArrayElements(joperation_properties, body,
is_copy == JNI_TRUE ? 0 : JNI_ABORT);
jobject jcfd = env->NewObject(jclazz, mid, jobject jcfd = env->NewObject(jclazz, mid,
static_cast<jlong>(thread_status->thread_id), static_cast<jlong>(thread_status->thread_id),
@ -7415,7 +7420,7 @@ class AbstractTraceWriterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getWriteProxyMethodId(JNIEnv* env) { static jmethodID getWriteProxyMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -7436,7 +7441,7 @@ class AbstractTraceWriterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getCloseWriterProxyMethodId(JNIEnv* env) { static jmethodID getCloseWriterProxyMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -7457,7 +7462,7 @@ class AbstractTraceWriterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getGetFileSizeMethodId(JNIEnv* env) { static jmethodID getGetFileSizeMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -7498,7 +7503,7 @@ class AbstractWalFilterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getColumnFamilyLogNumberMapMethodId(JNIEnv* env) { static jmethodID getColumnFamilyLogNumberMapMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -7520,7 +7525,7 @@ class AbstractWalFilterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getLogRecordFoundProxyMethodId(JNIEnv* env) { static jmethodID getLogRecordFoundProxyMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);
@ -7541,7 +7546,7 @@ class AbstractWalFilterJni
* @param env A pointer to the Java environment * @param env A pointer to the Java environment
* *
* @return The Java Method ID or nullptr if the class or method id could not * @return The Java Method ID or nullptr if the class or method id could not
* be retieved * be retrieved
*/ */
static jmethodID getNameMethodId(JNIEnv* env) { static jmethodID getNameMethodId(JNIEnv* env) {
jclass jclazz = getJClass(env); jclass jclazz = getJClass(env);

@ -421,8 +421,8 @@ jlongArray Java_org_rocksdb_RocksDB_createColumnFamilies__J_3J_3_3B(
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor> cf_descriptors; std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor> cf_descriptors;
cf_descriptors.reserve(jlen); cf_descriptors.reserve(jlen);
jboolean jcf_options_handles_is_copy = JNI_FALSE; jlong* jcf_options_handles_elems =
jlong *jcf_options_handles_elems = env->GetLongArrayElements(jcf_options_handles, &jcf_options_handles_is_copy); env->GetLongArrayElements(jcf_options_handles, nullptr);
if(jcf_options_handles_elems == nullptr) { if(jcf_options_handles_elems == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return nullptr; return nullptr;
@ -2343,9 +2343,7 @@ jlongArray Java_org_rocksdb_RocksDB_getApproximateSizes(
const jsize jlen = env->GetArrayLength(jrange_slice_handles); const jsize jlen = env->GetArrayLength(jrange_slice_handles);
const size_t range_count = jlen / 2; const size_t range_count = jlen / 2;
jboolean jranges_is_copy = JNI_FALSE; jlong* jranges = env->GetLongArrayElements(jrange_slice_handles, nullptr);
jlong* jranges = env->GetLongArrayElements(jrange_slice_handles,
&jranges_is_copy);
if (jranges == nullptr) { if (jranges == nullptr) {
// exception thrown: OutOfMemoryError // exception thrown: OutOfMemoryError
return nullptr; return nullptr;
@ -3256,9 +3254,8 @@ jobject Java_org_rocksdb_RocksDB_getPropertiesOfTablesInRange(
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle); reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
} }
const jsize jlen = env->GetArrayLength(jrange_slice_handles); const jsize jlen = env->GetArrayLength(jrange_slice_handles);
jboolean jrange_slice_handles_is_copy = JNI_FALSE; jlong* jrange_slice_handle =
jlong *jrange_slice_handle = env->GetLongArrayElements( env->GetLongArrayElements(jrange_slice_handles, nullptr);
jrange_slice_handles, &jrange_slice_handles_is_copy);
if (jrange_slice_handle == nullptr) { if (jrange_slice_handle == nullptr) {
// exception occurred // exception occurred
return nullptr; return nullptr;

@ -689,6 +689,7 @@ void txn_write_kv_parts_helper(JNIEnv* env,
// out of memory // out of memory
env->DeleteLocalRef(jobj_value_part); env->DeleteLocalRef(jobj_value_part);
env->DeleteLocalRef(jobj_key_part); env->DeleteLocalRef(jobj_key_part);
env->ReleaseByteArrayElements(jba_key_part, jkey_part, JNI_ABORT);
free_parts(env, jparts_to_free); free_parts(env, jparts_to_free);
return; return;
} }
@ -698,6 +699,7 @@ void txn_write_kv_parts_helper(JNIEnv* env,
env->ReleaseByteArrayElements(jba_value_part, jvalue_part, JNI_ABORT); env->ReleaseByteArrayElements(jba_value_part, jvalue_part, JNI_ABORT);
env->DeleteLocalRef(jobj_value_part); env->DeleteLocalRef(jobj_value_part);
env->DeleteLocalRef(jobj_key_part); env->DeleteLocalRef(jobj_key_part);
env->ReleaseByteArrayElements(jba_key_part, jkey_part, JNI_ABORT);
free_parts(env, jparts_to_free); free_parts(env, jparts_to_free);
return; return;
} }

@ -197,7 +197,7 @@ jlong Java_org_rocksdb_TtlDB_createColumnFamilyWithTtl(
*cfOptions, std::string(reinterpret_cast<char*>(cfname), len), &handle, *cfOptions, std::string(reinterpret_cast<char*>(cfname), len), &handle,
jttl); jttl);
env->ReleaseByteArrayElements(jcolumn_name, cfname, 0); env->ReleaseByteArrayElements(jcolumn_name, cfname, JNI_ABORT);
if (s.ok()) { if (s.ok()) {
return reinterpret_cast<jlong>(handle); return reinterpret_cast<jlong>(handle);

Loading…
Cancel
Save