From 06c8afeff5b9fd38a79bdd4ba1bbb9df572c8096 Mon Sep 17 00:00:00 2001 From: Si Ke Date: Tue, 1 Mar 2022 09:02:15 -0800 Subject: [PATCH] Fix pointer to jlong conversion in 32 bit OS (#9396) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9396 Reviewed By: jay-zhuang Differential Revision: D34529654 Pulled By: pdillinger fbshipit-source-id: cf62152ba86b02f9ffa7780f370ad49089e56a0b --- java/rocksjni/backupablejni.cc | 3 +- java/rocksjni/backupenginejni.cc | 3 +- .../rocksjni/cassandra_compactionfilterjni.cc | 3 +- java/rocksjni/cassandra_value_operator.cc | 4 +- java/rocksjni/checkpoint.cc | 7 ++- java/rocksjni/clock_cache.cc | 6 ++- java/rocksjni/compact_range_options.cc | 3 +- java/rocksjni/compaction_filter_factory.cc | 4 +- java/rocksjni/compaction_job_info.cc | 5 +- java/rocksjni/compaction_job_stats.cc | 6 ++- java/rocksjni/compaction_options.cc | 4 +- java/rocksjni/compaction_options_fifo.cc | 3 +- java/rocksjni/compaction_options_universal.cc | 3 +- java/rocksjni/comparator.cc | 4 +- java/rocksjni/compression_options.cc | 3 +- java/rocksjni/concurrent_task_limiter.cc | 3 +- java/rocksjni/config_options.cc | 3 +- java/rocksjni/cplusplus_to_java_convert.h | 37 ++++++++++++++ java/rocksjni/env.cc | 7 +-- java/rocksjni/env_options.cc | 5 +- java/rocksjni/event_listener.cc | 3 +- java/rocksjni/filter.cc | 4 +- java/rocksjni/ingest_external_file_options.cc | 5 +- java/rocksjni/loggerjnicallback.cc | 10 ++-- java/rocksjni/lru_cache.cc | 6 ++- java/rocksjni/memtablejni.cc | 9 ++-- java/rocksjni/merge_operator.cc | 11 ++-- .../native_comparator_wrapper_test.cc | 7 +-- java/rocksjni/optimistic_transaction_db.cc | 18 +++---- .../optimistic_transaction_options.cc | 4 +- java/rocksjni/options.cc | 51 ++++++++++--------- java/rocksjni/persistent_cache.cc | 7 ++- java/rocksjni/portal.h | 18 ++++--- java/rocksjni/ratelimiterjni.cc | 3 +- .../remove_emptyvalue_compactionfilterjni.cc | 3 +- java/rocksjni/restorejni.cc | 3 +- java/rocksjni/rocksjni.cc | 23 +++++---- java/rocksjni/slice.cc | 15 +++--- java/rocksjni/sst_file_manager.cc | 7 ++- java/rocksjni/sst_file_readerjni.cc | 6 ++- java/rocksjni/sst_file_writerjni.cc | 6 ++- java/rocksjni/sst_partitioner.cc | 3 +- java/rocksjni/statistics.cc | 7 ++- java/rocksjni/table.cc | 7 ++- java/rocksjni/table_filter.cc | 4 +- java/rocksjni/trace_writer.cc | 3 +- java/rocksjni/transaction.cc | 18 ++++--- java/rocksjni/transaction_db.cc | 25 ++++----- java/rocksjni/transaction_db_options.cc | 5 +- java/rocksjni/transaction_notifier.cc | 3 +- .../transaction_notifier_jnicallback.cc | 6 ++- java/rocksjni/transaction_options.cc | 4 +- java/rocksjni/ttl.cc | 10 ++-- java/rocksjni/wal_filter.cc | 3 +- java/rocksjni/wal_filter_jnicallback.cc | 14 ++--- java/rocksjni/write_batch.cc | 10 ++-- java/rocksjni/write_batch_with_index.cc | 18 ++++--- java/rocksjni/write_buffer_manager.cc | 7 +-- 58 files changed, 300 insertions(+), 182 deletions(-) create mode 100644 java/rocksjni/cplusplus_to_java_convert.h diff --git a/java/rocksjni/backupablejni.cc b/java/rocksjni/backupablejni.cc index 5a71c042e..25bfb6720 100644 --- a/java/rocksjni/backupablejni.cc +++ b/java/rocksjni/backupablejni.cc @@ -16,6 +16,7 @@ #include "include/org_rocksdb_BackupEngineOptions.h" #include "rocksdb/utilities/backup_engine.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /////////////////////////////////////////////////////////////////////////// @@ -35,7 +36,7 @@ jlong Java_org_rocksdb_BackupEngineOptions_newBackupEngineOptions( } auto* bopt = new ROCKSDB_NAMESPACE::BackupEngineOptions(cpath); env->ReleaseStringUTFChars(jpath, cpath); - return reinterpret_cast(bopt); + return GET_CPLUSPLUS_POINTER(bopt); } /* diff --git a/java/rocksjni/backupenginejni.cc b/java/rocksjni/backupenginejni.cc index fd9fdcc3a..1ba7ea286 100644 --- a/java/rocksjni/backupenginejni.cc +++ b/java/rocksjni/backupenginejni.cc @@ -12,6 +12,7 @@ #include "include/org_rocksdb_BackupEngine.h" #include "rocksdb/utilities/backup_engine.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -31,7 +32,7 @@ jlong Java_org_rocksdb_BackupEngine_open(JNIEnv* env, jclass /*jcls*/, rocks_env, *backup_engine_options, &backup_engine); if (status.ok()) { - return reinterpret_cast(backup_engine); + return GET_CPLUSPLUS_POINTER(backup_engine); } else { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status); return 0; diff --git a/java/rocksjni/cassandra_compactionfilterjni.cc b/java/rocksjni/cassandra_compactionfilterjni.cc index 10d482baf..25817aeca 100644 --- a/java/rocksjni/cassandra_compactionfilterjni.cc +++ b/java/rocksjni/cassandra_compactionfilterjni.cc @@ -6,6 +6,7 @@ #include #include "include/org_rocksdb_CassandraCompactionFilter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "utilities/cassandra/cassandra_compaction_filter.h" /* @@ -20,5 +21,5 @@ jlong Java_org_rocksdb_CassandraCompactionFilter_createNewCassandraCompactionFil new ROCKSDB_NAMESPACE::cassandra::CassandraCompactionFilter( purge_ttl_on_expiration, gc_grace_period_in_seconds); // set the native handle to our native compaction filter - return reinterpret_cast(compaction_filter); + return GET_CPLUSPLUS_POINTER(compaction_filter); } diff --git a/java/rocksjni/cassandra_value_operator.cc b/java/rocksjni/cassandra_value_operator.cc index 9bd31b9fb..6de28c1b1 100644 --- a/java/rocksjni/cassandra_value_operator.cc +++ b/java/rocksjni/cassandra_value_operator.cc @@ -6,6 +6,7 @@ #include #include #include + #include #include @@ -17,6 +18,7 @@ #include "rocksdb/slice_transform.h" #include "rocksdb/statistics.h" #include "rocksdb/table.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #include "utilities/cassandra/merge_operator.h" @@ -31,7 +33,7 @@ jlong Java_org_rocksdb_CassandraValueMergeOperator_newSharedCassandraValueMergeO auto* op = new std::shared_ptr( new ROCKSDB_NAMESPACE::cassandra::CassandraValueMergeOperator( gcGracePeriodInSeconds, operands_limit)); - return reinterpret_cast(op); + return GET_CPLUSPLUS_POINTER(op); } /* diff --git a/java/rocksjni/checkpoint.cc b/java/rocksjni/checkpoint.cc index b04846e87..d7cfd813b 100644 --- a/java/rocksjni/checkpoint.cc +++ b/java/rocksjni/checkpoint.cc @@ -6,14 +6,17 @@ // This file implements the "bridge" between Java and C++ and enables // calling c++ ROCKSDB_NAMESPACE::Checkpoint methods from Java side. +#include "rocksdb/utilities/checkpoint.h" + #include #include #include + #include #include "include/org_rocksdb_Checkpoint.h" #include "rocksdb/db.h" -#include "rocksdb/utilities/checkpoint.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* * Class: org_rocksdb_Checkpoint @@ -26,7 +29,7 @@ jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* /*env*/, auto* db = reinterpret_cast(jdb_handle); ROCKSDB_NAMESPACE::Checkpoint* checkpoint; ROCKSDB_NAMESPACE::Checkpoint::Create(db, &checkpoint); - return reinterpret_cast(checkpoint); + return GET_CPLUSPLUS_POINTER(checkpoint); } /* diff --git a/java/rocksjni/clock_cache.cc b/java/rocksjni/clock_cache.cc index 56ddcfce5..e04991aa9 100644 --- a/java/rocksjni/clock_cache.cc +++ b/java/rocksjni/clock_cache.cc @@ -6,10 +6,12 @@ // This file implements the "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::ClockCache. +#include "cache/clock_cache.h" + #include -#include "cache/clock_cache.h" #include "include/org_rocksdb_ClockCache.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_ClockCache @@ -23,7 +25,7 @@ jlong Java_org_rocksdb_ClockCache_newClockCache( ROCKSDB_NAMESPACE::NewClockCache( static_cast(jcapacity), static_cast(jnum_shard_bits), static_cast(jstrict_capacity_limit))); - return reinterpret_cast(sptr_clock_cache); + return GET_CPLUSPLUS_POINTER(sptr_clock_cache); } /* diff --git a/java/rocksjni/compact_range_options.cc b/java/rocksjni/compact_range_options.cc index af5a200e7..d0b91b47a 100644 --- a/java/rocksjni/compact_range_options.cc +++ b/java/rocksjni/compact_range_options.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_CompactRangeOptions.h" #include "rocksdb/options.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -20,7 +21,7 @@ jlong Java_org_rocksdb_CompactRangeOptions_newCompactRangeOptions( JNIEnv* /*env*/, jclass /*jclazz*/) { auto* options = new ROCKSDB_NAMESPACE::CompactRangeOptions(); - return reinterpret_cast(options); + return GET_CPLUSPLUS_POINTER(options); } diff --git a/java/rocksjni/compaction_filter_factory.cc b/java/rocksjni/compaction_filter_factory.cc index 3b7c462c4..16fbdbbdd 100644 --- a/java/rocksjni/compaction_filter_factory.cc +++ b/java/rocksjni/compaction_filter_factory.cc @@ -7,10 +7,12 @@ // ROCKSDB_NAMESPACE::CompactionFilterFactory. #include + #include #include "include/org_rocksdb_AbstractCompactionFilterFactory.h" #include "rocksjni/compaction_filter_factory_jnicallback.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_AbstractCompactionFilterFactory @@ -23,7 +25,7 @@ jlong Java_org_rocksdb_AbstractCompactionFilterFactory_createNewCompactionFilter new ROCKSDB_NAMESPACE::CompactionFilterFactoryJniCallback(env, jobj); auto* ptr_sptr_cff = new std::shared_ptr< ROCKSDB_NAMESPACE::CompactionFilterFactoryJniCallback>(cff); - return reinterpret_cast(ptr_sptr_cff); + return GET_CPLUSPLUS_POINTER(ptr_sptr_cff); } /* diff --git a/java/rocksjni/compaction_job_info.cc b/java/rocksjni/compaction_job_info.cc index 245ff7e61..de65478b6 100644 --- a/java/rocksjni/compaction_job_info.cc +++ b/java/rocksjni/compaction_job_info.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_CompactionJobInfo.h" #include "rocksdb/listener.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -20,7 +21,7 @@ jlong Java_org_rocksdb_CompactionJobInfo_newCompactionJobInfo( JNIEnv*, jclass) { auto* compact_job_info = new ROCKSDB_NAMESPACE::CompactionJobInfo(); - return reinterpret_cast(compact_job_info); + return GET_CPLUSPLUS_POINTER(compact_job_info); } /* @@ -227,5 +228,5 @@ jlong Java_org_rocksdb_CompactionJobInfo_stats( reinterpret_cast(jhandle); auto* stats = new ROCKSDB_NAMESPACE::CompactionJobStats(); stats->Add(compact_job_info->stats); - return reinterpret_cast(stats); + return GET_CPLUSPLUS_POINTER(stats); } diff --git a/java/rocksjni/compaction_job_stats.cc b/java/rocksjni/compaction_job_stats.cc index efaec69ee..a9bd9499e 100644 --- a/java/rocksjni/compaction_job_stats.cc +++ b/java/rocksjni/compaction_job_stats.cc @@ -6,10 +6,12 @@ // This file implements the "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::CompactionJobStats. +#include "rocksdb/compaction_job_stats.h" + #include #include "include/org_rocksdb_CompactionJobStats.h" -#include "rocksdb/compaction_job_stats.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -20,7 +22,7 @@ jlong Java_org_rocksdb_CompactionJobStats_newCompactionJobStats( JNIEnv*, jclass) { auto* compact_job_stats = new ROCKSDB_NAMESPACE::CompactionJobStats(); - return reinterpret_cast(compact_job_stats); + return GET_CPLUSPLUS_POINTER(compact_job_stats); } /* diff --git a/java/rocksjni/compaction_options.cc b/java/rocksjni/compaction_options.cc index e904d4abc..f5ddcd6d4 100644 --- a/java/rocksjni/compaction_options.cc +++ b/java/rocksjni/compaction_options.cc @@ -10,9 +10,9 @@ #include "include/org_rocksdb_CompactionOptions.h" #include "rocksdb/options.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" - /* * Class: org_rocksdb_CompactionOptions * Method: newCompactionOptions @@ -21,7 +21,7 @@ jlong Java_org_rocksdb_CompactionOptions_newCompactionOptions( JNIEnv*, jclass) { auto* compact_opts = new ROCKSDB_NAMESPACE::CompactionOptions(); - return reinterpret_cast(compact_opts); + return GET_CPLUSPLUS_POINTER(compact_opts); } /* diff --git a/java/rocksjni/compaction_options_fifo.cc b/java/rocksjni/compaction_options_fifo.cc index 08993524b..36f99749b 100644 --- a/java/rocksjni/compaction_options_fifo.cc +++ b/java/rocksjni/compaction_options_fifo.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_CompactionOptionsFIFO.h" #include "rocksdb/advanced_options.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_CompactionOptionsFIFO @@ -19,7 +20,7 @@ jlong Java_org_rocksdb_CompactionOptionsFIFO_newCompactionOptionsFIFO( JNIEnv*, jclass) { const auto* opt = new ROCKSDB_NAMESPACE::CompactionOptionsFIFO(); - return reinterpret_cast(opt); + return GET_CPLUSPLUS_POINTER(opt); } /* diff --git a/java/rocksjni/compaction_options_universal.cc b/java/rocksjni/compaction_options_universal.cc index 899ee6d1a..c3a1401e6 100644 --- a/java/rocksjni/compaction_options_universal.cc +++ b/java/rocksjni/compaction_options_universal.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_CompactionOptionsUniversal.h" #include "rocksdb/advanced_options.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -20,7 +21,7 @@ jlong Java_org_rocksdb_CompactionOptionsUniversal_newCompactionOptionsUniversal( JNIEnv*, jclass) { const auto* opt = new ROCKSDB_NAMESPACE::CompactionOptionsUniversal(); - return reinterpret_cast(opt); + return GET_CPLUSPLUS_POINTER(opt); } /* diff --git a/java/rocksjni/comparator.cc b/java/rocksjni/comparator.cc index 485d18f0b..4bf53a446 100644 --- a/java/rocksjni/comparator.cc +++ b/java/rocksjni/comparator.cc @@ -9,12 +9,14 @@ #include #include #include + #include #include #include "include/org_rocksdb_AbstractComparator.h" #include "include/org_rocksdb_NativeComparatorWrapper.h" #include "rocksjni/comparatorjnicallback.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -29,7 +31,7 @@ jlong Java_org_rocksdb_AbstractComparator_createNewComparator( copt_handle); auto* c = new ROCKSDB_NAMESPACE::ComparatorJniCallback(env, jcomparator, copt); - return reinterpret_cast(c); + return GET_CPLUSPLUS_POINTER(c); } /* diff --git a/java/rocksjni/compression_options.cc b/java/rocksjni/compression_options.cc index 1857faf68..7f6d1441a 100644 --- a/java/rocksjni/compression_options.cc +++ b/java/rocksjni/compression_options.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_CompressionOptions.h" #include "rocksdb/advanced_options.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_CompressionOptions @@ -19,7 +20,7 @@ jlong Java_org_rocksdb_CompressionOptions_newCompressionOptions( JNIEnv*, jclass) { const auto* opt = new ROCKSDB_NAMESPACE::CompressionOptions(); - return reinterpret_cast(opt); + return GET_CPLUSPLUS_POINTER(opt); } /* diff --git a/java/rocksjni/concurrent_task_limiter.cc b/java/rocksjni/concurrent_task_limiter.cc index 591f721a2..d88a32301 100644 --- a/java/rocksjni/concurrent_task_limiter.cc +++ b/java/rocksjni/concurrent_task_limiter.cc @@ -6,6 +6,7 @@ #include #include "include/org_rocksdb_ConcurrentTaskLimiterImpl.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -25,7 +26,7 @@ jlong Java_org_rocksdb_ConcurrentTaskLimiterImpl_newConcurrentTaskLimiterImpl0( auto* ptr = new std::shared_ptr( ROCKSDB_NAMESPACE::NewConcurrentTaskLimiter(name, limit)); - return reinterpret_cast(ptr); + return GET_CPLUSPLUS_POINTER(ptr); } /* diff --git a/java/rocksjni/config_options.cc b/java/rocksjni/config_options.cc index 299d69815..3cda2524e 100644 --- a/java/rocksjni/config_options.cc +++ b/java/rocksjni/config_options.cc @@ -11,6 +11,7 @@ #include "include/org_rocksdb_ConfigOptions.h" #include "rocksdb/convenience.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -32,7 +33,7 @@ void Java_org_rocksdb_ConfigOptions_disposeInternal(JNIEnv *, jobject, */ jlong Java_org_rocksdb_ConfigOptions_newConfigOptions(JNIEnv *, jclass) { auto *cfg_opt = new ROCKSDB_NAMESPACE::ConfigOptions(); - return reinterpret_cast(cfg_opt); + return GET_CPLUSPLUS_POINTER(cfg_opt); } /* diff --git a/java/rocksjni/cplusplus_to_java_convert.h b/java/rocksjni/cplusplus_to_java_convert.h new file mode 100644 index 000000000..0eea6fa2c --- /dev/null +++ b/java/rocksjni/cplusplus_to_java_convert.h @@ -0,0 +1,37 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// 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). + +#pragma once + +/* + * This macro is used for 32 bit OS. In 32 bit OS, the result number is a + negative number if we use reinterpret_cast(pointer). + * For example, jlong ptr = reinterpret_cast(pointer), ptr is a negative + number in 32 bit OS. + * If we check ptr using ptr > 0, it fails. For example, the following code is + not correct. + * if (jblock_cache_handle > 0) { + std::shared_ptr *pCache = + reinterpret_cast *>( + jblock_cache_handle); + options.block_cache = *pCache; + } + * But the result number is positive number if we do + reinterpret_cast(pointer) first and then cast it to jlong. size_t is 4 + bytes long in 32 bit OS and 8 bytes long in 64 bit OS. + static_cast(reinterpret_cast(_pointer)) is also working in 64 + bit OS. + * + * We don't need an opposite cast because it works from jlong to c++ pointer in + both 32 bit and 64 bit OS. + * For example, the following code is working in both 32 bit and 64 bit OS. + jblock_cache_handle is jlong. + * std::shared_ptr *pCache = + reinterpret_cast *>( + jblock_cache_handle); +*/ + +#define GET_CPLUSPLUS_POINTER(_pointer) \ + static_cast(reinterpret_cast(_pointer)) diff --git a/java/rocksjni/env.cc b/java/rocksjni/env.cc index 6f4fd7657..b40a9b1d5 100644 --- a/java/rocksjni/env.cc +++ b/java/rocksjni/env.cc @@ -17,6 +17,7 @@ #include "include/org_rocksdb_RocksMemEnv.h" #include "include/org_rocksdb_TimedEnv.h" #include "portal.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_Env @@ -25,7 +26,7 @@ */ jlong Java_org_rocksdb_Env_getDefaultEnvInternal( JNIEnv*, jclass) { - return reinterpret_cast(ROCKSDB_NAMESPACE::Env::Default()); + return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::Env::Default()); } /* @@ -162,7 +163,7 @@ jobjectArray Java_org_rocksdb_Env_getThreadList( jlong Java_org_rocksdb_RocksMemEnv_createMemEnv( JNIEnv*, jclass, jlong jbase_env_handle) { auto* base_env = reinterpret_cast(jbase_env_handle); - return reinterpret_cast(ROCKSDB_NAMESPACE::NewMemEnv(base_env)); + return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::NewMemEnv(base_env)); } /* @@ -185,7 +186,7 @@ void Java_org_rocksdb_RocksMemEnv_disposeInternal( jlong Java_org_rocksdb_TimedEnv_createTimedEnv( JNIEnv*, jclass, jlong jbase_env_handle) { auto* base_env = reinterpret_cast(jbase_env_handle); - return reinterpret_cast(ROCKSDB_NAMESPACE::NewTimedEnv(base_env)); + return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::NewTimedEnv(base_env)); } /* diff --git a/java/rocksjni/env_options.cc b/java/rocksjni/env_options.cc index 2a9c8aeb0..64c948332 100644 --- a/java/rocksjni/env_options.cc +++ b/java/rocksjni/env_options.cc @@ -11,6 +11,7 @@ #include "include/org_rocksdb_EnvOptions.h" #include "rocksdb/env.h" +#include "rocksjni/cplusplus_to_java_convert.h" #define ENV_OPTIONS_SET_BOOL(_jhandle, _opt) \ reinterpret_cast(_jhandle)->_opt = \ @@ -35,7 +36,7 @@ jlong Java_org_rocksdb_EnvOptions_newEnvOptions__( JNIEnv*, jclass) { auto *env_opt = new ROCKSDB_NAMESPACE::EnvOptions(); - return reinterpret_cast(env_opt); + return GET_CPLUSPLUS_POINTER(env_opt); } /* @@ -48,7 +49,7 @@ jlong Java_org_rocksdb_EnvOptions_newEnvOptions__J( auto *db_options = reinterpret_cast(jdboptions_handle); auto *env_opt = new ROCKSDB_NAMESPACE::EnvOptions(*db_options); - return reinterpret_cast(env_opt); + return GET_CPLUSPLUS_POINTER(env_opt); } /* diff --git a/java/rocksjni/event_listener.cc b/java/rocksjni/event_listener.cc index a3b43b029..965932c9c 100644 --- a/java/rocksjni/event_listener.cc +++ b/java/rocksjni/event_listener.cc @@ -11,6 +11,7 @@ #include #include "include/org_rocksdb_AbstractEventListener.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/event_listener_jnicallback.h" #include "rocksjni/portal.h" @@ -28,7 +29,7 @@ jlong Java_org_rocksdb_AbstractEventListener_createNewEventListener( new std::shared_ptr( new ROCKSDB_NAMESPACE::EventListenerJniCallback( env, jobj, enabled_event_callbacks)); - return reinterpret_cast(sptr_event_listener); + return GET_CPLUSPLUS_POINTER(sptr_event_listener); } /* diff --git a/java/rocksjni/filter.cc b/java/rocksjni/filter.cc index c0a86a1b1..ed22016d2 100644 --- a/java/rocksjni/filter.cc +++ b/java/rocksjni/filter.cc @@ -9,11 +9,13 @@ #include #include #include + #include #include "include/org_rocksdb_BloomFilter.h" #include "include/org_rocksdb_Filter.h" #include "rocksdb/filter_policy.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -27,7 +29,7 @@ jlong Java_org_rocksdb_BloomFilter_createNewBloomFilter(JNIEnv* /*env*/, auto* sptr_filter = new std::shared_ptr( ROCKSDB_NAMESPACE::NewBloomFilterPolicy(bits_per_key)); - return reinterpret_cast(sptr_filter); + return GET_CPLUSPLUS_POINTER(sptr_filter); } /* diff --git a/java/rocksjni/ingest_external_file_options.cc b/java/rocksjni/ingest_external_file_options.cc index ceaa6b179..4460c8040 100644 --- a/java/rocksjni/ingest_external_file_options.cc +++ b/java/rocksjni/ingest_external_file_options.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_IngestExternalFileOptions.h" #include "rocksdb/options.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_IngestExternalFileOptions @@ -19,7 +20,7 @@ jlong Java_org_rocksdb_IngestExternalFileOptions_newIngestExternalFileOptions__( JNIEnv*, jclass) { auto* options = new ROCKSDB_NAMESPACE::IngestExternalFileOptions(); - return reinterpret_cast(options); + return GET_CPLUSPLUS_POINTER(options); } /* @@ -36,7 +37,7 @@ jlong Java_org_rocksdb_IngestExternalFileOptions_newIngestExternalFileOptions__Z options->snapshot_consistency = static_cast(jsnapshot_consistency); options->allow_global_seqno = static_cast(jallow_global_seqno); options->allow_blocking_flush = static_cast(jallow_blocking_flush); - return reinterpret_cast(options); + return GET_CPLUSPLUS_POINTER(options); } /* diff --git a/java/rocksjni/loggerjnicallback.cc b/java/rocksjni/loggerjnicallback.cc index e9a9ce689..aa9f95cd4 100644 --- a/java/rocksjni/loggerjnicallback.cc +++ b/java/rocksjni/loggerjnicallback.cc @@ -6,11 +6,13 @@ // This file implements the callback "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::Logger. -#include "include/org_rocksdb_Logger.h" +#include "rocksjni/loggerjnicallback.h" #include #include -#include "rocksjni/loggerjnicallback.h" + +#include "include/org_rocksdb_Logger.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" namespace ROCKSDB_NAMESPACE { @@ -234,7 +236,7 @@ jlong Java_org_rocksdb_Logger_createNewLoggerOptions(JNIEnv* env, jobject jobj, auto* options = reinterpret_cast(joptions); sptr_logger->get()->SetInfoLogLevel(options->info_log_level); - return reinterpret_cast(sptr_logger); + return GET_CPLUSPLUS_POINTER(sptr_logger); } /* @@ -253,7 +255,7 @@ jlong Java_org_rocksdb_Logger_createNewLoggerDbOptions(JNIEnv* env, reinterpret_cast(jdb_options); sptr_logger->get()->SetInfoLogLevel(db_options->info_log_level); - return reinterpret_cast(sptr_logger); + return GET_CPLUSPLUS_POINTER(sptr_logger); } /* diff --git a/java/rocksjni/lru_cache.cc b/java/rocksjni/lru_cache.cc index 7b62702c6..7d03f43b1 100644 --- a/java/rocksjni/lru_cache.cc +++ b/java/rocksjni/lru_cache.cc @@ -6,10 +6,12 @@ // This file implements the "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::LRUCache. +#include "cache/lru_cache.h" + #include -#include "cache/lru_cache.h" #include "include/org_rocksdb_LRUCache.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_LRUCache @@ -26,7 +28,7 @@ jlong Java_org_rocksdb_LRUCache_newLRUCache(JNIEnv* /*env*/, jclass /*jcls*/, static_cast(jcapacity), static_cast(jnum_shard_bits), static_cast(jstrict_capacity_limit), static_cast(jhigh_pri_pool_ratio))); - return reinterpret_cast(sptr_lru_cache); + return GET_CPLUSPLUS_POINTER(sptr_lru_cache); } /* diff --git a/java/rocksjni/memtablejni.cc b/java/rocksjni/memtablejni.cc index 1188c5e59..a4d02f354 100644 --- a/java/rocksjni/memtablejni.cc +++ b/java/rocksjni/memtablejni.cc @@ -10,6 +10,7 @@ #include "include/org_rocksdb_SkipListMemTableConfig.h" #include "include/org_rocksdb_VectorMemTableConfig.h" #include "rocksdb/memtablerep.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -23,7 +24,7 @@ jlong Java_org_rocksdb_HashSkipListMemTableConfig_newMemTableFactoryHandle( ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::JniUtil::check_if_jlong_fits_size_t(jbucket_count); if (s.ok()) { - return reinterpret_cast(ROCKSDB_NAMESPACE::NewHashSkipListRepFactory( + return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::NewHashSkipListRepFactory( static_cast(jbucket_count), static_cast(jheight), static_cast(jbranching_factor))); } @@ -46,7 +47,7 @@ jlong Java_org_rocksdb_HashLinkedListMemTableConfig_newMemTableFactoryHandle( ROCKSDB_NAMESPACE::JniUtil::check_if_jlong_fits_size_t( jhuge_page_tlb_size); if (statusBucketCount.ok() && statusHugePageTlb.ok()) { - return reinterpret_cast(ROCKSDB_NAMESPACE::NewHashLinkListRepFactory( + return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::NewHashLinkListRepFactory( static_cast(jbucket_count), static_cast(jhuge_page_tlb_size), static_cast(jbucket_entries_logging_threshold), @@ -68,7 +69,7 @@ jlong Java_org_rocksdb_VectorMemTableConfig_newMemTableFactoryHandle( ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::JniUtil::check_if_jlong_fits_size_t(jreserved_size); if (s.ok()) { - return reinterpret_cast(new ROCKSDB_NAMESPACE::VectorRepFactory( + return GET_CPLUSPLUS_POINTER(new ROCKSDB_NAMESPACE::VectorRepFactory( static_cast(jreserved_size))); } ROCKSDB_NAMESPACE::IllegalArgumentExceptionJni::ThrowNew(env, s); @@ -85,7 +86,7 @@ jlong Java_org_rocksdb_SkipListMemTableConfig_newMemTableFactoryHandle0( ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::JniUtil::check_if_jlong_fits_size_t(jlookahead); if (s.ok()) { - return reinterpret_cast(new ROCKSDB_NAMESPACE::SkipListFactory( + return GET_CPLUSPLUS_POINTER(new ROCKSDB_NAMESPACE::SkipListFactory( static_cast(jlookahead))); } ROCKSDB_NAMESPACE::IllegalArgumentExceptionJni::ThrowNew(env, s); diff --git a/java/rocksjni/merge_operator.cc b/java/rocksjni/merge_operator.cc index 63ebf8973..ce3c5df56 100644 --- a/java/rocksjni/merge_operator.cc +++ b/java/rocksjni/merge_operator.cc @@ -7,9 +7,12 @@ // This file implements the "bridge" between Java and C++ // for ROCKSDB_NAMESPACE::MergeOperator. +#include "rocksdb/merge_operator.h" + #include #include #include + #include #include @@ -17,11 +20,11 @@ #include "include/org_rocksdb_UInt64AddOperator.h" #include "rocksdb/db.h" #include "rocksdb/memtablerep.h" -#include "rocksdb/merge_operator.h" #include "rocksdb/options.h" #include "rocksdb/slice_transform.h" #include "rocksdb/statistics.h" #include "rocksdb/table.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #include "utilities/merge_operators.h" @@ -36,7 +39,7 @@ jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__C( new std::shared_ptr( ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator( (char)jdelim)); - return reinterpret_cast(sptr_string_append_op); + return GET_CPLUSPLUS_POINTER(sptr_string_append_op); } jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__Ljava_lang_String_2( @@ -50,7 +53,7 @@ jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__Ljava auto* sptr_string_append_op = new std::shared_ptr( ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator(delim)); - return reinterpret_cast(sptr_string_append_op); + return GET_CPLUSPLUS_POINTER(sptr_string_append_op); } /* @@ -77,7 +80,7 @@ jlong Java_org_rocksdb_UInt64AddOperator_newSharedUInt64AddOperator( auto* sptr_uint64_add_op = new std::shared_ptr( ROCKSDB_NAMESPACE::MergeOperators::CreateUInt64AddOperator()); - return reinterpret_cast(sptr_uint64_add_op); + return GET_CPLUSPLUS_POINTER(sptr_uint64_add_op); } /* diff --git a/java/rocksjni/native_comparator_wrapper_test.cc b/java/rocksjni/native_comparator_wrapper_test.cc index d2f5c1bda..ac33ca22d 100644 --- a/java/rocksjni/native_comparator_wrapper_test.cc +++ b/java/rocksjni/native_comparator_wrapper_test.cc @@ -4,12 +4,13 @@ // (found in the LICENSE.Apache file in the root directory). #include + #include +#include "include/org_rocksdb_NativeComparatorWrapperTest_NativeStringComparatorWrapper.h" #include "rocksdb/comparator.h" #include "rocksdb/slice.h" - -#include "include/org_rocksdb_NativeComparatorWrapperTest_NativeStringComparatorWrapper.h" +#include "rocksjni/cplusplus_to_java_convert.h" namespace ROCKSDB_NAMESPACE { @@ -40,5 +41,5 @@ jlong Java_org_rocksdb_NativeComparatorWrapperTest_00024NativeStringComparatorWr JNIEnv* /*env*/, jobject /*jobj*/) { auto* comparator = new ROCKSDB_NAMESPACE::NativeComparatorWrapperTestStringComparator(); - return reinterpret_cast(comparator); + return GET_CPLUSPLUS_POINTER(comparator); } diff --git a/java/rocksjni/optimistic_transaction_db.cc b/java/rocksjni/optimistic_transaction_db.cc index 4f966cdd7..dd507caa7 100644 --- a/java/rocksjni/optimistic_transaction_db.cc +++ b/java/rocksjni/optimistic_transaction_db.cc @@ -6,14 +6,14 @@ // This file implements the "bridge" between Java and C++ // for ROCKSDB_NAMESPACE::TransactionDB. +#include "rocksdb/utilities/optimistic_transaction_db.h" + #include #include "include/org_rocksdb_OptimisticTransactionDB.h" - #include "rocksdb/options.h" -#include "rocksdb/utilities/optimistic_transaction_db.h" #include "rocksdb/utilities/transaction.h" - +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -38,7 +38,7 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_open__JLjava_lang_String_2( env->ReleaseStringUTFChars(jdb_path, db_path); if (s.ok()) { - return reinterpret_cast(otdb); + return GET_CPLUSPLUS_POINTER(otdb); } else { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; @@ -194,7 +194,7 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_beginTransaction__JJ( reinterpret_cast(jwrite_options_handle); ROCKSDB_NAMESPACE::Transaction* txn = optimistic_txn_db->BeginTransaction(*write_options); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -214,7 +214,7 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_beginTransaction__JJJ( joptimistic_txn_options_handle); ROCKSDB_NAMESPACE::Transaction* txn = optimistic_txn_db->BeginTransaction( *write_options, *optimistic_txn_options); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -240,7 +240,7 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_beginTransaction_1withOld__JJJ( // when providing an old_optimistic_txn assert(txn == old_txn); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -268,7 +268,7 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_beginTransaction_1withOld__JJJJ( // when providing an old_optimisic_txn assert(txn == old_txn); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -280,5 +280,5 @@ jlong Java_org_rocksdb_OptimisticTransactionDB_getBaseDB( JNIEnv*, jobject, jlong jhandle) { auto* optimistic_txn_db = reinterpret_cast(jhandle); - return reinterpret_cast(optimistic_txn_db->GetBaseDB()); + return GET_CPLUSPLUS_POINTER(optimistic_txn_db->GetBaseDB()); } diff --git a/java/rocksjni/optimistic_transaction_options.cc b/java/rocksjni/optimistic_transaction_options.cc index 6bc80fdf0..501c6c4fb 100644 --- a/java/rocksjni/optimistic_transaction_options.cc +++ b/java/rocksjni/optimistic_transaction_options.cc @@ -9,9 +9,9 @@ #include #include "include/org_rocksdb_OptimisticTransactionOptions.h" - #include "rocksdb/comparator.h" #include "rocksdb/utilities/optimistic_transaction_db.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_OptimisticTransactionOptions @@ -22,7 +22,7 @@ jlong Java_org_rocksdb_OptimisticTransactionOptions_newOptimisticTransactionOpti JNIEnv* /*env*/, jclass /*jcls*/) { ROCKSDB_NAMESPACE::OptimisticTransactionOptions* opts = new ROCKSDB_NAMESPACE::OptimisticTransactionOptions(); - return reinterpret_cast(opts); + return GET_CPLUSPLUS_POINTER(opts); } /* diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 42cb1e244..8eae762b3 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -33,6 +33,7 @@ #include "rocksdb/statistics.h" #include "rocksdb/table.h" #include "rocksjni/comparatorjnicallback.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #include "rocksjni/statisticsjni.h" #include "rocksjni/table_filter_jnicallback.h" @@ -46,7 +47,7 @@ jlong Java_org_rocksdb_Options_newOptions__( JNIEnv*, jclass) { auto* op = new ROCKSDB_NAMESPACE::Options(); - return reinterpret_cast(op); + return GET_CPLUSPLUS_POINTER(op); } /* @@ -61,7 +62,7 @@ jlong Java_org_rocksdb_Options_newOptions__JJ( auto* cfOpt = reinterpret_cast( jcfoptions); auto* op = new ROCKSDB_NAMESPACE::Options(*dbOpt, *cfOpt); - return reinterpret_cast(op); + return GET_CPLUSPLUS_POINTER(op); } /* @@ -73,7 +74,7 @@ jlong Java_org_rocksdb_Options_copyOptions( JNIEnv*, jclass, jlong jhandle) { auto new_opt = new ROCKSDB_NAMESPACE::Options( *(reinterpret_cast(jhandle))); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -332,7 +333,7 @@ jlong Java_org_rocksdb_Options_statistics( } else { std::shared_ptr* pSptr = new std::shared_ptr(sptr); - return reinterpret_cast(pSptr); + return GET_CPLUSPLUS_POINTER(pSptr); } } @@ -3850,7 +3851,7 @@ jlong Java_org_rocksdb_Options_blobCompactionReadaheadSize(JNIEnv*, jobject, jlong Java_org_rocksdb_ColumnFamilyOptions_newColumnFamilyOptions( JNIEnv*, jclass) { auto* op = new ROCKSDB_NAMESPACE::ColumnFamilyOptions(); - return reinterpret_cast(op); + return GET_CPLUSPLUS_POINTER(op); } /* @@ -3862,7 +3863,7 @@ jlong Java_org_rocksdb_ColumnFamilyOptions_copyColumnFamilyOptions( JNIEnv*, jclass, jlong jhandle) { auto new_opt = new ROCKSDB_NAMESPACE::ColumnFamilyOptions( *(reinterpret_cast(jhandle))); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -3874,7 +3875,7 @@ jlong Java_org_rocksdb_ColumnFamilyOptions_newColumnFamilyOptionsFromOptions( JNIEnv*, jclass, jlong joptions_handle) { auto new_opt = new ROCKSDB_NAMESPACE::ColumnFamilyOptions( *reinterpret_cast(joptions_handle)); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -3902,7 +3903,7 @@ jlong Java_org_rocksdb_ColumnFamilyOptions_getColumnFamilyOptionsFromProps__JLja // Check if ColumnFamilyOptions creation was possible. jlong ret_value = 0; if (status.ok()) { - ret_value = reinterpret_cast(cf_options); + ret_value = GET_CPLUSPLUS_POINTER(cf_options); } else { // if operation failed the ColumnFamilyOptions need to be deleted // again to prevent a memory leak. @@ -3934,7 +3935,7 @@ jlong Java_org_rocksdb_ColumnFamilyOptions_getColumnFamilyOptionsFromProps__Ljav // Check if ColumnFamilyOptions creation was possible. jlong ret_value = 0; if (status.ok()) { - ret_value = reinterpret_cast(cf_options); + ret_value = GET_CPLUSPLUS_POINTER(cf_options); } else { // if operation failed the ColumnFamilyOptions need to be deleted // again to prevent a memory leak. @@ -5633,7 +5634,7 @@ jlong Java_org_rocksdb_ColumnFamilyOptions_blobCompactionReadaheadSize( jlong Java_org_rocksdb_DBOptions_newDBOptions( JNIEnv*, jclass) { auto* dbop = new ROCKSDB_NAMESPACE::DBOptions(); - return reinterpret_cast(dbop); + return GET_CPLUSPLUS_POINTER(dbop); } /* @@ -5645,7 +5646,7 @@ jlong Java_org_rocksdb_DBOptions_copyDBOptions( JNIEnv*, jclass, jlong jhandle) { auto new_opt = new ROCKSDB_NAMESPACE::DBOptions( *(reinterpret_cast(jhandle))); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -5657,7 +5658,7 @@ jlong Java_org_rocksdb_DBOptions_newDBOptionsFromOptions( JNIEnv*, jclass, jlong joptions_handle) { auto new_opt = new ROCKSDB_NAMESPACE::DBOptions( *reinterpret_cast(joptions_handle)); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -5684,7 +5685,7 @@ jlong Java_org_rocksdb_DBOptions_getDBOptionsFromProps__JLjava_lang_String_2( // Check if DBOptions creation was possible. jlong ret_value = 0; if (status.ok()) { - ret_value = reinterpret_cast(db_options); + ret_value = GET_CPLUSPLUS_POINTER(db_options); } else { // if operation failed the DBOptions need to be deleted // again to prevent a memory leak. @@ -5715,7 +5716,7 @@ jlong Java_org_rocksdb_DBOptions_getDBOptionsFromProps__Ljava_lang_String_2( // Check if DBOptions creation was possible. jlong ret_value = 0; if (status.ok()) { - ret_value = reinterpret_cast(db_options); + ret_value = GET_CPLUSPLUS_POINTER(db_options); } else { // if operation failed the DBOptions need to be deleted // again to prevent a memory leak. @@ -6014,7 +6015,7 @@ jlong Java_org_rocksdb_DBOptions_statistics( } else { std::shared_ptr* pSptr = new std::shared_ptr(sptr); - return reinterpret_cast(pSptr); + return GET_CPLUSPLUS_POINTER(pSptr); } } @@ -7664,7 +7665,7 @@ jlong Java_org_rocksdb_DBOptions_bgerrorResumeRetryInterval(JNIEnv*, jclass, jlong Java_org_rocksdb_WriteOptions_newWriteOptions( JNIEnv*, jclass) { auto* op = new ROCKSDB_NAMESPACE::WriteOptions(); - return reinterpret_cast(op); + return GET_CPLUSPLUS_POINTER(op); } /* @@ -7676,7 +7677,7 @@ jlong Java_org_rocksdb_WriteOptions_copyWriteOptions( JNIEnv*, jclass, jlong jhandle) { auto new_opt = new ROCKSDB_NAMESPACE::WriteOptions( *(reinterpret_cast(jhandle))); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -7835,7 +7836,7 @@ void Java_org_rocksdb_WriteOptions_setMemtableInsertHintPerBatch( jlong Java_org_rocksdb_ReadOptions_newReadOptions__( JNIEnv*, jclass) { auto* read_options = new ROCKSDB_NAMESPACE::ReadOptions(); - return reinterpret_cast(read_options); + return GET_CPLUSPLUS_POINTER(read_options); } /* @@ -7847,7 +7848,7 @@ jlong Java_org_rocksdb_ReadOptions_newReadOptions__ZZ( JNIEnv*, jclass, jboolean jverify_checksums, jboolean jfill_cache) { auto* read_options = new ROCKSDB_NAMESPACE::ReadOptions( static_cast(jverify_checksums), static_cast(jfill_cache)); - return reinterpret_cast(read_options); + return GET_CPLUSPLUS_POINTER(read_options); } /* @@ -7859,7 +7860,7 @@ jlong Java_org_rocksdb_ReadOptions_copyReadOptions( JNIEnv*, jclass, jlong jhandle) { auto new_opt = new ROCKSDB_NAMESPACE::ReadOptions( *(reinterpret_cast(jhandle))); - return reinterpret_cast(new_opt); + return GET_CPLUSPLUS_POINTER(new_opt); } /* @@ -8136,7 +8137,7 @@ jlong Java_org_rocksdb_ReadOptions_snapshot( JNIEnv*, jobject, jlong jhandle) { auto& snapshot = reinterpret_cast(jhandle)->snapshot; - return reinterpret_cast(snapshot); + return GET_CPLUSPLUS_POINTER(snapshot); } /* @@ -8183,7 +8184,7 @@ jlong Java_org_rocksdb_ReadOptions_iterateUpperBound( auto& upper_bound_slice_handle = reinterpret_cast(jhandle) ->iterate_upper_bound; - return reinterpret_cast(upper_bound_slice_handle); + return GET_CPLUSPLUS_POINTER(upper_bound_slice_handle); } /* @@ -8208,7 +8209,7 @@ jlong Java_org_rocksdb_ReadOptions_iterateLowerBound( auto& lower_bound_slice_handle = reinterpret_cast(jhandle) ->iterate_lower_bound; - return reinterpret_cast(lower_bound_slice_handle); + return GET_CPLUSPLUS_POINTER(lower_bound_slice_handle); } /* @@ -8371,7 +8372,7 @@ void Java_org_rocksdb_ReadOptions_setValueSizeSoftLimit( jlong Java_org_rocksdb_ComparatorOptions_newComparatorOptions( JNIEnv*, jclass) { auto* comparator_opt = new ROCKSDB_NAMESPACE::ComparatorJniCallbackOptions(); - return reinterpret_cast(comparator_opt); + return GET_CPLUSPLUS_POINTER(comparator_opt); } /* @@ -8477,7 +8478,7 @@ void Java_org_rocksdb_ComparatorOptions_disposeInternal( jlong Java_org_rocksdb_FlushOptions_newFlushOptions( JNIEnv*, jclass) { auto* flush_opt = new ROCKSDB_NAMESPACE::FlushOptions(); - return reinterpret_cast(flush_opt); + return GET_CPLUSPLUS_POINTER(flush_opt); } /* diff --git a/java/rocksjni/persistent_cache.cc b/java/rocksjni/persistent_cache.cc index 6776022e8..ff930a74e 100644 --- a/java/rocksjni/persistent_cache.cc +++ b/java/rocksjni/persistent_cache.cc @@ -6,13 +6,16 @@ // This file implements the "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::PersistentCache. +#include "rocksdb/persistent_cache.h" + #include + #include #include "include/org_rocksdb_PersistentCache.h" -#include "rocksdb/persistent_cache.h" #include "loggerjnicallback.h" #include "portal.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_PersistentCache @@ -40,7 +43,7 @@ jlong Java_org_rocksdb_PersistentCache_newPersistentCache( if (!s.ok()) { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); } - return reinterpret_cast(cache); + return GET_CPLUSPLUS_POINTER(cache); } /* diff --git a/java/rocksjni/portal.h b/java/rocksjni/portal.h index 61113d801..45abe7c6d 100644 --- a/java/rocksjni/portal.h +++ b/java/rocksjni/portal.h @@ -36,6 +36,7 @@ #include "rocksdb/utilities/write_batch_with_index.h" #include "rocksjni/compaction_filter_factory_jnicallback.h" #include "rocksjni/comparatorjnicallback.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/event_listener_jnicallback.h" #include "rocksjni/loggerjnicallback.h" #include "rocksjni/table_filter_jnicallback.h" @@ -120,7 +121,8 @@ template class NativeRocksMutableObject return true; // signal exception } - env->CallVoidMethod(jobj, mid, reinterpret_cast(ptr), java_owns_handle); + env->CallVoidMethod(jobj, mid, GET_CPLUSPLUS_POINTER(ptr), + java_owns_handle); if(env->ExceptionCheck()) { return true; // signal exception } @@ -2243,9 +2245,9 @@ class JniUtil { jboolean *has_exception) { const jsize len = static_cast(pointers.size()); std::unique_ptr results(new jlong[len]); - std::transform(pointers.begin(), pointers.end(), results.get(), [](T* pointer) -> jlong { - return reinterpret_cast(pointer); - }); + std::transform( + pointers.begin(), pointers.end(), results.get(), + [](T* pointer) -> jlong { return GET_CPLUSPLUS_POINTER(pointer); }); jlongArray jpointers = env->NewLongArray(len); if (jpointers == nullptr) { @@ -2785,7 +2787,7 @@ class ColumnFamilyOptionsJni return nullptr; } - jobject jcfd = env->NewObject(jclazz, mid, reinterpret_cast(cfo)); + jobject jcfd = env->NewObject(jclazz, mid, GET_CPLUSPLUS_POINTER(cfo)); if (env->ExceptionCheck()) { return nullptr; } @@ -2871,7 +2873,7 @@ class WriteBatchJni return nullptr; } - jobject jwb = env->NewObject(jclazz, mid, reinterpret_cast(wb)); + jobject jwb = env->NewObject(jclazz, mid, GET_CPLUSPLUS_POINTER(wb)); if (env->ExceptionCheck()) { return nullptr; } @@ -3496,7 +3498,7 @@ class ColumnFamilyHandleJni assert(jclazz != nullptr); static jmethodID ctor = getConstructorMethodId(env, jclazz); assert(ctor != nullptr); - return env->NewObject(jclazz, ctor, reinterpret_cast(info)); + return env->NewObject(jclazz, ctor, GET_CPLUSPLUS_POINTER(info)); } static jmethodID getConstructorMethodId(JNIEnv* env, jclass clazz) { @@ -8327,7 +8329,7 @@ class CompactionJobInfoJni : public JavaClass { static jmethodID ctor = getConstructorMethodId(env, jclazz); assert(ctor != nullptr); return env->NewObject(jclazz, ctor, - reinterpret_cast(compaction_job_info)); + GET_CPLUSPLUS_POINTER(compaction_job_info)); } static jclass getJClass(JNIEnv* env) { diff --git a/java/rocksjni/ratelimiterjni.cc b/java/rocksjni/ratelimiterjni.cc index 96b440dcc..7a17f367e 100644 --- a/java/rocksjni/ratelimiterjni.cc +++ b/java/rocksjni/ratelimiterjni.cc @@ -7,6 +7,7 @@ #include "include/org_rocksdb_RateLimiter.h" #include "rocksdb/rate_limiter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -27,7 +28,7 @@ jlong Java_org_rocksdb_RateLimiter_newRateLimiterHandle( static_cast(jrefill_period_micros), static_cast(jfairness), rate_limiter_mode, jauto_tune)); - return reinterpret_cast(sptr_rate_limiter); + return GET_CPLUSPLUS_POINTER(sptr_rate_limiter); } /* diff --git a/java/rocksjni/remove_emptyvalue_compactionfilterjni.cc b/java/rocksjni/remove_emptyvalue_compactionfilterjni.cc index 8f0037b39..c0b09e151 100644 --- a/java/rocksjni/remove_emptyvalue_compactionfilterjni.cc +++ b/java/rocksjni/remove_emptyvalue_compactionfilterjni.cc @@ -6,6 +6,7 @@ #include #include "include/org_rocksdb_RemoveEmptyValueCompactionFilter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "utilities/compaction_filters/remove_emptyvalue_compactionfilter.h" /* @@ -19,5 +20,5 @@ jlong Java_org_rocksdb_RemoveEmptyValueCompactionFilter_createNewRemoveEmptyValu new ROCKSDB_NAMESPACE::RemoveEmptyValueCompactionFilter(); // set the native handle to our native compaction filter - return reinterpret_cast(compaction_filter); + return GET_CPLUSPLUS_POINTER(compaction_filter); } diff --git a/java/rocksjni/restorejni.cc b/java/rocksjni/restorejni.cc index 9cc681201..aadc86128 100644 --- a/java/rocksjni/restorejni.cc +++ b/java/rocksjni/restorejni.cc @@ -15,6 +15,7 @@ #include "include/org_rocksdb_RestoreOptions.h" #include "rocksdb/utilities/backup_engine.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* * Class: org_rocksdb_RestoreOptions @@ -24,7 +25,7 @@ jlong Java_org_rocksdb_RestoreOptions_newRestoreOptions( JNIEnv* /*env*/, jclass /*jcls*/, jboolean keep_log_files) { auto* ropt = new ROCKSDB_NAMESPACE::RestoreOptions(keep_log_files); - return reinterpret_cast(ropt); + return GET_CPLUSPLUS_POINTER(ropt); } /* diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index ec0911440..a37b76d68 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -24,6 +24,7 @@ #include "rocksdb/options.h" #include "rocksdb/types.h" #include "rocksdb/version.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #ifdef min @@ -48,7 +49,7 @@ jlong rocksdb_open_helper(JNIEnv* env, jlong jopt_handle, jstring jdb_path, env->ReleaseStringUTFChars(jdb_path, db_path); if (s.ok()) { - return reinterpret_cast(db); + return GET_CPLUSPLUS_POINTER(db); } else { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; @@ -152,9 +153,9 @@ jlongArray rocksdb_open_helper( const jsize resultsLen = 1 + len_cols; // db handle + column family handles std::unique_ptr results = std::unique_ptr(new jlong[resultsLen]); - results[0] = reinterpret_cast(db); + results[0] = GET_CPLUSPLUS_POINTER(db); for (int i = 1; i <= len_cols; i++) { - results[i] = reinterpret_cast(cf_handles[i - 1]); + results[i] = GET_CPLUSPLUS_POINTER(cf_handles[i - 1]); } jlongArray jresults = env->NewLongArray(resultsLen); @@ -364,7 +365,7 @@ jlong Java_org_rocksdb_RocksDB_createColumnFamily( ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; } - return reinterpret_cast(cf_handle); + return GET_CPLUSPLUS_POINTER(cf_handle); } /* @@ -1321,7 +1322,7 @@ jlong rocksdb_iterator_helper( } else { iterator = db->NewIterator(read_options); } - return reinterpret_cast(iterator); + return GET_CPLUSPLUS_POINTER(iterator); } /* @@ -2524,7 +2525,7 @@ jlong Java_org_rocksdb_RocksDB_getSnapshot( JNIEnv*, jobject, jlong db_handle) { auto* db = reinterpret_cast(db_handle); const ROCKSDB_NAMESPACE::Snapshot* snapshot = db->GetSnapshot(); - return reinterpret_cast(snapshot); + return GET_CPLUSPLUS_POINTER(snapshot); } /* @@ -3239,7 +3240,7 @@ jstring Java_org_rocksdb_RocksDB_getName( jlong Java_org_rocksdb_RocksDB_getEnv( JNIEnv*, jobject, jlong jdb_handle) { auto* db = reinterpret_cast(jdb_handle); - return reinterpret_cast(db->GetEnv()); + return GET_CPLUSPLUS_POINTER(db->GetEnv()); } /* @@ -3424,7 +3425,7 @@ jlong Java_org_rocksdb_RocksDB_getUpdatesSince( std::unique_ptr iter; ROCKSDB_NAMESPACE::Status s = db->GetUpdatesSince(sequence_number, &iter); if (s.ok()) { - return reinterpret_cast(iter.release()); + return GET_CPLUSPLUS_POINTER(iter.release()); } ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); @@ -3568,7 +3569,7 @@ jlong Java_org_rocksdb_RocksDB_getDefaultColumnFamily( JNIEnv*, jobject, jlong jdb_handle) { auto* db_handle = reinterpret_cast(jdb_handle); auto* cf_handle = db_handle->DefaultColumnFamily(); - return reinterpret_cast(cf_handle); + return GET_CPLUSPLUS_POINTER(cf_handle); } /* @@ -3728,8 +3729,8 @@ jlongArray Java_org_rocksdb_RocksDB_suggestCompactRange( } jlong slice_handles[2]; - slice_handles[0] = reinterpret_cast(begin); - slice_handles[1] = reinterpret_cast(end); + slice_handles[0] = GET_CPLUSPLUS_POINTER(begin); + slice_handles[1] = GET_CPLUSPLUS_POINTER(end); env->SetLongArrayRegion(jslice_handles, 0, 2, slice_handles); if (env->ExceptionCheck()) { // exception thrown: ArrayIndexOutOfBoundsException diff --git a/java/rocksjni/slice.cc b/java/rocksjni/slice.cc index e670174be..63c6b1b9f 100644 --- a/java/rocksjni/slice.cc +++ b/java/rocksjni/slice.cc @@ -6,15 +6,18 @@ // This file implements the "bridge" between Java and C++ for // ROCKSDB_NAMESPACE::Slice. +#include "rocksdb/slice.h" + #include #include #include + #include #include "include/org_rocksdb_AbstractSlice.h" #include "include/org_rocksdb_DirectSlice.h" #include "include/org_rocksdb_Slice.h" -#include "rocksdb/slice.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" // + #include #include "include/org_rocksdb_SstFileManager.h" -#include "rocksdb/sst_file_manager.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -49,7 +52,7 @@ jlong Java_org_rocksdb_SstFileManager_newSstFileManager( auto* sptr_sst_file_manager = new std::shared_ptr(sst_file_manager); - return reinterpret_cast(sptr_sst_file_manager); + return GET_CPLUSPLUS_POINTER(sptr_sst_file_manager); } /* diff --git a/java/rocksjni/sst_file_readerjni.cc b/java/rocksjni/sst_file_readerjni.cc index d79a2c09a..7ef711842 100644 --- a/java/rocksjni/sst_file_readerjni.cc +++ b/java/rocksjni/sst_file_readerjni.cc @@ -8,6 +8,7 @@ // from Java side. #include + #include #include "include/org_rocksdb_SstFileReader.h" @@ -15,6 +16,7 @@ #include "rocksdb/env.h" #include "rocksdb/options.h" #include "rocksdb/sst_file_reader.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -29,7 +31,7 @@ jlong Java_org_rocksdb_SstFileReader_newSstFileReader(JNIEnv * /*env*/, reinterpret_cast(joptions); ROCKSDB_NAMESPACE::SstFileReader *sst_file_reader = new ROCKSDB_NAMESPACE::SstFileReader(*options); - return reinterpret_cast(sst_file_reader); + return GET_CPLUSPLUS_POINTER(sst_file_reader); } /* @@ -67,7 +69,7 @@ jlong Java_org_rocksdb_SstFileReader_newIterator(JNIEnv * /*env*/, reinterpret_cast(jhandle); auto *read_options = reinterpret_cast(jread_options_handle); - return reinterpret_cast(sst_file_reader->NewIterator(*read_options)); + return GET_CPLUSPLUS_POINTER(sst_file_reader->NewIterator(*read_options)); } /* diff --git a/java/rocksjni/sst_file_writerjni.cc b/java/rocksjni/sst_file_writerjni.cc index 5ca8c5309..1898c3cfc 100644 --- a/java/rocksjni/sst_file_writerjni.cc +++ b/java/rocksjni/sst_file_writerjni.cc @@ -8,6 +8,7 @@ // from Java side. #include + #include #include "include/org_rocksdb_SstFileWriter.h" @@ -15,6 +16,7 @@ #include "rocksdb/env.h" #include "rocksdb/options.h" #include "rocksdb/sst_file_writer.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -45,7 +47,7 @@ jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter__JJJB( reinterpret_cast(joptions); ROCKSDB_NAMESPACE::SstFileWriter *sst_file_writer = new ROCKSDB_NAMESPACE::SstFileWriter(*env_options, *options, comparator); - return reinterpret_cast(sst_file_writer); + return GET_CPLUSPLUS_POINTER(sst_file_writer); } /* @@ -63,7 +65,7 @@ jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter__JJ(JNIEnv * /*env*/, reinterpret_cast(joptions); ROCKSDB_NAMESPACE::SstFileWriter *sst_file_writer = new ROCKSDB_NAMESPACE::SstFileWriter(*env_options, *options); - return reinterpret_cast(sst_file_writer); + return GET_CPLUSPLUS_POINTER(sst_file_writer); } /* diff --git a/java/rocksjni/sst_partitioner.cc b/java/rocksjni/sst_partitioner.cc index 92c0ebdda..1cea3b0cb 100644 --- a/java/rocksjni/sst_partitioner.cc +++ b/java/rocksjni/sst_partitioner.cc @@ -15,6 +15,7 @@ #include "include/org_rocksdb_SstPartitionerFixedPrefixFactory.h" #include "rocksdb/sst_file_manager.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -26,7 +27,7 @@ jlong Java_org_rocksdb_SstPartitionerFixedPrefixFactory_newSstPartitionerFixedPr JNIEnv*, jclass, jlong prefix_len) { auto* ptr = new std::shared_ptr( ROCKSDB_NAMESPACE::NewSstPartitionerFixedPrefixFactory(prefix_len)); - return reinterpret_cast(ptr); + return GET_CPLUSPLUS_POINTER(ptr); } /* diff --git a/java/rocksjni/statistics.cc b/java/rocksjni/statistics.cc index f59e79e6c..6672cbdcf 100644 --- a/java/rocksjni/statistics.cc +++ b/java/rocksjni/statistics.cc @@ -6,12 +6,15 @@ // This file implements the "bridge" between Java and C++ and enables // calling c++ ROCKSDB_NAMESPACE::Statistics methods from Java side. +#include "rocksdb/statistics.h" + #include + #include #include #include "include/org_rocksdb_Statistics.h" -#include "rocksdb/statistics.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #include "rocksjni/statisticsjni.h" @@ -94,7 +97,7 @@ jlong Java_org_rocksdb_Statistics_newStatistics___3BJ( new ROCKSDB_NAMESPACE::StatisticsJni(sptr_other_statistics, histograms)); - return reinterpret_cast(pSptr_statistics); + return GET_CPLUSPLUS_POINTER(pSptr_statistics); } /* diff --git a/java/rocksjni/table.cc b/java/rocksjni/table.cc index 1b98cd8b0..f85905bc6 100644 --- a/java/rocksjni/table.cc +++ b/java/rocksjni/table.cc @@ -7,12 +7,15 @@ // ROCKSDB_NAMESPACE::Options. #include "rocksdb/table.h" + #include + #include "include/org_rocksdb_BlockBasedTableConfig.h" #include "include/org_rocksdb_PlainTableConfig.h" #include "portal.h" #include "rocksdb/cache.h" #include "rocksdb/filter_policy.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_PlainTableConfig @@ -35,7 +38,7 @@ jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle( static_cast(jencoding_type); options.full_scan_mode = jfull_scan_mode; options.store_index_in_file = jstore_index_in_file; - return reinterpret_cast( + return GET_CPLUSPLUS_POINTER( ROCKSDB_NAMESPACE::NewPlainTableFactory(options)); } @@ -150,6 +153,6 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( ROCKSDB_NAMESPACE::IndexShorteningModeJni::toCppIndexShorteningMode( jindex_shortening); - return reinterpret_cast( + return GET_CPLUSPLUS_POINTER( ROCKSDB_NAMESPACE::NewBlockBasedTableFactory(options)); } diff --git a/java/rocksjni/table_filter.cc b/java/rocksjni/table_filter.cc index a9024ce88..1400fa1d9 100644 --- a/java/rocksjni/table_filter.cc +++ b/java/rocksjni/table_filter.cc @@ -7,9 +7,11 @@ // org.rocksdb.AbstractTableFilter. #include + #include #include "include/org_rocksdb_AbstractTableFilter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/table_filter_jnicallback.h" /* @@ -21,5 +23,5 @@ jlong Java_org_rocksdb_AbstractTableFilter_createNewTableFilter( JNIEnv* env, jobject jtable_filter) { auto* table_filter_jnicallback = new ROCKSDB_NAMESPACE::TableFilterJniCallback(env, jtable_filter); - return reinterpret_cast(table_filter_jnicallback); + return GET_CPLUSPLUS_POINTER(table_filter_jnicallback); } diff --git a/java/rocksjni/trace_writer.cc b/java/rocksjni/trace_writer.cc index 3beafd45e..0fc3afd99 100644 --- a/java/rocksjni/trace_writer.cc +++ b/java/rocksjni/trace_writer.cc @@ -9,6 +9,7 @@ #include #include "include/org_rocksdb_AbstractTraceWriter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/trace_writer_jnicallback.h" /* @@ -19,5 +20,5 @@ jlong Java_org_rocksdb_AbstractTraceWriter_createNewTraceWriter( JNIEnv* env, jobject jobj) { auto* trace_writer = new ROCKSDB_NAMESPACE::TraceWriterJniCallback(env, jobj); - return reinterpret_cast(trace_writer); + return GET_CPLUSPLUS_POINTER(trace_writer); } diff --git a/java/rocksjni/transaction.cc b/java/rocksjni/transaction.cc index 444730667..5c01436f1 100644 --- a/java/rocksjni/transaction.cc +++ b/java/rocksjni/transaction.cc @@ -6,12 +6,14 @@ // This file implements the "bridge" between Java and C++ // for ROCKSDB_NAMESPACE::Transaction. +#include "rocksdb/utilities/transaction.h" + #include + #include #include "include/org_rocksdb_Transaction.h" - -#include "rocksdb/utilities/transaction.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #if defined(_MSC_VER) @@ -67,7 +69,7 @@ jlong Java_org_rocksdb_Transaction_getSnapshot(JNIEnv* /*env*/, jlong jhandle) { auto* txn = reinterpret_cast(jhandle); const ROCKSDB_NAMESPACE::Snapshot* snapshot = txn->GetSnapshot(); - return reinterpret_cast(snapshot); + return GET_CPLUSPLUS_POINTER(snapshot); } /* @@ -532,7 +534,7 @@ jlong Java_org_rocksdb_Transaction_getIterator__JJ(JNIEnv* /*env*/, auto* txn = reinterpret_cast(jhandle); auto* read_options = reinterpret_cast(jread_options_handle); - return reinterpret_cast(txn->GetIterator(*read_options)); + return GET_CPLUSPLUS_POINTER(txn->GetIterator(*read_options)); } /* @@ -549,7 +551,7 @@ jlong Java_org_rocksdb_Transaction_getIterator__JJJ( auto* column_family_handle = reinterpret_cast( jcolumn_family_handle); - return reinterpret_cast( + return GET_CPLUSPLUS_POINTER( txn->GetIterator(*read_options, column_family_handle)); } @@ -1379,7 +1381,7 @@ jlong Java_org_rocksdb_Transaction_getWriteBatch(JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) { auto* txn = reinterpret_cast(jhandle); - return reinterpret_cast(txn->GetWriteBatch()); + return GET_CPLUSPLUS_POINTER(txn->GetWriteBatch()); } /* @@ -1404,7 +1406,7 @@ jlong Java_org_rocksdb_Transaction_getWriteOptions(JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) { auto* txn = reinterpret_cast(jhandle); - return reinterpret_cast(txn->GetWriteOptions()); + return GET_CPLUSPLUS_POINTER(txn->GetWriteOptions()); } /* @@ -1496,7 +1498,7 @@ jlong Java_org_rocksdb_Transaction_getCommitTimeWriteBatch(JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) { auto* txn = reinterpret_cast(jhandle); - return reinterpret_cast(txn->GetCommitTimeWriteBatch()); + return GET_CPLUSPLUS_POINTER(txn->GetCommitTimeWriteBatch()); } /* diff --git a/java/rocksjni/transaction_db.cc b/java/rocksjni/transaction_db.cc index c6ec64640..2066d6d7e 100644 --- a/java/rocksjni/transaction_db.cc +++ b/java/rocksjni/transaction_db.cc @@ -6,17 +6,18 @@ // This file implements the "bridge" between Java and C++ // for ROCKSDB_NAMESPACE::TransactionDB. +#include "rocksdb/utilities/transaction_db.h" + #include + #include #include #include #include "include/org_rocksdb_TransactionDB.h" - #include "rocksdb/options.h" #include "rocksdb/utilities/transaction.h" -#include "rocksdb/utilities/transaction_db.h" - +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -43,7 +44,7 @@ jlong Java_org_rocksdb_TransactionDB_open__JJLjava_lang_String_2( env->ReleaseStringUTFChars(jdb_path, db_path); if (s.ok()) { - return reinterpret_cast(tdb); + return GET_CPLUSPLUS_POINTER(tdb); } else { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; @@ -132,9 +133,9 @@ jlongArray Java_org_rocksdb_TransactionDB_open__JJLjava_lang_String_2_3_3B_3J( const jsize resultsLen = 1 + len_cols; // db handle + column family handles std::unique_ptr results = std::unique_ptr(new jlong[resultsLen]); - results[0] = reinterpret_cast(tdb); + results[0] = GET_CPLUSPLUS_POINTER(tdb); for (int i = 1; i <= len_cols; i++) { - results[i] = reinterpret_cast(handles[i - 1]); + results[i] = GET_CPLUSPLUS_POINTER(handles[i - 1]); } jlongArray jresults = env->NewLongArray(resultsLen); @@ -192,7 +193,7 @@ jlong Java_org_rocksdb_TransactionDB_beginTransaction__JJ( reinterpret_cast(jwrite_options_handle); ROCKSDB_NAMESPACE::Transaction* txn = txn_db->BeginTransaction(*write_options); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -210,7 +211,7 @@ jlong Java_org_rocksdb_TransactionDB_beginTransaction__JJJ( jtxn_options_handle); ROCKSDB_NAMESPACE::Transaction* txn = txn_db->BeginTransaction(*write_options, *txn_options); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -235,7 +236,7 @@ jlong Java_org_rocksdb_TransactionDB_beginTransaction_1withOld__JJJ( // when providing an old_txn assert(txn == old_txn); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -261,7 +262,7 @@ jlong Java_org_rocksdb_TransactionDB_beginTransaction_1withOld__JJJJ( // when providing an old_txn assert(txn == old_txn); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -279,7 +280,7 @@ jlong Java_org_rocksdb_TransactionDB_getTransactionByName( } ROCKSDB_NAMESPACE::Transaction* txn = txn_db->GetTransactionByName(name); env->ReleaseStringUTFChars(jname, name); - return reinterpret_cast(txn); + return GET_CPLUSPLUS_POINTER(txn); } /* @@ -299,7 +300,7 @@ jlongArray Java_org_rocksdb_TransactionDB_getAllPreparedTransactions( const jsize len = static_cast(size); std::vector tmp(len); for (jsize i = 0; i < len; ++i) { - tmp[i] = reinterpret_cast(txns[i]); + tmp[i] = GET_CPLUSPLUS_POINTER(txns[i]); } jlongArray jtxns = env->NewLongArray(len); diff --git a/java/rocksjni/transaction_db_options.cc b/java/rocksjni/transaction_db_options.cc index c64ff9456..4cf27121e 100644 --- a/java/rocksjni/transaction_db_options.cc +++ b/java/rocksjni/transaction_db_options.cc @@ -9,9 +9,8 @@ #include #include "include/org_rocksdb_TransactionDBOptions.h" - #include "rocksdb/utilities/transaction_db.h" - +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -23,7 +22,7 @@ jlong Java_org_rocksdb_TransactionDBOptions_newTransactionDBOptions( JNIEnv* /*env*/, jclass /*jcls*/) { ROCKSDB_NAMESPACE::TransactionDBOptions* opts = new ROCKSDB_NAMESPACE::TransactionDBOptions(); - return reinterpret_cast(opts); + return GET_CPLUSPLUS_POINTER(opts); } /* diff --git a/java/rocksjni/transaction_notifier.cc b/java/rocksjni/transaction_notifier.cc index 4e42af359..cefeb648a 100644 --- a/java/rocksjni/transaction_notifier.cc +++ b/java/rocksjni/transaction_notifier.cc @@ -9,6 +9,7 @@ #include #include "include/org_rocksdb_AbstractTransactionNotifier.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/transaction_notifier_jnicallback.h" /* @@ -23,7 +24,7 @@ jlong Java_org_rocksdb_AbstractTransactionNotifier_createNewTransactionNotifier( auto* sptr_transaction_notifier = new std::shared_ptr( transaction_notifier); - return reinterpret_cast(sptr_transaction_notifier); + return GET_CPLUSPLUS_POINTER(sptr_transaction_notifier); } /* diff --git a/java/rocksjni/transaction_notifier_jnicallback.cc b/java/rocksjni/transaction_notifier_jnicallback.cc index 06b62ad6d..cd77c60ae 100644 --- a/java/rocksjni/transaction_notifier_jnicallback.cc +++ b/java/rocksjni/transaction_notifier_jnicallback.cc @@ -7,6 +7,8 @@ // ROCKSDB_NAMESPACE::TransactionNotifier. #include "rocksjni/transaction_notifier_jnicallback.h" + +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" namespace ROCKSDB_NAMESPACE { @@ -24,8 +26,8 @@ void TransactionNotifierJniCallback::SnapshotCreated( JNIEnv* env = getJniEnv(&attached_thread); assert(env != nullptr); - env->CallVoidMethod(m_jcallback_obj, - m_jsnapshot_created_methodID, reinterpret_cast(newSnapshot)); + env->CallVoidMethod(m_jcallback_obj, m_jsnapshot_created_methodID, + GET_CPLUSPLUS_POINTER(newSnapshot)); if(env->ExceptionCheck()) { // exception thrown from CallVoidMethod diff --git a/java/rocksjni/transaction_options.cc b/java/rocksjni/transaction_options.cc index 0544f255e..dcf363e14 100644 --- a/java/rocksjni/transaction_options.cc +++ b/java/rocksjni/transaction_options.cc @@ -9,8 +9,8 @@ #include #include "include/org_rocksdb_TransactionOptions.h" - #include "rocksdb/utilities/transaction_db.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_TransactionOptions @@ -20,7 +20,7 @@ jlong Java_org_rocksdb_TransactionOptions_newTransactionOptions( JNIEnv* /*env*/, jclass /*jcls*/) { auto* opts = new ROCKSDB_NAMESPACE::TransactionOptions(); - return reinterpret_cast(opts); + return GET_CPLUSPLUS_POINTER(opts); } /* diff --git a/java/rocksjni/ttl.cc b/java/rocksjni/ttl.cc index a898bffb8..1b51954cf 100644 --- a/java/rocksjni/ttl.cc +++ b/java/rocksjni/ttl.cc @@ -10,12 +10,14 @@ #include #include #include + #include #include #include #include "include/org_rocksdb_TtlDB.h" #include "rocksdb/utilities/db_ttl.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -41,7 +43,7 @@ jlong Java_org_rocksdb_TtlDB_open( // as TTLDB extends RocksDB on the java side, we can reuse // the RocksDB portal here. if (s.ok()) { - return reinterpret_cast(db); + return GET_CPLUSPLUS_POINTER(db); } else { ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; @@ -121,9 +123,9 @@ jlongArray Java_org_rocksdb_TtlDB_openCF( const jsize resultsLen = 1 + len_cols; // db handle + column family handles std::unique_ptr results = std::unique_ptr(new jlong[resultsLen]); - results[0] = reinterpret_cast(db); + results[0] = GET_CPLUSPLUS_POINTER(db); for (int i = 1; i <= len_cols; i++) { - results[i] = reinterpret_cast(handles[i - 1]); + results[i] = GET_CPLUSPLUS_POINTER(handles[i - 1]); } jlongArray jresults = env->NewLongArray(resultsLen); @@ -200,7 +202,7 @@ jlong Java_org_rocksdb_TtlDB_createColumnFamilyWithTtl( env->ReleaseByteArrayElements(jcolumn_name, cfname, JNI_ABORT); if (s.ok()) { - return reinterpret_cast(handle); + return GET_CPLUSPLUS_POINTER(handle); } ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); return 0; diff --git a/java/rocksjni/wal_filter.cc b/java/rocksjni/wal_filter.cc index e4040b1f8..5d9ef32fb 100644 --- a/java/rocksjni/wal_filter.cc +++ b/java/rocksjni/wal_filter.cc @@ -9,6 +9,7 @@ #include #include "include/org_rocksdb_AbstractWalFilter.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/wal_filter_jnicallback.h" /* @@ -19,5 +20,5 @@ jlong Java_org_rocksdb_AbstractWalFilter_createNewWalFilter( JNIEnv* env, jobject jobj) { auto* wal_filter = new ROCKSDB_NAMESPACE::WalFilterJniCallback(env, jobj); - return reinterpret_cast(wal_filter); + return GET_CPLUSPLUS_POINTER(wal_filter); } diff --git a/java/rocksjni/wal_filter_jnicallback.cc b/java/rocksjni/wal_filter_jnicallback.cc index 48fe2d505..656cc592e 100644 --- a/java/rocksjni/wal_filter_jnicallback.cc +++ b/java/rocksjni/wal_filter_jnicallback.cc @@ -7,6 +7,8 @@ // ROCKSDB_NAMESPACE::WalFilter. #include "rocksjni/wal_filter_jnicallback.h" + +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" namespace ROCKSDB_NAMESPACE { @@ -109,13 +111,11 @@ void WalFilterJniCallback::ColumnFamilyLogNumberMap( return WalFilter::WalProcessingOption::kCorruptedRecord; } - jshort jlog_record_found_result = env->CallShortMethod(m_jcallback_obj, - m_log_record_found_proxy_mid, - static_cast(log_number), - jlog_file_name, - reinterpret_cast(&batch), - reinterpret_cast(new_batch)); - + jshort jlog_record_found_result = env->CallShortMethod( + m_jcallback_obj, m_log_record_found_proxy_mid, + static_cast(log_number), jlog_file_name, + GET_CPLUSPLUS_POINTER(&batch), GET_CPLUSPLUS_POINTER(new_batch)); + env->DeleteLocalRef(jlog_file_name); if (env->ExceptionCheck()) { diff --git a/java/rocksjni/write_batch.cc b/java/rocksjni/write_batch.cc index cd43a3481..6704e4a7e 100644 --- a/java/rocksjni/write_batch.cc +++ b/java/rocksjni/write_batch.cc @@ -5,6 +5,8 @@ // // This file implements the "bridge" between Java and C++ and enables // calling c++ ROCKSDB_NAMESPACE::WriteBatch methods from Java side. +#include "rocksdb/write_batch.h" + #include #include "db/memtable.h" @@ -16,8 +18,8 @@ #include "rocksdb/env.h" #include "rocksdb/memtablerep.h" #include "rocksdb/status.h" -#include "rocksdb/write_batch.h" #include "rocksdb/write_buffer_manager.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" #include "rocksjni/writebatchhandlerjnicallback.h" #include "table/scoped_arena_iterator.h" @@ -32,7 +34,7 @@ jlong Java_org_rocksdb_WriteBatch_newWriteBatch__I(JNIEnv* /*env*/, jint jreserved_bytes) { auto* wb = new ROCKSDB_NAMESPACE::WriteBatch(static_cast(jreserved_bytes)); - return reinterpret_cast(wb); + return GET_CPLUSPLUS_POINTER(wb); } /* @@ -55,7 +57,7 @@ jlong Java_org_rocksdb_WriteBatch_newWriteBatch___3BI(JNIEnv* env, } auto* wb = new ROCKSDB_NAMESPACE::WriteBatch(serialized); - return reinterpret_cast(wb); + return GET_CPLUSPLUS_POINTER(wb); } /* @@ -670,5 +672,5 @@ void Java_org_rocksdb_WriteBatch_disposeInternal(JNIEnv* /*env*/, jlong Java_org_rocksdb_WriteBatch_00024Handler_createNewHandler0(JNIEnv* env, jobject jobj) { auto* wbjnic = new ROCKSDB_NAMESPACE::WriteBatchHandlerJniCallback(env, jobj); - return reinterpret_cast(wbjnic); + return GET_CPLUSPLUS_POINTER(wbjnic); } diff --git a/java/rocksjni/write_batch_with_index.cc b/java/rocksjni/write_batch_with_index.cc index eaf126d0a..45834264f 100644 --- a/java/rocksjni/write_batch_with_index.cc +++ b/java/rocksjni/write_batch_with_index.cc @@ -7,9 +7,11 @@ // calling c++ ROCKSDB_NAMESPACE::WriteBatchWithIndex methods from Java side. #include "rocksdb/utilities/write_batch_with_index.h" + #include "include/org_rocksdb_WBWIRocksIterator.h" #include "include/org_rocksdb_WriteBatchWithIndex.h" #include "rocksdb/comparator.h" +#include "rocksjni/cplusplus_to_java_convert.h" #include "rocksjni/portal.h" /* @@ -20,7 +22,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__( JNIEnv* /*env*/, jclass /*jcls*/) { auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex(); - return reinterpret_cast(wbwi); + return GET_CPLUSPLUS_POINTER(wbwi); } /* @@ -33,7 +35,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__Z( auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex( ROCKSDB_NAMESPACE::BytewiseComparator(), 0, static_cast(joverwrite_key)); - return reinterpret_cast(wbwi); + return GET_CPLUSPLUS_POINTER(wbwi); } /* @@ -62,7 +64,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__JBIZ( auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex( fallback_comparator, static_cast(jreserved_bytes), static_cast(joverwrite_key)); - return reinterpret_cast(wbwi); + return GET_CPLUSPLUS_POINTER(wbwi); } /* @@ -510,7 +512,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(JNIEnv* /*env*/, auto* wbwi = reinterpret_cast(jwbwi_handle); auto* wbwi_iterator = wbwi->NewIterator(); - return reinterpret_cast(wbwi_iterator); + return GET_CPLUSPLUS_POINTER(wbwi_iterator); } /* @@ -527,7 +529,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(JNIEnv* /*env*/, auto* cf_handle = reinterpret_cast(jcf_handle); auto* wbwi_iterator = wbwi->NewIterator(cf_handle); - return reinterpret_cast(wbwi_iterator); + return GET_CPLUSPLUS_POINTER(wbwi_iterator); } /* @@ -551,7 +553,7 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase( jread_opts_handle); auto* iterator = wbwi->NewIteratorWithBase(cf_handle, base_iterator, read_opts); - return reinterpret_cast(iterator); + return GET_CPLUSPLUS_POINTER(iterator); } /* @@ -825,7 +827,7 @@ jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(JNIEnv* env, // org.rocksdb.DirectSlice#close auto* key_slice = new ROCKSDB_NAMESPACE::Slice(we.key.data(), we.key.size()); - results[1] = reinterpret_cast(key_slice); + results[1] = GET_CPLUSPLUS_POINTER(key_slice); if (we.type == ROCKSDB_NAMESPACE::kDeleteRecord || we.type == ROCKSDB_NAMESPACE::kSingleDeleteRecord || we.type == ROCKSDB_NAMESPACE::kLogDataRecord) { @@ -834,7 +836,7 @@ jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(JNIEnv* env, } else { auto* value_slice = new ROCKSDB_NAMESPACE::Slice(we.value.data(), we.value.size()); - results[2] = reinterpret_cast(value_slice); + results[2] = GET_CPLUSPLUS_POINTER(value_slice); } jlongArray jresults = env->NewLongArray(3); diff --git a/java/rocksjni/write_buffer_manager.cc b/java/rocksjni/write_buffer_manager.cc index e5c1e23f3..85a810615 100644 --- a/java/rocksjni/write_buffer_manager.cc +++ b/java/rocksjni/write_buffer_manager.cc @@ -3,12 +3,13 @@ // COPYING file in the root directory) and Apache 2.0 License // (found in the LICENSE.Apache file in the root directory). +#include "rocksdb/write_buffer_manager.h" + #include #include "include/org_rocksdb_WriteBufferManager.h" - #include "rocksdb/cache.h" -#include "rocksdb/write_buffer_manager.h" +#include "rocksjni/cplusplus_to_java_convert.h" /* * Class: org_rocksdb_WriteBufferManager @@ -25,7 +26,7 @@ jlong Java_org_rocksdb_WriteBufferManager_newWriteBufferManager( new std::shared_ptr( std::make_shared( jbuffer_size, *cache_ptr, allow_stall)); - return reinterpret_cast(write_buffer_manager); + return GET_CPLUSPLUS_POINTER(write_buffer_manager); } /*