lru_cache.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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::LRUCache.
  8. #include "cache/lru_cache.h"
  9. #include <jni.h>
  10. #include "include/org_rocksdb_LRUCache.h"
  11. #include "rocksjni/cplusplus_to_java_convert.h"
  12. /*
  13. * Class: org_rocksdb_LRUCache
  14. * Method: newLRUCache
  15. * Signature: (JIZD)J
  16. */
  17. jlong Java_org_rocksdb_LRUCache_newLRUCache(JNIEnv* /*env*/, jclass /*jcls*/,
  18. jlong jcapacity,
  19. jint jnum_shard_bits,
  20. jboolean jstrict_capacity_limit,
  21. jdouble jhigh_pri_pool_ratio,
  22. jdouble jlow_pri_pool_ratio) {
  23. auto* sptr_lru_cache = new std::shared_ptr<ROCKSDB_NAMESPACE::Cache>(
  24. ROCKSDB_NAMESPACE::NewLRUCache(
  25. static_cast<size_t>(jcapacity), static_cast<int>(jnum_shard_bits),
  26. static_cast<bool>(jstrict_capacity_limit),
  27. static_cast<double>(jhigh_pri_pool_ratio),
  28. nullptr /* memory_allocator */, rocksdb::kDefaultToAdaptiveMutex,
  29. rocksdb::kDefaultCacheMetadataChargePolicy,
  30. static_cast<double>(jlow_pri_pool_ratio)));
  31. return GET_CPLUSPLUS_POINTER(sptr_lru_cache);
  32. }
  33. /*
  34. * Class: org_rocksdb_LRUCache
  35. * Method: disposeInternal
  36. * Signature: (J)V
  37. */
  38. void Java_org_rocksdb_LRUCache_disposeInternalJni(JNIEnv* /*env*/,
  39. jclass /*jcls*/,
  40. jlong jhandle) {
  41. auto* sptr_lru_cache =
  42. reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>(jhandle);
  43. delete sptr_lru_cache; // delete std::shared_ptr
  44. }