Skip to content
Permalink
Browse files
Merge branch 2.0.X
  • Loading branch information
davecromberge committed Sep 15, 2021
2 parents a94680f + f2128e3 commit 2aabed32c90dfbe2a7b5d552006e23f8ca986b89
Showing 18 changed files with 612 additions and 158 deletions.
@@ -122,6 +122,12 @@ jobs:
-Dmatrix.jdk.version=${{matrix.jdk}}
--toolchains .github/workflows/.toolchains.xml
# The GitTag for CI purposes is irrelevant
- name: Custom build script
run: |
./tools/scripts/compile-package-jar.sh $JAVA_HOME x.y.z .
shell: bash

- name: Test & Report
if: ${{ matrix.jdk == 8 && success() }}
run: >
155 README.md
@@ -26,28 +26,75 @@
=================

# DataSketches Java Memory Component
The goal of this component of the library is to provide high performance access to heap memory or
native memory for primitives, primitive arrays, ByteBuffers and memory mapped files.
This package is general purpose, has minimal external runtime dependencies and can be used in any
application that needs to manage data structures outside the Java heap.
This Memory component is general purpose, has no external runtime dependencies and can be used in any
application that needs to manage data structures inside or outside the Java heap.

The goal of this component of the DataSketches library is to provide a high performance access API for accessing four different types of memory resources. Each of the four resource types is accessed using different API methods in the Memory component.

* **Heap:** Contiguous bytes on the Java Heap constructed by, e.g., *WritableMemory.writableWrap(byte[])* or using the *WritableMemory.allocate(int)* method. For purposes of this document this includes on-heap ByteBuffers constructed using *ByteBuffer.allocate(int)*.

* **DirectByteBuffer:** Contiguous bytes of a ByteBuffer constructed by, e.g., *WritableMemory.writableWrap(ByteBuffer)* where the ByteBuffer was previously constructed using *ByteBuffer.allocateDirect(int)*; or, is a slice() thereof.

* **Direct:** Contiguous bytes off the Java Heap constructed by, e.g., *WritableMemory.allocateDirect(long)* method.

* **Memory-Mapped Files** Contiguous bytes of a file represented in off-heap memory and created using, e.g., the *WritableMemory.writableMap(File)* method.

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.
If you are interested in making contributions to this Memory component please see our
[Community](https://datasketches.apache.org/docs/Community/) page.

---
## Release 2.0.0+
Starting with release *datasketches-memory-2.0.0*, this Memory component supports Java 8 through Java 13. Providing access to the four contiguous byte resources (mentioned above) in Java 8 only requires reflection. However, **Java 9 introduced the Java Platform Module System (JPMS) where access to these internal classes requires starting up the JVM with special JPMS arguments.** The actual JVM arguments required will depend on how the user intends to use the Memory API, the Java version used to run the user's application and whether the user's application is a JPMS application or not.

## Java Support
Datasketches Memory currently supports Java 8 up to and including Java 13.
Also see the [usage examples](docs/usage-examples.md) for more information.

__NOTE:__ You may have to provide additional JPMS arguments in order to use the library in Java 9 and above,
see the [usage instructions](docs/usage-instructions.md) for details.
## USE AS A LIBRARY (using jars from Maven Central)
In this environment, the user is using the Jars from Maven Central as a library dependency and not attempting to build the Memory component from the source code or run the Memory component tests.

---
* If you are running Java 8, no extra JVM arguments are required.
* If you are running Java 9-13 and only using the **Heap** related API, no extra JVM arguments are required.

Otherwise, if you are running Java 9-13 and ...

* If your application **is not a JPMS module** use the following table. Choose the columns that describe your use of the Memory API. If any of the columns contain a *Yes*, then the JVM argument in the first column of the row containing a *Yes* will be required. If you are not sure the extent of the Memory API being used, there is no harm in specifying all 4 JVM arguments. Note: do not embed any spaces in the full argument.

| JVM Arguments for non-JPMS Applications | Direct ByteBuffer | Direct | MemoryMapped Files |
|:------------------------------------------------------:|:----------------:|:------:|:------------------:|
| --add-exports java.base/jdk.internal.misc= ALL-UNNAMED | | Yes | |
| --add-exports java.base/jdk.internal.ref= ALL-UNNAMED | | Yes | Yes |
| --add-opens java.base/java.nio= ALL-UNNAMED | | Yes | Yes |
| --add-opens java.base/sun.nio.ch= ALL-UNNAMED | | | Yes |

* If your application **is a JPMS module** use the following table. Choose the columns that describe your use of the Memory API. If any of the columns contain a *Yes*, then the JVM argument in the first column of the row containing a *Yes* will be required. If you are not sure the extent of the Memory API being used, there is no harm in specifying all 4 JVM arguments. Note: do not embed any spaces in the full argument.

| JVM Arguments for JPMS Applications | Direct ByteBuffer | Direct | MemoryMapped Files |
|:-------------------------------------------------------------------------:|:----------------:|:------:|:------------------:|
| --add-exports java.base/jdk.internal.misc= org.apache.datasketches.memory | | Yes | |
| --add-exports java.base/jdk.internal.ref= org.apache.datasketches.memory | | Yes | Yes |
| --add-opens java.base/java.nio= org.apache.datasketches.memory | | Yes | Yes |
| --add-opens java.base/sun.nio.ch= org.apache.datasketches.memory | Yes | | Yes |


## DEVELOPER USAGE
In this environment the developer needs to build the Memory component from source and run the Memory Component tests. There are two use cases. The first is for a *System Developer* that needs to build and test their own Jar from source for a specific Java version. The second use case is for a *Memory Component Developer and Contributor*.

* System Developer
* Compile, test and create a Jar for a specific Java version
* use the provided script for this purpose

## Build Instructions
__NOTE:__
* Memory Component Developer / Contributor
* Compile & test the library from source code using:
* Eclipse (version)
* IntelliJ (version)
* Maven (version)
* Command-line or scripts
* The developer must have installed in their development system at least JDK versions 8, 9 and 11.
* Unless building with the provided script, the developer must have a valid [Maven toolchain configuration](docs/maven-toolchains.md).


### Build Instructions
__NOTES:__

1) 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.
@@ -56,87 +103,107 @@ __NOTE:__
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)

2) This project is structured as a Maven multi-module project.
2) This project is structured as a Maven multi-module project.
Building this project might affect plugins that require early dependency resolution, such as the
javadoc and eclipse plugins.
The build instructions below have been modified to use the `process-classes` phase (instead of `compile`)
The Maven build instructions below have been modified to use the `process-classes` phase (instead of `compile`)
for these use cases.

For more information, see this [Maven Reactor Issue](https://issues.apache.org/jira/browse/MNG-3283).

### JDK versions required to compile
This DataSketches component is pure Java and requires the following JDKs to compile:
#### Dependencies
There are no run-time dependencies. See the pom.xml file for test dependencies.

#### Maven build instructions
The Maven build requires the following JDKs to compile:

- JDK8/Hotspot
- JDK9/Hotspot
- JDK11/Hotspot

Ensure that your local environment has been configured according to the
[Maven Toolchains Configuration](docs/maven-toolchains.md).
Before building, first ensure that your local environment has been configured according to the [Maven Toolchains Configuration](docs/maven-toolchains.md).

### 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 three types of tests: normal unit tests, tests run by the strict profile and continuous integration(CI) tests.
The CI tests target the Multi-Release (MR) JAR and run the entire test suite using a specific version of Java. Running the CI test command also runs the default unit tests.

To run normal unit tests:

$ mvn clean test
mvn clean test

To run the strict profile tests (only supported in Java 8):

$ mvn clean test -P strict
mvn clean test -P strict

To run javadoc on this multi-module project, use:

$ mvn clean process-classes javadoc:javadoc -DskipTests=true
mvn clean process-classes javadoc:javadoc -DskipTests=true

To run the CI tests against the multi-release JAR for specific JVM versions [9-13], use:

$ mvn clean package -Denvironment=ci -Dmatrix.jdk.version=9
mvn clean package -Denvironment=ci -Dmatrix.jdk.version=9

To run the eclipse plugin on this multi-module project, use:

$ mvn clean process-classes eclipse:eclipse -DskipTests=true
mvn clean process-classes eclipse:eclipse -DskipTests=true

To install jars built from the downloaded source:

$ mvn clean install -DskipTests=true
mvn clean install -DskipTests=true

This will create the following Jars:

* 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.
* datasketches-memory-X.Y.Z-javadoc.jar The compressed Javadocs.

#### Building for a specific java version

A build script named **compile-package-jar.sh** has been provided to package a JAR for a specific java version. This is necessary in cases where a developer is unable to install all the required versions of the JDK that are required as part of the Maven build.

The build script performs the following steps:

1. Sets up staging directories under **target/** for the package files
2. Uses git commands to gather information about the current Git commit and branch
3. Compiles java source tree
4. Packages a JAR containing compiled sources together with the Manifest, Licence and Notice files
5. Checks and tests the assembled JAR by using the API to access four different resource types

The build script is located in the **tools/scripts/** directory and requires the following arguments:

* JDK Home Directory - The first argument is the absolute path of JDK home directory e.g. $JAVA_HOME
* Git Version Tag - The second argument is the Git Version Tag for this deployment e.g. 1.0.0-SNAPSHOT, 1.0.0-RC1, 1.0.0 etc.
* Project Directory - The third argument is the absolute path of project.basedir e.g. /src/apache-datasketches-memory

For example, if the project base directory is `/src/datasketches-memory`;

To run the script for a release version:

./tools/scripts/compile-package-jar.sh $JAVA_HOME 2.0.0 /src/datasketches-memory

### Toolchains
To run the script for a snapshot version:

This project makes use of Maven toolchains to ensure that the correct Java compiler version is
used when compiling source files.
See the [Maven Toolchains Configuration](docs/maven-toolchains.md) for more details.
./tools/scripts/compile-package-jar.sh $JAVA_HOME 2.1.0-SNAPSHOT /src/datasketches-memory

### Dependencies
To run the script for an RC version:

There are no run-time dependencies.
./tools/scripts/compile-package-jar.sh $JAVA_HOME 2.0.0-RC1 /src/datasketches-memory

#### Testing
See the pom.xml file for test dependencies.
Note that the script does **not** use the _Git Version Tag_ to adjust the working copy to a remote tag - it is expected that the user has a pristine copy of the desired branch/tag available **before** using the script.

---

## Further documentation for contributors
### Further documentation for contributors

For more information on the project configuration, the following topics are discussed in more
For more information on the project configuration, the following topics are discussed in more
detail:

* [Maven Configuration](docs/maven.md)
* [Maven Toolchains Configuration](docs/maven-toolchains.md)
* [Multi-Release Jar](docs/multi-release-jar.md)
* [Java Platform Module System](docs/module-system.md)
* [Usage instructions](docs/usage-instructions.md)
* [Usage examples](docs/usage-examples.md)

In order to build and contribute to this project, please read the relevant IDE documentation:

@@ -34,7 +34,7 @@
<groupId>org.apache.datasketches</groupId>
<artifactId>datasketches-memory-java8</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
@@ -38,7 +38,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@SuppressWarnings("javadoc")
@SuppressWarnings({"javadoc", "unused"})
public class AllocateDirectMapMemoryTest {
private static final String LS = System.getProperty("line.separator");
MapHandle hand = null;
@@ -33,6 +33,7 @@
<groupId>org.apache.datasketches</groupId>
<artifactId>datasketches-memory-java8</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

@@ -24,7 +24,7 @@
* 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
* For more information, see: https://openjdk.java.net/jeps/238
*/
class NioBitsFields {
static String COUNT_FIELD_NAME = "count";
@@ -35,6 +35,7 @@
<groupId>org.apache.datasketches</groupId>
<artifactId>datasketches-memory</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
@@ -112,6 +113,7 @@
<dependenciesToScan>
<dependency>org.apache.datasketches:datasketches-memory-java8-tests</dependency>
</dependenciesToScan>
<reportsDirectory>${project.build.directory}/test-output/${maven.build.timestamp}</reportsDirectory>
<argLine />
</configuration>
</execution>
@@ -177,6 +179,7 @@
<dependenciesToScan>
<dependency>org.apache.datasketches:datasketches-memory-java8-tests</dependency>
</dependenciesToScan>
<reportsDirectory>${project.build.directory}/test-output/${maven.build.timestamp}</reportsDirectory>
</configuration>
</execution>
</executions>

0 comments on commit 2aabed3

Please sign in to comment.