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