Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Release candidate for version 1.2.1
Browse files Browse the repository at this point in the history
- Bugfixes
- Added compiler flags for stack protection and immediate binding
  • Loading branch information
asonje committed Jan 12, 2022
1 parent f66285e commit 1aba0ff
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ JAVADOC = $(JAVA_HOME)/bin/javadoc

JNI_INCLUDES = $(JAVA_HOME)/include $(JAVA_HOME)/include/linux

CFLAGS = -O3 -DNDEBUG -fPIC -shared -D_FORTIFY_SOURCE=2 -z noexecstack -z,relro -z,now -Wformat -Wformat-security -Werror=format-security
CFLAGS = -O3 -DNDEBUG -fPIC -shared -D_FORTIFY_SOURCE=2 -z noexecstack -fstack-protector -Wformat -Wformat-security -Werror=format-security
JAVAFLAGS = -Xlint:unchecked -proc:none -XDenableSunApiLintControl
LINK_FLAGS = -fPIC -pie -O3 -DNDEBUG -shared -lpmem -lpmemobj -lpmempool -Wl,-rpath,/usr/local/lib:/usr/local/lib64
LINK_FLAGS = -fPIC -pie -O3 -DNDEBUG -shared -lpmem -lpmemobj -lpmempool -Wl,-rpath,/usr/local/lib:/usr/local/lib64 -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack

CPP_SOURCE_DIR = src/main/cpp
JAVA_SOURCE_DIR = src/main/java
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.intel.pmem</groupId>
<artifactId>llpl</artifactId>
<version>1.2.0-release</version>
<version>1.2.1-release</version>
<packaging>jar</packaging>
<name>LLPL</name>
<description>This project will provide APIs to interface with persistent memory</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cmake_minimum_required(VERSION 2.8.9)
project(llpl)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared -D_FORTIFY_SOURCE=2 -z noexecstack -z,relro -z,now -Wformat -Wformat-security -Werror=format-security")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared -D_FORTIFY_SOURCE=2 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wformat -Wformat-security -Werror=format-security -fstack-protector")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pie")

#include Java packages
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/com_intel_pmem_llpl_MemoryPoolImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ JNIEXPORT void JNICALL Java_com_intel_pmem_llpl_MemoryPoolImpl_nativeCopyFromByt
JNIEXPORT void JNICALL Java_com_intel_pmem_llpl_MemoryPoolImpl_nativeCopyFromByteBufferNT
(JNIEnv *env, jobject obj, jobject srcBuf, jint srcIndex, jlong dst, jint byteCount)
{
void* src = env->GetDirectBufferAddress(srcBuf);
jbyte* src = (jbyte*)env->GetDirectBufferAddress(srcBuf);
void *addr = pmem_memcpy((void *)dst, src + srcIndex, byteCount, PMEM_F_MEM_NONTEMPORAL);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/intel/pmem/llpl/AnyHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class AnyHeap {
private static final int MAX_USER_CLASSES = (TOTAL_ALLOCATION_CLASSES - USER_CLASS_INDEX) / 2;
static Unsafe UNSAFE;
private static final Map<String, AnyHeap> heaps = new ConcurrentHashMap<>();
private static final long HEAP_VERSION = 1200;
private static final long HEAP_VERSION = 1210;
private static final long MIN_HEAP_VERSION = 900;

/**
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/intel/pmem/llpl/MemoryAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,6 @@ void rawCopy(MemoryAccessor srcAccessor, long srcOffset, long dstOffset, long le
MemoryAccessor.uncheckedCopyBlockToBlock(srcAccessor.directAddress() + srcAccessor.metadataSize() + srcOffset, directAddress() + metadataSize() + dstOffset, length);
}

void rawCopyFromMemoryBlock(MemoryAccessor srcBlock, long srcOffset, long dstOffset, long length) {
rawCopy(srcBlock, srcOffset, dstOffset, length);
}

void rawCopyFromArray(byte[] srcArray, int srcOffset, long dstOffset, int length) {
if (srcOffset < 0 || srcOffset + length > srcArray.length) throw new IndexOutOfBoundsException(MemoryAccessor.outOfBoundsMessage(srcOffset, length));
checkValid();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/intel/pmem/llpl/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ public void copyFromByteBuffer(ByteBuffer srcBuf, long dstOffset) {
if (srcAddress <= 0) throw new IllegalArgumentException("Invalid ByteBuffer");
MemoryAccessor.uncheckedCopyBlockToBlock(srcAddress + srcBuf.position(), accessor.directAddress() + accessor.metadataSize() + dstOffset, size);
}
else {
else if (srcBuf.hasArray()) {
copyFromArray(srcBuf.array(), srcBuf.position(), dstOffset, srcBuf.remaining());
}
else {
byte[] tmp = new byte[size];
srcBuf.get(tmp);
copyFromArray(tmp, 0, dstOffset, size);
}
}

void rawCopyFromDirectByteBuffer(long srcAddress, long dstOffset, long length) {
Expand Down
242 changes: 242 additions & 0 deletions src/test/java/com/intel/pmem/llpl/RangeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package com.intel.pmem.llpl;

import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import java.util.Random;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -78,4 +81,243 @@ public void testRangeCopy(){
Assert.assertEquals(mb1.getShort(5), (short)2345);
}

@Test
public void testCopyFromBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromROBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf.asReadOnlyBuffer(), 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromDirectBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer dbuf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
dbuf.position(100).mark();
dbuf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(dbuf, 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromRODirectBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer dbuf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
dbuf.position(100).mark();
dbuf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(dbuf.asReadOnlyBuffer(), 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromBBCompact() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromROBBCompact() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf.asReadOnlyBuffer(), 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromDirectBBCompact() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer dbuf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
dbuf.position(100).mark();
dbuf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(dbuf, 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromRODirectBBCompact() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer dbuf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
dbuf.position(100).mark();
dbuf.put(arr, 0, arr.length).limit(200).reset();
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(dbuf.asReadOnlyBuffer(), 100);
});
for (int i = 0; i < arr.length; i++) {
Assert.assertEquals(mb.getByte(100+i), arr[i]);
}
}

@Test
public void testCopyFromEmptyRangeBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100);
buf.put(arr, 0, arr.length).position(1024);
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 100);
});
}

@Test
public void testCopyFromEmptyRangeDirectBB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100);
buf.put(arr, 0, arr.length).position(1024);
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 100);
});
}

@Test
public void testCopyFromBBInvalidMB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
try {
mb.withRange(1000, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 1000);
});
Assert.fail();
} catch(IndexOutOfBoundsException e) {
Assert.assertTrue(true);
}
}

@Test
public void testCopyFromDirectBBInvalidMB() {
heap = TestVars.createHeap();
MemoryBlock mb = heap.allocateMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
try {
mb.withRange(1000, 100, (Range range) -> {
range.copyFromByteBuffer(buf, 1000);
});
Assert.fail();
} catch(IndexOutOfBoundsException e) {
Assert.assertTrue(true);
}
}

@Test
public void testCopyFromBBInvalidCMB() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocate(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
try {
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, -100);
});
Assert.fail();
} catch(IndexOutOfBoundsException e) {
Assert.assertTrue(true);
}
}

@Test
public void testCopyFromDirectBBInvalidCMB() {
heap = TestVars.createHeap();
CompactMemoryBlock mb = heap.allocateCompactMemoryBlock(1024);
ByteBuffer buf = ByteBuffer.allocateDirect(1024);
byte[] arr = new byte[100];
new Random().nextBytes(arr);
buf.position(100).mark();
buf.put(arr, 0, arr.length).limit(200).reset();
try {
mb.withRange(100, 100, (Range range) -> {
range.copyFromByteBuffer(buf, -100);
});
Assert.fail();
} catch(IndexOutOfBoundsException e) {
Assert.assertTrue(true);
}
}
}

0 comments on commit 1aba0ff

Please sign in to comment.