A little update on my progress with memory management. I have pretty much finished the native API for memory managment. There continued to be small tweaks here and there when I started implementing the new API in various native methods. In my view the API is very clean and easy to use, while enormously enhancing capabilities.
I've upgraded nio_jmemory.cpp file to utilize new API and the java JMemory.class counter part. The main changes in java were that all of the JMemory class properties are now stored natively and not in java. This should speed up all native java calls, especially JBuffer getter/setter methods since they won't have to make multiple JNI calls in order to to check boundaries and other properties. Everything is now stored in native memory where it can be quickly accessed.
Here is what the native memory managment API looks like now:
/* * Memory node API. * * All functions that take a JNIEnv* argument, automatically throw a java * exception upon an error. No exceptions are thrown if return status or * jmem_error() == JMEM_OK. */ jmemory_t *jmem_get (JNIEnv *env, jobject obj); char *jmem_allocate (JNIEnv *env, jobject obj, size_t size); int jmem_connect (JNIEnv *env, jobject obj, jmemory_t *jmem); int jmem_is_connected (JNIEnv *env, jobject obj); int jmem_disconnect (JNIEnv *env, jobject obj); int jmem_free (JNIEnv *env, jmemory_t *jmem); int jmem_reset (JNIEnv *env, jmemory_t *jmem); int jmem_active (JNIEnv *env, jmemory_t *jmem); int jmem_set_mode (jmemory_t *jmem, int mode); char *jmem_data_mode (jmemory_t *jmem, int mode); char *jmem_data (jmemory_t *jmem); char *jmem_data_ro (jmemory_t *jmem); char *jmem_data_wo (jmemory_t *jmem); size_t jmem_size (jmemory_t *jmem); int jmem_is_active (jmemory_t *jmem); int jmem_is_java_owned(jmemory_t *jmem); int jmem_is_data (jmemory_t *jmem); int jmem_bounds (jmemory_t *jmem, int offset, size_t length); int jmem_error (); const char *jmem_perror (); #define jmem_code(code) (jmem_error_code = code) #define jmem_OK() (jmem_error_code = JMEM_OK) #define jmem_ARG() (jmem_error_code = JMEM_NULL_ARG) int jmem_exception (JNIEnv *env); int jmem_exception_code(JNIEnv *env, int code); int jmem_exception_msg (JNIEnv *env, int code, const char *msg); block_t *jblock_get (JNIEnv *env, jobject obj); block_t *jblock_create (size_t size); block_t *jblock_resize (size_t size, block_t *block); peer_t *jpeer_get(JNIEnv *env, jobject obj); peer_t *jpeer_create(); int jpeer_enable_proxy(peer_t *peer); int jpeer_ref_jmem(JNIEnv *env, peer_t *us, int offset, size_t size, jmemory_t *jmem); int jpeer_ref_direct(JNIEnv *env, peer_t *us, char *data, size_t size, jobject jref); jref_t *jref_get (JNIEnv *env, jobject obj); jref_t *jref_create(); int jref_ref (JNIEnv *env, jobject jref);
Error handling and exception reporting has been significantly improved.