Skip to content

Commit

Permalink
Change Java native methods to be static.
Browse files Browse the repository at this point in the history
This should give us some performance benefit calling native C++ code.
See bug #4786 and https://github.com/evolvedbinary/jni-benchmarks/ for more info.
  • Loading branch information
rhubner committed Oct 4, 2023
1 parent 40b618f commit 430d614
Show file tree
Hide file tree
Showing 123 changed files with 3,473 additions and 3,157 deletions.
53 changes: 26 additions & 27 deletions java/rocksjni/backup_engine_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jlong Java_org_rocksdb_BackupEngineOptions_newBackupEngineOptions(
* Signature: (J)Ljava/lang/String;
*/
jstring Java_org_rocksdb_BackupEngineOptions_backupDir(JNIEnv* env,
jobject /*jopt*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -58,7 +58,7 @@ jstring Java_org_rocksdb_BackupEngineOptions_backupDir(JNIEnv* env,
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setBackupEnv(
JNIEnv* /*env*/, jobject /*jopt*/, jlong jhandle, jlong jrocks_env_handle) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle, jlong jrocks_env_handle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
auto* rocks_env =
Expand All @@ -72,7 +72,7 @@ void Java_org_rocksdb_BackupEngineOptions_setBackupEnv(
* Signature: (JZ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setShareTableFiles(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle,
jboolean flag) {
auto* bopt =
Expand All @@ -86,7 +86,7 @@ void Java_org_rocksdb_BackupEngineOptions_setShareTableFiles(JNIEnv* /*env*/,
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_BackupEngineOptions_shareTableFiles(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -99,7 +99,7 @@ jboolean Java_org_rocksdb_BackupEngineOptions_shareTableFiles(JNIEnv* /*env*/,
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setInfoLog(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle,
jlong /*jlogger_handle*/) {
auto* bopt =
Expand All @@ -116,7 +116,7 @@ void Java_org_rocksdb_BackupEngineOptions_setInfoLog(JNIEnv* /*env*/,
* Signature: (JZ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setSync(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle,
jboolean flag) {
auto* bopt =
Expand All @@ -130,7 +130,7 @@ void Java_org_rocksdb_BackupEngineOptions_setSync(JNIEnv* /*env*/,
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_BackupEngineOptions_sync(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -143,7 +143,7 @@ jboolean Java_org_rocksdb_BackupEngineOptions_sync(JNIEnv* /*env*/,
* Signature: (JZ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setDestroyOldData(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle,
jboolean flag) {
auto* bopt =
Expand All @@ -157,7 +157,7 @@ void Java_org_rocksdb_BackupEngineOptions_setDestroyOldData(JNIEnv* /*env*/,
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_BackupEngineOptions_destroyOldData(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -170,7 +170,7 @@ jboolean Java_org_rocksdb_BackupEngineOptions_destroyOldData(JNIEnv* /*env*/,
* Signature: (JZ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setBackupLogFiles(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle,
jboolean flag) {
auto* bopt =
Expand All @@ -184,7 +184,7 @@ void Java_org_rocksdb_BackupEngineOptions_setBackupLogFiles(JNIEnv* /*env*/,
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_BackupEngineOptions_backupLogFiles(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -197,8 +197,7 @@ jboolean Java_org_rocksdb_BackupEngineOptions_backupLogFiles(JNIEnv* /*env*/,
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setBackupRateLimit(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
jlong jbackup_rate_limit) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle, jlong jbackup_rate_limit) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
bopt->backup_rate_limit = jbackup_rate_limit;
Expand All @@ -210,7 +209,7 @@ void Java_org_rocksdb_BackupEngineOptions_setBackupRateLimit(
* Signature: (J)J
*/
jlong Java_org_rocksdb_BackupEngineOptions_backupRateLimit(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -223,7 +222,7 @@ jlong Java_org_rocksdb_BackupEngineOptions_backupRateLimit(JNIEnv* /*env*/,
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setBackupRateLimiter(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle,
jlong jrate_limiter_handle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -239,7 +238,7 @@ void Java_org_rocksdb_BackupEngineOptions_setBackupRateLimiter(
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setRestoreRateLimit(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle,
jlong jrestore_rate_limit) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -252,7 +251,7 @@ void Java_org_rocksdb_BackupEngineOptions_setRestoreRateLimit(
* Signature: (J)J
*/
jlong Java_org_rocksdb_BackupEngineOptions_restoreRateLimit(JNIEnv* /*env*/,
jobject /*jobj*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -265,7 +264,7 @@ jlong Java_org_rocksdb_BackupEngineOptions_restoreRateLimit(JNIEnv* /*env*/,
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setRestoreRateLimiter(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle,
jlong jrate_limiter_handle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -281,7 +280,7 @@ void Java_org_rocksdb_BackupEngineOptions_setRestoreRateLimiter(
* Signature: (JZ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setShareFilesWithChecksum(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle, jboolean flag) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle, jboolean flag) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
bopt->share_files_with_checksum = flag;
Expand All @@ -293,7 +292,7 @@ void Java_org_rocksdb_BackupEngineOptions_setShareFilesWithChecksum(
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_BackupEngineOptions_shareFilesWithChecksum(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
return bopt->share_files_with_checksum;
Expand All @@ -305,7 +304,7 @@ jboolean Java_org_rocksdb_BackupEngineOptions_shareFilesWithChecksum(
* Signature: (JI)V
*/
void Java_org_rocksdb_BackupEngineOptions_setMaxBackgroundOperations(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle,
jint max_background_operations) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -318,7 +317,7 @@ void Java_org_rocksdb_BackupEngineOptions_setMaxBackgroundOperations(
* Signature: (J)I
*/
jint Java_org_rocksdb_BackupEngineOptions_maxBackgroundOperations(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
return static_cast<jint>(bopt->max_background_operations);
Expand All @@ -330,7 +329,7 @@ jint Java_org_rocksdb_BackupEngineOptions_maxBackgroundOperations(
* Signature: (JJ)V
*/
void Java_org_rocksdb_BackupEngineOptions_setCallbackTriggerIntervalSize(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle,
jlong jcallback_trigger_interval_size) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
Expand All @@ -344,7 +343,7 @@ void Java_org_rocksdb_BackupEngineOptions_setCallbackTriggerIntervalSize(
* Signature: (J)J
*/
jlong Java_org_rocksdb_BackupEngineOptions_callbackTriggerIntervalSize(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
return static_cast<jlong>(bopt->callback_trigger_interval_size);
Expand All @@ -355,9 +354,9 @@ jlong Java_org_rocksdb_BackupEngineOptions_callbackTriggerIntervalSize(
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_BackupEngineOptions_disposeInternal(JNIEnv* /*env*/,
jobject /*jopt*/,
jlong jhandle) {
void Java_org_rocksdb_BackupEngineOptions_disposeInternalJni(JNIEnv* /*env*/,
jclass /*jcls*/,
jlong jhandle) {
auto* bopt =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngineOptions*>(jhandle);
assert(bopt != nullptr);
Expand Down
24 changes: 12 additions & 12 deletions java/rocksjni/backupenginejni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jlong Java_org_rocksdb_BackupEngine_open(JNIEnv* env, jclass /*jcls*/,
* Signature: (JJZ)V
*/
void Java_org_rocksdb_BackupEngine_createNewBackup(
JNIEnv* env, jobject /*jbe*/, jlong jbe_handle, jlong db_handle,
JNIEnv* env, jclass /*jbe*/, jlong jbe_handle, jlong db_handle,
jboolean jflush_before_backup) {
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(db_handle);
auto* backup_engine =
Expand All @@ -66,7 +66,7 @@ void Java_org_rocksdb_BackupEngine_createNewBackup(
* Signature: (JJLjava/lang/String;Z)V
*/
void Java_org_rocksdb_BackupEngine_createNewBackupWithMetadata(
JNIEnv* env, jobject /*jbe*/, jlong jbe_handle, jlong db_handle,
JNIEnv* env, jclass /*jbe*/, jlong jbe_handle, jlong db_handle,
jstring japp_metadata, jboolean jflush_before_backup) {
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(db_handle);
auto* backup_engine =
Expand Down Expand Up @@ -97,7 +97,7 @@ void Java_org_rocksdb_BackupEngine_createNewBackupWithMetadata(
* Signature: (J)Ljava/util/List;
*/
jobject Java_org_rocksdb_BackupEngine_getBackupInfo(JNIEnv* env,
jobject /*jbe*/,
jclass /*jcls*/,
jlong jbe_handle) {
auto* backup_engine =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
Expand All @@ -112,7 +112,7 @@ jobject Java_org_rocksdb_BackupEngine_getBackupInfo(JNIEnv* env,
* Signature: (J)[I
*/
jintArray Java_org_rocksdb_BackupEngine_getCorruptedBackups(JNIEnv* env,
jobject /*jbe*/,
jclass /*jcls*/,
jlong jbe_handle) {
auto* backup_engine =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
Expand All @@ -139,7 +139,7 @@ jintArray Java_org_rocksdb_BackupEngine_getCorruptedBackups(JNIEnv* env,
* Method: garbageCollect
* Signature: (J)V
*/
void Java_org_rocksdb_BackupEngine_garbageCollect(JNIEnv* env, jobject /*jbe*/,
void Java_org_rocksdb_BackupEngine_garbageCollect(JNIEnv* env, jclass /*jbe*/,
jlong jbe_handle) {
auto* backup_engine =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
Expand All @@ -157,7 +157,7 @@ void Java_org_rocksdb_BackupEngine_garbageCollect(JNIEnv* env, jobject /*jbe*/,
* Method: purgeOldBackups
* Signature: (JI)V
*/
void Java_org_rocksdb_BackupEngine_purgeOldBackups(JNIEnv* env, jobject /*jbe*/,
void Java_org_rocksdb_BackupEngine_purgeOldBackups(JNIEnv* env, jclass /*jbe*/,
jlong jbe_handle,
jint jnum_backups_to_keep) {
auto* backup_engine =
Expand All @@ -177,7 +177,7 @@ void Java_org_rocksdb_BackupEngine_purgeOldBackups(JNIEnv* env, jobject /*jbe*/,
* Method: deleteBackup
* Signature: (JI)V
*/
void Java_org_rocksdb_BackupEngine_deleteBackup(JNIEnv* env, jobject /*jbe*/,
void Java_org_rocksdb_BackupEngine_deleteBackup(JNIEnv* env, jclass /*jbe*/,
jlong jbe_handle,
jint jbackup_id) {
auto* backup_engine =
Expand All @@ -198,7 +198,7 @@ void Java_org_rocksdb_BackupEngine_deleteBackup(JNIEnv* env, jobject /*jbe*/,
* Signature: (JILjava/lang/String;Ljava/lang/String;J)V
*/
void Java_org_rocksdb_BackupEngine_restoreDbFromBackup(
JNIEnv* env, jobject /*jbe*/, jlong jbe_handle, jint jbackup_id,
JNIEnv* env, jclass /*jbe*/, jlong jbe_handle, jint jbackup_id,
jstring jdb_dir, jstring jwal_dir, jlong jrestore_options_handle) {
auto* backup_engine =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
Expand Down Expand Up @@ -235,7 +235,7 @@ void Java_org_rocksdb_BackupEngine_restoreDbFromBackup(
* Signature: (JLjava/lang/String;Ljava/lang/String;J)V
*/
void Java_org_rocksdb_BackupEngine_restoreDbFromLatestBackup(
JNIEnv* env, jobject /*jbe*/, jlong jbe_handle, jstring jdb_dir,
JNIEnv* env, jclass /*jbe*/, jlong jbe_handle, jstring jdb_dir,
jstring jwal_dir, jlong jrestore_options_handle) {
auto* backup_engine =
reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
Expand Down Expand Up @@ -270,9 +270,9 @@ void Java_org_rocksdb_BackupEngine_restoreDbFromLatestBackup(
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_BackupEngine_disposeInternal(JNIEnv* /*env*/,
jobject /*jbe*/,
jlong jbe_handle) {
void Java_org_rocksdb_BackupEngine_disposeInternalJni(JNIEnv* /*env*/,
jclass /*jcls*/,
jlong jbe_handle) {
auto* be = reinterpret_cast<ROCKSDB_NAMESPACE::BackupEngine*>(jbe_handle);
assert(be != nullptr);
delete be;
Expand Down
4 changes: 2 additions & 2 deletions java/rocksjni/cassandra_value_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jlong Java_org_rocksdb_CassandraValueMergeOperator_newSharedCassandraValueMergeO
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_CassandraValueMergeOperator_disposeInternal(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
void Java_org_rocksdb_CassandraValueMergeOperator_disposeInternalJni(
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) {
auto* op =
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>*>(
jhandle);
Expand Down
8 changes: 4 additions & 4 deletions java/rocksjni/checkpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* /*env*/,
* Method: dispose
* Signature: (J)V
*/
void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
void Java_org_rocksdb_Checkpoint_disposeInternalJni(JNIEnv* /*env*/,
jclass /*jobj*/,
jlong jhandle) {
auto* checkpoint = reinterpret_cast<ROCKSDB_NAMESPACE::Checkpoint*>(jhandle);
assert(checkpoint != nullptr);
delete checkpoint;
Expand All @@ -50,7 +50,7 @@ void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* /*env*/,
* Method: createCheckpoint
* Signature: (JLjava/lang/String;)V
*/
void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/,
void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jclass /*jcls*/,
jlong jcheckpoint_handle,
jstring jcheckpoint_path) {
const char* checkpoint_path = env->GetStringUTFChars(jcheckpoint_path, 0);
Expand Down
6 changes: 3 additions & 3 deletions java/rocksjni/clock_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jlong Java_org_rocksdb_ClockCache_newClockCache(
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_ClockCache_disposeInternal(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
void Java_org_rocksdb_ClockCache_disposeInternalJni(JNIEnv* /*env*/,
jclass /*jcls*/,
jlong jhandle) {
auto* sptr_clock_cache =
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>(jhandle);
delete sptr_clock_cache; // delete std::shared_ptr
Expand Down
Loading

0 comments on commit 430d614

Please sign in to comment.