[Java] Add RocksObject, the base class of all java objects with a c++ pointer.

Summary:
Add RocksObject, the base class of all java objects which has a c++ pointer.
While the finalizer of a RocksObject will release its c++ resource, it is
suggested to call its RocksObject.dispose() to manually release its
c++ resource.

Existing RocksDB java classes are now extending RocksObject.

Test Plan:
make rocksdbjava
make jtest
make jdb_bench

Reviewers: haobo, dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D18411
This commit is contained in:
Yueh-Hsuan Chiang
2014-05-01 01:44:46 -07:00
parent 096f5be0ed
commit 61955a0dda
13 changed files with 94 additions and 107 deletions

View File

@@ -12,7 +12,7 @@ package org.rocksdb;
* Note that dispose() must be called before an Options instance
* become out-of-scope to release the allocated memory in c++.
*/
public class Options {
public class Options extends RocksObject {
static final long DEFAULT_CACHE_SIZE = 8 << 20;
/**
* Construct options for opening a RocksDB.
@@ -21,7 +21,7 @@ public class Options {
* an rocksdb::Options in the c++ side.
*/
public Options() {
nativeHandle_ = 0;
super();
cacheSize_ = DEFAULT_CACHE_SIZE;
newOptions();
}
@@ -2311,20 +2311,12 @@ public class Options {
* Release the memory allocated for the current instance
* in the c++ side.
*/
public synchronized void dispose() {
@Override public synchronized void dispose() {
if (isInitialized()) {
dispose0();
}
}
@Override protected void finalize() {
dispose();
}
private boolean isInitialized() {
return (nativeHandle_ != 0);
}
static final int DEFAULT_PLAIN_TABLE_BLOOM_BITS_PER_KEY = 10;
static final double DEFAULT_PLAIN_TABLE_HASH_TABLE_RATIO = 0.75;
static final int DEFAULT_PLAIN_TABLE_INDEX_SPARSENESS = 16;
@@ -2358,7 +2350,6 @@ public class Options {
private native void useFixedLengthPrefixExtractor(
long handle, int prefixLength);
long nativeHandle_;
long cacheSize_;
Filter filter_;
}