diff --git a/.github/workflows/.toolchains.xml b/.github/workflows/.toolchains.xml
index 111252f5..7df79b88 100644
--- a/.github/workflows/.toolchains.xml
+++ b/.github/workflows/.toolchains.xml
@@ -1,20 +1,50 @@
+
+ jdk
+
+ 1.8
+ openjdk
+
+
+ ${env.JAVA8_HOME}
+
+ jdk8
- adoptopenjdk
+ openjdk
+
+
+ ${env.JAVA8_HOME}
+
+
+
+ jdk
+
+ 9
+ openjdk
+
+
+ ${env.JAVA9_HOME}
+
+
+
+ jdk
+
+ 10
+ openjdk
- ${JAVA_HOME}
+ ${env.JAVA10_HOME}jdk11
- adoptopenjdk
+ openjdk${env.JAVA11_HOME}
@@ -23,21 +53,21 @@
jdk
- 15
- adoptopenjdk
+ 12
+ openjdk
- ${env.JAVA15_HOME}
+ ${env.JAVA12_HOME}jdk
- 16
- adoptopenjdk
+ 13
+ openjdk
- ${env.JAVA16_HOME}
+ ${env.JAVA13_HOME}
\ No newline at end of file
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index f20252f3..c2ac063b 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -1,54 +1,123 @@
name: Java Test Coverage with Maven, Coveralls
on:
- pull_request:
- push:
- branches: [ master ]
- workflow_dispatch:
+ pull_request:
+ push:
+ branches: [ master ]
+ workflow_dispatch:
env:
- MAVEN_OPTS: -Xmx4g -Xms1g
- repo_token: ${{secrets.coveralls_token}}
+ MAVEN_OPTS: -Xmx4g -Xms1g
+ repo_token: ${{secrets.coveralls_token}}
+ RUNNER_TEMP: /tmp
jobs:
- build:
- name: Build, Test, Coverage
- runs-on: ubuntu-latest
-
- steps:
- - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
- uses: actions/checkout@v2
- with:
- persist-credentials: false
-
- - name: Cache local Maven repository
- uses: actions/cache@v2
- with:
- path: ~/.m2/repository
- key: build-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- restore-keys: build-${{ runner.os }}-maven-
-
- - name: Install JDK
- uses: AdoptOpenJDK/install-jdk@v1
- with:
- version: '8'
- architecture: x64
- impl: hotspot
- targets: 'JDK_8;JAVA_HOME'
-
- - name: Install Dependencies
- run: >
- mvn clean install -B -V -q
- -DskipTests=true
- -Dmaven.javadoc.skip=true
- -Dgpg.skip=true
- --toolchains .github/workflows/.toolchains.xml
-
- - name: Test & Report
- if: ${{ success() }}
- run: >
- mvn verify coveralls:report -B -V -q
- -Dcoveralls-repo-token=${repo_token}
- -Dmaven.javadoc.skip=true
- -Dgpg.skip=true
- --toolchains .github/workflows/.toolchains.xml
+ build:
+ name: Build, Test, Coverage
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ jdk: [8,9,10,11,12,13]
+
+ # All JDKs are installed per build machine which is inefficient
+
+ env:
+ JDK_VERSION: ${{ matrix.jdk }}
+
+ steps:
+ - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
+ uses: actions/checkout@v2
+ with:
+ persist-credentials: false
+
+ - name: Cache local Maven repository
+ uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: build-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: build-${{ runner.os }}-maven-
+
+ - name: Install JDK 8
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '8'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA8_HOME'
+
+ - name: Install JDK 9
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '9'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA9_HOME'
+
+ - name: Install JDK 10
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '10'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA10_HOME'
+
+ - name: Install JDK 11
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '11'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA11_HOME'
+
+ - name: Install JDK 12
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '12'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA12_HOME'
+
+ - name: Install JDK 13
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: '13'
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA13_HOME'
+
+ - name: Install Matrix JDK
+ uses: AdoptOpenJDK/install-jdk@v1
+ with:
+ version: ${{ matrix.jdk }}
+ architecture: x64
+ impl: hotspot
+ targets: 'JAVA_HOME'
+
+ - name: Echo Java Version
+ run: >
+ java -version
+
+ - name: Install Dependencies
+ run: >
+ mvn clean install
+ -DskipTests=true
+ -Dmaven.javadoc.skip=true
+ -Dgpg.skip=true
+ --toolchains .github/workflows/.toolchains.xml
+
+ - name: Package
+ run: >
+ mvn package
+ -Dmaven.javadoc.skip=true
+ -Dgpg.skip=true
+ --toolchains .github/workflows/.toolchains.xml
+
+ - name: Test & Report
+ if: ${{ matrix.jdk == 8 && success() }}
+ run: >
+ mvn verify coveralls:report -B -V
+ -Dcoveralls-repo-token=${repo_token}
+ -Dmaven.javadoc.skip=true
+ -Dgpg.skip=true
+ --toolchains .github/workflows/.toolchains.xml
diff --git a/.lgtm.yml b/.lgtm.yml
new file mode 100644
index 00000000..53a53b5a
--- /dev/null
+++ b/.lgtm.yml
@@ -0,0 +1,60 @@
+##########################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##########################################################################################
+
+#########################################################################################
+# Use the extraction block to define changes to the default code extraction process #
+# for one or more languages. The settings for each language are defined in a child #
+# block, with one or more steps. #
+#########################################################################################
+
+extraction:
+
+ # Define settings for Java analysis
+ ####################################
+ java:
+ # The `index` step extracts information from the files in the codebase.
+ index:
+ # Specify the Java version required to build the project.
+ java_version: 8
+ # Specify Maven settings.
+ maven:
+ # Specify the path of a Maven toolchains file.
+ # Default: Maven uses a toolchains file in the default location, if it exists.
+ toolchains_file: .github/workflows/.toolchains.xml
+
+ # Define settings for JavaScript analysis
+ ##########################################
+ javascript:
+
+ # The `index` step extracts information from the files in the codebase.
+ index:
+ # Specify a list of files and folders to exclude from extraction.
+ exclude:
+ - **/*/site
+ # Specify a list of glob patterns to include/exclude files from extraction; this
+ # is applied on top of the include/exclude paths from above; patterns are
+ # processed in the same way as for path classifiers above.
+ # Default: include all files with known extensions (such as .js, .ts and .html),
+ # but exclude files ending in `-min.js` or `.min.js` and folders named `node_modules`
+ # or `bower_components`
+ filters:
+ # exclude any *.js files anywhere.
+ - exclude: "**/*.js"
+ # exclude any *.html files anywhere.
+ - exclude: "**/*.html"
diff --git a/README.md b/README.md
index 0eb082bb..7e4c5629 100644
--- a/README.md
+++ b/README.md
@@ -17,8 +17,8 @@
under the License.
-->
-[![Build Status](https://travis-ci.org/apache/datasketches-memory.svg?branch=master)](https://travis-ci.org/apache/datasketches-memory)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.datasketches/datasketches-memory/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.datasketches/datasketches-memory)
+[![Build Status](https://travis-ci.org/apache/datasketches-memory.svg?branch=master)](https://travis-ci.org/apache/datasketches-memory)
+[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.datasketches/datasketches-memory/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.datasketches/datasketches-memory)
[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/datasketches-memory.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/datasketches-memory/context:java)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/apache/datasketches-memory.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/datasketches-memory/alerts/)
[![Coverage Status](https://coveralls.io/repos/github/apache/datasketches-memory/badge.svg?branch=master)](https://coveralls.io/github/apache/datasketches-memory?branch=master)
@@ -32,22 +32,58 @@
runtime dependencies and can be used in any application that needs to manage data structures outside
the Java heap.
-Please visit the main [DataSketches website](https://datasketches.apache.org) for more information.
+Please visit the main [DataSketches website](https://datasketches.apache.org) for more information.
If you are interested in making contributions to this site please see our [Community](https://datasketches.apache.org/docs/Community/) page for how to contact us.
+---
+
+## Java Support
+
+Datasketches memory currently supports Java 8 up to and including Java 13.
+
+In order to use the library in Java 9 and above, you must provide the following runtime arguments to the JVM:
+
+```shell
+ --add-opens java.base/java.nio=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.misc=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.ref=org.apache.datasketches.memory
+```
+
+For example, to run your local application with full compatibility for the Java module system, you might use the following command:
+```shell
+ $JAVA \
+ --module-path mods \
+ --add-opens java.base/java.nio=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.misc=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.ref=org.apache.datasketches.memory \
+ --module my.main.application.module
+```
+
+where `mods` is your module path and `my.main.application.module` is your own JPMS module:
+
+```java
+module datasketches.memory.multirelease.test {
+ requires org.apache.datasketches.memory;
+}
+```
+
+
---
## Build Instructions
__NOTE:__ This component accesses resource files for testing. As a result, the directory elements of the full absolute path of the target installation directory must qualify as Java identifiers. In other words, the directory elements must not have any space characters (or non-Java identifier characters) in any of the path elements. This is required by the Oracle Java Specification in order to ensure location-independent access to resources: [See Oracle Location-Independent Access to Resources](https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html)
-### JDK8/Hotspot is required to compile
-This DataSketches component is pure Java and you must compile using JDK 8 with Hotspot.
+### JDK versions required to compile
+This DataSketches component is pure Java and requires the following JDKs to compile:
+- JDK8/Hotspot
+- JDK9/Hotspot
+- JDK11/Hotspot
### Recommended Build Tool
This DataSketches component is structured as a Maven project and Maven is the recommended Build Tool.
-There are two types of tests: normal unit tests and tests run by the strict profile.
+There are two types of tests: normal unit tests and tests run by the strict profile.
To run normal unit tests:
@@ -57,6 +93,12 @@ To run the strict profile tests:
$ mvn clean test -P strict
+To run javadoc on this multi-module project, use:
+
+ $ mvn clean package javadoc:javadoc -DskipTests=true
+
+* There are sometimes problems resolving module deps, e.g. see https://issues.apache.org/jira/browse/MJAVADOC-437
+
To install jars built from the downloaded source:
$ mvn clean install -DskipTests=true
@@ -69,12 +111,34 @@ This will create the following Jars:
* datasketches-memory-X.Y.Z-test-sources.jar The test source files
* datasketches-memory-X.Y.Z-javadoc.jar The compressed Javadocs.
-### Dependencies
+### Toolchains
+
+This project makes use of Maven toolchains to ensure that the correct Java compiler version is used when compiling source files.
+
+The reference toolchains.xml can be found in .github/workflows/.toolchains.xml, and can be copied to your local maven home
+directory e.g. `~/.m2/toolchains.xml`.
+
+Alternatively, the maven commands above can be supplemented with: `--toolchains .github/workflows/.toolchains.xml`
-#### Run-time
-There is one run-time dependency:
+For example, to run normal unit tests:
+
+ $ mvn clean test --toolchains .github/workflows/.toolchains.xml
+
+### Dependencies
-* org.slf4j:slf4j-api
+There are no run-time dependencies.
#### Testing
See the pom.xml file for test dependencies.
+
+---
+
+## Further documentation for contributors
+
+For more information on the project configuration, the following topics are discussed in more detail:
+
+* [Maven configuration](docs/maven.md)
+* [Multi-release jar](docs/multi-release-jar.md)
+* [Java Platform Module System](docs/module-system.md)
+
+In order to build and contribute to this project, please read the [development setup documentation](docs/development.md).
diff --git a/datasketches-memory-java11/pom.xml b/datasketches-memory-java11/pom.xml
new file mode 100644
index 00000000..d1362bcc
--- /dev/null
+++ b/datasketches-memory-java11/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+ datasketches-memory-java11
+ ${project.artifactId}
+
+
+ 11
+ 11
+ ${java.version}
+ ${java.version}
+
+
+
diff --git a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
new file mode 100644
index 00000000..633c6854
--- /dev/null
+++ b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+/**
+ * Extracts version-dependent field names into standalone class.
+ * Some field names in the VM internal class have changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+class NioBitsFields {
+ static String COUNT_FIELD_NAME = "COUNT";
+ static String RESERVED_MEMORY_FIELD_NAME = "RESERVED_MEMORY";
+ static String TOTAL_CAPACITY_FIELD_NAME = "TOTAL_CAPACITY";
+}
diff --git a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/package-info.java b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/package-info.java
new file mode 100644
index 00000000..03c6da38
--- /dev/null
+++ b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.internal;
\ No newline at end of file
diff --git a/src/main/javadoc/overview.html b/datasketches-memory-java11/src/main/javadoc/overview.html
similarity index 100%
rename from src/main/javadoc/overview.html
rename to datasketches-memory-java11/src/main/javadoc/overview.html
diff --git a/datasketches-memory-java8-tests/pom.xml b/datasketches-memory-java8-tests/pom.xml
new file mode 100644
index 00000000..d98db7b6
--- /dev/null
+++ b/datasketches-memory-java8-tests/pom.xml
@@ -0,0 +1,71 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory-java8
+ ${project.parent.version}
+ test
+
+
+ org.testng
+ testng
+ ${testng.version}
+ test
+
+
+
+ com.google.protobuf
+ protobuf-java
+ ${protobuf-java.version}
+ test
+
+
+
+ net.openhft
+ zero-allocation-hashing
+ ${zero-allocation-hashing.version}
+ test
+
+
+
+ datasketches-memory-java8-tests
+ ${project.artifactId}
+
+
+ 1.8
+ 8
+ ${java.version}
+ ${java.version}
+
+
+
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/BufferTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/IsValidUtf8TestUtil.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/IsValidUtf8TestUtil.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/IsValidUtf8TestUtil.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/IsValidUtf8TestUtil.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
diff --git a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java
new file mode 100644
index 00000000..88583536
--- /dev/null
+++ b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.test;
+
+import org.apache.datasketches.memory.internal.MemoryCleaner;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+@SuppressWarnings("javadoc")
+public class MemoryCleanerTest {
+
+ @Test
+ public void cleanerDeallocates() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ org.apache.datasketches.memory.internal.MemoryCleaner cleaner = new org.apache.datasketches.memory.internal.MemoryCleaner(this, deallocator);
+ cleaner.clean();
+ assertTrue(deallocator.getHasRun());
+ }
+
+ @Test
+ public void noDeallocation() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ org.apache.datasketches.memory.internal.MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ assertFalse(deallocator.getHasRun());
+ }
+
+ private static final class SimpleDeallocator implements Runnable {
+ static final AtomicBoolean hasRun = new AtomicBoolean();
+
+ private SimpleDeallocator() {
+ hasRun.set(false);
+ }
+
+ @Override
+ public void run() {
+ hasRun.compareAndSet(false, true);
+ }
+
+ public Boolean getHasRun() {
+ return hasRun.get();
+ }
+ }
+}
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/NativeWritableBufferImplTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NativeWritableBufferImplTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/NativeWritableBufferImplTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NativeWritableBufferImplTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/NativeWritableMemoryImplTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NativeWritableMemoryImplTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/NativeWritableMemoryImplTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NativeWritableMemoryImplTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/UnsafeUtilTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/UnsafeUtilTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/UnsafeUtilTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/UnsafeUtilTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/UtilTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/UtilTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/UtilTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/UtilTest.java
diff --git a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
new file mode 100644
index 00000000..f4a0f2af
--- /dev/null
+++ b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.test.internal;
+
+import org.apache.datasketches.memory.internal.VirtualMachineMemory;
+import org.testng.annotations.Test;
+
+@SuppressWarnings("javadoc")
+public class VirtualMachineMemoryTest {
+
+ @Test
+ public void maxDirectBufferMemory() {
+ assert(org.apache.datasketches.memory.internal.VirtualMachineMemory.getMaxDBBMemory() >= 0);
+ }
+
+ @Test
+ public void inertPageAlignment() {
+ System.out.println("VM page alignment:" + VirtualMachineMemory.getIsPageAligned());
+ assert(true);
+ }
+}
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
diff --git a/src/test/java/org/apache/datasketches/memory/test/package-info.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/package-info.java
similarity index 100%
rename from src/test/java/org/apache/datasketches/memory/test/package-info.java
rename to datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/package-info.java
diff --git a/src/test/resources/GettysburgAddress.txt b/datasketches-memory-java8-tests/src/test/resources/GettysburgAddress.txt
similarity index 100%
rename from src/test/resources/GettysburgAddress.txt
rename to datasketches-memory-java8-tests/src/test/resources/GettysburgAddress.txt
diff --git a/datasketches-memory-java8/pom.xml b/datasketches-memory-java8/pom.xml
new file mode 100644
index 00000000..7c3bcd3a
--- /dev/null
+++ b/datasketches-memory-java8/pom.xml
@@ -0,0 +1,103 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+ datasketches-memory-java8
+ ${project.artifactId}
+
+
+ 1.8
+ 8
+ ${java.version}
+ ${java.version}
+
+ false
+
+
+
+
+
+ strict
+
+
+ [1.8, 1.9),8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ org.codehaus.plexus
+ plexus-compiler-javac-errorprone
+ ${plexus-compiler-javac-errorprone.version}
+
+
+
+
+ ${maven.compiler.target}
+ javac-with-errorprone
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+ ${jdk-toolchain.version}
+
+
+
+
+ javadoc-aggregate
+ package
+
+ javadoc-no-fork
+
+
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/apache/datasketches/memory/BaseBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/BaseBuffer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
diff --git a/src/main/java/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/BaseState.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
diff --git a/src/main/java/org/apache/datasketches/memory/Buffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/Buffer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
diff --git a/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
diff --git a/src/main/java/org/apache/datasketches/memory/Handle.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Handle.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/Handle.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Handle.java
diff --git a/src/main/java/org/apache/datasketches/memory/Map.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Map.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/Map.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Map.java
diff --git a/src/main/java/org/apache/datasketches/memory/MapHandle.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MapHandle.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/MapHandle.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MapHandle.java
diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/Memory.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
diff --git a/src/main/java/org/apache/datasketches/memory/MemoryCloseException.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryCloseException.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/MemoryCloseException.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryCloseException.java
diff --git a/src/main/java/org/apache/datasketches/memory/MemoryException.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryException.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/MemoryException.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryException.java
diff --git a/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
diff --git a/src/main/java/org/apache/datasketches/memory/Utf8CodingException.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Utf8CodingException.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/Utf8CodingException.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Utf8CodingException.java
diff --git a/src/main/java/org/apache/datasketches/memory/WritableBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/WritableBuffer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
diff --git a/src/main/java/org/apache/datasketches/memory/WritableHandle.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableHandle.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/WritableHandle.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableHandle.java
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMap.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMap.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/WritableMap.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMap.java
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMapHandle.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMapHandle.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/WritableMapHandle.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMapHandle.java
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/WritableMemory.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
similarity index 91%
rename from src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
index f529c8a3..fd90d9f8 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
@@ -21,10 +21,7 @@
import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
+import java.util.logging.Logger;
/**
* Provides access to direct (native) memory.
@@ -34,11 +31,11 @@
*/
@SuppressWarnings({"restriction","synthetic-access"})
final class AllocateDirect {
- private static final Logger LOG = LoggerFactory.getLogger(AllocateDirect.class);
+ private static final Logger LOG = Logger.getLogger(AllocateDirect.class.getCanonicalName());
private final Deallocator deallocator;
- private final Cleaner cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
private final long nativeBaseOffset;
+ private final MemoryCleaner cleaner;
/**
* Base Constructor for allocate native memory.
@@ -68,7 +65,7 @@ final class AllocateDirect {
nativeBaseOffset = nativeAddress;
}
deallocator = new Deallocator(nativeAddress, allocationSize, capacityBytes);
- cleaner = Cleaner.create(this, deallocator);
+ cleaner = new MemoryCleaner(this, deallocator);
}
boolean doClose() {
@@ -123,7 +120,7 @@ boolean deallocate(final boolean calledFromCleaner) {
if (valid.change()) {
if (calledFromCleaner) {
// Warn about non-deterministic resource cleanup.
- LOG.warn("A WritableHandle was not closed manually");
+ LOG.warning("A WritableHandle was not closed manually");
}
unsafe.freeMemory(nativeAddress);
NioBits.unreserveMemory(allocationSize, capacity);
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
similarity index 96%
rename from src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
index e1076a4a..cc69672e 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
@@ -29,13 +29,11 @@
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
+import java.util.logging.Logger;
import org.apache.datasketches.memory.Map;
import org.apache.datasketches.memory.MemoryCloseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
import sun.nio.ch.FileChannelImpl;
/**
@@ -56,7 +54,7 @@
*/
@SuppressWarnings({"restriction","synthetic-access"})
class AllocateDirectMap implements Map {
- private static final Logger LOG = LoggerFactory.getLogger(AllocateDirectMap.class);
+ private static final Logger LOG = Logger.getLogger(AllocateDirectMap.class.getCanonicalName());
private static final int MAP_RO = 0;
private static final int MAP_RW = 1;
@@ -97,7 +95,7 @@ class AllocateDirectMap implements Map {
}
private final Deallocator deallocator;
- private final Cleaner cleaner;//JDK9+ moved to jdk.internal.ref.Cleaner;
+ private final MemoryCleaner cleaner;
final long capacityBytes;
final RandomAccessFile raf;
@@ -120,7 +118,7 @@ class AllocateDirectMap implements Map {
raf = mapper(file, fileOffsetBytes, capacityBytes, resourceReadOnly);
nativeBaseOffset = map(raf.getChannel(), resourceReadOnly, fileOffsetBytes, capacityBytes);
deallocator = new Deallocator(nativeBaseOffset, capacityBytes, raf);
- cleaner = Cleaner.create(this, deallocator);
+ cleaner = new MemoryCleaner(this, deallocator);
}
//Map Interface
@@ -287,7 +285,7 @@ boolean deallocate(final boolean calledFromCleaner) {
if (valid.change()) {
if (calledFromCleaner) {
// Warn about non-deterministic resource cleanup.
- LOG.warn("A WritableMapHandleImpl was not closed manually");
+ LOG.warning("A WritableMapHandleImpl was not closed manually");
}
try {
unmap();
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Ints.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Ints.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/Ints.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Ints.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.java
new file mode 100644
index 00000000..97412880
--- /dev/null
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.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.internal;
+
+import sun.misc.Cleaner;
+
+/**
+ * Extracts a version-dependent reference to the `sun.misc.Cleaner` into
+ * a standalone class. The package name for Cleaner has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+public class MemoryCleaner {
+ private final Cleaner cleaner;
+
+ /**
+ * Creates a new `sun.misc.Cleaner`.
+ * @param referent the object to be cleaned
+ * @param deallocator - the cleanup code to be run when the cleaner is invoked.
+ * return MemoryCleaner
+ */
+ public MemoryCleaner(final Object referent, final Runnable deallocator) {
+ cleaner = Cleaner.create(referent, deallocator);
+ }
+
+ /**
+ * Runs this cleaner, if it has not been run before.
+ */
+ public void clean() {
+ cleaner.clean();
+ }
+}
+
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NioBits.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBits.java
similarity index 81%
rename from src/main/java/org/apache/datasketches/memory/internal/NioBits.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBits.java
index 73d95cc3..6659de6f 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NioBits.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBits.java
@@ -33,10 +33,6 @@
*/
@SuppressWarnings({"restriction"})
final class NioBits {
- private static final Class> VM_CLASS;
- private static final Method VM_MAX_DIRECT_MEMORY_METHOD;
- private static final Method VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD;
-
private static final Class> NIO_BITS_CLASS;
private static final Method NIO_BITS_RESERVE_MEMORY_METHOD;
private static final Method NIO_BITS_UNRESERVE_MEMORY_METHOD;
@@ -51,18 +47,8 @@ final class NioBits {
static {
try {
- VM_CLASS = Class.forName("sun.misc.VM"); //JDK9+ moved to jdk.internal.misc.VM
- VM_MAX_DIRECT_MEMORY_METHOD =
- VM_CLASS.getDeclaredMethod("maxDirectMemory");
- VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
- maxDBBMemory = (long)VM_MAX_DIRECT_MEMORY_METHOD
- .invoke(null); //static method
-
- VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD =
- VM_CLASS.getDeclaredMethod("isDirectMemoryPageAligned");
- VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.setAccessible(true);
- isPageAligned = (boolean)VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD
- .invoke(null); //static method
+ isPageAligned = VirtualMachineMemory.getIsPageAligned();
+ maxDBBMemory = VirtualMachineMemory.getMaxDBBMemory();
NIO_BITS_CLASS = Class.forName("java.nio.Bits");
@@ -74,22 +60,20 @@ final class NioBits {
.getDeclaredMethod("unreserveMemory", long.class, int.class); //JD16 requires (long, long)
NIO_BITS_UNRESERVE_MEMORY_METHOD.setAccessible(true);
- //JDK 8-10: "count", "reservedMemory", "totalCapacity"
- //JDK 11-16: "COUNT", "RESERVE_MEMORY", "TOTAL_CAPACITY"
- final Field countField = NIO_BITS_CLASS.getDeclaredField("count");
+ final Field countField = NIO_BITS_CLASS.getDeclaredField(NioBitsFields.COUNT_FIELD_NAME);
countField.setAccessible(true);
nioBitsCount = (AtomicLong) (countField.get(null));
- final Field reservedMemoryField = NIO_BITS_CLASS.getDeclaredField("reservedMemory");
+ final Field reservedMemoryField = NIO_BITS_CLASS.getDeclaredField(NioBitsFields.RESERVED_MEMORY_FIELD_NAME);
reservedMemoryField.setAccessible(true);
nioBitsReservedMemory = (AtomicLong) (reservedMemoryField.get(null));
- final Field totalCapacityField = NIO_BITS_CLASS.getDeclaredField("totalCapacity");
+ final Field totalCapacityField = NIO_BITS_CLASS.getDeclaredField(NioBitsFields.TOTAL_CAPACITY_FIELD_NAME);
totalCapacityField.setAccessible(true);
nioBitsTotalCapacity = (AtomicLong) (totalCapacityField.get(null));
} catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException | SecurityException | NoSuchFieldException e) {
+ | IllegalArgumentException | SecurityException | NoSuchFieldException e) {
throw new RuntimeException("Could not acquire java.nio.Bits class: " + e.getClass());
}
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
new file mode 100644
index 00000000..56f1e20e
--- /dev/null
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+/**
+ * Extracts version-dependent field names into standalone class.
+ * Some field names in the VM internal class have changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+class NioBitsFields {
+ static String COUNT_FIELD_NAME = "count";
+ static String RESERVED_MEMORY_FIELD_NAME = "reservedMemory";
+ static String TOTAL_CAPACITY_FIELD_NAME = "totalCapacity";
+}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Prim.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Prim.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/Prim.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Prim.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/ReadOnlyException.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ReadOnlyException.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/ReadOnlyException.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ReadOnlyException.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/StepBoolean.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/StepBoolean.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/StepBoolean.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/StepBoolean.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Utf8.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/Utf8.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Util.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/Util.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
new file mode 100644
index 00000000..0bf9b8e0
--- /dev/null
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.internal;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Extracts a version-dependent reference to the `sun.misc.VM` into a standalone
+ * class. The package name for VM has changed in later versions. The appropriate
+ * class will be loaded by the class loader depending on the Java version that
+ * is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+public final class VirtualMachineMemory {
+
+ private static final Class> VM_CLASS;
+ private static final Method VM_MAX_DIRECT_MEMORY_METHOD;
+ private static final Method VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD;
+ private static final long maxDBBMemory;
+ private static final boolean isPageAligned;
+
+ static {
+ try {
+ VM_CLASS = Class.forName("sun.misc.VM");
+ VM_MAX_DIRECT_MEMORY_METHOD = VM_CLASS.getDeclaredMethod("maxDirectMemory");
+ VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
+ maxDBBMemory = (long) VM_MAX_DIRECT_MEMORY_METHOD.invoke(null); // static method
+
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD = VM_CLASS.getDeclaredMethod("isDirectMemoryPageAligned");
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.setAccessible(true);
+ isPageAligned = (boolean) VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.invoke(null); // static method
+ } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException | SecurityException e) {
+ throw new RuntimeException("Could not acquire sun.misc.VM class: " + e.getClass());
+ }
+ }
+
+ /**
+ * Returns the maximum amount of allocatable direct buffer memory. The
+ * directMemory variable is initialized during system initialization.
+ *
+ * @return the maximum amount of allocatable direct buffer memory.
+ */
+ public static long getMaxDBBMemory() {
+ return maxDBBMemory;
+ }
+
+ /**
+ * Returns true if the direct buffers should be page aligned.
+ *
+ * @return flag that determines whether direct buffers should be page aligned.
+ */
+ public static boolean getIsPageAligned() {
+ return isPageAligned;
+ }
+}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
diff --git a/src/main/java/org/apache/datasketches/memory/internal/package-info.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/package-info.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/internal/package-info.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/package-info.java
diff --git a/src/main/java/org/apache/datasketches/memory/package-info.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
similarity index 100%
rename from src/main/java/org/apache/datasketches/memory/package-info.java
rename to datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
diff --git a/datasketches-memory-java8/src/main/javadoc/overview.html b/datasketches-memory-java8/src/main/javadoc/overview.html
new file mode 100644
index 00000000..86ef2bb5
--- /dev/null
+++ b/datasketches-memory-java8/src/main/javadoc/overview.html
@@ -0,0 +1,34 @@
+
+
+
+
+
+
Note: If the requirements or promises of any method's contract are not fulfilled (that is, if there is a bug in either the method or its caller), then an unchecked exception will be thrown. The precise type of such an unchecked exception does not form part of any method's contract.
+
+
\ No newline at end of file
diff --git a/datasketches-memory-java9-tests/pom.xml b/datasketches-memory-java9-tests/pom.xml
new file mode 100644
index 00000000..17cd2f82
--- /dev/null
+++ b/datasketches-memory-java9-tests/pom.xml
@@ -0,0 +1,75 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory-java9
+ ${project.version}
+
+
+ org.testng
+ testng
+ ${testng.version}
+ compile
+
+
+
+ datasketches-memory-java9-tests
+ ${project.artifactId}
+
+
+ 9
+ 9
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ --add-opens java.base/jdk.internal.ref=org.apache.datasketches.memory
+ --add-opens java.base/jdk.internal.misc=org.apache.datasketches.memory
+ --add-exports org.apache.datasketches.memory.tests/org.apache.datasketches.memory.test=org.testng
+
+
+
+
+
+
+
+
diff --git a/datasketches-memory-java9-tests/src/main/java/module-info.java b/datasketches-memory-java9-tests/src/main/java/module-info.java
new file mode 100644
index 00000000..7d6029bd
--- /dev/null
+++ b/datasketches-memory-java9-tests/src/main/java/module-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+module org.apache.datasketches.memory.tests {
+ requires java.base;
+ requires org.testng;
+ requires org.apache.datasketches.memory;
+}
diff --git a/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java
new file mode 100644
index 00000000..9518e494
--- /dev/null
+++ b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/MemoryCleanerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.test;
+
+import org.apache.datasketches.memory.internal.MemoryCleaner;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+@SuppressWarnings("javadoc")
+public class MemoryCleanerTest {
+
+ @Test
+ public void cleanerDeallocates() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ cleaner.clean();
+ assertTrue(deallocator.getHasRun());
+ }
+
+ @Test
+ public void noDeallocation() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ assertFalse(deallocator.getHasRun());
+ }
+
+ private static final class SimpleDeallocator implements Runnable {
+ static final AtomicBoolean hasRun = new AtomicBoolean();
+
+ private SimpleDeallocator() {
+ hasRun.set(false);
+ }
+
+ @Override
+ public void run() {
+ hasRun.compareAndSet(false, true);
+ }
+
+ public Boolean getHasRun() {
+ return hasRun.get();
+ }
+ }
+}
diff --git a/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
new file mode 100644
index 00000000..0002a85a
--- /dev/null
+++ b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.test;
+
+import org.apache.datasketches.memory.internal.VirtualMachineMemory;
+import org.testng.annotations.Test;
+
+@SuppressWarnings("javadoc")
+public class VirtualMachineMemoryTest {
+
+ @Test
+ public void maxDirectBufferMemory() {
+ assert(VirtualMachineMemory.getMaxDBBMemory() >= 0);
+ }
+
+ @Test
+ public void inertPageAlignment() {
+ System.out.println("VM page alignment:" + VirtualMachineMemory.getIsPageAligned());
+ assert(true);
+ }
+}
diff --git a/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/package-info.java b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/package-info.java
new file mode 100644
index 00000000..30a742b0
--- /dev/null
+++ b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/test/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.test;
\ No newline at end of file
diff --git a/datasketches-memory-java9/pom.xml b/datasketches-memory-java9/pom.xml
new file mode 100644
index 00000000..99903861
--- /dev/null
+++ b/datasketches-memory-java9/pom.xml
@@ -0,0 +1,69 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory-java8
+ ${project.version}
+
+
+
+ datasketches-memory-java9
+ ${project.artifactId}
+
+
+ 9
+ 9
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ --add-exports
+ java.base/jdk.internal.ref=org.apache.datasketches.memory
+ --add-exports
+ java.base/jdk.internal.misc=org.apache.datasketches.memory
+
+
+
+
+
+
+
+
diff --git a/datasketches-memory-java9/src/main/java/module-info.java b/datasketches-memory-java9/src/main/java/module-info.java
new file mode 100644
index 00000000..6ed3f90c
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/module-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+module org.apache.datasketches.memory {
+ requires java.base;
+ requires java.logging;
+ requires jdk.unsupported;
+
+ exports org.apache.datasketches.memory;
+ exports org.apache.datasketches.memory.internal to org.apache.datasketches.memory.tests;
+}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java
new file mode 100644
index 00000000..6b990594
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * Read only interface for a memory mapped file
+ *
+ * @author Roman Leventov
+ * @author Lee Rhodes
+ * @author Praveenkumar Venkatesan
+ */
+public interface Map extends AutoCloseable {
+
+ /**
+ * @see
+ * java/nio/MappedByteBuffer.load
+ */
+ void load();
+
+ /**
+ * @return true if loaded
+ *
+ * @see java
+ * /nio/MappedByteBuffer.isLoaded
+ */
+ boolean isLoaded();
+
+}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.java
new file mode 100644
index 00000000..448f3654
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/MemoryCleaner.java
@@ -0,0 +1,50 @@
+/*
+ * 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.internal;
+
+import jdk.internal.ref.Cleaner;
+
+/**
+ * Extracts a version-dependent reference to the `jdk.internal.ref.Cleaner` into
+ * a standalone class. The package name for Cleaner has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+public class MemoryCleaner {
+ private final Cleaner cleaner;
+
+ /**
+ * Creates a new `jdk.internal.ref.Cleaner`.
+ * @param referent the object to be cleaned
+ * @param deallocator - the cleanup code to be run when the cleaner is invoked.
+ * return MemoryCleaner
+ */
+ public MemoryCleaner(final Object referent, final Runnable deallocator) {
+ cleaner = Cleaner.create(referent, deallocator);
+ }
+
+ /**
+ * Runs this cleaner, if it has not been run before.
+ */
+ public void clean() {
+ cleaner.clean();
+ }
+}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
new file mode 100644
index 00000000..a2771bfc
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/NioBitsFields.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+/**
+ * Extracts version-dependent field names into standalone class.
+ * Some field names in the VM internal class have changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * * For more information, see: https://openjdk.java.net/jeps/238
+ */
+class NioBitsFields {
+ static String COUNT_FIELD_NAME = "count";
+ static String RESERVED_MEMORY_FIELD_NAME = "reservedMemory";
+ static String TOTAL_CAPACITY_FIELD_NAME = "totalCapacity";
+}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
new file mode 100644
index 00000000..d644228e
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.internal;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Extracts a version-dependent reference to the `jdk.internal.misc.VM` into
+ * a standalone class. The package name for VM has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+public final class VirtualMachineMemory {
+
+ private static final Class> VM_CLASS;
+ private static final Method VM_MAX_DIRECT_MEMORY_METHOD;
+ private static final Method VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD;
+ private static final long maxDBBMemory;
+ private static final boolean isPageAligned;
+
+ static {
+ try {
+ VM_CLASS = Class.forName("jdk.internal.misc.VM");
+ VM_MAX_DIRECT_MEMORY_METHOD = VM_CLASS.getDeclaredMethod("maxDirectMemory");
+ VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
+ maxDBBMemory = (long) VM_MAX_DIRECT_MEMORY_METHOD.invoke(null); //static method
+
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD =
+ VM_CLASS.getDeclaredMethod("isDirectMemoryPageAligned");
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.setAccessible(true);
+ isPageAligned = (boolean) VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD
+ .invoke(null); //static method
+ } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException | SecurityException e) {
+ throw new RuntimeException("Could not acquire jdk.internal.misc.VM: " + e.getClass());
+ }
+ }
+
+ /**
+ * Returns the maximum amount of allocatable direct buffer memory.
+ * The directMemory variable is initialized during system initialization.
+ * @return the maximum amount of allocatable direct buffer memory.
+ */
+ public static long getMaxDBBMemory() {
+ return maxDBBMemory;
+ }
+
+ /**
+ * Returns true if the direct buffers should be page aligned.
+ * @return flag that determines whether direct buffers should be page aligned.
+ */
+ public static boolean getIsPageAligned() {
+ return isPageAligned;
+ }
+}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/package-info.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/package-info.java
new file mode 100644
index 00000000..03c6da38
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.internal;
\ No newline at end of file
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java
new file mode 100644
index 00000000..d2f9b3b6
--- /dev/null
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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;
\ No newline at end of file
diff --git a/datasketches-memory-tests/pom.xml b/datasketches-memory-tests/pom.xml
new file mode 100644
index 00000000..61510c16
--- /dev/null
+++ b/datasketches-memory-tests/pom.xml
@@ -0,0 +1,360 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache.datasketches
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory
+ ${project.version}
+
+
+ org.apache.datasketches
+ datasketches-memory-java8-tests
+ ${project.version}
+ tests
+ test
+
+
+ org.testng
+ testng
+ ${testng.version}
+ test
+
+
+
+ com.google.protobuf
+ protobuf-java
+ ${protobuf-java.version}
+ test
+
+
+
+ net.openhft
+ zero-allocation-hashing
+ ${zero-allocation-hashing.version}
+ test
+
+
+
+ datasketches-memory-tests
+ ${project.artifactId}
+
+
+
+
+ java8
+
+ [1.8,1.9),8
+
+
+
+ 1.8
+ 8
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+
+ false
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+
+
+ java9
+
+ 9
+
+
+
+ 9
+ 9
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+ false
+
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.ref=ALL-UNNAMED
+
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+ java10
+
+ 10
+
+
+
+ 10
+ 10
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+ false
+
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.ref=ALL-UNNAMED
+
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+ java11
+
+ 11
+
+
+
+ 11
+ 11
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+ false
+
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.ref=ALL-UNNAMED
+
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+ java12
+
+ 12
+
+
+
+ 12
+ 12
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+ false
+
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.ref=ALL-UNNAMED
+
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+
+ java13
+
+ 13
+
+
+
+ 13
+ 13
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ package-test
+ package
+
+ test
+
+
+ false
+
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.ref=ALL-UNNAMED
+
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/datasketches-memory-tests/src/test/resources/GettysburgAddress.txt b/datasketches-memory-tests/src/test/resources/GettysburgAddress.txt
new file mode 100644
index 00000000..3969d176
--- /dev/null
+++ b/datasketches-memory-tests/src/test/resources/GettysburgAddress.txt
@@ -0,0 +1,7 @@
+Abraham Lincoln's Gettysburg Address:
+
+ Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
+
+ Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
+
+ But, in a larger sense, we can not dedicate —- we can not consecrate —- we can not hallow —- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -— that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -— that we here highly resolve that these dead shall not have died in vain -— that this nation, under God, shall have a new birth of freedom -— and that government of the people, by the people, for the people, shall not perish from the earth.
diff --git a/datasketches-memory/pom.xml b/datasketches-memory/pom.xml
new file mode 100644
index 00000000..8c74953d
--- /dev/null
+++ b/datasketches-memory/pom.xml
@@ -0,0 +1,382 @@
+
+
+
+
+ 4.0.0
+
+
+ org.apache
+ apache
+ 23
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory
+ 2.0.0-SNAPSHOT
+
+ ${project.artifactId}
+ High-performance native memory access.
+ https://datasketches.apache.org/
+ 2015
+
+
+
+ DataSketches Developers
+ dev-subscribe@datasketches.apache.org
+ dev-unsubscribe@datasketches.apache.org
+ dev@datasketches.apache.org
+ https://mail-archives.apache.org/mod_mbox/datasketches-dev
+
+
+ sketches-user
+ https://groups.google.com/forum/#!forum/sketches-user
+ mailto:sketches-user%2Bsubscribe@googlegroups.com
+ mailto:sketches-user%2Bunsubscribe@googlegroups.com
+ mailto:sketches-user@googlegroups.com
+
+
+
+
+ scm:git:ssh://git@github.com/apache/${project.artifactId}.git
+ scm:git:ssh://git@github.com/apache/${project.artifactId}.git
+ https://github.com/apache/${project.artifactId}
+ HEAD
+
+
+
+
+ GitHub
+ https://github.com/apache/${project.artifactId}/issues
+
+
+
+
+ The Apache DataSketches Team
+ dev@datasketches.apache.org
+ https://datasketches.apache.org
+ Apache Software Foundation
+ http://www.apache.org
+
+
+
+
+
+ true
+
+ 4.0.0-rc-2
+
+ 0.15
+
+
+
+
+ 7.1.0
+
+ 1.6
+ 4.0.4
+ 3.3.0
+
+ 0.8.6
+
+ false
+ false
+ true
+
+
+
+
+
+ org.apache.datasketches
+ datasketches-memory-java8
+ ${project.version}
+ provided
+
+
+ org.apache.datasketches
+ datasketches-memory-java9
+ ${project.version}
+ provided
+
+
+ org.apache.datasketches
+ datasketches-memory-java11
+ ${project.version}
+ provided
+
+
+
+ org.apache.datasketches
+ datasketches-memory-java8-tests
+ ${project.version}
+ test
+
+
+ org.apache.datasketches
+ datasketches-memory-java9-tests
+ ${project.version}
+ test
+
+
+
+ com.google.protobuf
+ protobuf-java
+ ${protobuf-java.version}
+ test
+
+
+
+ net.openhft
+ zero-allocation-hashing
+ ${zero-allocation-hashing.version}
+ test
+
+
+
+
+
+
+
+
+
+
+ maven-assembly-plugin
+
+ ${maven-assembly-plugin.version}
+
+
+
+ false
+ false
+ false
+
+
+ ${java.version} (${java.vendor} ${java.vm.version})
+ ${os.name} ${os.arch} ${os.version}
+ The Apache Software Foundation
+ ${project.groupId}:${project.artifactId}
+
+
+ ${git.branch}
+
+ ${git.commit.id.full}
+
+ ${git.commit.time}
+
+ ${git.commit.user.email}
+
+ ${git.tags}
+
+
+
+
+
+
+
+ assemble-jar
+ package
+
+ single
+
+
+ false
+ true
+
+ src/assembly/assemble-mr-jar.xml
+
+
+
+
+ true
+
+
+
+
+
+
+
+ assemble-sources-tests-javadocs
+ package
+
+ single
+
+
+ true
+ true
+
+
+ src/assembly/assemble-test-jar.xml
+
+ src/assembly/assemble-sources.xml
+
+ src/assembly/assemble-test-sources.xml
+
+ src/assembly/assemble-javadoc.xml
+
+
+
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ ${jacoco-maven-plugin.version}
+
+
+ default-report
+ verify
+
+ report-aggregate
+
+
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+ ${git-commit-id-plugin.version}
+
+
+
+
+
+
+
+
+
+ nexus-jars
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+ ${git-commit-id-plugin.version}
+
+
+
+ revision
+
+ initialize
+
+
+
+ ${project.basedir}/.git
+ UTC
+ false
+ false
+ json
+ true
+ ${project.build.directory}/git.properties
+ true
+ true
+ full
+
+ git.branch
+ git.commit.id.full
+ git.commit.time
+ git.commit.user.email
+ git.tags
+
+
+ false
+ true
+ 7
+ -dirty
+ true
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ ${maven-gpg-plugin.version}
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+ --verbose
+
+ --personal-digest-preferences=SHA512
+
+
+
+
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+
+
+
+
+
+
+
+
diff --git a/datasketches-memory/src/assembly/assemble-javadoc.xml b/datasketches-memory/src/assembly/assemble-javadoc.xml
new file mode 100644
index 00000000..4b82493c
--- /dev/null
+++ b/datasketches-memory/src/assembly/assemble-javadoc.xml
@@ -0,0 +1,69 @@
+
+
+
+ javadoc
+
+ jar
+
+ false
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java8
+
+
+ false
+
+
+ ${project.build.directory}/apidocs
+ /
+
+
+
+
+
+
+
+
+
+ ${project.build.outputDirectory}/META-INF
+ META-INF
+
+
+
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
diff --git a/datasketches-memory/src/assembly/assemble-mr-jar.xml b/datasketches-memory/src/assembly/assemble-mr-jar.xml
new file mode 100644
index 00000000..28fa7968
--- /dev/null
+++ b/datasketches-memory/src/assembly/assemble-mr-jar.xml
@@ -0,0 +1,104 @@
+
+
+
+ assemble-jar
+
+ jar
+
+ false
+
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java8
+
+
+ false
+
+
+ ${project.build.outputDirectory}
+ /
+
+
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java9
+
+
+ META-INF/versions/9
+ true
+ false
+
+
+ /META-INF/**
+
+
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java11
+
+
+ META-INF/versions/11
+ true
+ false
+
+
+ /META-INF/**
+
+
+
+
+
+
+
+
+
+ ${project.build.outputDirectory}/META-INF
+ META-INF
+
+
+
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
diff --git a/datasketches-memory/src/assembly/assemble-sources.xml b/datasketches-memory/src/assembly/assemble-sources.xml
new file mode 100644
index 00000000..972bd760
--- /dev/null
+++ b/datasketches-memory/src/assembly/assemble-sources.xml
@@ -0,0 +1,69 @@
+
+
+
+ sources
+
+ jar
+
+ false
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java8
+
+
+ false
+
+
+ ${project.build.sourceDirectory}
+ /
+
+
+
+
+
+
+
+
+
+ ${project.build.outputDirectory}/META-INF
+ META-INF
+
+
+
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
diff --git a/datasketches-memory/src/assembly/assemble-test-jar.xml b/datasketches-memory/src/assembly/assemble-test-jar.xml
new file mode 100644
index 00000000..7558566e
--- /dev/null
+++ b/datasketches-memory/src/assembly/assemble-test-jar.xml
@@ -0,0 +1,70 @@
+
+
+
+ tests
+
+ jar
+
+ false
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+ false
+
+
+ ${project.build.testOutputDirectory}
+ /
+
+
+
+
+
+
+
+
+
+ ${project.build.outputDirectory}/META-INF
+ META-INF
+
+
+
+
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
diff --git a/datasketches-memory/src/assembly/assemble-test-sources.xml b/datasketches-memory/src/assembly/assemble-test-sources.xml
new file mode 100644
index 00000000..5930b0f7
--- /dev/null
+++ b/datasketches-memory/src/assembly/assemble-test-sources.xml
@@ -0,0 +1,70 @@
+
+
+
+ test-sources
+
+ jar
+
+ false
+
+
+
+
+ true
+
+ org.apache.datasketches:datasketches-memory-java8-tests
+
+
+ false
+
+
+ ${project.build.testSourceDirectory}
+ /
+
+
+
+
+
+
+
+
+
+ ${project.build.outputDirectory}/META-INF
+ META-INF
+
+
+
+
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
+ META-INF/maven/org.apache.datasketches/datasketches-memory
+
+
+
+
diff --git a/docs/development.md b/docs/development.md
new file mode 100644
index 00000000..e3d82808
--- /dev/null
+++ b/docs/development.md
@@ -0,0 +1,70 @@
+# Development environment setup
+
+The use of Maven submodules to build a Multi Release JAR was motivated by its compatibility with popular IDEs.
+
+There are two configuration properties to be aware of when configuring your local development environment:
+
+#### Java compiler versions
+
+Settings are usually synchronised with maven toolchain configuration, otherwise the Java version for a maven module
+should be set as follows:
+
+| Maven submodule | JDK |
+| --------------------------------- | --- |
+| datasketches-memory-root | 8 |
+| datasketches-memory | 8 |
+| datasketches-memory-java8 | 8 |
+| datasketches-memory-java8-tests | 8 |
+| datasketches-memory-java9 | 9 |
+| datasketches-memory-java9-tests | 9 |
+| datasketches-memory-java11 | 11 |
+
+#### Compiler arguments for JPMS
+
+In order to compile Maven modules in Java versions 9 and above, it is necessary to provide the following arguments to the
+compiler. These are usually synchronised with the `pom.xml` configuration:
+
+```xml
+
+ --add-exports
+ java.base/jdk.internal.ref=org.apache.datasketches.memory
+ --add-exports
+ java.base/jdk.internal.misc=org.apache.datasketches.memory
+
+```
+
+---
+
+## IntelliJ configuration
+
+Note that the following configuration was verified using IntelliJ IDEA 2021.1.2 (Community Edition).
+
+#### Java compiler versions
+
+Ensure that the correct SDK is used for each module using the IntelliJ project structure dialog:
+
+![IntelliJ project structure dialog](img/intellij-project-structure.png "Intellij project structure dialogue")
+
+#### Compiler arguments for JPMS
+
+Ensure that the required JPMS arguments are set for the compiler (Java 9 only)
+
+![IntelliJ java compiler arguments](img/intellij-java-compiler-arguments.png "Intellij project compiler arguments")
+
+---
+
+## Eclipse configuration
+
+Note that the following configuration was verified using Eclipse Version: 2020-12 (4.18.0)
+
+#### Java compiler versions
+
+Ensure that the correct SDK is used for each module using the Eclipse build path dialog:
+
+![Eclipse project structure dialog](img/eclipse-project-structure.png "Eclipse project structure dialogue")
+
+#### Compiler arguments for JPMS
+
+Ensure that the required JPMS arguments are set for the compiler (Java 9 only)
+
+![Eclipse java compiler arguments](img/eclipse-java-compiler-arguments.png "Eclipse project compiler arguments")
diff --git a/docs/img/eclipse-java-compiler-arguments.png b/docs/img/eclipse-java-compiler-arguments.png
new file mode 100644
index 00000000..b9893b8a
Binary files /dev/null and b/docs/img/eclipse-java-compiler-arguments.png differ
diff --git a/docs/img/eclipse-project-structure.png b/docs/img/eclipse-project-structure.png
new file mode 100644
index 00000000..9032cfd0
Binary files /dev/null and b/docs/img/eclipse-project-structure.png differ
diff --git a/docs/img/intellij-java-compiler-arguments.png b/docs/img/intellij-java-compiler-arguments.png
new file mode 100644
index 00000000..01a039ae
Binary files /dev/null and b/docs/img/intellij-java-compiler-arguments.png differ
diff --git a/docs/img/intellij-project-structure.png b/docs/img/intellij-project-structure.png
new file mode 100644
index 00000000..214e4d7a
Binary files /dev/null and b/docs/img/intellij-project-structure.png differ
diff --git a/docs/img/mr-jar-manifest.png b/docs/img/mr-jar-manifest.png
new file mode 100644
index 00000000..02e47459
Binary files /dev/null and b/docs/img/mr-jar-manifest.png differ
diff --git a/docs/img/mr-jar-sources.png b/docs/img/mr-jar-sources.png
new file mode 100644
index 00000000..78cf4f7c
Binary files /dev/null and b/docs/img/mr-jar-sources.png differ
diff --git a/docs/maven.md b/docs/maven.md
new file mode 100644
index 00000000..f78805e0
--- /dev/null
+++ b/docs/maven.md
@@ -0,0 +1,49 @@
+# Maven multi-module project
+
+This project is a multi-module Maven project. A multi-module Maven project consists of an aggregator project
+(the `datasketches-memory-root` project), together with a set of submodules. The aggregator's configuration is inherited
+by each submodule, thus reducing duplication.
+
+`datasketches-memory` makes use of some features of the Java platform, namely `Unsafe`, which have evolved in
+Java versions 9 and above. Therefore, a multi-module project allows us to add support for later versions of
+Java by using indepent Maven modules to target platform-specific APIs. For example, to deallocate references
+a `sun.misc.Cleaner` may be used in Java8, but the `jdk.internal.ref.Cleaner` is used in Java 9.
+
+This project has been divided into the following submodules:
+
+* datasketches-memory-java8 (base version of the JVM that is currently supported)
+* datasketches-memory-java8-tests
+* datasketches-memory-java9 (Java9 equivalent of some platform specific classes in datasketches-memory-java8)
+* datasketches-memory-java9-tests
+* datasketches-memory-java11 (Java11 equivalent of some platform specific classes in datasketches-memory-java8)
+* datasketches-memory-java11-tests
+* datasketches-memory (JAR assembly, does not contain source files)
+* datasketches-memory-tests (Runs test suite against assembled JAR)
+
+### Artifact assembly
+
+The [Maven assembly plugin](https://maven.apache.org/plugins/maven-assembly-plugin/) builds all artifacts for this
+project from the other modules within the project. These modules are complementary and not standalone.
+Therefore, they are not installed and downloaded independently by the end user.
+
+Instead, the Maven assembly plugin builds all jars, and hides the multi-module configuration from the end user.
+
+The following jars are assembled by the `datasketches-memory` module:
+
+* datasketches-memory-X.Y.Z.jar The compiled main class files.
+* datasketches-memory-X.Y.Z-tests.jar The compiled test class files.
+* datasketches-memory-X.Y.Z-sources.jar The main source files.
+* datasketches-memory-X.Y.Z-test-sources.jar The test source files
+* datasketches-memory-X.Y.Z-javadoc.jar The compressed Javadocs.
+
+### Toolchains
+
+From the [maven-toolchain-plugin documentation](https://maven.apache.org/plugins/maven-toolchains-plugin/usage.html):
+> A Toolchain is an object that Maven plugins can use to retrieve preconfigured tools (including location and
+other information).
+With the jdk toolchain, for example, instead of being stuck with the JDK used to run Maven, all plugins
+can use the same other JDK instance without hardcoding absolute paths into the pom.xml and without configuring
+every plugin that require a path to JDK tools.
+
+Since this project targets version-specific Java API's, toolchains are used in different maven modules to ensure
+that the correct Java compiler version is used when compiling source files.
diff --git a/docs/module-system.md b/docs/module-system.md
new file mode 100644
index 00000000..19bb9ac0
--- /dev/null
+++ b/docs/module-system.md
@@ -0,0 +1,107 @@
+# Java Platform Module System (JPMS)
+
+The [Java Platform Module System](https://openjdk.java.net/projects/jigsaw/spec/) defines a module system for the Java
+Platform. For more documentation on the implementation, see [JEP-261](https://openjdk.java.net/jeps/261).
+
+#### Reliable configuration
+
+> Reliable configuration, to replace the brittle, error-prone class-path mechanism with a means for program components
+> to declare explicit dependences upon one another;
+
+This prevents ClassLoader errors such as `NoClassDefFoundError` that typically occur at runtime and make applications
+less reliable.
+
+#### Strong encapsulation
+
+> Strong encapsulation, to allow a component to declare which of its APIs are accessible by other components, and which
+> are not;
+
+JDK internals are now strongly encapsulated, except for critical internal APIs such as `sun.misc.Unsafe`
+(see [JEP-396](https://openjdk.java.net/jeps/396) and [JEP-403](https://openjdk.java.net/jeps/403)).
+`datasketches-memory` can no longer access these APIs by default, and requires explicit access.
+
+### Module declarations
+
+A module declaration is a java file (typically `module-info.java`) that explicitly defines a dependency graph.
+
+#### org.apache.datasketches.memory
+
+In the `datasketches-memory-java9` maven submodule root, the following module declaration has been added:
+
+```java
+module org.apache.datasketches.memory {
+ requires java.base;
+ requires java.logging;
+ requires jdk.unsupported;
+
+ exports org.apache.datasketches.memory;
+ exports org.apache.datasketches.memory.internal to org.apache.datasketches.memory.tests;
+}
+```
+
+This declaration explicitly defines the dependencies for `datasketches-memory`, as well as the external API.
+The `org.apache.datasketches.internal` package is now inaccessible to the end user, providing better encapsulation.
+
+#### org.apache.datasketches.memory.tests
+
+The module declaration above makes provision for unit testing. The `org.apache.datasketches.internal` package is not
+accessible to the end user, but is accessible to the `org.apache.datasketches.memory.tests` module:
+
+```java
+module org.apache.datasketches.memory.tests {
+ requires java.base;
+ requires org.testng;
+ requires org.apache.datasketches.memory;
+}
+```
+
+### Compiler arguments
+
+Some dependencies are encapsulated by default, and this causes compilation to fail for Java versions 9 and above.
+These dependencies can be made accessible at compile time through the use of the `add-exports` compiler argument.
+This argument allows one module to access some of the unexported types of another module. Datasketches memory has come
+to depend on several internal APIs and therefore requires special exposition.
+
+For example, in order to compile the `datasketches-memory-java9` submodule, the following compiler arguments are added
+to the Maven compiler plugin in the module's pom.xml file:
+
+```xml
+
+ --add-exports
+ java.base/jdk.internal.ref=org.apache.datasketches.memory
+ --add-exports
+ java.base/jdk.internal.misc=org.apache.datasketches.memory
+
+```
+
+### Runtime arguments
+
+Reflection is used by the datasketches memory library in cases where fields and methods that do not have `public` visibility
+in a class. Reflective access requires additional arguments to be provided by the user at runtime, in order to use the
+`datasketches-memory` JPMS module in Java versions 9 and above.
+
+The following runtime arguments should be provided when using the library:
+```shell
+ --add-opens java.base/java.nio=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.misc=org.apache.datasketches.memory \
+ --add-opens java.base/jdk.internal.ref=org.apache.datasketches.memory
+```
+
+In order to run unit tests, the Maven surefire plugin also requires similar runtime arguments in the
+`datasketches-memory-java9-tests Maven submodule pom.xml:
+
+```xml
+
+
+ --add-opens java.base/jdk.internal.ref=org.apache.datasketches.memory
+ --add-opens java.base/jdk.internal.misc=org.apache.datasketches.memory
+ --add-exports org.apache.datasketches.memory.tests/org.apache.datasketches.memory.test=org.testng
+
+
+```
+
+### JPMS and Java 8
+
+Java 8 does not support module declarations and the JPMS module system.
+However, support is retained for Java 8 users by only including the compiled declaration (`module-info.class`)
+in the `datasketches-memory` multi-release JAR for Java9 and above.
diff --git a/docs/multi-release-jar.md b/docs/multi-release-jar.md
new file mode 100644
index 00000000..1dc83d73
--- /dev/null
+++ b/docs/multi-release-jar.md
@@ -0,0 +1,31 @@
+# Multi-release JAR
+
+The `datasketches-memory` module assembles a JAR for release that consists of multiple Java-release-specific versions
+of class files to coexist in a single archive (the MR-JAR).
+
+From [JEP-238](https://openjdk.java.net/jeps/238):
+
+> Third party libraries and frameworks typically support a range of Java platform versions, generally going several
+ versions back. As a consequence they often do not take advantage of language or API features available in newer
+ releases since it is difficult to express conditional platform dependencies, which generally involves reflection, or
+ to distribute different library artifacts for different platform versions.
+
+and, specifically for libraries like `datasketches-memory`:
+
+> Some libraries and frameworks, furthermore, use internal APIs of the JDK that will be made inaccessible in Java 9
+ when module boundaries are strictly enforced. This also creates a disincentive to support new platform versions when
+ there are public, supported API replacements for such internal APIs.
+
+### Assembly
+
+The Maven assembly plugin uses the Maven submodules during the `package` phase. The following maven submodules to
+source the compiled class files for the MR-JAR:
+
+![MR-JAR maven module mapping](img/mr-jar-sources.png "MR-JAR maven module mapping")
+
+### Manifest
+
+The Maven assembly plugin copies version specific class files into JAR manifest META-INF directory, as
+shown in the diagram below:
+
+![MR-JAR manifest file contents](img/mr-jar-manifest.png "MR-JAR manifest file contents")
diff --git a/pom.xml b/pom.xml
index 98479869..d16d1d51 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,9 +31,10 @@ under the License.
org.apache.datasketches
- datasketches-memory
- 1.4.0-SNAPSHOT
- jar
+ datasketches-memory-root
+ 2.0.0-SNAPSHOT
+
+ pom${project.artifactId}High-performance native memory access.
@@ -81,21 +82,30 @@ under the License.
+
+
+
- 1.7.30
- 1.7.30
- 3.6.0
+ 4.0.0-rc-2
- 0.8
+ 0.15
- 7.4.0
+
+ 7.1.03.5.01.8
+ 8${java.version}${java.version}-Xmx4g -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8
@@ -110,18 +120,17 @@ under the License.
2.8.1
- 3.3.03.8.13.0.0-M1
- 3.0.0-M2
- 1.6
+ 3.0.0-M33.2.0
- 3.2.0
+ 3.3.03.0.0-M1[1.7.0,)3.2.13.0.0-M53.0.0
+ 3.0.0-M10.13
@@ -131,7 +140,9 @@ under the License.
4.3.01.0.0
- 4.0.4
+ true
+ true
+ true
@@ -159,44 +170,30 @@ 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
-
-
-
-
-
- org.testng
- testng
- ${testng.version}
- test
-
-
+
+
+
+ org.testng
+ testng
+ ${testng.version}
+ test
+
+
+
+ com.google.protobuf
+ protobuf-java
+ ${protobuf-java.version}
+ test
+
+
+
+ net.openhft
+ zero-allocation-hashing
+ ${zero-allocation-hashing.version}
+ test
+
+
+
@@ -253,10 +250,15 @@ under the License.
${maven-javadoc-plugin.version}true
+ none
+
+ ${jdk-toolchain.version}
+ attach-javadocs
+ packagejar
@@ -277,7 +279,7 @@ under the License.
- ${java.version}
+ [1.8,1.9),[8,14)${maven.version},
@@ -318,6 +320,7 @@ under the License.
**/*.yml**/.***/test/resources/**/*.txt
+ **/docs/*.mdLICENSENOTICE
@@ -356,6 +359,9 @@ under the License.
falsefalsetrue
+
+ ${jdk-toolchain.version}
+
@@ -365,7 +371,9 @@ under the License.
${maven-toolchains-plugin.version}
- 8
+
+ [1.8,1.9),[9,14)
+
@@ -387,12 +395,6 @@ under the License.
prepare-agent
-
- default-report
-
- report
-
-
@@ -402,14 +404,22 @@ under the License.
coveralls-maven-plugin${coveralls-maven-plugin.version}
+
${coveralls-repo-token}
+
+ ${maven.multiModuleProjectDirectory}/datasketches-memory/target/site/jacoco-aggregate/jacoco.xml
- pl.project13.maven
- git-commit-id-plugin
- ${git-commit-id-plugin.version}
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ ${jdk-toolchain.version}
+
+
@@ -455,186 +465,14 @@ under the License.
org.eluder.coverallscoveralls-maven-plugin
-
- pl.project13.maven
- git-commit-id-plugin
-
+
-
- strict
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
-
- org.codehaus.plexus
- plexus-compiler-javac-errorprone
- ${plexus-compiler-javac-errorprone.version}
-
-
-
-
- ${maven.compiler.target}
- javac-with-errorprone
- true
-
-
-
-
-
-
-
-
- nexus-jars
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
- ${git-commit-id-plugin.version}
-
-
-
- revision
-
- initialize
-
-
-
- ${project.basedir}/.git
- UTC
- false
- false
- json
- true
- ${project.build.directory}/git.properties
- true
- true
- full
-
- git.branch
- git.commit.id.full
- git.commit.time
- git.commit.user.email
- git.tags
-
-
- false
- true
- 7
- -dirty
- true
- true
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${maven-jar-plugin.version}
-
-
- default-jar
-
- jar
-
-
-
- default-test-jar
-
- test-jar
-
-
-
-
-
-
- false
- false
- false
-
-
- ${java.version} (${java.vendor} ${java.vm.version})
- ${os.name} ${os.arch} ${os.version}
- The Apache Software Foundation
- ${project.groupId}:${project.artifactId}
-
-
- ${git.branch}
-
- ${git.commit.id.full}
-
- ${git.commit.time}
-
- ${git.commit.user.email}
-
- ${git.tags}
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- ${maven-gpg-plugin.version}
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
- --verbose
-
- --personal-digest-preferences=SHA512
-
-
-
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
-
-
-
-
-
@@ -655,4 +493,20 @@ under the License.
+
+
+
+ datasketches-memory-java8
+ datasketches-memory-java8-tests
+ datasketches-memory-java9
+ datasketches-memory-java9-tests
+ datasketches-memory-java11
+ datasketches-memory
+ datasketches-memory-tests
+
+
diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml
index 5fe40e59..93c3bf3e 100644
--- a/tools/MemoryCheckstyle.xml
+++ b/tools/MemoryCheckstyle.xml
@@ -23,7 +23,7 @@ under the License.
-->