From 5ccbdd774208effe00ebb06697aebf1d3b25b256 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Tue, 23 Mar 2021 16:59:27 -0700 Subject: [PATCH] Initial commit using Eclipse & Maven --- README.md | 27 +- compile.sh | 43 +++ dry-run.sh | 31 ++ pom.xml | 150 ++++----- run.sh | 30 ++ src/main/java/module-info.java | 28 ++ .../datasketches/memory/AllocateDirect.java | 69 +++++ .../memory/AllocateDirectTest.java | 51 ++++ tools/CloverConfig.txt | 49 +++ tools/FindBugsExcludeFilter.xml | 96 ++++++ tools/MemoryCheckstyle.xml | 284 ++++++++++++++++++ 11 files changed, 758 insertions(+), 100 deletions(-) create mode 100755 compile.sh create mode 100755 dry-run.sh create mode 100755 run.sh create mode 100644 src/main/java/module-info.java create mode 100644 src/main/java/org/apache/datasketches/memory/AllocateDirect.java create mode 100644 src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java create mode 100644 tools/CloverConfig.txt create mode 100644 tools/FindBugsExcludeFilter.xml create mode 100644 tools/MemoryCheckstyle.xml diff --git a/README.md b/README.md index b93654f..b3a8f6b 100644 --- a/README.md +++ b/README.md @@ -1 +1,26 @@ -# DataSketches Memory 16 \ No newline at end of file + + +# DataSketches Memory 16 + +Experimental and temporary development of Memory based on JDK 16. + +See [demo-jpms-monitor](https://github.com/nipafx/demo-jpms-monitor). + + diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..f556534 --- /dev/null +++ b/compile.sh @@ -0,0 +1,43 @@ +#!/bin/bash -e + +# 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. + +#Java executables for mac environment +export JAVAC=$JAVA16_HOME/bin/javac +export JAR=$JAVA16_HOME/bin/jar +export JAVA=$JAVA16_HOME/bin/java + +echo "--- CLEAN & COMPILE ---" + +rm -rf target +mkdir target +mkdir target/classes +mkdir target/mods +mkdir target/test-classes + +$JAVAC \ + -d target/classes/\ + $(find . -name '*.java') + +echo "--- JAR ---" +$JAR \ + --create \ + --file target/mods/org.apache.datasketches.memory.jar \ + --main-class org.apache.datasketches.memory.AllocateDirect \ + -C target/classes . + diff --git a/dry-run.sh b/dry-run.sh new file mode 100755 index 0000000..597f2ca --- /dev/null +++ b/dry-run.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +# 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. + +#Java executables for mac environment +export JAVAC=$JAVA16_HOME/bin/javac +export JAR=$JAVA16_HOME/bin/jar +export JAVA=$JAVA16_HOME/bin/java + +echo "--- DRY RUN ---" + +$JAVA \ + --module-path target/mods \ + --dry-run \ + --module org.apache.datasketches.memory + diff --git a/pom.xml b/pom.xml index 29103c0..b95de49 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,8 @@ under the License. --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 @@ -81,16 +82,9 @@ under the License. - - 1.7.30 - 1.7.30 - 3.6.0 - - 0.8 - - 7.1.0 + 7.4.0 3.5.0 @@ -120,6 +114,7 @@ under the License. [1.7.0,) 3.2.1 3.0.0-M5 + 3.0.0 0.13 @@ -128,7 +123,7 @@ under the License. 4.3.0 1.0.0 - 4.0.0 + 4.0.4 @@ -157,34 +152,6 @@ under the License. - - - org.slf4j - slf4j-api - ${slf4j-api.version} - - - - org.slf4j - slf4j-simple - ${slf4j-simple.version} - test - - - - com.google.protobuf - protobuf-java - ${protobuf-java.version} - test - - - - net.openhft - zero-allocation-hashing - ${zero-allocation-hashing.version} - test - - @@ -198,11 +165,13 @@ under the License. + org.codehaus.mojo versions-maven-plugin ${versions-maven-plugin.version} + @@ -210,12 +179,14 @@ under the License. maven-deploy-plugin ${maven-deploy-plugin.version} + org.apache.maven.plugins maven-release-plugin ${maven-release-plugin.version} + org.apache.maven.plugins @@ -238,6 +209,7 @@ under the License. + org.apache.maven.plugins @@ -255,6 +227,7 @@ under the License. + org.apache.maven.plugins maven-enforcer-plugin @@ -275,7 +248,7 @@ under the License. - + com.google.code.findbugs:annotations @@ -285,6 +258,7 @@ under the License. + org.apache.rat @@ -313,6 +287,7 @@ under the License. + org.apache.maven.plugins @@ -335,6 +310,7 @@ under the License. + org.apache.maven.plugins @@ -344,15 +320,28 @@ under the License. false false true - - --add-opens java.base/java.nio=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/jdk.internal.misc=ALL-UNNAMED - --add-opens java.base/jdk.internal.ref=ALL-UNNAMED - --add-opens java.base/sun.nio.ch=ALL-UNNAMED - + + + + org.apache.maven.plugins + maven-toolchains-plugin + ${maven-toolchains-plugin.version} + + + 8 + + + + + toolchain + + + + org.jacoco @@ -370,15 +359,23 @@ under the License. report - + + org.eluder.coveralls coveralls-maven-plugin ${coveralls-maven-plugin.version} + + + pl.project13.maven + git-commit-id-plugin + ${git-commit-id-plugin.version} + + org.apache.maven.plugins maven-compiler-plugin @@ -386,12 +383,9 @@ under the License. ${maven.compiler.source} ${maven.compiler.target} - - --add-exports - java.base/sun.nio.ch=ALL-UNNAMED - --add-exports - java.base/jdk.internal.ref=ALL-UNNAMED - + @@ -438,54 +432,13 @@ under the License. org.eluder.coveralls coveralls-maven-plugin + + pl.project13.maven + git-commit-id-plugin + - - - m2e - - - m2e.version - - - - - - - org.eclipse.m2e - lifecycle-mapping - ${lifecycle-mapping.version} - - - - - - org.apache.maven.plugins - maven-remote-resources-plugin - ${maven-remote-resources-plugin.version} - - process - - - - - - - - - - - - - - strict @@ -509,7 +462,6 @@ under the License. javac-with-errorprone true - diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..8a07f65 --- /dev/null +++ b/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash -e + +# 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. + +#Java executables for mac environment +export JAVAC=$JAVA16_HOME/bin/javac +export JAR=$JAVA16_HOME/bin/jar +export JAVA=$JAVA16_HOME/bin/java + +echo "--- RUN ---" + +$JAVA \ + --module-path target/mods \ + --module org.apache.datasketches.memory +# --class-path "libs/*" \ \ No newline at end of file diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..dcee60c --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,28 @@ +/* + * 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. + */ + +/** + * Preliminary module + * @author lrhodes + * + */ +module org.apache.datasketches.memory { + requires jdk.incubator.foreign; + exports org.apache.datasketches.memory; +} diff --git a/src/main/java/org/apache/datasketches/memory/AllocateDirect.java b/src/main/java/org/apache/datasketches/memory/AllocateDirect.java new file mode 100644 index 0000000..ab564d0 --- /dev/null +++ b/src/main/java/org/apache/datasketches/memory/AllocateDirect.java @@ -0,0 +1,69 @@ +/* + * 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.datasketches.memory; + +//import jdk.incubator.foreign.MemoryAddress; +import jdk.incubator.foreign.MemorySegment; +//import static jdk.incubator.foreign.MemorySegment.*; + + +/** + * + * @author Lee Rhodes + */ +class AllocateDirect { + private final MemorySegment directSeg; + + /** + * Construct Memory Segment + * @param capacityBytes blah + */ + AllocateDirect(final long capacityBytes) { + directSeg = MemorySegment.allocateNative(capacityBytes); + } + + MemorySegment getMemorySegment() { + return directSeg; + } + + long getNativeAddress() { + return directSeg.address().toRawLongValue(); + } + + 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(); + } +} + diff --git a/src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java b/src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java new file mode 100644 index 0000000..1d03488 --- /dev/null +++ b/src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java @@ -0,0 +1,51 @@ +/* + * 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.datasketches.memory; + +import jdk.incubator.foreign.MemorySegment; +import org.testng.annotations.Test; +//import static org.testng.Assert.assertEquals; + + +/** + * Test AllocateDirect. + * + * @author Lee Rhodes + * + */ +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(); + } + +} + diff --git a/tools/CloverConfig.txt b/tools/CloverConfig.txt new file mode 100644 index 0000000..77ea2ce --- /dev/null +++ b/tools/CloverConfig.txt @@ -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. + +Clover Config for Eclipse: + +At Project Level Properties: + Instrumentation: + Initstring: Default value + Output Folder: ...project output dir(s) + Flush Policy: At JVM shutdown ... + Misc: Fully qualify ... , Instrument and compile at statement level + Contexts: + Check: assert statements + Add Custom Coverage Context Filter: + private-constructor: also see link below + Method + (.* )?private +[a-zA-Z0-9_$]+ *\( *\).* + Source Files + Only look ... + [check] src/main/java[includes=**/*.java][excludes=] + [check] src/test/java[includes=**/*.java][excludes=] + Test Classes + Assume all source in the specified folders are tests or test utility classes + [check] src/test/java + +At Clover "down-triangle" menu: + Columns: + Element + % TOTAL Coverage + Uncovered Elements: Custom: %UncoveredElements * TotalElements / 100 + Total Elements + + + +http://alexruizlog.blogspot.com/2009/04/how-to-make-clover-ignore-private_21.html \ No newline at end of file diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml new file mode 100644 index 0000000..ae68389 --- /dev/null +++ b/tools/FindBugsExcludeFilter.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml new file mode 100644 index 0000000..3b80313 --- /dev/null +++ b/tools/MemoryCheckstyle.xml @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +