Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master b0c45c3ef -> c2ce66b56


MNEMONIC-115: Add a new memory service nvml-pmem


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/c2ce66b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/c2ce66b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/c2ce66b5

Branch: refs/heads/master
Commit: c2ce66b56fa0c9005b2a7aa9b6b96dd92a67df1f
Parents: b0c45c3
Author: Wang, Gang(Gary) <gang1.w...@intel.com>
Authored: Fri Sep 16 16:46:26 2016 -0700
Committer: Wang, Gang(Gary) <gang1.w...@intel.com>
Committed: Sat Sep 17 00:45:53 2016 -0700

----------------------------------------------------------------------
 .../src/main/native/CMakeLists.txt              |   2 +-
 .../mnemonic-nvml-pmem-service/pom.xml          | 168 ++++++++++
 .../memoryservice/internal/PMemServiceImpl.java | 158 +++++++++
 .../src/main/native/CMakeLists.txt              |  60 ++++
 .../src/main/native/LICENSE                     | 202 +++++++++++
 .../src/main/native/common.c                    | 103 ++++++
 .../src/main/native/common.h                    |  56 ++++
 .../src/main/native/config.h.in                 |  24 ++
 .../src/main/native/layout.h                    |  54 +++
 ...ice_memoryservice_internal_PMemServiceImpl.c | 336 +++++++++++++++++++
 ...ice_memoryservice_internal_PMemServiceImpl.h |  48 +++
 ...oryservice.NonVolatileMemoryAllocatorService |   1 +
 .../src/main/resources/log4j.properties         |  33 ++
 .../src/main/native/CMakeLists.txt              |   6 +-
 .../src/main/native/CMakeLists.txt              |   6 +-
 mnemonic-memory-services/pom.xml                |   1 +
 16 files changed, 1251 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git 
a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
 
b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
index 2d9ed6d..afe1eda 100644
--- 
a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
+++ 
b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
@@ -27,7 +27,7 @@ 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(CMAKE_BUILD_TYPE "Release")
-set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
+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)

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-pmem-service/pom.xml 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/pom.xml
new file mode 100644
index 0000000..c5861a3
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-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.2.0-incubating-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>mnemonic-nvml-pmem-service</artifactId>
+  <name>mnemonic-nvml-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>

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
new file mode 100644
index 0000000..4dd88be
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
@@ -0,0 +1,158 @@
+/*
+ * 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.memoryservice.internal;
+
+import 
org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+
+import java.nio.ByteBuffer;
+
+public class PMemServiceImpl implements NonVolatileMemoryAllocatorService {
+  static {
+    try {
+      NativeLibraryLoader.loadFromJar("pmemallocator");
+    } catch (Exception e) {
+      throw new Error(e);
+    }
+  }
+
+  @Override
+  public String getServiceId() {
+    return "pmem";
+  }
+
+  @Override
+  public long init(long capacity, String uri, boolean isnew) {
+    return ninit(capacity, uri, isnew);
+  }
+
+  @Override
+  public void close(long id) {
+    nclose(id);
+  }
+
+  @Override
+  public void sync(long id) {
+    nsync(id);
+  }
+
+  @Override
+  public long 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 address, long size, boolean initzero) {
+    return nreallocate(id, address, size, initzero);
+  }
+
+  @Override
+  public void free(long id, long address) {
+    nfree(id, address);
+  }
+
+  @Override
+  public ByteBuffer createByteBuffer(long id, long size) {
+    return ncreateByteBuffer(id, size);
+  }
+
+  @Override
+  public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+    return nresizeByteBuffer(id, bytebuf, size);
+  }
+
+  @Override
+  public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+    ndestroyByteBuffer(id, bytebuf);
+  }
+
+  @Override
+  public ByteBuffer retrieveByteBuffer(long id, long handler) {
+    return nretrieveByteBuffer(id, handler);
+  }
+
+  @Override
+  public long retrieveSize(long id, long handler) {
+    return nretrieveSize(id, handler);
+  }
+
+  @Override
+  public long getByteBufferHandler(long id, ByteBuffer buf) {
+    return ngetByteBufferHandler(id, buf);
+  }
+
+  @Override
+  public void setHandler(long id, long key, long handler) {
+    nsetHandler(id, key, handler);
+  }
+
+  @Override
+  public long getHandler(long id, long key) {
+    return ngetHandler(id, key);
+  }
+
+  @Override
+  public long handlerCapacity(long id) {
+    return nhandlerCapacity(id);
+  }
+
+  @Override
+  public long getBaseAddress(long id) {
+    return ngetBaseAddress(id);
+  }
+
+  protected native long ninit(long capacity, String uri, boolean isnew);
+
+  protected native void nclose(long id);
+
+  protected native void nsync(long id);
+
+  protected native long ncapacity(long id);
+
+  protected native long nallocate(long id, long size, boolean initzero);
+
+  protected native long nreallocate(long id, long address, long size, boolean 
initzero);
+
+  protected native void nfree(long id, long address);
+
+  protected native ByteBuffer ncreateByteBuffer(long id, long size);
+
+  protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, 
long size);
+
+  protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+
+  protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
+
+  protected native long nretrieveSize(long id, long handler);
+
+  protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
+
+  protected native void nsetHandler(long id, long key, long handler);
+
+  protected native long ngetHandler(long id, long key);
+
+  protected native long nhandlerCapacity(long id);
+
+  protected native long ngetBaseAddress(long id);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/CMakeLists.txt
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/CMakeLists.txt
new file mode 100644
index 0000000..2876ba7
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-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(pmemallocator)
+
+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(pmemallocator_VERSION_MAJOR 0)
+set(pmemallocator_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)
+if (NOT LIBPMEM_LIBRARIES)
+   message(FATAL_ERROR "not found pmem library")
+endif (NOT LIBPMEM_LIBRARIES)
+
+find_library(LIBPMEMOBJ_LIBRARIES NAMES libpmemobj.a)
+if (NOT LIBPMEMOBJ_LIBRARIES)
+   message(FATAL_ERROR "not found pmemobj library")
+endif (NOT LIBPMEMOBJ_LIBRARIES)
+
+add_library(pmemallocator SHARED common.c 
org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c)
+target_include_directories(pmemallocator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(pmemallocator ${LIBPMEMOBJ_LIBRARIES} 
${LIBPMEM_LIBRARIES})
+
+include (InstallRequiredSystemLibraries)
+set (CPACK_RESOURCE_FILE_LICENSE
+  "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+set (CPACK_PACKAGE_VERSION_MAJOR "${pmemallocator_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${pmemallocator_VERSION_MINOR}")
+include (CPack)

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/LICENSE
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/LICENSE 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/LICENSE
new file mode 100644
index 0000000..8f71f43
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-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.
+

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.c
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.c 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.c
new file mode 100644
index 0000000..9a20fcc
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.c
@@ -0,0 +1,103 @@
+/**
+ * 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.
+ */
+void throw(JNIEnv* env, const char* msg) {
+  if (msg == NULL)
+    msg = sys_errlist[errno];
+
+  jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
+  (*env)->ThrowNew(env, xklass, msg);
+}
+
+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;
+}
+
+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);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.h
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.h 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/common.h
new file mode 100644
index 0000000..5e6f2cc
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-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

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/config.h.in
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/config.h.in
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/config.h.in
new file mode 100644
index 0000000..9950a43
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-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

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/layout.h
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/layout.h 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/layout.h
new file mode 100644
index 0000000..c5ddf9e
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/layout.h
@@ -0,0 +1,54 @@
+/**
+ * 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];
+};
+
+POBJ_LAYOUT_BEGIN(memory_service);
+POBJ_LAYOUT_ROOT(memory_service, struct pmem_root);
+POBJ_LAYOUT_TOID(memory_service, uint8_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;
+  pthread_mutex_t mutex;
+} PMPool;
+
+#define PMBHSZ (sizeof(PMBHeader))
+
+#ifdef __cplusplus
+}
+#endif
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
new file mode 100644
index 0000000..0975bbd
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
@@ -0,0 +1,336 @@
+/**
+ * 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_memoryservice_internal_PMemServiceImpl.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_memoryservice_internal_PMemServiceImpl_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;
+  pthread_mutex_lock(&pool->mutex);
+  p = prealloc(pool, NULL, size, initzero ? 1 : 0);
+  if (NULL != p) {
+    ret = addr_to_java(p);
+  }
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+  return ret;
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nreallocate(JNIEnv*
 env,
+    jobject this, jlong id, jlong e_addr, jlong size, jboolean initzero) {
+  PMPool *pool;
+  jlong ret = 0L;
+  void *p;
+  pthread_rwlock_rdlock(&g_pmp_rwlock);
+  pool = g_pmpool_arr + id;
+  pthread_mutex_lock(&pool->mutex);
+  p = addr_from_java(e_addr);
+  p = prealloc(pool, p, size, initzero ? 1 : 0);
+  if (NULL != p) {
+    ret = addr_to_java(p);
+  }
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+  return ret;
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nfree(
+    JNIEnv* env,
+    jobject this, jlong id,
+    jlong e_addr)
+{
+  PMPool *pool;
+  void* nativebuf;
+  pthread_rwlock_rdlock(&g_pmp_rwlock);
+  pool = g_pmpool_arr + id;
+  pthread_mutex_lock(&pool->mutex);
+  //fprintf(stderr, "nfree Get Called %ld, %X\n", id, address);
+  nativebuf = addr_from_java(e_addr);
+  pfree(pool, nativebuf);
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nsync(
+    JNIEnv* env,
+    jobject this, jlong id)
+{
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_ncapacity(
+    JNIEnv* env,
+    jobject this, jlong id)
+{
+  PMPool *pool;
+  jlong ret;
+  TOID(struct pmem_root) root;
+  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_memoryservice_internal_PMemServiceImpl_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;
+  pthread_mutex_lock(&pool->mutex);
+  nativebuf = prealloc(pool, NULL, size, 0);
+  if (NULL != nativebuf) {
+    ret = (*env)->NewDirectByteBuffer(env, nativebuf, size);
+  }
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+  return ret;
+}
+
+JNIEXPORT
+jobject JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nretrieveByteBuffer(
+    JNIEnv *env, jobject this, jlong id, jlong e_addr) {
+  jobject ret = NULL;
+  void* p = addr_from_java(e_addr);
+  if (NULL != p) {
+    void* nativebuf = p - PMBHSZ;
+    ret = (*env)->NewDirectByteBuffer(env, p, ((PMBHeader *) nativebuf)->size 
- PMBHSZ);
+  }
+  return ret;
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nretrieveSize(JNIEnv
 *env,
+    jobject this, jlong id, jlong e_addr) {
+  jlong ret = 0L;
+  void* p = addr_from_java(e_addr);
+  if (NULL != p) {
+    void* nativebuf = p - PMBHSZ;
+    ret = ((PMBHeader *) nativebuf)->size - PMBHSZ;
+//        fprintf(stderr, "### nretrieveSize size: %lld, %X ###, header size: 
%ld \n",
+//                     ((PMBHeader *)nativebuf)->size, 
nativebuf-b_addr(*(g_pmpool_arr + id)), PMBHSZ);
+  }
+  return ret;
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_ngetByteBufferHandler(
+    JNIEnv *env, jobject this, jlong id, jobject bytebuf) {
+//     fprintf(stderr, "ngetByteBufferAddress Get Called %X, %X\n", env, 
bytebuf);
+  jlong ret = 0L;
+  if (NULL != bytebuf) {
+    void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+//     fprintf(stderr, "ngetByteBufferAddress Get Native address %X\n", 
nativebuf);
+    ret = addr_to_java(nativebuf);
+  }
+//    fprintf(stderr, "ngetByteBufferAddress returned address %016lx\n", ret);
+  return ret;
+}
+
+JNIEXPORT
+jobject JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_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;
+  pthread_mutex_lock(&pool->mutex);
+  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_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+  return ret;
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_ndestroyByteBuffer(
+    JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+  PMPool *pool;
+  pthread_rwlock_rdlock(&g_pmp_rwlock);
+  pool = g_pmpool_arr + id;
+  pthread_mutex_lock(&pool->mutex);
+  if (NULL != bytebuf) {
+    void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+    pfree(pool, nativebuf);
+  }
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_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;
+  pthread_mutex_lock(&pool->mutex);
+  root = POBJ_ROOT(pool->pop, struct pmem_root);
+  if (key < MAX_HANDLER_STORE_LEN && key >= 0) {
+    D_RW(root)->hdl_buf[key] = value;
+  }
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_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;
+  pthread_mutex_lock(&pool->mutex);
+  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_mutex_unlock(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+  return ret;
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nhandlerCapacity(
+    JNIEnv *env, jobject this) {
+  return MAX_HANDLER_STORE_LEN;
+}
+
+JNIEXPORT
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_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_memoryservice_internal_PMemServiceImpl_ninit(JNIEnv
 *env,
+    jclass this, jlong capacity, jstring pathname, jboolean isnew) {
+  PMPool *pool;
+  TOID(struct pmem_root) root;
+  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!");
+  }
+  if (capacity < PMEMOBJ_MIN_POOL) {
+    capacity = PMEMOBJ_MIN_POOL;
+  }
+  if (access(mpathname, F_OK)) {
+    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;
+    pthread_mutex_init(&pool->mutex, NULL);
+    root = POBJ_ROOT(pool->pop, struct pmem_root);
+    pool->uuid_lo = root.oid.pool_uuid_lo;
+    pool->base = (void*)pop;
+    pool->capacity = 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_memoryservice_internal_PMemServiceImpl_nclose
+(JNIEnv *env, jobject this, jlong id)
+{
+  PMPool *pool;
+  pthread_rwlock_wrlock(&g_pmp_rwlock);
+  pool = g_pmpool_arr + id;
+  pthread_mutex_lock(&pool->mutex);
+  pmemobj_close(pool->pop);
+  pool->pop = NULL;
+  pool->base = NULL;
+  pool->uuid_lo = 0;
+  pool->capacity = 0;
+  pthread_mutex_unlock(&pool->mutex);
+  pthread_mutex_destroy(&pool->mutex);
+  pthread_rwlock_unlock(&g_pmp_rwlock);
+}
+
+__attribute__((destructor)) void fini(void) {
+  int i;
+  PMPool *pool;
+  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;
+        pthread_mutex_destroy(&pool->mutex);
+      }
+    }
+    free(g_pmpool_arr);
+    g_pmpool_arr = NULL;
+    g_pmpool_count = 0;
+  }
+  pthread_rwlock_destroy(&g_pmp_rwlock);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.h
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.h
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.h
new file mode 100644
index 0000000..543fee2
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.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_memoryservice_internal_PMemServiceImpl */
+
+#include "common.h"
+
+#ifndef 
_Included_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl
+#define 
_Included_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     
org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl
+ * Method:    jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class:     
org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl
+ * Method:    jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService
new file mode 100644
index 0000000..e4b40da
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.memoryservice.internal.PMemServiceImpl

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/log4j.properties
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/resources/log4j.properties
new file mode 100644
index 0000000..24b0e3c
--- /dev/null
+++ 
b/mnemonic-memory-services/mnemonic-nvml-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

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
index 4393912..0611d6c 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
+++ 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} 
"${CMAKE_SOURCE_DIR}/CMakeModules/")
 set(vmemallocator_VERSION_MAJOR 0)
 set(vmemallocator_VERSION_MINOR 0)
 set(CMAKE_BUILD_TYPE "Release")
-set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
+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)
@@ -50,6 +50,6 @@ target_link_libraries(vmemallocator ${LIBVMEM_LIBRARIES})
 include (InstallRequiredSystemLibraries)
 set (CPACK_RESOURCE_FILE_LICENSE
   "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
-set (CPACK_PACKAGE_VERSION_MAJOR "${pmalloc_VERSION_MAJOR}")
-set (CPACK_PACKAGE_VERSION_MINOR "${pmalloc_VERSION_MINOR}")
+set (CPACK_PACKAGE_VERSION_MAJOR "${vmemallocator_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${vmemallocator_VERSION_MINOR}")
 include (CPack)

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
index d70aaa5..641808f 100644
--- 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
+++ 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} 
"${CMAKE_SOURCE_DIR}/CMakeModules/")
 set(pmallocallocator_VERSION_MAJOR 0)
 set(pmallocallocator_VERSION_MINOR 0)
 set(CMAKE_BUILD_TYPE "Release")
-set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
+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)
@@ -50,6 +50,6 @@ target_link_libraries(pmallocallocator 
${LIBPMALLOC_LIBRARIES})
 include (InstallRequiredSystemLibraries)
 set (CPACK_RESOURCE_FILE_LICENSE
   "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
-set (CPACK_PACKAGE_VERSION_MAJOR "${pmalloc_VERSION_MAJOR}")
-set (CPACK_PACKAGE_VERSION_MINOR "${pmalloc_VERSION_MINOR}")
+set (CPACK_PACKAGE_VERSION_MAJOR "${pmallocallocator_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${pmallocallocator_VERSION_MINOR}")
 include (CPack)

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/c2ce66b5/mnemonic-memory-services/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/pom.xml b/mnemonic-memory-services/pom.xml
index 2b8a07a..d55b7f4 100644
--- a/mnemonic-memory-services/pom.xml
+++ b/mnemonic-memory-services/pom.xml
@@ -40,6 +40,7 @@
 
   <modules>
     <module>mnemonic-nvml-vmem-service</module>
+    <module>mnemonic-nvml-pmem-service</module>
     <module>mnemonic-pmalloc-service</module>
   </modules>
 

Reply via email to