hyper_clock_cache.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // This file implements the "bridge" between Java and C++ for
  7. // ROCKSDB_NAMESPACE::HyperClockCache.
  8. #include <jni.h>
  9. #include "cache/clock_cache.h"
  10. #include "include/org_rocksdb_HyperClockCache.h"
  11. #include "rocksjni/cplusplus_to_java_convert.h"
  12. /*
  13. * Class: org_rocksdb_HyperClockCache
  14. * Method: newHyperClockCache
  15. * Signature: (JJIZ)J
  16. */
  17. jlong Java_org_rocksdb_HyperClockCache_newHyperClockCache(
  18. JNIEnv*, jclass, jlong capacity, jlong estimatedEntryCharge,
  19. jint numShardBits, jboolean strictCapacityLimit) {
  20. ROCKSDB_NAMESPACE::HyperClockCacheOptions cacheOptions =
  21. ROCKSDB_NAMESPACE::HyperClockCacheOptions(
  22. capacity, estimatedEntryCharge, numShardBits, strictCapacityLimit);
  23. auto* cache = new std::shared_ptr<ROCKSDB_NAMESPACE::Cache>(
  24. cacheOptions.MakeSharedCache());
  25. return GET_CPLUSPLUS_POINTER(cache);
  26. }
  27. /*
  28. * Class: org_rocksdb_HyperClockCache
  29. * Method: disposeInternalJni
  30. * Signature: (J)V
  31. */
  32. void Java_org_rocksdb_HyperClockCache_disposeInternalJni(JNIEnv*, jclass,
  33. jlong jhandle) {
  34. auto* hyper_clock_cache =
  35. reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>(jhandle);
  36. delete hyper_clock_cache; // delete std::shared_ptr
  37. }