Skip to content
Permalink
Browse files
Update
  • Loading branch information
leerho committed Mar 24, 2021
1 parent 5ccbdd7 commit 9d2798b16b5abd679587eef7e602602d8d02b90c
Showing 6 changed files with 56 additions and 35 deletions.
@@ -63,3 +63,4 @@ build.xml
_site/
_*
_*/
deps/
@@ -22,7 +22,7 @@
* @author lrhodes
*
*/
module org.apache.datasketches.memory {
module org.apache.datasketches.memseg {
requires jdk.incubator.foreign;
exports org.apache.datasketches.memory;
exports org.apache.datasketches.memseg;
}
@@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.datasketches.memory;
package org.apache.datasketches.memseg;

//import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
@@ -28,15 +28,19 @@
*
* @author Lee Rhodes
*/
class AllocateDirect {
final class AllocateDirect implements AutoCloseable {
private final MemorySegment directSeg;

/**
* Construct Memory Segment
* @param capacityBytes blah
* Base Constructor for allocate native memory.
*
* <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory
* leveraging the Memory interface.
* The allocated memory will be 8-byte aligned, but may not be page aligned.
* @param capacityBytes the the requested capacity of off-heap memory. Cannot be zero.
*/
AllocateDirect(final long capacityBytes) {
directSeg = MemorySegment.allocateNative(capacityBytes);
directSeg = MemorySegment.allocateNative(capacityBytes, 8);
}

MemorySegment getMemorySegment() {
@@ -47,23 +51,12 @@ long getNativeAddress() {
return directSeg.address().toRawLongValue();
}

void close() {
@Override
public void close() {
directSeg.close();
}



@SuppressWarnings("resource")
public static void checkAllocDirect() {
final long bytesIn = 64;
AllocateDirect allocateDirect = new AllocateDirect(bytesIn);
final MemorySegment seg = allocateDirect.getMemorySegment();
final long bytesOut = seg.byteSize();
String out = (bytesOut == bytesIn) ? "OK" : "Not OK";
System.out.println(out);
allocateDirect.close();
}

public static void main(final String[] args) {
checkAllocDirect();
}
}

@@ -0,0 +1,23 @@
/*
* 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.
*/

/**
* @author lrhodes
*/
package org.apache.datasketches.memseg;
@@ -17,11 +17,14 @@
* under the License.
*/

package org.apache.datasketches.memory;
package org.apache.datasketches.memseg;

import static org.testng.Assert.assertEquals;

import jdk.incubator.foreign.MemorySegment;
import org.testng.annotations.Test;
//import static org.testng.Assert.assertEquals;

import jdk.incubator.foreign.MemorySegment;



/**
@@ -32,20 +35,21 @@
*/
public class AllocateDirectTest {

/**
* check AllocDirect.
*/
@Test
@SuppressWarnings("resource")
public void checkAllocDirect() {
final long bytesIn = 64;
AllocateDirect allocateDirect = new AllocateDirect(bytesIn);
final MemorySegment seg = allocateDirect.getMemorySegment();
final long bytesOut = seg.byteSize();
String out = (bytesOut == bytesIn) ? "OK" : "Not OK";
System.out.println(out);
allocateDirect.close();
try (AllocateDirect allocateDirect = new AllocateDirect(bytesIn)) {
final MemorySegment seg = allocateDirect.getMemorySegment();
final long bytesOut = seg.byteSize();
assertEquals(bytesOut, bytesIn);
String str = (bytesOut == bytesIn) ? "OK" : "Not OK";
println(str);
//allocateDirect.close(); //fast close
}
}


static void println(Object o) { System.out.println(o.toString()); }
}

@@ -126,7 +126,7 @@ under the License.
<module name="JavadocParagraph"/>
<module name="JavadocTagContinuationIndentation">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
<!-- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/> -->
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="SingleLineJavadoc">

0 comments on commit 9d2798b

Please sign in to comment.