@ -1360,9 +1360,9 @@ class JniUtil {
public :
public :
/**
/**
* Detect if jlong overflows size_t
* Detect if jlong overflows size_t
*
*
* @ param jvalue the jlong value
* @ param jvalue the jlong value
*
*
* @ return
* @ return
*/
*/
inline static Status check_if_jlong_fits_size_t ( const jlong & jvalue ) {
inline static Status check_if_jlong_fits_size_t ( const jlong & jvalue ) {
@ -1588,8 +1588,8 @@ class JniUtil {
* @ param bytes The bytes to copy
* @ param bytes The bytes to copy
*
*
* @ return the Java byte [ ] , or nullptr if an exception occurs
* @ return the Java byte [ ] , or nullptr if an exception occurs
*
*
* @ throws RocksDBException thrown
* @ throws RocksDBException thrown
* if memory size to copy exceeds general java specific array size limitation .
* if memory size to copy exceeds general java specific array size limitation .
*/
*/
static jbyteArray copyBytes ( JNIEnv * env , std : : string bytes ) {
static jbyteArray copyBytes ( JNIEnv * env , std : : string bytes ) {
@ -1827,7 +1827,7 @@ class JniUtil {
return env - > NewStringUTF ( string - > c_str ( ) ) ;
return env - > NewStringUTF ( string - > c_str ( ) ) ;
}
}
/**
/**
* Copies bytes to a new jByteArray with the check of java array size limitation .
* Copies bytes to a new jByteArray with the check of java array size limitation .
*
*
@ -1835,29 +1835,29 @@ class JniUtil {
* @ param size number of bytes to copy
* @ param size number of bytes to copy
*
*
* @ return the Java byte [ ] , or nullptr if an exception occurs
* @ return the Java byte [ ] , or nullptr if an exception occurs
*
*
* @ throws RocksDBException thrown
* @ throws RocksDBException thrown
* if memory size to copy exceeds general java array size limitation to avoid overflow .
* if memory size to copy exceeds general java array size limitation to avoid overflow .
*/
*/
static jbyteArray createJavaByteArrayWithSizeCheck ( JNIEnv * env , const char * bytes , const size_t size ) {
static jbyteArray createJavaByteArrayWithSizeCheck ( JNIEnv * env , const char * bytes , const size_t size ) {
// Limitation for java array size is vm specific
// Limitation for java array size is vm specific
// In general it cannot exceed Integer.MAX_VALUE (2^31 - 1)
// In general it cannot exceed Integer.MAX_VALUE (2^31 - 1)
// Current HotSpot VM limitation for array size is Integer.MAX_VALUE - 5 (2^31 - 1 - 5)
// Current HotSpot VM limitation for array size is Integer.MAX_VALUE - 5 (2^31 - 1 - 5)
// It means that the next call to env->NewByteArray can still end with
// It means that the next call to env->NewByteArray can still end with
// OutOfMemoryError("Requested array size exceeds VM limit") coming from VM
// OutOfMemoryError("Requested array size exceeds VM limit") coming from VM
static const size_t MAX_JARRAY_SIZE = ( static_cast < size_t > ( 1 ) ) < < 31 ;
static const size_t MAX_JARRAY_SIZE = ( static_cast < size_t > ( 1 ) ) < < 31 ;
if ( size > MAX_JARRAY_SIZE ) {
if ( size > MAX_JARRAY_SIZE ) {
rocksdb : : RocksDBExceptionJni : : ThrowNew ( env , " Requested array size exceeds VM limit " ) ;
rocksdb : : RocksDBExceptionJni : : ThrowNew ( env , " Requested array size exceeds VM limit " ) ;
return nullptr ;
return nullptr ;
}
}
const jsize jlen = static_cast < jsize > ( size ) ;
const jsize jlen = static_cast < jsize > ( size ) ;
jbyteArray jbytes = env - > NewByteArray ( jlen ) ;
jbyteArray jbytes = env - > NewByteArray ( jlen ) ;
if ( jbytes = = nullptr ) {
if ( jbytes = = nullptr ) {
// exception thrown: OutOfMemoryError
// exception thrown: OutOfMemoryError
return nullptr ;
return nullptr ;
}
}
env - > SetByteArrayRegion ( jbytes , 0 , jlen ,
env - > SetByteArrayRegion ( jbytes , 0 , jlen ,
const_cast < jbyte * > ( reinterpret_cast < const jbyte * > ( bytes ) ) ) ;
const_cast < jbyte * > ( reinterpret_cast < const jbyte * > ( bytes ) ) ) ;
if ( env - > ExceptionCheck ( ) ) {
if ( env - > ExceptionCheck ( ) ) {
@ -1876,8 +1876,8 @@ class JniUtil {
* @ param bytes The bytes to copy
* @ param bytes The bytes to copy
*
*
* @ return the Java byte [ ] or nullptr if an exception occurs
* @ return the Java byte [ ] or nullptr if an exception occurs
*
*
* @ throws RocksDBException thrown
* @ throws RocksDBException thrown
* if memory size to copy exceeds general java specific array size limitation .
* if memory size to copy exceeds general java specific array size limitation .
*/
*/
static jbyteArray copyBytes ( JNIEnv * env , const Slice & bytes ) {
static jbyteArray copyBytes ( JNIEnv * env , const Slice & bytes ) {
@ -2007,13 +2007,13 @@ class JniUtil {
/**
/**
* Creates a vector < T * > of C + + pointers from
* Creates a vector < T * > of C + + pointers from
* a Java array of C + + pointer addresses .
* a Java array of C + + pointer addresses .
*
*
* @ param env ( IN ) A pointer to the java environment
* @ param env ( IN ) A pointer to the java environment
* @ param pointers ( IN ) A Java array of C + + pointer addresses
* @ param pointers ( IN ) A Java array of C + + pointer addresses
* @ param has_exception ( OUT ) will be set to JNI_TRUE
* @ param has_exception ( OUT ) will be set to JNI_TRUE
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
* exception occurs .
* exception occurs .
*
*
* @ return A vector of C + + pointers .
* @ return A vector of C + + pointers .
*/
*/
template < typename T > static std : : vector < T * > fromJPointers (
template < typename T > static std : : vector < T * > fromJPointers (
@ -2037,13 +2037,13 @@ class JniUtil {
/**
/**
* Creates a Java array of C + + pointer addresses
* Creates a Java array of C + + pointer addresses
* from a vector of C + + pointers .
* from a vector of C + + pointers .
*
*
* @ param env ( IN ) A pointer to the java environment
* @ param env ( IN ) A pointer to the java environment
* @ param pointers ( IN ) A vector of C + + pointers
* @ param pointers ( IN ) A vector of C + + pointers
* @ param has_exception ( OUT ) will be set to JNI_TRUE
* @ param has_exception ( OUT ) will be set to JNI_TRUE
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
* exception occurs
* exception occurs
*
*
* @ return Java array of C + + pointer addresses .
* @ return Java array of C + + pointer addresses .
*/
*/
template < typename T > static jlongArray toJPointers ( JNIEnv * env ,
template < typename T > static jlongArray toJPointers ( JNIEnv * env ,
@ -4084,6 +4084,8 @@ class BottommostLevelCompactionJni {
return 0x1 ;
return 0x1 ;
case rocksdb : : BottommostLevelCompaction : : kForce :
case rocksdb : : BottommostLevelCompaction : : kForce :
return 0x2 ;
return 0x2 ;
case rocksdb : : BottommostLevelCompaction : : kForceOptimized :
return 0x3 ;
default :
default :
return 0x7F ; // undefined
return 0x7F ; // undefined
}
}
@ -4100,6 +4102,8 @@ class BottommostLevelCompactionJni {
return rocksdb : : BottommostLevelCompaction : : kIfHaveCompactionFilter ;
return rocksdb : : BottommostLevelCompaction : : kIfHaveCompactionFilter ;
case 0x2 :
case 0x2 :
return rocksdb : : BottommostLevelCompaction : : kForce ;
return rocksdb : : BottommostLevelCompaction : : kForce ;
case 0x3 :
return rocksdb : : BottommostLevelCompaction : : kForceOptimized ;
default :
default :
// undefined/default
// undefined/default
return rocksdb : : BottommostLevelCompaction : : kIfHaveCompactionFilter ;
return rocksdb : : BottommostLevelCompaction : : kIfHaveCompactionFilter ;
@ -5670,7 +5674,7 @@ class TablePropertiesJni : public JavaClass {
env - > DeleteLocalRef ( jmerge_operator_name ) ;
env - > DeleteLocalRef ( jmerge_operator_name ) ;
return nullptr ;
return nullptr ;
}
}
jstring jproperty_collectors_names = rocksdb : : JniUtil : : toJavaString ( env , & table_properties . property_collectors_names , true ) ;
jstring jproperty_collectors_names = rocksdb : : JniUtil : : toJavaString ( env , & table_properties . property_collectors_names , true ) ;
if ( env - > ExceptionCheck ( ) ) {
if ( env - > ExceptionCheck ( ) ) {
// exception occurred creating java string
// exception occurred creating java string