This is an automated email from the ASF dual-hosted git repository.
garyw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mnemonic.git
The following commit(s) were added to refs/heads/master by this push:
new 9f403cd MNEMONIC-515: PMDK based Persistent Memory Service
9f403cd is described below
commit 9f403cd96d4ef0d2008b5d826b0e575ae9806645
Author: Wang, Gang(Gary) <[email protected]>
AuthorDate: Mon Oct 7 23:42:59 2019 -0700
MNEMONIC-515: PMDK based Persistent Memory Service
Completed by Afrin Jaman and improved according to Kevin Ratnasekera's
feedback
---
bin/source-assembly.xml | 3 +-
bin/test.conf | 3 +
.../PMDKNonVolatileMemAllocatorNGTest.java | 131 +++++++
.../mnemonic/PMDKVolatileMemAllocatorNGTest.java | 68 ++++
.../mnemonic-pmdk-pmem-service/pom.xml | 168 +++++++++
.../memory/internal/PMDKPMemServiceImpl.java | 290 +++++++++++++++
.../src/main/native/CMakeLists.txt | 60 +++
.../src/main/native/LICENSE | 202 ++++++++++
.../src/main/native/common.c | 106 ++++++
.../src/main/native/common.h | 56 +++
.../src/main/native/config.h.in | 24 ++
.../src/main/native/layout.h | 55 +++
...c_service_memory_internal_PMDKPMemServiceImpl.c | 414 +++++++++++++++++++++
...c_service_memory_internal_PMDKPMemServiceImpl.h | 48 +++
...ervice.memory.NonVolatileMemoryAllocatorService | 1 +
.../src/main/resources/log4j.properties | 33 ++
.../mnemonic-pmdk-vmem-service/pom.xml | 168 +++++++++
.../memory/internal/PMDKVMemServiceImpl.java | 275 ++++++++++++++
.../src/main/native/CMakeLists.txt | 55 +++
.../src/main/native/LICENSE | 202 ++++++++++
.../src/main/native/common.c | 89 +++++
.../src/main/native/common.h | 68 ++++
.../src/main/native/config.h.in | 24 ++
...c_service_memory_internal_PMDKVMemServiceImpl.c | 279 ++++++++++++++
...c_service_memory_internal_PMDKVMemServiceImpl.h | 48 +++
...c.service.memory.VolatileMemoryAllocatorService | 1 +
.../src/main/resources/log4j.properties | 33 ++
mnemonic-memory-services/pom.xml | 2 +
pom.xml | 2 +-
29 files changed, 2906 insertions(+), 2 deletions(-)
diff --git a/bin/source-assembly.xml b/bin/source-assembly.xml
index 1668a38..a2a8dce 100644
--- a/bin/source-assembly.xml
+++ b/bin/source-assembly.xml
@@ -82,6 +82,8 @@
<include>org.apache.mnemonic:mnemonic-nvml-pmem-service</include>
<include>org.apache.mnemonic:mnemonic-sys-vmem-service</include>
<include>org.apache.mnemonic:mnemonic-java-vmem-service</include>
+ <include>org.apache.mnemonic:mnemonic-pmdk-vmem-service</include>
+ <include>org.apache.mnemonic:mnemonic-pmdk-pmem-service</include>
</includes>
<sources>
<fileSets>
@@ -281,4 +283,3 @@
</fileSet>
</fileSets>
</assembly>
-
diff --git a/bin/test.conf b/bin/test.conf
index 3f4d799..eeac1c4 100644
--- a/bin/test.conf
+++ b/bin/test.conf
@@ -27,6 +27,9 @@ mvn -Dtest=NonVolatileMemAllocatorNGTest test -pl
mnemonic-core -DskipTests=fals
# a testcase for module "mnemonic-core" that requires 'vmem' memory service to
pass
mvn -Dtest=VolatileMemAllocatorNGTest test -pl mnemonic-core -DskipTests=false
+# a testcase for module "mnemonic-core" that requires 'pmdk_vmem' memory
service to pass
+mvn -Dtest=PMDKVolatileMemAllocatorNGTest test -pl mnemonic-core
-DskipTests=false
+
# a testcase for module "mnemonic-core" that requires 'vmem memory service to
pass
mvn -Dtest=MemClusteringNGTest test -pl mnemonic-core -DskipTests=false
diff --git
a/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKNonVolatileMemAllocatorNGTest.java
b/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKNonVolatileMemAllocatorNGTest.java
new file mode 100644
index 0000000..eb215a9
--- /dev/null
+++
b/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKNonVolatileMemAllocatorNGTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mnemonic;
+
+import java.nio.ByteBuffer;
+import java.util.Random;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Represent a set of test cases for class PMDKNonVolatileMemAllocator.
+ * It mainly covers the bytebuffer data structure on non-volatile memory space.
+ */
+
+public class PMDKNonVolatileMemAllocatorNGTest {
+ @Test
+ public void testPMemByteBuffer() {
+ Random randomGenerator = new Random();
+ NonVolatileMemAllocator act = new
NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmdk_pmem"),
+ 1024 * 1024 * 1024, "./pmdk_pmtest.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size:
%s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 500; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ Assert.assertNotNull(mbh);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ Assert.assertEquals(size, mbh.get().capacity());
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx,
size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ }
+ act.close();
+ }
+
+ @Test
+ public void testGetBufferAddress() {
+ NonVolatileMemAllocator act = new
NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmdk_pmem"),
+ 1024 * 1024 * 1024, "./pmdk_pmtest_buffer.dat", true);
+ MemBufferHolder<NonVolatileMemAllocator> mbh;
+ mbh = act.createBuffer(20000);
+ long phandler = act.getBufferHandler(mbh);
+ System.out.println(String.format("**** 0x%X", phandler));
+ act.close();
+ }
+
+ @Test
+ public void testGenPMemByteBufferWithKey() {
+ Random randomGenerator = Utils.createRandom();
+ NonVolatileMemAllocator act = new
NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmdk_pmem"),
+ 1024 * 1024 * 1024, "./pmdk_pmtest_key.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size:
%s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<NonVolatileMemAllocator> mbh;
+ Long phandler;
+ long keycount = act.handlerCapacity();
+ for (int idx = 0; idx < keycount; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ if (6 == idx) {
+ size += 2000;
+ mbh = mbh.resize(size);
+ }
+ Assert.assertNotNull(mbh);
+ mbh.get().putInt(size);
+ Assert.assertEquals(size, mbh.get().capacity());
+ System.out.println(String.format("Generating PKey Value [Seq.%d] size %d
- %d, (%s)", idx, size,
+ mbh.get().capacity(), size == mbh.get().capacity() ? "Correct" :
"Failed!!!"));
+ phandler = act.getBufferHandler(mbh);
+ System.out.println(String.format("---- 0x%X", phandler));
+ act.setHandler(idx, phandler);
+ mbh.cancelAutoReclaim();
+ }
+ act.close();
+ }
+
+ @Test(dependsOnMethods = { "testGenPMemByteBufferWithKey" })
+ public void testCheckPMemByteBufferWithKey() {
+ NonVolatileMemAllocator act = new
NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmdk_pmem"),
+ 1024 * 1024 * 1024, "./pmdk_pmtest_key.dat", false);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size:
%s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<NonVolatileMemAllocator> mbh;
+ for (int idx = 0; idx < act.handlerCapacity(); ++idx) {
+ long phandler = act.getHandler(idx);
+ mbh = act.retrieveBuffer(phandler);
+ Assert.assertNotNull(mbh);
+ int val = mbh.get().getInt();
+ Assert.assertEquals(val, mbh.get().capacity());
+ System.out.println(String.format("Checking PKey Value [Seq.%d] size %d -
%d, (%s)", idx, val,
+ mbh.get().capacity(), val == mbh.get().capacity() ? "Correct" :
"Failed!!!"));
+ }
+ act.close();
+ }
+
+}
diff --git
a/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKVolatileMemAllocatorNGTest.java
b/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKVolatileMemAllocatorNGTest.java
new file mode 100644
index 0000000..4324b3d
--- /dev/null
+++
b/mnemonic-core/src/test/java/org/apache/mnemonic/PMDKVolatileMemAllocatorNGTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mnemonic;
+
+import org.testng.annotations.Test;
+
+import java.util.Random;
+
+/**
+ * test the functionality of VolatileMemAllocator class.
+ *
+ */
+public class PMDKVolatileMemAllocatorNGTest {
+ /**
+ * test to allocate MemBufferHolder objects and then verify them.
+ */
+ @Test
+ public void testMemByteBuffer() {
+ Random randomGenerator = new Random();
+ Allocator<VolatileMemAllocator> act = new
VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("pmdk_vmem"),
+ 1024 * 1024 * 1024, ".");
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 5; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx,
size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ // mbh.destroy();
+ }
+ }
+
+ /**
+ * test to allocate MemChunkHolder objects and then verify them.
+ */
+ @Test
+ public void testMemChunk() {
+ Random randomGenerator = new Random();
+ Allocator<VolatileMemAllocator> act = new
VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("pmdk_vmem"),
+ 1024 * 1024 * 1024, ".");
+ MemChunkHolder<?> mch;
+ for (int idx = 1; idx <= 5; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mch = act.createChunk(size);
+ System.out.println(String.format("[Seq.%d] addr : %X", idx, size,
mch.get()));
+ mch.destroy();
+ }
+ }
+
+}
diff --git a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/pom.xml
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/pom.xml
new file mode 100644
index 0000000..9dc7ff0
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/pom.xml
@@ -0,0 +1,168 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<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>org.apache.mnemonic</groupId>
+ <artifactId>mnemonic-memory-services</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mnemonic-pmdk-pmem-service</artifactId>
+ <name>mnemonic-pmdk-pmem-service</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/native/dist</directory>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <echo>Java Home: ${java.home}</echo>
+ <mkdir dir="src/main/native/build" />
+ <exec dir="src/main/native/build" executable="cmake"
failonerror="true">
+ <arg value=".." />
+ </exec>
+ <exec dir="src/main/native/build" executable="make"
failonerror="true">
+ <env key="JAVA_HOME" value="${java.home}/.." />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ <execution>
+ <id>clean-native</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <delete dir="src/main/native/build" />
+ <delete dir="src/main/native/dist" />
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-publish-plugin</artifactId>
+ <configuration>
+
<checkoutDirectory>${project.build.directory}/scmpublish</checkoutDirectory>
+ <checkinComment>Publishing javadoc for
${project.artifactId}:${project.version}</checkinComment>
+ <content>${project.reporting.outputDirectory}/apidocs</content>
+ <skipDeletedFiles>true</skipDeletedFiles>
+
<pubScmUrl>scm:git:https://github.com/bigdata-memory/mnenomic-project.git</pubScmUrl>
+ <scmBranch>gh-pages</scmBranch> <!-- branch with static site -->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>doc</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <aggregate>true</aggregate>
+ <show>public</show>
+ <nohelp>true</nohelp>
+ <header>Mnenomic-PMemAllocator, ${project.version}</header>
+ <footer>Mnenomic-PMemAllocator, ${project.version}</footer>
+ <doctitle>Mnenomic, ${project.version}</doctitle>
+ <links>
+
<link>http://static.springsource.org/spring/docs/3.0.x/javadoc-api/</link>
+ <additionalparam>-Xdoclint:all
-Xdoclint:-missing</additionalparam>
+ </links>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>test</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>-Xmx2g -XX:MaxPermSize=1g</argLine>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+
+</project>
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKPMemServiceImpl.java
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKPMemServiceImpl.java
new file mode 100644
index 0000000..b551b1d
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKPMemServiceImpl.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mnemonic.service.memory.internal;
+
+import org.apache.mnemonic.query.memory.EntityInfo;
+import org.apache.mnemonic.query.memory.ResultSet;
+import org.apache.mnemonic.service.computing.ValueInfo;
+import org.apache.mnemonic.service.memory.MemoryServiceFeature;
+import org.apache.mnemonic.service.memory.NonVolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+import org.flowcomputing.commons.resgc.ReclaimContext;
+
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Represent a PMDK based memory service to manage non-volatile memory space.
+ * It makes use of native code to implement the interface of
NonVolatileMemoryAllocatorService.
+ */
+public class PMDKPMemServiceImpl implements NonVolatileMemoryAllocatorService {
+ private static boolean nativeLoaded = false;
+ static void loadNativeLibrary() {
+ try {
+ NativeLibraryLoader.loadFromJar("pmdkpmemallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ nativeLoaded = true;
+ }
+
+ @Override
+ public String getServiceId() {
+ return "pmdk_pmem";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ if (!nativeLoaded) {
+ loadNativeLibrary();
+ }
+ return ninit(capacity, uri, isnew);
+ }
+
+ @Override
+ public long adjustCapacity(long id, long reserve) {
+ throw new UnsupportedOperationException("Unsupported to reduce capacity of
this memory service");
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void syncToVolatileMemory(long id, long addr, long length, boolean
autodetect) {
+ nsync(id, addr, length, autodetect);
+ }
+
+ @Override
+ public long capacity(long id) {
+ return ncapacity(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long addr, long size, boolean initzero) {
+ return nreallocate(id, addr, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long addr, ReclaimContext rctx) {
+ nfree(id, addr);
+ }
+
+ @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, ReclaimContext
rctx) {
+ 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 void syncToNonVolatileMemory(long id, long addr, long length, boolean
autodetect) {
+ npersist(id, addr, length, autodetect);
+ }
+
+ @Override
+ public void syncToLocal(long id, long addr, long length, boolean autodetect)
{
+ nflush(id, addr, length, autodetect);
+ }
+
+ @Override
+ public void drain(long id) {
+ ndrain(id);
+ }
+
+ @Override
+ public long getBaseAddress(long id) {
+ return ngetBaseAddress(id);
+ }
+
+ @Override
+ public void beginTransaction(boolean readOnly) {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public void commitTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public void abortTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public boolean isInTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public Set<MemoryServiceFeature> getFeatures() {
+ Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+ ret.add(MemoryServiceFeature.VOLATILE);
+ ret.add(MemoryServiceFeature.NONVOLATILE);
+ return ret;
+ }
+
+ @Override
+ public byte[] getAbstractAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get abstract
address");
+ }
+
+ @Override
+ public long getPortableAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get portable
address");
+ }
+
+ @Override
+ public long getEffectiveAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get effective
address");
+ }
+
+ @Override
+ public long[] getMemoryFunctions() {
+ return new long[0];
+ }
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+ protected native void nclose(long id);
+
+ protected native void nsync(long id, long addr, long length, boolean
autodetect);
+
+ protected native long ncapacity(long id);
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+ protected native long nreallocate(long id, long addr, long size, boolean
initzero);
+
+ protected native void nfree(long id, long addr);
+
+ 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 void npersist(long id, long addr, long length, boolean
autodetect);
+
+ protected native void nflush(long id, long addr, long length, boolean
autodetect);
+
+ protected native void ndrain(long id);
+
+ protected native long ngetBaseAddress(long id);
+
+ /* Optional Queryable Service */
+
+ @Override
+ public String[] getClassNames(long id) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String[] getEntityNames(long id, String clsname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public EntityInfo getEntityInfo(long id, String clsname, String etyname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void createEntity(long id, EntityInfo entityinfo) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void destroyEntity(long id, String clsname, String etyname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void updateQueryableInfo(long id, String clsname, String etyname,
ValueInfo updobjs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void deleteQueryableInfo(long id, String clsname, String etyname,
ValueInfo updobjs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ResultSet query(long id, String querystr) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/CMakeLists.txt
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/CMakeLists.txt
new file mode 100644
index 0000000..65de2d0
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/CMakeLists.txt
@@ -0,0 +1,60 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+cmake_minimum_required(VERSION 2.8.11)
+project(pmdkpmemallocator)
+
+configure_file (
+ "${PROJECT_SOURCE_DIR}/config.h.in"
+ "${PROJECT_BINARY_DIR}/config.h"
+ )
+include_directories(${PROJECT_BINARY_DIR})
+
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../dist/native")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
+set(pmdkpmemallocator_VERSION_MAJOR 0)
+set(pmdkpmemallocator_VERSION_MINOR 0)
+set(CMAKE_BUILD_TYPE "Release")
+set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -rdynamic -g -ggdb")
+set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O3 -Wall")
+
+find_package(JNI REQUIRED)
+include_directories(${JNI_INCLUDE_DIRS})
+
+find_package(Threads REQUIRED)
+include_directories(${CMAKE_THREAD_LIBS_INIT})
+
+find_library(LIBPMEM_LIBRARIES NAMES libpmem.a libpmem.so)
+if (NOT LIBPMEM_LIBRARIES)
+ message(FATAL_ERROR "not found pmem library")
+endif (NOT LIBPMEM_LIBRARIES)
+
+find_library(LIBPMEMOBJ_LIBRARIES NAMES libpmemobj.a libpmemobj.so)
+if (NOT LIBPMEMOBJ_LIBRARIES)
+ message(FATAL_ERROR "not found pmemobj library")
+endif (NOT LIBPMEMOBJ_LIBRARIES)
+
+add_library(pmdkpmemallocator SHARED common.c
org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.c)
+target_include_directories(pmdkpmemallocator PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(pmdkpmemallocator ${LIBPMEMOBJ_LIBRARIES}
${LIBPMEM_LIBRARIES})
+
+include (InstallRequiredSystemLibraries)
+set (CPACK_RESOURCE_FILE_LICENSE
+ "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+set (CPACK_PACKAGE_VERSION_MAJOR "${pmdkpmemallocator_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${pmdkpmemallocator_VERSION_MINOR}")
+include (CPack)
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/LICENSE
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/LICENSE
new file mode 100644
index 0000000..8f71f43
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/LICENSE
@@ -0,0 +1,202 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.c
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.c
new file mode 100644
index 0000000..e7bcca6
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.c
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <common.h>
+
+/******************************************************************************
+ ** Generally-useful functions for JNI programming.
+ *****************************************************************************/
+
+/**
+ * Throws a RuntimeException, with either an explicit message or the message
+ * corresponding to the current system error value.
+ */
+inline void
+throw(JNIEnv* env, const char* msg) {
+ if (msg == NULL)
+ msg = strerror(errno);
+
+ jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
+ (*env)->ThrowNew(env, xklass, msg);
+}
+
+inline void*
+addr_from_java(jlong addr) {
+ // This assert fails in a variety of ways on 32-bit systems.
+ // It is impossible to predict whether native code that converts
+ // pointers to longs will sign-extend or zero-extend the addresses.
+ //assert(addr == (uintptr_t)addr, "must not be odd high bits");
+ return (void*) (uintptr_t) addr;
+}
+
+inline jlong
+addr_to_java(void* p) {
+ assert(p == (void*) (uintptr_t) p);
+ return (long) (uintptr_t) p;
+}
+
+inline PMEMoid
+pmemobj_undirect(PMPool *pool, void *p)
+{
+ PMEMoid ret = {0, 0};
+ if (NULL != pool && NULL != p && (void*)(pool->base) < p) {
+ if (pmemobj_pool_by_ptr(p) == pool->pop) {
+ ret.pool_uuid_lo = pool->uuid_lo;
+ ret.off = (uint64_t)p - (uint64_t)(pool->base);
+ }
+ }
+ return ret;
+}
+
+inline void *
+prealloc(PMPool *pool, void *p, size_t size, int initzero) {
+ void *ret = NULL;
+ TOID(uint8_t) m;
+ void *nativebuf = NULL;
+ if (size > PMEMOBJ_MAX_ALLOC_SIZE) {
+ return NULL;
+ }
+ if (NULL == p) {
+ if (initzero) {
+ POBJ_ZALLOC(pool->pop, &m.oid, uint8_t, sizeof(uint8_t) * size + PMBHSZ);
+ } else {
+ POBJ_ALLOC(pool->pop, &m.oid, uint8_t, sizeof(uint8_t) * size + PMBHSZ,
NULL, NULL);
+ }
+ } else {
+ m.oid = pmemobj_undirect(pool, p - PMBHSZ);
+ if (!TOID_IS_NULL(m)) {
+ if (initzero) {
+ POBJ_ZREALLOC(pool->pop, &m.oid, uint8_t, sizeof(uint8_t) * size +
PMBHSZ);
+ } else {
+ POBJ_REALLOC(pool->pop, &m.oid, uint8_t, sizeof(uint8_t) * size +
PMBHSZ);
+ }
+ }
+ }
+ if (!TOID_IS_NULL(m)) {
+ nativebuf = pmemobj_direct(m.oid);
+ if (nativebuf != NULL) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = nativebuf + PMBHSZ;
+ }
+ }
+ return ret;
+}
+
+void pfree(PMPool *pool, void *p) {
+ PMEMoid oid;
+ if (p != NULL) {
+ oid = pmemobj_undirect(pool, p - PMBHSZ);
+ POBJ_FREE(&oid);
+ }
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.h
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.h
new file mode 100644
index 0000000..5e6f2cc
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/common.h
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _COMMON_H
+#define _COMMON_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdint.h>
+#include <assert.h>
+#include <pthread.h>
+#include <jni.h>
+#include <libpmemobj.h>
+#include "layout.h"
+
+void throw(JNIEnv* env, const char* msg);
+
+void* addr_from_java(jlong addr);
+
+jlong addr_to_java(void* p);
+
+PMEMoid pmemobj_undirect(PMPool *pool, void *p);
+
+void *prealloc(PMPool *pool, void *p, size_t size, int initzero);
+
+void pfree(PMPool *pool, void *p);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/config.h.in
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/config.h.in
new file mode 100644
index 0000000..9950a43
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/config.h.in
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GUARD
+#define GUARD
+
+#cmakedefine _CONFIG_HEADER_H_
+
+#endif //GUARD
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/layout.h
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/layout.h
new file mode 100644
index 0000000..43ba210
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/layout.h
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LAYOUT_H
+#define _LAYOUT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_HANDLER_STORE_LEN 256
+
+struct pmem_root {
+ long hdl_buf[MAX_HANDLER_STORE_LEN];
+ size_t capacity;
+};
+
+POBJ_LAYOUT_BEGIN(memory_service);
+POBJ_LAYOUT_ROOT(memory_service, struct pmem_root);
+POBJ_LAYOUT_TOID(memory_service, uint8_t);
+POBJ_LAYOUT_TOID(memory_service, size_t);
+POBJ_LAYOUT_END(memory_service);
+
+typedef struct {
+ //size_t size;
+ jlong size;
+} PMBHeader;
+
+typedef struct {
+ PMEMobjpool *pop;
+ uint64_t uuid_lo;
+ void *base;
+ size_t capacity;
+} PMPool;
+
+#define PMBHSZ (sizeof(PMBHeader))
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.c
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.c
new file mode 100644
index 0000000..9935e45
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.c
@@ -0,0 +1,414 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.h"
+#include "libpmem.h"
+
+static PMPool *g_pmpool_arr = NULL;
+static size_t g_pmpool_count = 0;
+
+static pthread_rwlock_t g_pmp_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nallocate(JNIEnv*
env,
+ jobject this, jlong id, jlong size, jboolean initzero) {
+ PMPool *pool;
+ jlong ret = 0L;
+ void *p;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ p = prealloc(pool, NULL, size, initzero ? 1 : 0);
+ if (NULL != p) {
+ ret = addr_to_java(p);
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nreallocate(JNIEnv*
env,
+ jobject this, jlong id, jlong addr, jlong size, jboolean initzero) {
+ PMPool *pool;
+ jlong ret = 0L;
+ void *p;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ p = addr_from_java(addr);
+ p = prealloc(pool, p, size, initzero ? 1 : 0);
+ if (NULL != p) {
+ ret = addr_to_java(p);
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nfree(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong addr)
+{
+ PMPool *pool;
+ void* nativebuf;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ //fprintf(stderr, "nfree Get Called %ld, %X\n", id, addr);
+ nativebuf = addr_from_java(addr);
+ pfree(pool, nativebuf);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nsync(
+ JNIEnv* env,
+ jobject this, jlong id, jlong addr, jlong len, jboolean autodetect)
+{
+ PMPool *pool;
+ size_t capa;
+ void* nativebuf;
+ void* p = addr_from_java(addr);
+ if (autodetect) {
+ if (NULL != p) {
+ nativebuf = p - PMBHSZ;
+ pmem_msync(nativebuf, ((PMBHeader *) nativebuf)->size);
+ } else {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ capa = pool->capacity;
+ pmem_msync(pool->base, capa);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ }
+ } else {
+ if (NULL != p && len > 0L) {
+ pmem_msync(p, len);
+ }
+ }
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_npersist(
+ JNIEnv* env,
+ jobject this, jlong id, jlong addr, jlong len, jboolean autodetect)
+{
+ PMPool *pool;
+ size_t capa;
+ void* nativebuf;
+ void* p = addr_from_java(addr);
+ if (autodetect) {
+ if (NULL != p) {
+ nativebuf = p - PMBHSZ;
+ pmem_persist(nativebuf, ((PMBHeader *) nativebuf)->size);
+ } else {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ capa = pool->capacity;
+ pmem_persist(pool->base, capa);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ }
+ } else {
+ if (NULL != p && len > 0L) {
+ pmem_persist(p, len);
+ }
+ }
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nflush(
+ JNIEnv* env,
+ jobject this, jlong id, jlong addr, jlong len, jboolean autodetect)
+{
+ PMPool *pool;
+ size_t capa;
+ void* nativebuf;
+ void* p = addr_from_java(addr);
+ if (autodetect) {
+ if (NULL != p) {
+ nativebuf = p - PMBHSZ;
+ pmem_flush(nativebuf, ((PMBHeader *) nativebuf)->size);
+ } else {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ capa = pool->capacity;
+ pmem_flush(pool->base, capa);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ }
+ } else {
+ if (NULL != p && len > 0L) {
+ pmem_flush(p, len);
+ }
+ }
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ndrain(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+ pmem_drain();
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ncapacity(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+ PMPool *pool;
+ jlong ret;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ ret = pool->capacity;
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ncreateByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong size) {
+ PMPool *pool;
+ jobject ret = NULL;
+ void* nativebuf = NULL;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ nativebuf = prealloc(pool, NULL, size, 0);
+ if (NULL != nativebuf) {
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf, size);
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nretrieveByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong addr) {
+ jobject ret = NULL;
+ void* p = addr_from_java(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_memory_internal_PMDKPMemServiceImpl_nretrieveSize(JNIEnv
*env,
+ jobject this, jlong id, jlong addr) {
+ jlong ret = 0L;
+ void* p = addr_from_java(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_pmpool_arr + id)), PMBHSZ);
+ }
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_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 addr %X\n",
nativebuf);
+ ret = addr_to_java(nativebuf);
+ }
+// fprintf(stderr, "ngetByteBufferAddress returned addr %016lx\n", ret);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nresizeByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size) {
+ PMPool *pool;
+ jobject ret = NULL;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = prealloc(pool, nativebuf, size, 0);
+ if (NULL != nativebuf) {
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf, size);
+ }
+ }
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ndestroyByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+ PMPool *pool;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ pfree(pool, nativebuf);
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nsetHandler(
+ JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
+{
+ PMPool *pool;
+ TOID(struct pmem_root) root;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ root = POBJ_ROOT(pool->pop, struct pmem_root);
+ if (key < MAX_HANDLER_STORE_LEN && key >= 0) {
+ D_RW(root)->hdl_buf[key] = value;
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ngetHandler(JNIEnv
*env,
+ jobject this, jlong id, jlong key) {
+ PMPool *pool;
+ TOID(struct pmem_root) root;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ root = POBJ_ROOT(pool->pop, struct pmem_root);
+ jlong ret = (key < MAX_HANDLER_STORE_LEN && key >= 0) ?
D_RO(root)->hdl_buf[key] : 0L;
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_nhandlerCapacity(
+ JNIEnv *env, jobject this) {
+ return MAX_HANDLER_STORE_LEN;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ngetBaseAddress(JNIEnv
*env,
+ jobject this, jlong id) {
+ PMPool *pool;
+ jlong ret;
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ ret = addr_to_java(pool->base);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_ninit(JNIEnv
*env,
+ jclass this, jlong capacity, jstring pathname, jboolean isnew) {
+ PMPool *pool;
+ TOID(struct pmem_root) root;
+ int needcreate;
+ jlong ret = -1;
+ PMEMobjpool *pop = NULL;
+ pthread_rwlock_wrlock(&g_pmp_rwlock);
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ needcreate = access(mpathname, F_OK);
+ if (isnew && !needcreate) {
+ if(0 != unlink(mpathname)) {
+ throw(env, "Failure to delete file to create new one.");
+ }
+ needcreate = 1;
+ }
+ if (needcreate && capacity < PMEMOBJ_MIN_POOL) {
+ capacity = PMEMOBJ_MIN_POOL;
+ }
+ if (needcreate) {
+ pop = pmemobj_create(mpathname, POBJ_LAYOUT_NAME(memory_service),
capacity, S_IRUSR | S_IWUSR);
+ } else {
+ pop = pmemobj_open(mpathname, POBJ_LAYOUT_NAME(memory_service));
+ }
+ if (pop == NULL) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ (*env)->ReleaseStringUTFChars(env, pathname, mpathname);
+ g_pmpool_arr = realloc(g_pmpool_arr, (g_pmpool_count + 1) * sizeof(PMPool));
+ if (NULL != g_pmpool_arr) {
+ pool = g_pmpool_arr + g_pmpool_count;
+ pool->pop = pop;
+ root = POBJ_ROOT(pool->pop, struct pmem_root);
+ pool->uuid_lo = root.oid.pool_uuid_lo;
+ pool->base = (void*)pop;
+ if (needcreate) {
+ pool->capacity = capacity;
+ D_RW(root)->capacity = capacity;
+ } else {
+ pool->capacity = D_RO(root)->capacity;
+ }
+ ret = g_pmpool_count;
+ ++g_pmpool_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_memory_internal_PMDKPMemServiceImpl_nclose
+(JNIEnv *env, jobject this, jlong id)
+{
+ PMPool *pool;
+ pthread_rwlock_wrlock(&g_pmp_rwlock);
+ pool = g_pmpool_arr + id;
+ if (NULL != pool->pop) {
+ pmemobj_close(pool->pop);
+ pool->pop = NULL;
+ pool->base = NULL;
+ pool->uuid_lo = 0;
+ pool->capacity = 0;
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+__attribute__((destructor)) void fini(void) {
+ int i;
+ PMPool *pool;
+ pthread_rwlock_wrlock(&g_pmp_rwlock);
+ if (NULL != g_pmpool_arr) {
+ for (i = 0; i < g_pmpool_count; ++i) {
+ pool = g_pmpool_arr + i;
+ if (NULL != pool->pop) {
+ pmemobj_close(pool->pop);
+ pool->pop = NULL;
+ pool->base = NULL;
+ pool->capacity = 0;
+ pool->uuid_lo = 0;
+ }
+ }
+ free(g_pmpool_arr);
+ g_pmpool_arr = NULL;
+ g_pmpool_count = 0;
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ pthread_rwlock_destroy(&g_pmp_rwlock);
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.h
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.h
new file mode 100644
index 0000000..11cc80c
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl.h
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <jni.h>
+/* Header for class
org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl */
+
+#include "common.h"
+
+#ifndef
_Included_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl
+#define
_Included_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKPMemServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.NonVolatileMemoryAllocatorService
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.NonVolatileMemoryAllocatorService
new file mode 100644
index 0000000..cd03a24
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.NonVolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.memory.internal.PMDKPMemServiceImpl
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/log4j.properties
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/log4j.properties
new file mode 100644
index 0000000..24b0e3c
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-pmem-service/src/main/resources/log4j.properties
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Root logger option
+log4j.rootLogger=INFO, file, stdout
+
+#to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}:
%m%n
+
+#to log.log file
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.File=log.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.MaxBackupIndex=10
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}:
%m%n
diff --git a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/pom.xml
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/pom.xml
new file mode 100644
index 0000000..ffa8978
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/pom.xml
@@ -0,0 +1,168 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<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>org.apache.mnemonic</groupId>
+ <artifactId>mnemonic-memory-services</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mnemonic-pmdk-vmem-service</artifactId>
+ <name>mnemonic-pmdk-vmem-service</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/native/dist</directory>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <echo>Java Home: ${java.home}</echo>
+ <mkdir dir="src/main/native/build" />
+ <exec dir="src/main/native/build" executable="cmake"
failonerror="true">
+ <arg value=".." />
+ </exec>
+ <exec dir="src/main/native/build" executable="make"
failonerror="true">
+ <env key="JAVA_HOME" value="${java.home}/.." />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ <execution>
+ <id>clean-native</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <delete dir="src/main/native/build" />
+ <delete dir="src/main/native/dist" />
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-publish-plugin</artifactId>
+ <configuration>
+
<checkoutDirectory>${project.build.directory}/scmpublish</checkoutDirectory>
+ <checkinComment>Publishing javadoc for
${project.artifactId}:${project.version}</checkinComment>
+ <content>${project.reporting.outputDirectory}/apidocs</content>
+ <skipDeletedFiles>true</skipDeletedFiles>
+
<pubScmUrl>scm:git:https://github.com/bigdata-memory/mnenomic-project.git</pubScmUrl>
+ <scmBranch>gh-pages</scmBranch> <!-- branch with static site -->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>doc</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <aggregate>true</aggregate>
+ <show>public</show>
+ <nohelp>true</nohelp>
+ <header>Mnenomic-VMemAllocator, ${project.version}</header>
+ <footer>Mnenomic-VMemAllocator, ${project.version}</footer>
+ <doctitle>Mnenomic, ${project.version}</doctitle>
+ <links>
+
<link>http://static.springsource.org/spring/docs/3.0.x/javadoc-api/</link>
+ <additionalparam>-Xdoclint:all
-Xdoclint:-missing</additionalparam>
+ </links>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>test</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>-Xmx2g -XX:MaxPermSize=1g</argLine>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+
+</project>
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKVMemServiceImpl.java
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKVMemServiceImpl.java
new file mode 100644
index 0000000..26e284f
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/java/org/apache/mnemonic/service/memory/internal/PMDKVMemServiceImpl.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mnemonic.service.memory.internal;
+
+import org.apache.mnemonic.query.memory.EntityInfo;
+import org.apache.mnemonic.query.memory.ResultSet;
+import org.apache.mnemonic.service.computing.ValueInfo;
+import org.apache.mnemonic.service.memory.MemoryServiceFeature;
+import org.apache.mnemonic.service.memory.VolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+import org.flowcomputing.commons.resgc.ReclaimContext;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * Represent a PMDK based memory service to manage volatile memory space.
+ * it makes use of the native code to implement the interface of
VolatileMemoryAllocatorService.
+ */
+public class PMDKVMemServiceImpl implements VolatileMemoryAllocatorService {
+ private static boolean nativeLoaded = false;
+ static void loadNativeLibrary() {
+ try {
+ NativeLibraryLoader.loadFromJar("pmdkvmemallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ nativeLoaded = true;
+ }
+
+ protected Map<Long, Long> m_info = Collections.synchronizedMap(new
HashMap<Long, Long>());
+
+ @Override
+ public String getServiceId() {
+ return "pmdk_vmem";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ if (!nativeLoaded) {
+ loadNativeLibrary();
+ }
+ long ret = ninit(capacity, uri, isnew);
+ m_info.put(ret, capacity);
+ return ret;
+ }
+
+ @Override
+ public long adjustCapacity(long id, long reserve) {
+ throw new UnsupportedOperationException("Unsupported to reduce capacity of
this memory service");
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void syncToVolatileMemory(long id, long addr, long length, boolean
autodetect) {
+ nsync(id, addr, length, autodetect);
+ }
+
+ @Override
+ public long capacity(long id) {
+ return m_info.get(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long addr, long size, boolean initzero) {
+ return nreallocate(id, addr, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long addr, ReclaimContext rctx) {
+ nfree(id, addr);
+ }
+
+ @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, ReclaimContext
rctx) {
+ 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 0L;
+ //return ngetBaseAddress(id);
+ }
+
+ @Override
+ public void beginTransaction(boolean readOnly) {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public void commitTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public void abortTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public boolean isInTransaction() {
+ throw new UnsupportedOperationException("Not support transaction");
+ }
+
+ @Override
+ public Set<MemoryServiceFeature> getFeatures() {
+ Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+ ret.add(MemoryServiceFeature.VOLATILE);
+ return ret;
+ }
+
+ @Override
+ public byte[] getAbstractAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get abstract
address");
+ }
+
+ @Override
+ public long getPortableAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get portable
address");
+ }
+
+ @Override
+ public long getEffectiveAddress(long addr) {
+ throw new UnsupportedOperationException("Unrsupported to get effective
address");
+ }
+
+ @Override
+ public long[] getMemoryFunctions() {
+ return new long[0];
+ }
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+ protected native void nclose(long id);
+
+ protected native void nsync(long id, long addr, long length, boolean
autodetect);
+
+ protected native long ncapacity(long id);
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+ protected native long nreallocate(long id, long addr, long size, boolean
initzero);
+
+ protected native void nfree(long id, long addr);
+
+ 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);
+
+ /* Optional Queryable Service */
+
+ @Override
+ public String[] getClassNames(long id) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String[] getEntityNames(long id, String clsname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public EntityInfo getEntityInfo(long id, String clsname, String etyname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void createEntity(long id, EntityInfo entityinfo) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void destroyEntity(long id, String clsname, String etyname) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void updateQueryableInfo(long id, String clsname, String etyname,
ValueInfo updobjs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void deleteQueryableInfo(long id, String clsname, String etyname,
ValueInfo updobjs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ResultSet query(long id, String querystr) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/CMakeLists.txt
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/CMakeLists.txt
new file mode 100644
index 0000000..e0ab097
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/CMakeLists.txt
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+cmake_minimum_required(VERSION 2.8.11)
+project(pmdkvmemallocator)
+
+configure_file (
+ "${PROJECT_SOURCE_DIR}/config.h.in"
+ "${PROJECT_BINARY_DIR}/config.h"
+ )
+include_directories(${PROJECT_BINARY_DIR})
+
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../dist/native")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
+set(pmdkvmemallocator_VERSION_MAJOR 0)
+set(pmdkvmemallocator_VERSION_MINOR 0)
+set(CMAKE_BUILD_TYPE "Release")
+set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -rdynamic -g -ggdb")
+set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O3 -Wall")
+
+find_package(JNI REQUIRED)
+include_directories(${JNI_INCLUDE_DIRS})
+
+find_package(Threads REQUIRED)
+include_directories(${CMAKE_THREAD_LIBS_INIT})
+
+find_library(LIBVMEM_LIBRARIES NAMES libvmem.a libvmem.so)
+if (NOT LIBVMEM_LIBRARIES)
+ message(FATAL_ERROR "not found pmdk vmem library")
+endif (NOT LIBVMEM_LIBRARIES)
+
+add_library(pmdkvmemallocator SHARED common.c
org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.c)
+target_include_directories(pmdkvmemallocator PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(pmdkvmemallocator ${LIBVMEM_LIBRARIES})
+
+include (InstallRequiredSystemLibraries)
+set (CPACK_RESOURCE_FILE_LICENSE
+ "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+set (CPACK_PACKAGE_VERSION_MAJOR "${pmdkvmemallocator_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${pmdkvmemallocator_VERSION_MINOR}")
+include (CPack)
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/LICENSE
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/LICENSE
new file mode 100644
index 0000000..8f71f43
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/LICENSE
@@ -0,0 +1,202 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.c
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.c
new file mode 100644
index 0000000..7d2983a
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.c
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <common.h>
+
+/******************************************************************************
+ ** Generally-useful functions for JNI programming.
+ *****************************************************************************/
+
+/**
+ * Throws a RuntimeException, with either an explicit message or the message
+ * corresponding to the current system error value.
+ */
+inline void
+throw(JNIEnv* env, const char* msg) {
+ if (msg == NULL)
+ msg = strerror(errno);
+
+ jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
+ (*env)->ThrowNew(env, xklass, msg);
+}
+
+inline void*
+addr_from_java(jlong addr) {
+ // This assert fails in a variety of ways on 32-bit systems.
+ // It is impossible to predict whether native code that converts
+ // pointers to longs will sign-extend or zero-extend the addresses.
+ //assert(addr == (uintptr_t)addr, "must not be odd high bits");
+ return (void*) (uintptr_t) addr;
+}
+
+inline jlong
+addr_to_java(void* p) {
+ assert(p == (void*) (uintptr_t) p);
+ return (long) (uintptr_t) p;
+}
+
+inline void *
+vrealloc(VMPool *pool, void *p, size_t size, int initzero) {
+ void *ret = NULL;
+ void *nativebuf = NULL;
+ if (NULL == p) {
+ if (initzero) {
+ nativebuf = vmem_calloc(pool->vmp, 1, sizeof(uint8_t) * size + PMBHSZ);
+ } else {
+ nativebuf = vmem_malloc(pool->vmp, sizeof(uint8_t) * size + PMBHSZ);
+ }
+ } else {
+ nativebuf = vmem_realloc(pool->vmp, p, sizeof(uint8_t) * size + PMBHSZ);
+ }
+ if (NULL != nativebuf) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = nativebuf + PMBHSZ;
+ }
+ return ret;
+}
+
+inline void
+vfree(VMPool *pool, void *p) {
+ if (p != NULL) {
+ vmem_free(pool->vmp, p);
+ }
+}
+
+inline size_t
+vsize(VMPool *pool, void *p) {
+ size_t ret = 0;
+ void* nativebuf;
+ if (p != NULL) {
+ nativebuf = p - PMBHSZ;
+ ret = ((PMBHeader *) nativebuf)->size - PMBHSZ;
+ }
+ return ret;
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.h
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.h
new file mode 100644
index 0000000..a4b87bd
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/common.h
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _COMMON_H
+#define _COMMON_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdint.h>
+#include <assert.h>
+#include <pthread.h>
+#include <jni.h>
+#include <libvmem.h>
+
+void throw(JNIEnv* env, const char* msg);
+
+void* addr_from_java(jlong addr);
+
+jlong addr_to_java(void* p);
+
+typedef struct {
+ //size_t size;
+ jlong size;
+} PMBHeader;
+
+#define PMBHSZ (sizeof(PMBHeader))
+
+typedef struct {
+ VMEM *vmp;
+ size_t capacity;
+ pthread_mutex_t mutex;
+} VMPool;
+
+void *vrealloc(VMPool *pool, void *p, size_t size, int initzero);
+
+void vfree(VMPool *pool, void *p);
+
+size_t vsize(VMPool *pool, void *p);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/config.h.in
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/config.h.in
new file mode 100644
index 0000000..9950a43
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/config.h.in
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GUARD
+#define GUARD
+
+#cmakedefine _CONFIG_HEADER_H_
+
+#endif //GUARD
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.c
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.c
new file mode 100644
index 0000000..7e60325
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.c
@@ -0,0 +1,279 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.h"
+
+static VMPool *g_vmpool_arr = NULL;
+static size_t g_vmpool_count = 0;
+
+static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nallocate(JNIEnv*
env,
+ jobject this, jlong id, jlong size, jboolean initzero) {
+ VMPool *pool;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ void* nativebuf = vrealloc(pool, NULL, size, initzero);
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nreallocate(JNIEnv*
env,
+ jobject this, jlong id, jlong addr, jlong size, jboolean initzero) {
+ VMPool *pool;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ void* p = addr_from_java(addr);
+ void* nativebuf = vrealloc(pool, p, size, initzero);
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nfree(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong addr) {
+ VMPool *pool;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ void* nativebuf = addr_from_java(addr);
+ vfree(pool, nativebuf);
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nsync(
+ JNIEnv* env,
+ jobject this, jlong id, jlong addr, jlong len, jboolean autodetect)
+{
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ncapacity(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+ VMPool *pool;
+ pool = g_vmpool_arr + id;
+ return pool->capacity;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ncreateByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong size) {
+ VMPool *pool;
+ jobject ret = NULL;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ void* nativebuf = vrealloc(pool, NULL, size, 0);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size)
: NULL;
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nretrieveByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong addr) {
+ jobject ret = NULL;
+ void* p = addr_from_java(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_memory_internal_PMDKVMemServiceImpl_nretrieveSize(JNIEnv
*env,
+ jobject this, jlong id, jlong addr) {
+ VMPool *pool;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ void* p = addr_from_java(addr);
+ jlong ret = vsize(pool, p);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_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 addr %X\n",
nativebuf);
+ ret = addr_to_java(nativebuf);
+ }
+// fprintf(stderr, "ngetByteBufferAddress returned addr %016lx\n", ret);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nresizeByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size) {
+ VMPool *pool;
+ jobject ret = NULL;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*) (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = vrealloc(pool, nativebuf, size, 0);
+ if (NULL != nativebuf) {
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf, size);
+ }
+ }
+ }
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ndestroyByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf) {
+ VMPool *pool;
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ vfree(pool, nativebuf);
+ }
+ }
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+
+JNIEXPORT
+void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nsetHandler(
+ JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
+{
+ throw(env, "setkey()/getkey() temporarily not supported");
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ngetHandler(JNIEnv
*env,
+ jobject this, jlong id, jlong key) {
+ throw(env, "setkey()/getkey() temporarily not supported");
+ return 0;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_nhandlerCapacity(
+ JNIEnv *env, jobject this) {
+ throw(env, "setkey()/getkey() temporarily not supported");
+ return 0;
+}
+
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ngetBaseAddress(JNIEnv
*env,
+ jobject this, jlong id) {
+ return 0L;
+}
+
+JNIEXPORT
+jlong JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_ninit(JNIEnv
*env, jclass this,
+ jlong capacity, jstring pathname, jboolean isnew) {
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ VMPool *pool;
+ 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,
+ VMEM_MIN_POOL > capacity ? VMEM_MIN_POOL : capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ g_vmpool_arr = realloc(g_vmpool_arr, (g_vmpool_count + 1) * sizeof(VMPool));
+ if (NULL != g_vmpool_arr) {
+ pool = g_vmpool_arr + g_vmpool_count;
+ pool->vmp = vmp;
+ pool->capacity = capacity;
+ pthread_mutex_init(&pool->mutex, NULL);
+ ret = g_vmpool_count;
+ g_vmpool_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_memory_internal_PMDKVMemServiceImpl_nclose
+(JNIEnv *env, jobject this, jlong id)
+{
+ VMPool *pool;
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ pool = g_vmpool_arr + id;
+ pthread_mutex_lock(&pool->mutex);
+ if (NULL != pool->vmp) {
+ pool->vmp = NULL;
+ pool->capacity = 0;
+ }
+ pthread_mutex_unlock(&pool->mutex);
+ pthread_mutex_destroy(&pool->mutex);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+__attribute__((destructor)) void fini(void) {
+ int i;
+ VMPool *pool;
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ if (NULL != g_vmpool_arr) {
+ for (i = 0; i < g_vmpool_count; ++i) {
+ pool = g_vmpool_arr + i;
+ if (NULL != pool->vmp) {
+ pool->vmp = NULL;
+ pool->capacity = 0;
+ pthread_mutex_destroy(&pool->mutex);
+ }
+ }
+ free(g_vmpool_arr);
+ g_vmpool_arr = NULL;
+ g_vmpool_count = 0;
+ }
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ pthread_rwlock_destroy(&g_vmem_rwlock);
+}
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.h
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.h
new file mode 100644
index 0000000..6a4c032
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/native/org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl.h
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <jni.h>
+/* Header for class
org_apache_mnemonic_service_memory_internal_VMemServiceImpl */
+
+#include "common.h"
+
+#ifndef
_Included_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl
+#define
_Included_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
Java_org_apache_mnemonic_service_memory_internal_PMDKVMemServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.VolatileMemoryAllocatorService
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.VolatileMemoryAllocatorService
new file mode 100644
index 0000000..0901ac6
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memory.VolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.memory.internal.PMDKVMemServiceImpl
diff --git
a/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/log4j.properties
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/log4j.properties
new file mode 100644
index 0000000..24b0e3c
--- /dev/null
+++
b/mnemonic-memory-services/mnemonic-pmdk-vmem-service/src/main/resources/log4j.properties
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Root logger option
+log4j.rootLogger=INFO, file, stdout
+
+#to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}:
%m%n
+
+#to log.log file
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.File=log.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.MaxBackupIndex=10
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}:
%m%n
diff --git a/mnemonic-memory-services/pom.xml b/mnemonic-memory-services/pom.xml
index 99b5d14..bc61b7b 100644
--- a/mnemonic-memory-services/pom.xml
+++ b/mnemonic-memory-services/pom.xml
@@ -44,6 +44,8 @@
<module>mnemonic-pmalloc-service</module>
<module>mnemonic-sys-vmem-service</module>
<module>mnemonic-java-vmem-service</module>
+ <module>mnemonic-pmdk-vmem-service</module>
+ <module>mnemonic-pmdk-pmem-service</module>
</modules>
<dependencies>
diff --git a/pom.xml b/pom.xml
index 316881e..8039ac9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -372,7 +372,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.20.1</version>
+ <version>3.0.0-M3</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<enableAssertions>true</enableAssertions>