You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mnemonic.apache.org by ga...@apache.org on 2016/04/05 21:51:55 UTC
[7/7] incubator-mnemonic git commit: MNEMONIC-5 MNEMONIC-6 #resolve
refactored package names
MNEMONIC-5 MNEMONIC-6 #resolve refactored package names
Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/8e83efe5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/8e83efe5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/8e83efe5
Branch: refs/heads/master
Commit: 8e83efe5be11b9875fd7cb71d65122602c96619b
Parents: b53b241
Author: Wang, Gang(Gary) <ga...@intel.com>
Authored: Tue Apr 5 11:13:46 2016 -0700
Committer: Wang, Gang(Gary) <ga...@intel.com>
Committed: Tue Apr 5 11:13:46 2016 -0700
----------------------------------------------------------------------
allocator-services/nvml-vmem-service/pom.xml | 4 +-
.../internal/VMemServiceImpl.java | 94 --
.../internal/VMemServiceImpl.java | 94 ++
.../src/main/native/CMakeLists.txt | 2 +-
..._allocatorservice_internal_VMemServiceImpl.c | 185 ----
..._allocatorservice_internal_VMemServiceImpl.h | 31 -
..._allocatorservice_internal_VMemServiceImpl.c | 185 ++++
..._allocatorservice_internal_VMemServiceImpl.h | 31 +
...ocatorservice.VolatileMemoryAllocatorService | 1 -
...ocatorservice.VolatileMemoryAllocatorService | 1 +
allocator-services/pmalloc-service/pom.xml | 4 +-
.../internal/PMallocServiceImpl.java | 150 ---
.../internal/PMallocServiceImpl.java | 150 +++
.../src/main/native/CMakeLists.txt | 2 +-
...locatorservice_internal_PMallocServiceImpl.c | 319 ------
...locatorservice_internal_PMallocServiceImpl.h | 31 -
...locatorservice_internal_PMallocServiceImpl.c | 319 ++++++
...locatorservice_internal_PMallocServiceImpl.h | 31 +
...torservice.NonVolatileMemoryAllocatorService | 1 -
...torservice.NonVolatileMemoryAllocatorService | 1 +
allocator-services/pom.xml | 6 +-
collections/pom.xml | 10 +-
.../collections/NonVolatileNodeValue.java | 150 ---
.../collections/NonVolatileNodeValue.java | 150 +++
.../collections/NonVolatileNodeValueNGTest.java | 256 -----
.../collections/NonVolatilePersonNGTest.java | 136 ---
.../intel/bigdatamem/collections/Payload.java | 29 -
.../intel/bigdatamem/collections/Person.java | 65 --
.../collections/NonVolatileNodeValueNGTest.java | 255 +++++
.../collections/NonVolatilePersonNGTest.java | 134 +++
.../apache/mnemonic/collections/Payload.java | 29 +
.../org/apache/mnemonic/collections/Person.java | 64 ++
collections/src/test/resources/testng.xml | 10 +-
core/pom.xml | 4 +-
.../java/com/intel/bigdatamem/Allocatable.java | 102 --
.../java/com/intel/bigdatamem/Allocator.java | 39 -
.../AnnotatedNonVolatileEntityClass.java | 977 -------------------
.../AnnotationProcessingException.java | 23 -
.../intel/bigdatamem/BigDataMemAllocator.java | 278 ------
.../intel/bigdatamem/BigDataPMemAllocator.java | 469 ---------
.../bigdatamem/ByteBufferBackedInputStream.java | 61 --
.../ByteBufferBackedOutputStream.java | 56 --
.../intel/bigdatamem/ByteBufferSerializer.java | 149 ---
.../java/com/intel/bigdatamem/CachePool.java | 144 ---
.../com/intel/bigdatamem/CommonAllocator.java | 104 --
.../bigdatamem/CommonPersistAllocator.java | 120 ---
.../bigdatamem/ContainerOverflowException.java | 20 -
.../java/com/intel/bigdatamem/DropEvent.java | 24 -
.../main/java/com/intel/bigdatamem/Durable.java | 74 --
.../intel/bigdatamem/EntityFactoryProxy.java | 35 -
.../java/com/intel/bigdatamem/EvictFilter.java | 24 -
.../java/com/intel/bigdatamem/GenericField.java | 288 ------
.../com/intel/bigdatamem/MemBufferHolder.java | 56 --
.../bigdatamem/MemBufferHolderCachePool.java | 236 -----
.../com/intel/bigdatamem/MemChunkHolder.java | 58 --
.../com/intel/bigdatamem/MemClustering.java | 297 ------
.../main/java/com/intel/bigdatamem/MemFile.java | 51 -
.../java/com/intel/bigdatamem/MemHolder.java | 58 --
.../bigdatamem/MemoryNonVolatileEntity.java | 19 -
.../com/intel/bigdatamem/NonVolatileEntity.java | 13 -
.../bigdatamem/NonVolatileEntityProcessor.java | 134 ---
.../com/intel/bigdatamem/NonVolatileGetter.java | 18 -
.../com/intel/bigdatamem/NonVolatileSetter.java | 16 -
.../intel/bigdatamem/OutOfPersistentMemory.java | 15 -
.../intel/bigdatamem/PMAddressTranslator.java | 45 -
.../main/java/com/intel/bigdatamem/Reclaim.java | 23 -
.../RetrieveNonVolatileEntityError.java | 19 -
.../com/intel/bigdatamem/SysMemAllocator.java | 305 ------
.../main/java/com/intel/bigdatamem/Utils.java | 384 --------
.../NonVolatileMemoryAllocatorService.java | 97 --
.../VolatileMemoryAllocatorService.java | 130 ---
.../java/org/apache/mnemonic/Allocatable.java | 102 ++
.../java/org/apache/mnemonic/Allocator.java | 39 +
.../AnnotatedNonVolatileEntityClass.java | 977 +++++++++++++++++++
.../mnemonic/AnnotationProcessingException.java | 23 +
.../apache/mnemonic/BigDataMemAllocator.java | 278 ++++++
.../apache/mnemonic/BigDataPMemAllocator.java | 469 +++++++++
.../mnemonic/ByteBufferBackedInputStream.java | 61 ++
.../mnemonic/ByteBufferBackedOutputStream.java | 56 ++
.../apache/mnemonic/ByteBufferSerializer.java | 149 +++
.../java/org/apache/mnemonic/CachePool.java | 144 +++
.../org/apache/mnemonic/CommonAllocator.java | 104 ++
.../apache/mnemonic/CommonPersistAllocator.java | 120 +++
.../mnemonic/ContainerOverflowException.java | 20 +
.../java/org/apache/mnemonic/DropEvent.java | 24 +
.../main/java/org/apache/mnemonic/Durable.java | 74 ++
.../org/apache/mnemonic/EntityFactoryProxy.java | 35 +
.../java/org/apache/mnemonic/EvictFilter.java | 24 +
.../java/org/apache/mnemonic/GenericField.java | 288 ++++++
.../org/apache/mnemonic/MemBufferHolder.java | 56 ++
.../mnemonic/MemBufferHolderCachePool.java | 236 +++++
.../org/apache/mnemonic/MemChunkHolder.java | 58 ++
.../java/org/apache/mnemonic/MemClustering.java | 297 ++++++
.../main/java/org/apache/mnemonic/MemFile.java | 51 +
.../java/org/apache/mnemonic/MemHolder.java | 58 ++
.../mnemonic/MemoryNonVolatileEntity.java | 19 +
.../org/apache/mnemonic/NonVolatileEntity.java | 13 +
.../mnemonic/NonVolatileEntityProcessor.java | 134 +++
.../org/apache/mnemonic/NonVolatileGetter.java | 18 +
.../org/apache/mnemonic/NonVolatileSetter.java | 16 +
.../apache/mnemonic/OutOfPersistentMemory.java | 15 +
.../apache/mnemonic/PMAddressTranslator.java | 45 +
.../main/java/org/apache/mnemonic/Reclaim.java | 23 +
.../RetrieveNonVolatileEntityError.java | 19 +
.../org/apache/mnemonic/SysMemAllocator.java | 305 ++++++
.../main/java/org/apache/mnemonic/Utils.java | 384 ++++++++
.../NonVolatileMemoryAllocatorService.java | 97 ++
.../VolatileMemoryAllocatorService.java | 130 +++
.../javax.annotation.processing.Processor | 2 +-
.../bigdatamem/BigDataMemAllocatorNGTest.java | 59 --
.../bigdatamem/BigDataPMemAllocatorNGTest.java | 124 ---
.../bigdatamem/ByteBufferSerializerNGTest.java | 65 --
.../MemBufferHolderCachePoolNGTest.java | 150 ---
.../intel/bigdatamem/MemClusteringNGTest.java | 190 ----
.../bigdatamem/NonVolatilePersonNGTest.java | 136 ---
.../test/java/com/intel/bigdatamem/Payload.java | 29 -
.../test/java/com/intel/bigdatamem/Person.java | 61 --
.../mnemonic/BigDataMemAllocatorNGTest.java | 58 ++
.../mnemonic/BigDataPMemAllocatorNGTest.java | 124 +++
.../mnemonic/ByteBufferSerializerNGTest.java | 65 ++
.../MemBufferHolderCachePoolNGTest.java | 150 +++
.../apache/mnemonic/MemClusteringNGTest.java | 189 ++++
.../mnemonic/NonVolatilePersonNGTest.java | 136 +++
.../test/java/org/apache/mnemonic/Payload.java | 29 +
.../test/java/org/apache/mnemonic/Person.java | 61 ++
core/src/test/resources/testng.xml | 16 +-
examples/pom.xml | 6 +-
.../java/com/intel/bigdatamem/example/Main.java | 189 ----
.../java/org/apache/mnemonic/example/Main.java | 191 ++++
pom.xml | 2 +-
130 files changed, 7442 insertions(+), 7446 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/pom.xml
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/pom.xml b/allocator-services/nvml-vmem-service/pom.xml
index 7259033..7104a82 100644
--- a/allocator-services/nvml-vmem-service/pom.xml
+++ b/allocator-services/nvml-vmem-service/pom.xml
@@ -3,11 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.intel.mnemonic.service.allocatorservice</groupId>
+ <groupId>org.apache.mnemonic.service.allocatorservice</groupId>
<artifactId>allocator-services-parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
- <groupId>com.intel.mnemonic.service.allocatorservice</groupId>
+ <groupId>org.apache.mnemonic.service.allocatorservice</groupId>
<artifactId>nvml-vmem-service</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Mnemonic Project NVML VMem Allocator</name>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java b/allocator-services/nvml-vmem-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
deleted file mode 100644
index 5c9b2f2..0000000
--- a/allocator-services/nvml-vmem-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.intel.mnemonic.service.allocatorservice.internal;
-
-import com.intel.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService;
-import org.flowcomputing.commons.primitives.*;
-import java.nio.ByteBuffer;
-
-
-public class VMemServiceImpl implements VolatileMemoryAllocatorService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("vmemallocator");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- @Override
- public String getServiceId() {
- return "vmem";
- }
-
- @Override
- public long init(long capacity, String uri, boolean isnew) {
- return ninit(capacity, uri, isnew);
- }
-
- @Override
- public void close(long id) {
- nclose(id);
- }
-
- @Override
- public void sync(long id) {
- nsync(id);
- }
-
- @Override
- public long allocate(long id, long size, boolean initzero) {
- return nallocate(id, size, initzero);
- }
-
- @Override
- public long reallocate(long id, long address, long size, boolean initzero) {
- return nreallocate(id, address, size, initzero);
- }
-
- @Override
- public void free(long id, long address) {
- nfree(id, address);
- }
-
- @Override
- public ByteBuffer createByteBuffer(long id, long size) {
- return ncreateByteBuffer(id, size);
- }
-
- @Override
- public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
- return nresizeByteBuffer(id, bytebuf, size);
- }
-
- @Override
- public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
- ndestroyByteBuffer(id, bytebuf);
- }
-
-
- protected native long ninit(long capacity, String uri, boolean isnew);
-
-
- protected native void nclose(long id);
-
-
- protected native void nsync(long id);
-
-
- protected native long nallocate(long id, long size, boolean initzero);
-
-
- protected native long nreallocate(long id, long address, long size, boolean initzero);
-
-
- protected native void nfree(long id, long address);
-
-
- protected native ByteBuffer ncreateByteBuffer(long id, long size);
-
-
- protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
-
-
- protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java b/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
new file mode 100644
index 0000000..6e4558d
--- /dev/null
+++ b/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
@@ -0,0 +1,94 @@
+package org.apache.mnemonic.service.allocatorservice.internal;
+
+import org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.*;
+import java.nio.ByteBuffer;
+
+
+public class VMemServiceImpl implements VolatileMemoryAllocatorService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("vmemallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public String getServiceId() {
+ return "vmem";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
+
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
+
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
+
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
+
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+
+ protected native void nclose(long id);
+
+
+ protected native void nsync(long id);
+
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
+
+
+ protected native void nfree(long id, long address);
+
+
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
+
+
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
+
+
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/CMakeLists.txt b/allocator-services/nvml-vmem-service/src/main/native/CMakeLists.txt
index e3b39a6..537508f 100644
--- a/allocator-services/nvml-vmem-service/src/main/native/CMakeLists.txt
+++ b/allocator-services/nvml-vmem-service/src/main/native/CMakeLists.txt
@@ -26,7 +26,7 @@ if (NOT LIBVMEM_LIBRARIES)
message(FATAL_ERROR "not found vmem library")
endif (NOT LIBVMEM_LIBRARIES)
-add_library(vmemallocator SHARED common.c com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c)
+add_library(vmemallocator SHARED common.c org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c)
target_include_directories(vmemallocator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(vmemallocator vmem)
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c b/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
deleted file mode 100644
index ba8630f..0000000
--- a/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
-
-#include "com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h"
-
-#include <libvmem.h>
-
-static VMEM **g_vmp_ptr = NULL;
-static size_t g_vmp_count = 0;
-
-static pthread_mutex_t *g_vmem_mutex_ptr = NULL;
-
-static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;
-
-/******************************************************************************
- ** JNI implementations
- *****************************************************************************/
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return addr_to_java(nativebuf);
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nreallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
-
- void* p = addr_from_java(address);
-
- void* nativebuf = vmem_realloc(*(g_vmp_ptr + id), p, size);
-
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return addr_to_java(nativebuf);
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nfree(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- void* nativebuf = addr_from_java(address);
- if (nativebuf != NULL)
- vmem_free(*(g_vmp_ptr + id), nativebuf);
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nsync(
- JNIEnv* env,
- jobject this, jlong id)
-{
-}
-
-JNIEXPORT
-jobject JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ncreateByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong size)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- jobject ret = NULL;
- void* nativebuf = vmem_malloc(*(g_vmp_ptr + id), size);
- ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
-}
-
-JNIEXPORT
-jobject JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nresizeByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- jobject ret = NULL;
- if (NULL != bytebuf) {
- void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- nativebuf = vmem_realloc(*(g_vmp_ptr + id), nativebuf, size);
- ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
- }
- }
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ndestroyByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- vmem_free(*(g_vmp_ptr + id), nativebuf);
- }
- }
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ninit
- (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
-{
- pthread_rwlock_wrlock(&g_vmem_rwlock);
- size_t ret = -1;
- VMEM *vmp = NULL;
- const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
- if (NULL == mpathname) {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory path not specified!");
- }
- if ((vmp = vmem_create(mpathname, capacity)) == NULL) {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory init failure!");
- }
- g_vmp_ptr = realloc(g_vmp_ptr, (g_vmp_count + 1) * sizeof(VMEM*));
- g_vmem_mutex_ptr =
- realloc(g_vmem_mutex_ptr, (g_vmp_count + 1) * sizeof(pthread_mutex_t));
- if (NULL != g_vmp_ptr && NULL != g_vmem_mutex_ptr) {
- g_vmp_ptr[g_vmp_count] = vmp;
- pthread_mutex_init(g_vmem_mutex_ptr + g_vmp_count, NULL);
- ret = g_vmp_count;
- g_vmp_count++;
- } else {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory init Out of memory!");
- }
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nclose
- (JNIEnv *env, jobject this, jlong id)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
-
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
-}
-
-
-__attribute__((destructor)) void fini(void)
-{
- int i;
- if (NULL != g_vmp_ptr) {
- for (i = 0; i < g_vmp_count; ++i) {
- if (NULL != *(g_vmp_ptr + i)){
- /* vmem_close(*(g_vmp_ptr + i)); undefined function */
- *(g_vmp_ptr + i) = NULL;
- pthread_mutex_destroy(g_vmem_mutex_ptr + i);
- }
- }
- free(g_vmp_ptr);
- g_vmp_ptr = NULL;
- free(g_vmem_mutex_ptr);
- g_vmem_mutex_ptr = NULL;
- g_vmp_count = 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h b/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
deleted file mode 100644
index 6403d46..0000000
--- a/allocator-services/nvml-vmem-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl */
-
-#include "common.h"
-
-#ifndef _Included_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl
-#define _Included_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl
- * Method: jniInit
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniInit
- (JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl
- * Method: jniTerm
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniTerm
- (JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
new file mode 100644
index 0000000..824b703
--- /dev/null
+++ b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
@@ -0,0 +1,185 @@
+/****************************************************************************************
+Revise Date: 20 Apr. 2014
+*****************************************************************************************/
+
+#include "org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h"
+
+#include <libvmem.h>
+
+static VMEM **g_vmp_ptr = NULL;
+static size_t g_vmp_count = 0;
+
+static pthread_mutex_t *g_vmem_mutex_ptr = NULL;
+
+static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nallocate(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong size, jboolean initzero)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nreallocate(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address,
+ jlong size, jboolean initzero)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+
+ void* p = addr_from_java(address);
+
+ void* nativebuf = vmem_realloc(*(g_vmp_ptr + id), p, size);
+
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nfree(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = addr_from_java(address);
+ if (nativebuf != NULL)
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nsync(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ncreateByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong size)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ void* nativebuf = vmem_malloc(*(g_vmp_ptr + id), size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nresizeByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = vmem_realloc(*(g_vmp_ptr + id), nativebuf, size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
+ }
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ndestroyByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
+ }
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ninit
+ (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
+{
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ size_t ret = -1;
+ VMEM *vmp = NULL;
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ if ((vmp = vmem_create(mpathname, capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ g_vmp_ptr = realloc(g_vmp_ptr, (g_vmp_count + 1) * sizeof(VMEM*));
+ g_vmem_mutex_ptr =
+ realloc(g_vmem_mutex_ptr, (g_vmp_count + 1) * sizeof(pthread_mutex_t));
+ if (NULL != g_vmp_ptr && NULL != g_vmem_mutex_ptr) {
+ g_vmp_ptr[g_vmp_count] = vmp;
+ pthread_mutex_init(g_vmem_mutex_ptr + g_vmp_count, NULL);
+ ret = g_vmp_count;
+ g_vmp_count++;
+ } else {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init Out of memory!");
+ }
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nclose
+ (JNIEnv *env, jobject this, jlong id)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+
+__attribute__((destructor)) void fini(void)
+{
+ int i;
+ if (NULL != g_vmp_ptr) {
+ for (i = 0; i < g_vmp_count; ++i) {
+ if (NULL != *(g_vmp_ptr + i)){
+ /* vmem_close(*(g_vmp_ptr + i)); undefined function */
+ *(g_vmp_ptr + i) = NULL;
+ pthread_mutex_destroy(g_vmem_mutex_ptr + i);
+ }
+ }
+ free(g_vmp_ptr);
+ g_vmp_ptr = NULL;
+ free(g_vmem_mutex_ptr);
+ g_vmem_mutex_ptr = NULL;
+ g_vmp_count = 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
new file mode 100644
index 0000000..9a2e73a
--- /dev/null
+++ b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
@@ -0,0 +1,31 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl */
+
+#include "common.h"
+
+#ifndef _Included_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+#define _Included_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniInit
+ (JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniTerm
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService b/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
deleted file mode 100644
index 439c8bd..0000000
--- a/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
+++ /dev/null
@@ -1 +0,0 @@
-com.intel.mnemonic.service.allocatorservice.internal.VMemServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService b/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
new file mode 100644
index 0000000..4aacb0d
--- /dev/null
+++ b/allocator-services/nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.allocatorservice.internal.VMemServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/pom.xml
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/pom.xml b/allocator-services/pmalloc-service/pom.xml
index e9044b0..9f1bfb8 100644
--- a/allocator-services/pmalloc-service/pom.xml
+++ b/allocator-services/pmalloc-service/pom.xml
@@ -3,11 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.intel.mnemonic.service.allocatorservice</groupId>
+ <groupId>org.apache.mnemonic.service.allocatorservice</groupId>
<artifactId>allocator-services-parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
- <groupId>com.intel.mnemonic.service.allocatorservice</groupId>
+ <groupId>org.apache.mnemonic.service.allocatorservice</groupId>
<artifactId>pmalloc-service</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Mnemonic Project PMalloc Allocator</name>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java b/allocator-services/pmalloc-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
deleted file mode 100644
index 735762e..0000000
--- a/allocator-services/pmalloc-service/src/main/java/com/intel/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package com.intel.mnemonic.service.allocatorservice.internal;
-
-import com.intel.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService;
-import org.flowcomputing.commons.primitives.*;
-import java.nio.ByteBuffer;
-
-
-public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("pmallocallocator");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- @Override
- public String getServiceId() {
- return "pmalloc";
- }
-
- @Override
- public long init(long capacity, String uri, boolean isnew) {
- return ninit(capacity, uri, isnew);
- }
-
- @Override
- public void close(long id) {
- nclose(id);
- }
-
- @Override
- public void sync(long id) {
- nsync(id);
- }
-
- @Override
- public long allocate(long id, long size, boolean initzero) {
- return nallocate(id, size, initzero);
- }
-
- @Override
- public long reallocate(long id, long address, long size, boolean initzero) {
- return nreallocate(id, address, size, initzero);
- }
-
- @Override
- public void free(long id, long address) {
- nfree(id, address);
- }
-
- @Override
- public ByteBuffer createByteBuffer(long id, long size) {
- return ncreateByteBuffer(id, size);
- }
-
- @Override
- public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
- return nresizeByteBuffer(id, bytebuf, size);
- }
-
- @Override
- public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
- ndestroyByteBuffer(id, bytebuf);
- }
-
- @Override
- public ByteBuffer retrieveByteBuffer(long id, long handler) {
- return nretrieveByteBuffer(id, handler);
- }
-
- @Override
- public long retrieveSize(long id, long handler) {
- return nretrieveSize(id, handler);
- }
-
- @Override
- public long getByteBufferHandler(long id, ByteBuffer buf) {
- return ngetByteBufferHandler(id, buf);
- }
-
- @Override
- public void setHandler(long id, long key, long handler) {
- nsetHandler(id, key, handler);
- }
-
- @Override
- public long getHandler(long id, long key) {
- return ngetHandler(id, key);
- }
-
- @Override
- public long handlerCapacity(long id) {
- return nhandlerCapacity(id);
- }
-
- @Override
- public long getBaseAddress(long id) {
- return ngetBaseAddress(id);
- }
-
- protected native long ninit(long capacity, String uri, boolean isnew);
-
-
- protected native void nclose(long id);
-
-
- protected native void nsync(long id);
-
-
- protected native long nallocate(long id, long size, boolean initzero);
-
-
- protected native long nreallocate(long id, long address, long size, boolean initzero);
-
-
- protected native void nfree(long id, long address);
-
-
- protected native ByteBuffer ncreateByteBuffer(long id, long size);
-
-
- protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
-
-
- protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
-
-
- protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
-
-
- protected native long nretrieveSize(long id, long handler);
-
-
- protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
-
-
- protected native void nsetHandler(long id, long key, long handler);
-
-
- protected native long ngetHandler(long id, long key);
-
-
- protected native long nhandlerCapacity(long id);
-
-
- protected native long ngetBaseAddress(long id);
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java b/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
new file mode 100644
index 0000000..f96d3b3
--- /dev/null
+++ b/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
@@ -0,0 +1,150 @@
+package org.apache.mnemonic.service.allocatorservice.internal;
+
+import org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.*;
+import java.nio.ByteBuffer;
+
+
+public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("pmallocallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public String getServiceId() {
+ return "pmalloc";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
+
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
+
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
+
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
+
+ @Override
+ public ByteBuffer retrieveByteBuffer(long id, long handler) {
+ return nretrieveByteBuffer(id, handler);
+ }
+
+ @Override
+ public long retrieveSize(long id, long handler) {
+ return nretrieveSize(id, handler);
+ }
+
+ @Override
+ public long getByteBufferHandler(long id, ByteBuffer buf) {
+ return ngetByteBufferHandler(id, buf);
+ }
+
+ @Override
+ public void setHandler(long id, long key, long handler) {
+ nsetHandler(id, key, handler);
+ }
+
+ @Override
+ public long getHandler(long id, long key) {
+ return ngetHandler(id, key);
+ }
+
+ @Override
+ public long handlerCapacity(long id) {
+ return nhandlerCapacity(id);
+ }
+
+ @Override
+ public long getBaseAddress(long id) {
+ return ngetBaseAddress(id);
+ }
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+
+ protected native void nclose(long id);
+
+
+ protected native void nsync(long id);
+
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
+
+
+ protected native void nfree(long id, long address);
+
+
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
+
+
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
+
+
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+
+
+ protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
+
+
+ protected native long nretrieveSize(long id, long handler);
+
+
+ protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
+
+
+ protected native void nsetHandler(long id, long key, long handler);
+
+
+ protected native long ngetHandler(long id, long key);
+
+
+ protected native long nhandlerCapacity(long id);
+
+
+ protected native long ngetBaseAddress(long id);
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/CMakeLists.txt b/allocator-services/pmalloc-service/src/main/native/CMakeLists.txt
index 2715d73..39985de 100644
--- a/allocator-services/pmalloc-service/src/main/native/CMakeLists.txt
+++ b/allocator-services/pmalloc-service/src/main/native/CMakeLists.txt
@@ -26,7 +26,7 @@ if (NOT LIBPMALLOC_LIBRARIES)
message(FATAL_ERROR "not found pmalloc library")
endif (NOT LIBPMALLOC_LIBRARIES)
-add_library(pmallocallocator SHARED common.c com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c)
+add_library(pmallocallocator SHARED common.c org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c)
target_include_directories(pmallocallocator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(pmallocallocator pmalloc)
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c b/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
deleted file mode 100644
index 25d5a30..0000000
--- a/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
-
-#include "com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h"
-
-#include <pmalloc.h>
-
-typedef struct {
- //size_t size;
- jlong size;
-} PMBHeader;
-
-#define PMBHSZ (sizeof(PMBHeader))
-
-static void **g_pmp_ptr = NULL;
-static size_t g_pmp_count = 0;
-
-static pthread_mutex_t *g_pmalloc_mutex_ptr = NULL;
-
-static pthread_rwlock_t g_pmp_rwlock = PTHREAD_RWLOCK_INITIALIZER;
-
-/******************************************************************************
- ** JNI implementations
- *****************************************************************************/
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jlong ret = 0L;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = addr_to_java(nativebuf + PMBHSZ);
-// fprintf(stderr, "### nallocate size: %lld, %X, header size: %ld ### \n",
-// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nreallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jlong ret = 0L;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = NULL;
- void* p = addr_from_java(address);
- if (NULL != p) {
- nativebuf = pmrealloc(md, p - PMBHSZ, size + PMBHSZ);
- } else {
- nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
- }
- if (nativebuf != NULL) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = addr_to_java(nativebuf + PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nfree(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- //fprintf(stderr, "nfree Get Called %ld, %X\n", id, address);
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = addr_from_java(address);
- if (nativebuf != NULL) {
-// fprintf(stderr, "### nfree size: %lld, %X ###, header size: %ld \n",
-// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- pmfree(md, nativebuf - PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsync(
- JNIEnv* env,
- jobject this, jlong id)
-{
-}
-
-JNIEXPORT
-jobject JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ncreateByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong size)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jobject ret = NULL;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = pmalloc(md, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
-// fprintf(stderr, "### ncreateByteBuffer size: %lld, %X ###, header size: %ld \n",
-// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-jobject JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong e_addr)
-{
- jobject ret = NULL;
- void* p = addr_from_java(e_addr);
- if (NULL != p) {
- void* nativebuf = p - PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, p, ((PMBHeader *)nativebuf)->size - PMBHSZ);
- }
- return ret;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveSize(
- JNIEnv *env, jobject this, jlong id, jlong e_addr)
-{
- jlong ret = 0L;
- void* p = addr_from_java(e_addr);
- if (NULL != p) {
- void* nativebuf = p - PMBHSZ;
- ret = ((PMBHeader *)nativebuf)->size - PMBHSZ;
-// fprintf(stderr, "### nretrieveSize size: %lld, %X ###, header size: %ld \n",
-// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- return ret;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetByteBufferHandler(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
-{
-// fprintf(stderr, "ngetByteBufferAddress Get Called %X, %X\n", env, bytebuf);
- jlong ret = 0L;
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
-// fprintf(stderr, "ngetByteBufferAddress Get Native address %X\n", nativebuf);
- ret = addr_to_java(nativebuf);
- }
-// fprintf(stderr, "ngetByteBufferAddress returned address %016lx\n", ret);
- return ret;
-}
-
-JNIEXPORT
-jobject JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nresizeByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jobject ret = NULL;
- void *md = *(g_pmp_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- nativebuf = pmrealloc(md, nativebuf - PMBHSZ, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
- }
- }
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ndestroyByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
-// fprintf(stderr, "### ndestroyByteBuffer size: %lld, %X, header size: %ld ### \n",
-// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ -b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- pmfree(md, nativebuf - PMBHSZ);
- }
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsetHandler(
- JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- if (id < PMALLOC_KEYS && id >= 0) {
- pmalloc_setkey(md, key, (void*)value);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetHandler(
- JNIEnv *env, jobject this, jlong id, jlong key)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- jlong ret = (id < PMALLOC_KEYS && id >= 0) ? (long)pmalloc_getkey(md, key) : 0;
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nhandlerCapacity(
- JNIEnv *env, jobject this)
-{
- return PMALLOC_KEYS;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetBaseAddress(
- JNIEnv *env, jobject this, jlong id)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- void *md = *(g_pmp_ptr + id);
- jlong ret = (long)b_addr(md);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-jlong JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ninit
- (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
-{
- pthread_rwlock_wrlock(&g_pmp_rwlock);
- size_t ret = -1;
- void *md = NULL;
- const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
- if (NULL == mpathname) {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory path not specified!");
- }
- if ((md = pmopen(mpathname, NULL, capacity)) == NULL) {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory init failure!");
- }
- (*env)->ReleaseStringUTFChars(env, pathname, mpathname);
- g_pmp_ptr = realloc(g_pmp_ptr, (g_pmp_count + 1) * sizeof(void*));
- g_pmalloc_mutex_ptr =
- realloc(g_pmalloc_mutex_ptr, (g_pmp_count + 1) * sizeof(pthread_mutex_t));
- if (NULL != g_pmp_ptr && NULL != g_pmalloc_mutex_ptr) {
- *(g_pmp_ptr + g_pmp_count) = md;
- pthread_mutex_init(g_pmalloc_mutex_ptr + g_pmp_count, NULL);
- ret = g_pmp_count;
- ++g_pmp_count;
- } else {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory init Out of memory!");
- }
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
-}
-
-JNIEXPORT
-void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nclose
- (JNIEnv *env, jobject this, jlong id)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- pmclose(md);
- *(g_pmp_ptr + id) = NULL;
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_mutex_destroy(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
-}
-
-
-__attribute__((destructor)) void fini(void)
-{
- int i;
- if (NULL != g_pmp_ptr) {
- for (i = 0; i < g_pmp_count; ++i) {
- if (NULL != *(g_pmp_ptr + i)){
- pmclose(*(g_pmp_ptr + i));
- *(g_pmp_ptr + i) = NULL;
- pthread_mutex_destroy(g_pmalloc_mutex_ptr + i);
- }
- }
- free(g_pmp_ptr);
- g_pmp_ptr = NULL;
- free(g_pmalloc_mutex_ptr);
- g_pmalloc_mutex_ptr = NULL;
- g_pmp_count = 0;
- }
- pthread_rwlock_destroy(&g_pmp_rwlock);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h b/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
deleted file mode 100644
index edc59fc..0000000
--- a/allocator-services/pmalloc-service/src/main/native/com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class PMallocServiceImpl */
-
-#include "common.h"
-
-#ifndef _Included_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
-#define _Included_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
- * Method: jniInit
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniInit
- (JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
- * Method: jniTerm
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_com_intel_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniTerm
- (JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
new file mode 100644
index 0000000..c377e82
--- /dev/null
+++ b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
@@ -0,0 +1,319 @@
+/****************************************************************************************
+Revise Date: 20 Apr. 2014
+*****************************************************************************************/
+
+#include "org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h"
+
+#include <pmalloc.h>
+
+typedef struct {
+ //size_t size;
+ jlong size;
+} PMBHeader;
+
+#define PMBHSZ (sizeof(PMBHeader))
+
+static void **g_pmp_ptr = NULL;
+static size_t g_pmp_count = 0;
+
+static pthread_mutex_t *g_pmalloc_mutex_ptr = NULL;
+
+static pthread_rwlock_t g_pmp_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nallocate(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong size, jboolean initzero)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jlong ret = 0L;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
+ ret = addr_to_java(nativebuf + PMBHSZ);
+// fprintf(stderr, "### nallocate size: %lld, %X, header size: %ld ### \n",
+// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nreallocate(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address,
+ jlong size, jboolean initzero)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jlong ret = 0L;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = NULL;
+ void* p = addr_from_java(address);
+ if (NULL != p) {
+ nativebuf = pmrealloc(md, p - PMBHSZ, size + PMBHSZ);
+ } else {
+ nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
+ }
+ if (nativebuf != NULL) {
+ ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
+ ret = addr_to_java(nativebuf + PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nfree(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ //fprintf(stderr, "nfree Get Called %ld, %X\n", id, address);
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = addr_from_java(address);
+ if (nativebuf != NULL) {
+// fprintf(stderr, "### nfree size: %lld, %X ###, header size: %ld \n",
+// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
+ pmfree(md, nativebuf - PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsync(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ncreateByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong size)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jobject ret = NULL;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = pmalloc(md, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
+// fprintf(stderr, "### ncreateByteBuffer size: %lld, %X ###, header size: %ld \n",
+// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong e_addr)
+{
+ jobject ret = NULL;
+ void* p = addr_from_java(e_addr);
+ if (NULL != p) {
+ void* nativebuf = p - PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, p, ((PMBHeader *)nativebuf)->size - PMBHSZ);
+ }
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveSize(
+ JNIEnv *env, jobject this, jlong id, jlong e_addr)
+{
+ jlong ret = 0L;
+ void* p = addr_from_java(e_addr);
+ if (NULL != p) {
+ void* nativebuf = p - PMBHSZ;
+ ret = ((PMBHeader *)nativebuf)->size - PMBHSZ;
+// fprintf(stderr, "### nretrieveSize size: %lld, %X ###, header size: %ld \n",
+// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
+ }
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetByteBufferHandler(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+// fprintf(stderr, "ngetByteBufferAddress Get Called %X, %X\n", env, bytebuf);
+ jlong ret = 0L;
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+// fprintf(stderr, "ngetByteBufferAddress Get Native address %X\n", nativebuf);
+ ret = addr_to_java(nativebuf);
+ }
+// fprintf(stderr, "ngetByteBufferAddress returned address %016lx\n", ret);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nresizeByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jobject ret = NULL;
+ void *md = *(g_pmp_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = pmrealloc(md, nativebuf - PMBHSZ, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
+ }
+ }
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ndestroyByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+// fprintf(stderr, "### ndestroyByteBuffer size: %lld, %X, header size: %ld ### \n",
+// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ -b_addr(*(g_pmp_ptr + id)), PMBHSZ);
+ pmfree(md, nativebuf - PMBHSZ);
+ }
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsetHandler(
+ JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ if (id < PMALLOC_KEYS && id >= 0) {
+ pmalloc_setkey(md, key, (void*)value);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetHandler(
+ JNIEnv *env, jobject this, jlong id, jlong key)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ jlong ret = (id < PMALLOC_KEYS && id >= 0) ? (long)pmalloc_getkey(md, key) : 0;
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nhandlerCapacity(
+ JNIEnv *env, jobject this)
+{
+ return PMALLOC_KEYS;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetBaseAddress(
+ JNIEnv *env, jobject this, jlong id)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ void *md = *(g_pmp_ptr + id);
+ jlong ret = (long)b_addr(md);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ninit
+ (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
+{
+ pthread_rwlock_wrlock(&g_pmp_rwlock);
+ size_t ret = -1;
+ void *md = NULL;
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ if ((md = pmopen(mpathname, NULL, capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ (*env)->ReleaseStringUTFChars(env, pathname, mpathname);
+ g_pmp_ptr = realloc(g_pmp_ptr, (g_pmp_count + 1) * sizeof(void*));
+ g_pmalloc_mutex_ptr =
+ realloc(g_pmalloc_mutex_ptr, (g_pmp_count + 1) * sizeof(pthread_mutex_t));
+ if (NULL != g_pmp_ptr && NULL != g_pmalloc_mutex_ptr) {
+ *(g_pmp_ptr + g_pmp_count) = md;
+ pthread_mutex_init(g_pmalloc_mutex_ptr + g_pmp_count, NULL);
+ ret = g_pmp_count;
+ ++g_pmp_count;
+ } else {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory init Out of memory!");
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nclose
+ (JNIEnv *env, jobject this, jlong id)
+{
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ pmclose(md);
+ *(g_pmp_ptr + id) = NULL;
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_mutex_destroy(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+
+__attribute__((destructor)) void fini(void)
+{
+ int i;
+ if (NULL != g_pmp_ptr) {
+ for (i = 0; i < g_pmp_count; ++i) {
+ if (NULL != *(g_pmp_ptr + i)){
+ pmclose(*(g_pmp_ptr + i));
+ *(g_pmp_ptr + i) = NULL;
+ pthread_mutex_destroy(g_pmalloc_mutex_ptr + i);
+ }
+ }
+ free(g_pmp_ptr);
+ g_pmp_ptr = NULL;
+ free(g_pmalloc_mutex_ptr);
+ g_pmalloc_mutex_ptr = NULL;
+ g_pmp_count = 0;
+ }
+ pthread_rwlock_destroy(&g_pmp_rwlock);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
new file mode 100644
index 0000000..4b119c7
--- /dev/null
+++ b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
@@ -0,0 +1,31 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class PMallocServiceImpl */
+
+#include "common.h"
+
+#ifndef _Included_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
+#define _Included_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniInit
+ (JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniTerm
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService b/allocator-services/pmalloc-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
deleted file mode 100644
index 0b31d2a..0000000
--- a/allocator-services/pmalloc-service/src/main/resources/META-INF/services/com.intel.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
+++ /dev/null
@@ -1 +0,0 @@
-com.intel.mnemonic.service.allocatorservice.internal.PMallocServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pmalloc-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService b/allocator-services/pmalloc-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
new file mode 100644
index 0000000..4511285
--- /dev/null
+++ b/allocator-services/pmalloc-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.allocatorservice.internal.PMallocServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/allocator-services/pom.xml
----------------------------------------------------------------------
diff --git a/allocator-services/pom.xml b/allocator-services/pom.xml
index 4432f0e..5615ec4 100644
--- a/allocator-services/pom.xml
+++ b/allocator-services/pom.xml
@@ -2,13 +2,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.intel.mnemonic</groupId>
+ <groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>com.intel.mnemonic.service.allocatorservice</groupId>
+ <groupId>org.apache.mnemonic.service.allocatorservice</groupId>
<artifactId>allocator-services-parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
@@ -27,7 +27,7 @@
<dependencies>
<dependency>
- <groupId>com.intel.bigdatamem</groupId>
+ <groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-core</artifactId>
<version>${mnemonic.core.version}</version>
<scope>compile</scope>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/collections/pom.xml
----------------------------------------------------------------------
diff --git a/collections/pom.xml b/collections/pom.xml
index 900df84..cc5bd0b 100644
--- a/collections/pom.xml
+++ b/collections/pom.xml
@@ -3,21 +3,21 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.intel.mnemonic</groupId>
+ <groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <groupId>com.intel.bigdatamem</groupId>
+ <groupId>org.apache.mnemonic.collections</groupId>
<artifactId>mnemonic-collections</artifactId>
<packaging>jar</packaging>
<name>Mnemonic Project Collections</name>
<dependencies>
<dependency>
- <groupId>com.intel.bigdatamem</groupId>
+ <groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-core</artifactId>
<version>${project.version}</version>
</dependency>
@@ -80,7 +80,7 @@
<configuration>
<compilerArguments>-XDenableSunApiLintControl</compilerArguments>
<processors>
- <processor>${project.groupId}.NonVolatileEntityProcessor</processor>
+ <processor>${project.parent.groupId}.NonVolatileEntityProcessor</processor>
</processors>
</configuration>
</execution>
@@ -91,7 +91,7 @@
<configuration>
<compilerArguments>-XDenableSunApiLintControl</compilerArguments>
<processors>
- <processor>${project.groupId}.NonVolatileEntityProcessor</processor>
+ <processor>${project.parent.groupId}.NonVolatileEntityProcessor</processor>
</processors>
</configuration>
</execution>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/collections/src/main/java/com/intel/bigdatamem/collections/NonVolatileNodeValue.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/com/intel/bigdatamem/collections/NonVolatileNodeValue.java b/collections/src/main/java/com/intel/bigdatamem/collections/NonVolatileNodeValue.java
deleted file mode 100644
index 14797d3..0000000
--- a/collections/src/main/java/com/intel/bigdatamem/collections/NonVolatileNodeValue.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package com.intel.bigdatamem.collections;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import com.intel.bigdatamem.*;
-
-/**
- * this class defines a non-volatile node for a generic value to form a unidirectional link
- *
- */
-@NonVolatileEntity
-public abstract class NonVolatileNodeValue<E>
- implements Durable, Iterable<E> {
- protected transient EntityFactoryProxy[] m_node_efproxies;
- protected transient GenericField.GType[] m_node_gftypes;
-
- /**
- * creation callback for initialization
- *
- */
- @Override
- public void initializeAfterCreate() {
- // System.out.println("Initializing After Created");
- }
-
- /**
- * restore callback for initialization
- *
- */
- @Override
- public void initializeAfterRestore() {
- // System.out.println("Initializing After Restored");
- }
-
- /**
- * this function will be invoked by its factory to setup generic related info to avoid expensive operations from reflection
- *
- * @param efproxies
- * specify a array of factory to proxy the restoring of its generic field objects
- *
- * @param gftypes
- * specify a array of types corresponding to efproxies
- */
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
- m_node_efproxies = efproxies;
- m_node_gftypes = gftypes;
- }
-
- /**
- * get the item value of this node
- *
- * @return the item value of this node
- */
- @NonVolatileGetter(Id = 1L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
- abstract public E getItem();
-
- /**
- * set a value to this node item
- *
- * @param value
- * the value to be set
- *
- * @param destroy
- * true if want to destroy exist one
- *
- */
- @NonVolatileSetter
- abstract public void setItem(E value, boolean destroy);
-
- /**
- * get next node
- *
- * @return the next node
- *
- */
- @NonVolatileGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
- abstract public NonVolatileNodeValue<E> getNext();
-
- /**
- * set next node
- *
- * @param next
- * specify the next node
- *
- * @param destroy
- * true if want to destroy the exist node
- */
- @NonVolatileSetter
- abstract public void setNext(NonVolatileNodeValue<E> next, boolean destroy);
-
-
- /**
- * get an iterator instance of this list
- *
- * @return an iterator of this list
- */
- @Override
- public Iterator<E> iterator() {
- return new Intr(this);
- }
-
- /**
- * this class defines a iterator for this non-volatile list
- *
- */
- private class Intr implements Iterator<E> {
-
- protected NonVolatileNodeValue<E> next = null;
-
- /**
- * Constructor
- *
- * @param head
- * the start point for this iterator
- *
- */
- Intr(NonVolatileNodeValue<E> head) {
- next = head;
- }
-
- /**
- * determine the existing of next
- *
- * @return true if there is a next node
- *
- */
- @Override
- public boolean hasNext() {
- return null != next;
- }
-
- /**
- * get next node
- *
- * @return the next node
- */
- @Override
- public E next() {
- if (null == next) {
- new NoSuchElementException();
- }
- E ret = next.getItem();
- next = next.getNext();
- return ret;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/8e83efe5/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java b/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
new file mode 100644
index 0000000..d7f45e4
--- /dev/null
+++ b/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
@@ -0,0 +1,150 @@
+package org.apache.mnemonic.collections;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.mnemonic.*;
+
+/**
+ * this class defines a non-volatile node for a generic value to form a unidirectional link
+ *
+ */
+@NonVolatileEntity
+public abstract class NonVolatileNodeValue<E>
+ implements Durable, Iterable<E> {
+ protected transient EntityFactoryProxy[] m_node_efproxies;
+ protected transient GenericField.GType[] m_node_gftypes;
+
+ /**
+ * creation callback for initialization
+ *
+ */
+ @Override
+ public void initializeAfterCreate() {
+ // System.out.println("Initializing After Created");
+ }
+
+ /**
+ * restore callback for initialization
+ *
+ */
+ @Override
+ public void initializeAfterRestore() {
+ // System.out.println("Initializing After Restored");
+ }
+
+ /**
+ * this function will be invoked by its factory to setup generic related info to avoid expensive operations from reflection
+ *
+ * @param efproxies
+ * specify a array of factory to proxy the restoring of its generic field objects
+ *
+ * @param gftypes
+ * specify a array of types corresponding to efproxies
+ */
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+ m_node_efproxies = efproxies;
+ m_node_gftypes = gftypes;
+ }
+
+ /**
+ * get the item value of this node
+ *
+ * @return the item value of this node
+ */
+ @NonVolatileGetter(Id = 1L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
+ abstract public E getItem();
+
+ /**
+ * set a value to this node item
+ *
+ * @param value
+ * the value to be set
+ *
+ * @param destroy
+ * true if want to destroy exist one
+ *
+ */
+ @NonVolatileSetter
+ abstract public void setItem(E value, boolean destroy);
+
+ /**
+ * get next node
+ *
+ * @return the next node
+ *
+ */
+ @NonVolatileGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
+ abstract public NonVolatileNodeValue<E> getNext();
+
+ /**
+ * set next node
+ *
+ * @param next
+ * specify the next node
+ *
+ * @param destroy
+ * true if want to destroy the exist node
+ */
+ @NonVolatileSetter
+ abstract public void setNext(NonVolatileNodeValue<E> next, boolean destroy);
+
+
+ /**
+ * get an iterator instance of this list
+ *
+ * @return an iterator of this list
+ */
+ @Override
+ public Iterator<E> iterator() {
+ return new Intr(this);
+ }
+
+ /**
+ * this class defines a iterator for this non-volatile list
+ *
+ */
+ private class Intr implements Iterator<E> {
+
+ protected NonVolatileNodeValue<E> next = null;
+
+ /**
+ * Constructor
+ *
+ * @param head
+ * the start point for this iterator
+ *
+ */
+ Intr(NonVolatileNodeValue<E> head) {
+ next = head;
+ }
+
+ /**
+ * determine the existing of next
+ *
+ * @return true if there is a next node
+ *
+ */
+ @Override
+ public boolean hasNext() {
+ return null != next;
+ }
+
+ /**
+ * get next node
+ *
+ * @return the next node
+ */
+ @Override
+ public E next() {
+ if (null == next) {
+ new NoSuchElementException();
+ }
+ E ret = next.getItem();
+ next = next.getNext();
+ return ret;
+ }
+ }
+}