You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mnemonic.apache.org by ga...@apache.org on 2016/05/06 00:39:51 UTC
[02/11] incubator-mnemonic git commit: MNEMONIC-40 - Clean up
assembled source package for release MNEMONIC-41 - Create a script for
preparing a release of a single package with signing and hashing MNEMONIC-42
- Normalize the names of project submodules
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-core/src/test/java/org/apache/mnemonic/NonVolatileMemAllocatorNGTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/NonVolatileMemAllocatorNGTest.java b/mnemonic-core/src/test/java/org/apache/mnemonic/NonVolatileMemAllocatorNGTest.java
new file mode 100644
index 0000000..48b6be5
--- /dev/null
+++ b/mnemonic-core/src/test/java/org/apache/mnemonic/NonVolatileMemAllocatorNGTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+
+public class NonVolatileMemAllocatorNGTest {
+ @Test
+ public void testPMemByteBuffer() {
+ Random randomGenerator = new Random();
+ NonVolatileMemAllocator act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./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));
+ }
+ // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
+ 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!!!"));
+ // mbh.destroy();
+ }
+ act.close();
+ }
+
+ @Test
+ public void testGetBufferAddress() {
+ NonVolatileMemAllocator act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./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("pmalloc"),
+ 1024 * 1024 * 1024, "./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("pmalloc"),
+ 1024 * 1024 * 1024, "./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;
+ 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();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-core/src/test/java/org/apache/mnemonic/Payload.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/Payload.java b/mnemonic-core/src/test/java/org/apache/mnemonic/Payload.java
new file mode 100644
index 0000000..6a23707
--- /dev/null
+++ b/mnemonic-core/src/test/java/org/apache/mnemonic/Payload.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * a dummy object that is used for other test cases.
+ *
+ *
+ *
+ */
+public class Payload implements java.io.Serializable, Comparable<Payload> {
+
+ private static final long serialVersionUID = 187397440699436500L;
+
+ public Payload(int iv, String strv, double dv) {
+ ival = iv;
+ strval = strv;
+ dval = dv;
+ }
+
+ public int ival;
+ public String strval;
+ public double dval;
+
+ @Override
+ public int compareTo(Payload pl) {
+ return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0 : 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java b/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java
new file mode 100644
index 0000000..7d5942e
--- /dev/null
+++ b/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+/**
+ *
+ *
+ */
+
+@DurableEntity
+public abstract class Person<E> implements Durable, Comparable<Person<E>> {
+ E element;
+
+ @Override
+ public void initializeAfterCreate() {
+ System.out.println("Initializing After Created");
+ }
+
+ @Override
+ public void initializeAfterRestore() {
+ System.out.println("Initializing After Restored");
+ }
+
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+
+ }
+
+ public void testOutput() throws RetrieveDurableEntityError {
+ System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
+ null == getMother() ? "No Recorded Mother" : "Has Recorded Mother");
+ }
+
+ public int compareTo(Person<E> anotherPerson) {
+ int ret = 0;
+ if (0 == ret) {
+ ret = getAge().compareTo(anotherPerson.getAge());
+ }
+ if (0 == ret) {
+ ret = getName().compareTo(anotherPerson.getName());
+ }
+ return ret;
+ }
+
+ @DurableGetter
+ public abstract Short getAge();
+
+ @DurableSetter
+ public abstract void setAge(Short age);
+
+ @DurableGetter
+ public abstract String getName() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setName(String name, boolean destroy)
+ throws OutOfHybridMemory, RetrieveDurableEntityError;
+
+ @DurableGetter
+ public abstract Person<E> getMother() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setMother(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+
+ @DurableGetter
+ public abstract Person<E> getFather() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setFather(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-core/src/test/java/org/apache/mnemonic/VolatileMemAllocatorNGTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/VolatileMemAllocatorNGTest.java b/mnemonic-core/src/test/java/org/apache/mnemonic/VolatileMemAllocatorNGTest.java
new file mode 100644
index 0000000..6c96be7
--- /dev/null
+++ b/mnemonic-core/src/test/java/org/apache/mnemonic/VolatileMemAllocatorNGTest.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 VolatileMemAllocatorNGTest {
+ /**
+ * test to allocate MemBufferHolder objects and then verify them.
+ */
+ @Test
+ public void testMemByteBuffer() {
+ Random randomGenerator = new Random();
+ Allocator<VolatileMemAllocator> act = new VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
+ 1024 * 1024 * 1024, ".", true);
+ 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("vmem"),
+ 1024 * 1024 * 1024, ".", true);
+ 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();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-core/src/test/resources/testng.xml
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/test/resources/testng.xml b/mnemonic-core/src/test/resources/testng.xml
new file mode 100644
index 0000000..595f68d
--- /dev/null
+++ b/mnemonic-core/src/test/resources/testng.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<suite name="Mnenomic Core test Suite" verbose="1" parallel="tests" thread-count="1">
+ <test name="Memory Clustering test" >
+ <classes>
+ <class name="org.apache.mnemonic.DurableListNGTest" />
+ </classes>
+ </test>
+</suite>
+
+<!--
+ <class name="org.apache.mnemonic.MemBufferHolderCachePoolNGTest" />
+ <class name="org.apache.mnemonic.NonVolatileMemAllocatorNGTest" />
+ <class name="org.apache.mnemonic.ByteBufferSerializerNGTest" />
+ <class name="org.apache.mnemonic.MemClusteringNGTest" />
+ <class name="org.apache.mnemonic.VolatileMemAllocatorNGTest" />
+ <class name="org.apache.mnemonic.DurablePersonNGTest" />
+ <class name="org.apache.mnemonic.DurableListNGTest" />
+
+ -->
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-examples/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-examples/pom.xml b/mnemonic-examples/pom.xml
new file mode 100644
index 0000000..c8c5d9c
--- /dev/null
+++ b/mnemonic-examples/pom.xml
@@ -0,0 +1,114 @@
+<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-parent</artifactId>
+ <version>0.1.2-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>mnemonic-examples</artifactId>
+ <name>mnemonic-examples</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.mnemonic</groupId>
+ <artifactId>mnemonic-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </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>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>${project.groupId}.examples.Main</mainClass>
+ </transformer>
+ </transformers>
+ <minimizeJar>true</minimizeJar>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>doc</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <additionalparam>-Xdoclint:all -Xdoclint:-missing</additionalparam>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>example</id>
+ <activation>
+ <property>
+ <name>example</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <executable>java</executable>
+ <arguments>
+ <argument>-Djava.ext.dirs=${memory.service.dist.dir}</argument>
+ <argument>-ea</argument>
+ <argument>-classpath</argument>
+ <classpath />
+ <argument>${project.groupId}.examples.Main</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Main.java
----------------------------------------------------------------------
diff --git a/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Main.java b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Main.java
new file mode 100644
index 0000000..964480b
--- /dev/null
+++ b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Main.java
@@ -0,0 +1,200 @@
+/*
+ * 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.examples;
+
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+import org.apache.mnemonic.VolatileMemAllocator;
+import org.apache.mnemonic.CommonAllocator;
+import org.apache.mnemonic.MemBufferHolder;
+import org.apache.mnemonic.MemChunkHolder;
+import org.apache.mnemonic.MemClustering;
+import org.apache.mnemonic.Reclaim;
+import org.apache.mnemonic.SysMemAllocator;
+import org.apache.mnemonic.Utils;
+
+import sun.misc.Unsafe;
+
+/**
+ * Main is the class of example.
+ *
+ */
+@SuppressWarnings("restriction")
+public class Main {
+
+ /**
+ * Run a example code to demonstrate some basic functionalities.
+ *
+ * @param argv
+ * array of commandline parameters
+ */
+ public static void main(String[] argv) throws Exception {
+ Random randomGenerator = new Random();
+
+ /* Generate configuration for each node */
+ /*
+ * Currently only one node is supported due to the external native code
+ * 'vmem' returns null for multiple 'vmem' allocator instantialization
+ */
+ MemClustering.NodeConfig ncs[] = new MemClustering.NodeConfig[] {
+ new MemClustering.NodeConfig(new SysMemAllocator(1024 * 1024 * 20, true).disableActiveGC(),
+ MemClustering.PerformanceLevel.FASTEST),
+
+ // new MemClustering.NodeConfig(new
+ // BigDataMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new
+ // BigDataMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.NORMAL),
+ new MemClustering.NodeConfig(
+ new VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
+ // Utils.getVolatileMemoryAllocatorService("pmalloc"),
+ // 1024 * 1024 * 20, "./example.dat", true),
+ MemClustering.PerformanceLevel.SLOW), };
+
+ for (MemClustering.NodeConfig nc : ncs) {
+ /**
+ * set a reclaimer for memory buffers
+ */
+ nc.getAllocator().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;
+ }
+ });
+ /**
+ * set a reclaimer for memory chunks
+ */
+ nc.getAllocator().setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out
+ .println(String.format("Reclaim Memory Chunk: %X Size: %s", mres, null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ }
+
+ /* Deploy Memory Clustering */
+ MemClustering mclst = new MemClustering(ncs);
+
+ /**
+ * Set event callback for allocator changing. this callback is used to trace
+ * the event of spilling out of allocation when previous allocator is unable
+ * to meet the allocation requirement so trying to switch to next allocator.
+ */
+ mclst.setAllocatorChange(new MemClustering.AllocatorChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel lvl, CommonAllocator prevallocator,
+ CommonAllocator tgtallocator) {
+ System.out.println(String.format("AllocatorChanged: %s, %X -> %X", lvl.name(),
+ System.identityHashCode(prevallocator), System.identityHashCode(tgtallocator)));
+ }
+ });
+
+ /**
+ * Set event callback for performance level changing. this callback is used
+ * to trace the event of downgrading to low level performance allocation.
+ */
+ mclst.setPerformanceLevelChange(new MemClustering.PerformanceLevelChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel prevlvl, MemClustering.PerformanceLevel lvl) {
+ System.out.println(
+ String.format("PerfLevelChanged: %s -> %s", null == prevlvl ? "NULL" : prevlvl.name(), lvl.name()));
+ }
+ });
+
+ /**
+ * Start to create a piece of memory resource backed ByteBuffer and then
+ * automatically release it or manually release it every six objects.
+ */
+ System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
+ + "and Manual Destruction of Big Memory ByteBuffer.]]" + Utils.ANSI_RESET);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 50; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ if (null == mbh) {
+ throw new OutOfMemoryError("Memory Cluster out of memory!");
+ }
+ for (int i = 0; i < size; i++) {
+ /**
+ * Manipulate the ByteBuffer backed by external memory resource. Note:
+ * Do not assigned internal ByteBuffer object to any variable, only use
+ * function get() to access it all time.
+ */
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx, size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ if (idx % 6 == 0) {
+ /**
+ * Force to release memory resource of specified ByteBuffer object
+ * immediately.
+ */
+ System.out.println(String.format("Manually destroy Buffer at %X.", System.identityHashCode(mbh.get())));
+ mbh.destroy();
+ }
+ System.out.println("-------------------");
+ }
+ // Utils.collectGarbage();
+
+ /**
+ * Start to create a piece of memory resource backed chunk and then
+ * automatically release it or manually release it every six chunks.
+ */
+ System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
+ + "and Manual Destruction of Big Memory Chunk.]]" + Utils.ANSI_RESET);
+ Unsafe unsafe = Utils.getUnsafe();
+ MemChunkHolder<?> mch;
+ for (int idx = 1; idx <= 50; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mch = mclst.createChunk(size);
+ if (null == mch) {
+ throw new OutOfMemoryError("Memory Cluster out of memory!");
+ }
+ // mch.cancelAutoReclaim();
+ mch.resize(size - 10);
+ System.out.printf("chunk size is %d \n", mch.getSize());
+ for (int i = 0; i < mch.getSize(); i++) {
+ /**
+ * Manipulate the chunk data. Note: Do not assigned the internal memory
+ * space to any variable, please always use function get() to access it
+ * at all time.
+ */
+ unsafe.putByte(mch.get() + i, (byte) randomGenerator.nextInt(255));
+ }
+ System.out.println(String.format("[Seq.%d] size %d - %d at %X.", idx, size, mch.getSize(), mch.get()));
+ if (idx % 6 == 0) {
+ /**
+ * Force to release memory resource of specified Chunk object
+ * Immediately.
+ */
+ System.out.println(String.format("Manually destroy Chunk at %X.", mch.get()));
+ mch.destroy();
+ }
+ System.out.println("-------------------");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/pom.xml b/mnemonic-memory-services/mnemonic-nvml-vmem-service/pom.xml
new file mode 100644
index 0000000..0d1a2e1
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/pom.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0"?>
+<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.1.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mnemonic-nvml-vmem-service</artifactId>
+ <name>mnemonic-nvml-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>
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
new file mode 100644
index 0000000..d7084c0
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
@@ -0,0 +1,102 @@
+/*
+ * 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.allocatorservice.internal;
+
+import org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+
+import java.nio.ByteBuffer;
+
+public class VMemServiceImpl implements VolatileMemoryAllocatorService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("vmemallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public String getServiceId() {
+ return "vmem";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
+
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
+
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
+
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+ protected native void nclose(long id);
+
+ protected native void nsync(long id);
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
+
+ protected native void nfree(long id, long address);
+
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
+
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
+
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/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
new file mode 100644
index 0000000..537508f
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/CMakeLists.txt
@@ -0,0 +1,38 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(vmemallocator)
+
+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(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_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 vmem)
+if (NOT LIBVMEM_LIBRARIES)
+ message(FATAL_ERROR "not found vmem library")
+endif (NOT LIBVMEM_LIBRARIES)
+
+add_library(vmemallocator SHARED common.c org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c)
+target_include_directories(vmemallocator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(vmemallocator vmem)
+
+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}")
+include (CPack)
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/LICENSE
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/LICENSE b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/LICENSE
new file mode 100644
index 0000000..8f71f43
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-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.
+
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.c
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.c b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.c
new file mode 100644
index 0000000..143743e
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.c
@@ -0,0 +1,49 @@
+/**
+ * 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;
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.h
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.h b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.h
new file mode 100644
index 0000000..f03dbff
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/common.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.
+ */
+
+#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>
+
+void throw(JNIEnv* env, const char* msg);
+
+void* addr_from_java(jlong addr);
+
+jlong addr_to_java(void* p);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/config.h.in
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/config.h.in b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/config.h.in
new file mode 100644
index 0000000..acc54d6
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/config.h.in
@@ -0,0 +1,6 @@
+#ifndef GUARD
+#define GUARD
+
+#cmakedefine _CONFIG_HEADER_H_
+
+#endif //GUARD
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
new file mode 100644
index 0000000..eb02fe2
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
@@ -0,0 +1,186 @@
+/**
+ * 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_allocatorservice_internal_VMemServiceImpl.h"
+
+#include <libvmem.h>
+
+static VMEM **g_vmp_ptr = NULL;
+static size_t g_vmp_count = 0;
+
+static pthread_mutex_t *g_vmem_mutex_ptr = NULL;
+
+static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nallocate(JNIEnv* env,
+ jobject this, jlong id, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nreallocate(JNIEnv* env,
+ jobject this, jlong id, jlong address, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+
+ void* p = addr_from_java(address);
+
+ void* nativebuf = vmem_realloc(*(g_vmp_ptr + id), p, size);
+
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nfree(
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = addr_from_java(address);
+ if (nativebuf != NULL)
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nsync(
+ JNIEnv* env,
+ jobject this, jlong id)
+{
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ncreateByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jlong size) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ void* nativebuf = vmem_malloc(*(g_vmp_ptr + id), size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nresizeByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*) (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = vmem_realloc(*(g_vmp_ptr + id), nativebuf, size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
+ }
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ndestroyByteBuffer(
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
+ }
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ninit(JNIEnv *env, jclass this,
+ jlong capacity, jstring pathname, jboolean isnew) {
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ size_t ret = -1;
+ VMEM *vmp = NULL;
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ if ((vmp = vmem_create(mpathname, capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ g_vmp_ptr = realloc(g_vmp_ptr, (g_vmp_count + 1) * sizeof(VMEM*));
+ g_vmem_mutex_ptr = realloc(g_vmem_mutex_ptr, (g_vmp_count + 1) * sizeof(pthread_mutex_t));
+ if (NULL != g_vmp_ptr && NULL != g_vmem_mutex_ptr) {
+ g_vmp_ptr[g_vmp_count] = vmp;
+ pthread_mutex_init(g_vmem_mutex_ptr + g_vmp_count, NULL);
+ ret = g_vmp_count;
+ g_vmp_count++;
+ } else {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init Out of memory!");
+ }
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
+}
+
+JNIEXPORT
+void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nclose
+(JNIEnv *env, jobject this, jlong id)
+{
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+}
+
+__attribute__((destructor)) void fini(void) {
+ int i;
+ if (NULL != g_vmp_ptr) {
+ for (i = 0; i < g_vmp_count; ++i) {
+ if (NULL != *(g_vmp_ptr + i)) {
+ /* vmem_close(*(g_vmp_ptr + i)); undefined function */
+ *(g_vmp_ptr + i) = NULL;
+ pthread_mutex_destroy(g_vmem_mutex_ptr + i);
+ }
+ }
+ free(g_vmp_ptr);
+ g_vmp_ptr = NULL;
+ free(g_vmem_mutex_ptr);
+ g_vmem_mutex_ptr = NULL;
+ g_vmp_count = 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
new file mode 100644
index 0000000..bdea3a7
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.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_allocatorservice_internal_VMemServiceImpl */
+
+#include "common.h"
+
+#ifndef _Included_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+#define _Included_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
new file mode 100644
index 0000000..4aacb0d
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService
@@ -0,0 +1 @@
+org.apache.mnemonic.service.allocatorservice.internal.VMemServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/mnemonic-memory-services/mnemonic-pmalloc-service/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-pmalloc-service/pom.xml b/mnemonic-memory-services/mnemonic-pmalloc-service/pom.xml
new file mode 100644
index 0000000..2972ee7
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-pmalloc-service/pom.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0"?>
+<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.1.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mnemonic-pmalloc-service</artifactId>
+ <name>mnemonic-pmalloc-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-PMallocAllocator, ${project.version}</header>
+ <footer>Mnenomic-PMallocAllocator, ${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/30836536/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
new file mode 100644
index 0000000..adfa40b
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
@@ -0,0 +1,151 @@
+/*
+ * 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.allocatorservice.internal;
+
+import org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+
+import java.nio.ByteBuffer;
+
+public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("pmallocallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public String getServiceId() {
+ return "pmalloc";
+ }
+
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
+
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
+
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
+
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
+
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
+
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
+
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
+
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
+
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
+
+ @Override
+ public ByteBuffer retrieveByteBuffer(long id, long handler) {
+ return nretrieveByteBuffer(id, handler);
+ }
+
+ @Override
+ public long retrieveSize(long id, long handler) {
+ return nretrieveSize(id, handler);
+ }
+
+ @Override
+ public long getByteBufferHandler(long id, ByteBuffer buf) {
+ return ngetByteBufferHandler(id, buf);
+ }
+
+ @Override
+ public void setHandler(long id, long key, long handler) {
+ nsetHandler(id, key, handler);
+ }
+
+ @Override
+ public long getHandler(long id, long key) {
+ return ngetHandler(id, key);
+ }
+
+ @Override
+ public long handlerCapacity(long id) {
+ return nhandlerCapacity(id);
+ }
+
+ @Override
+ public long getBaseAddress(long id) {
+ return ngetBaseAddress(id);
+ }
+
+ protected native long ninit(long capacity, String uri, boolean isnew);
+
+ protected native void nclose(long id);
+
+ protected native void nsync(long id);
+
+ protected native long nallocate(long id, long size, boolean initzero);
+
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
+
+ protected native void nfree(long id, long address);
+
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
+
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
+
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+
+ protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
+
+ protected native long nretrieveSize(long id, long handler);
+
+ protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
+
+ protected native void nsetHandler(long id, long key, long handler);
+
+ protected native long ngetHandler(long id, long key);
+
+ protected native long nhandlerCapacity(long id);
+
+ protected native long ngetBaseAddress(long id);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/30836536/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
new file mode 100644
index 0000000..39985de
--- /dev/null
+++ b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/CMakeLists.txt
@@ -0,0 +1,38 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(pmallocallocator)
+
+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(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_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(LIBPMALLOC_LIBRARIES pmalloc)
+if (NOT LIBPMALLOC_LIBRARIES)
+ message(FATAL_ERROR "not found pmalloc library")
+endif (NOT LIBPMALLOC_LIBRARIES)
+
+add_library(pmallocallocator SHARED common.c org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c)
+target_include_directories(pmallocallocator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(pmallocallocator pmalloc)
+
+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}")
+include (CPack)