lru_cache.cc 1.6 KB

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