2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-06-06 02:09:25 +02:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
2020-02-20 21:07:53 +01:00
|
|
|
// calling c++ ROCKSDB_NAMESPACE::Env methods from Java side.
|
2014-06-06 02:09:25 +02:00
|
|
|
|
2022-01-25 04:56:37 +01:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
2019-02-22 23:36:38 +01:00
|
|
|
#include <jni.h>
|
2022-01-25 04:56:37 +01:00
|
|
|
|
2019-02-22 23:36:38 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2015-03-22 18:30:51 +01:00
|
|
|
#include "include/org_rocksdb_Env.h"
|
2014-06-06 02:09:25 +02:00
|
|
|
#include "include/org_rocksdb_RocksEnv.h"
|
2015-03-22 18:30:51 +01:00
|
|
|
#include "include/org_rocksdb_RocksMemEnv.h"
|
2019-02-22 23:36:38 +01:00
|
|
|
#include "include/org_rocksdb_TimedEnv.h"
|
2022-01-25 04:56:37 +01:00
|
|
|
#include "portal.h"
|
2014-06-06 02:09:25 +02:00
|
|
|
|
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: getDefaultEnvInternal
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_Env_getDefaultEnvInternal(
|
|
|
|
JNIEnv*, jclass) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<jlong>(ROCKSDB_NAMESPACE::Env::Default());
|
2014-06-06 02:09:25 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 23:36:38 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksEnv
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksEnv_disposeInternal(
|
|
|
|
JNIEnv*, jobject, jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* e = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
assert(e != nullptr);
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
2014-06-06 02:09:25 +02:00
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: setBackgroundThreads
|
2019-02-22 23:36:38 +01:00
|
|
|
* Signature: (JIB)V
|
2014-06-06 02:09:25 +02:00
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
void Java_org_rocksdb_Env_setBackgroundThreads(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jint jnum, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
|
|
|
rocks_env->SetBackgroundThreads(
|
|
|
|
static_cast<int>(jnum),
|
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2014-06-06 02:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-02-22 23:36:38 +01:00
|
|
|
* Class: org_rocksdb_Env
|
|
|
|
* Method: getBackgroundThreads
|
|
|
|
* Signature: (JB)I
|
|
|
|
*/
|
|
|
|
jint Java_org_rocksdb_Env_getBackgroundThreads(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
const int num = rocks_env->GetBackgroundThreads(
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2019-02-22 23:36:38 +01:00
|
|
|
return static_cast<jint>(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: getThreadPoolQueueLen
|
2019-02-22 23:36:38 +01:00
|
|
|
* Signature: (JB)I
|
|
|
|
*/
|
|
|
|
jint Java_org_rocksdb_Env_getThreadPoolQueueLen(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
const int queue_len = rocks_env->GetThreadPoolQueueLen(
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2019-02-22 23:36:38 +01:00
|
|
|
return static_cast<jint>(queue_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Env
|
|
|
|
* Method: incBackgroundThreadsIfNeeded
|
|
|
|
* Signature: (JIB)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_Env_incBackgroundThreadsIfNeeded(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jint jnum, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
|
|
|
rocks_env->IncBackgroundThreadsIfNeeded(
|
|
|
|
static_cast<int>(jnum),
|
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2019-02-22 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Env
|
|
|
|
* Method: lowerThreadPoolIOPriority
|
|
|
|
* Signature: (JB)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_Env_lowerThreadPoolIOPriority(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
rocks_env->LowerThreadPoolIOPriority(
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2019-02-22 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Env
|
|
|
|
* Method: lowerThreadPoolCPUPriority
|
|
|
|
* Signature: (JB)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_Env_lowerThreadPoolCPUPriority(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jpriority_value) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
rocks_env->LowerThreadPoolCPUPriority(
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::PriorityJni::toCppPriority(jpriority_value));
|
2019-02-22 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Env
|
|
|
|
* Method: getThreadList
|
|
|
|
* Signature: (J)[Lorg/rocksdb/ThreadStatus;
|
2014-06-06 02:09:25 +02:00
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jobjectArray Java_org_rocksdb_Env_getThreadList(
|
|
|
|
JNIEnv* env, jobject, jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
|
|
|
std::vector<ROCKSDB_NAMESPACE::ThreadStatus> thread_status;
|
|
|
|
ROCKSDB_NAMESPACE::Status s = rocks_env->GetThreadList(&thread_status);
|
2019-02-22 23:36:38 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
// error, throw exception
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2019-02-22 23:36:38 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// object[]
|
|
|
|
const jsize len = static_cast<jsize>(thread_status.size());
|
2020-02-20 21:07:53 +01:00
|
|
|
jobjectArray jthread_status = env->NewObjectArray(
|
|
|
|
len, ROCKSDB_NAMESPACE::ThreadStatusJni::getJClass(env), nullptr);
|
2019-02-22 23:36:38 +01:00
|
|
|
if (jthread_status == nullptr) {
|
|
|
|
// an exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (jsize i = 0; i < len; ++i) {
|
|
|
|
jobject jts =
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::ThreadStatusJni::construct(env, &(thread_status[i]));
|
2019-02-22 23:36:38 +01:00
|
|
|
env->SetObjectArrayElement(jthread_status, i, jts);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jthread_status);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-06 02:09:25 +02:00
|
|
|
}
|
2019-02-22 23:36:38 +01:00
|
|
|
|
|
|
|
return jthread_status;
|
2014-06-06 02:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
|
|
|
* Method: createMemEnv
|
2019-02-22 23:36:38 +01:00
|
|
|
* Signature: (J)J
|
2015-03-22 18:30:51 +01:00
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_RocksMemEnv_createMemEnv(
|
|
|
|
JNIEnv*, jclass, jlong jbase_env_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* base_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jbase_env_handle);
|
|
|
|
return reinterpret_cast<jlong>(ROCKSDB_NAMESPACE::NewMemEnv(base_env));
|
2015-03-22 18:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
void Java_org_rocksdb_RocksMemEnv_disposeInternal(
|
|
|
|
JNIEnv*, jobject, jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* e = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
assert(e != nullptr);
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_TimedEnv
|
|
|
|
* Method: createTimedEnv
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_TimedEnv_createTimedEnv(
|
|
|
|
JNIEnv*, jclass, jlong jbase_env_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* base_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jbase_env_handle);
|
|
|
|
return reinterpret_cast<jlong>(ROCKSDB_NAMESPACE::NewTimedEnv(base_env));
|
2019-02-22 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_TimedEnv
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_TimedEnv_disposeInternal(
|
|
|
|
JNIEnv*, jobject, jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* e = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle);
|
2019-02-22 23:36:38 +01:00
|
|
|
assert(e != nullptr);
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|