clock_cache.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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::ClockCache.
  8. #include <jni.h>
  9. #include "cache/clock_cache.h"
  10. #include "include/org_rocksdb_ClockCache.h"
  11. /*
  12. * Class: org_rocksdb_ClockCache
  13. * Method: newClockCache
  14. * Signature: (JIZ)J
  15. */
  16. jlong Java_org_rocksdb_ClockCache_newClockCache(
  17. JNIEnv* /*env*/, jclass /*jcls*/, jlong jcapacity, jint jnum_shard_bits,
  18. jboolean jstrict_capacity_limit) {
  19. auto* sptr_clock_cache = new std::shared_ptr<ROCKSDB_NAMESPACE::Cache>(
  20. ROCKSDB_NAMESPACE::NewClockCache(
  21. static_cast<size_t>(jcapacity), static_cast<int>(jnum_shard_bits),
  22. static_cast<bool>(jstrict_capacity_limit)));
  23. return reinterpret_cast<jlong>(sptr_clock_cache);
  24. }
  25. /*
  26. * Class: org_rocksdb_ClockCache
  27. * Method: disposeInternal
  28. * Signature: (J)V
  29. */
  30. void Java_org_rocksdb_ClockCache_disposeInternal(JNIEnv* /*env*/,
  31. jobject /*jobj*/,
  32. jlong jhandle) {
  33. auto* sptr_clock_cache =
  34. reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>(jhandle);
  35. delete sptr_clock_cache; // delete std::shared_ptr
  36. }