Skip to content
Snippets Groups Projects
Commit d9320680 authored by Andrius Merkys's avatar Andrius Merkys
Browse files

New upstream version 0.9.3

parent cfa108be
No related branches found
No related tags found
No related merge requests found
......@@ -26,14 +26,33 @@ jobs:
- uses: actions/checkout@v2
- name: jcheckstyle
run: ./sbt jcheckStyle
test_jdk17:
name: Test JDK17
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- uses: actions/cache@v2
with:
path: ~/.cache
key: ${{ runner.os }}-jdk11-${{ hashFiles('**/*.sbt') }}
restore-keys: ${{ runner.os }}-jdk17-
- name: Test
run: ./sbt test
- name: Universal Buffer Test
run: ./sbt test -J-Dmsgpack.universal-buffer=true
test_jdk11:
name: Test JDK11
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
- uses: actions/setup-java@v3
with:
java-version: adopt@1.11
distribution: 'zulu'
java-version: '11'
- uses: actions/cache@v2
with:
path: ~/.cache
......@@ -48,9 +67,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
- uses: actions/setup-java@v3
with:
java-version: adopt@1.8
distribution: 'zulu'
java-version: '8'
- uses: actions/cache@v2
with:
path: ~/.cache
......
This product includes the software developed by third-party:
* Google Guava https://code.google.com/p/guava-libraries/ (APL2)
* Google Guava https://code.google.com/p/guava-libraries/ (Apache-2.0)
* sbt-extras: https://github.com/paulp/sbt-extras (BSD) (LICENSE.sbt-extras.txt)
......@@ -42,6 +42,15 @@ dependencies {
- [Usage examples](https://github.com/msgpack/msgpack-java/blob/develop/msgpack-core/src/test/java/org/msgpack/core/example/MessagePackExample.java)
### Java 17 Support
For using DirectByteBuffer (off-heap memory access methods) in JDK17, you need to specify two JVM options:
```
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
```
### Integration with Jackson ObjectMapper (jackson-databind)
msgpack-java supports serialization and deserialization of Java objects through [jackson-databind](https://github.com/FasterXML/jackson-databind).
......
# Release Notes
## 0.9.3
This version supports JDK17 [#660](http://github.com/msgpack/msgpack-java/pull/660).
Important: If you need to use DirectByteBuffer (raw memory access) in JDK17 or later, specify two JVM options to allow accessing
native memory:
```
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
```
Internal updates:
* Use SPDX-ID in license name [#653](http://github.com/msgpack/msgpack-java/pull/653)
* Update airframe-json, airspec to 22.6.4 [#659](http://github.com/msgpack/msgpack-java/pull/659)
* Update akka-actor to 2.6.19 [#647](http://github.com/msgpack/msgpack-java/pull/647)
## 0.9.2
Internal updates:
......
......@@ -5,7 +5,7 @@ Global / concurrentRestrictions := Seq(
Tags.limit(Tags.Test, 1)
)
val AIRFRAME_VERSION = "22.6.1"
val AIRFRAME_VERSION = "22.6.4"
// Use dynamic snapshot version strings for non tagged versions
ThisBuild / dynverSonatypeSnapshots := true
......@@ -74,6 +74,13 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
"org.msgpack.value.impl"
),
testFrameworks += new TestFramework("wvlet.airspec.Framework"),
Test / javaOptions ++= Seq(
// --add-opens is not available in JDK8
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
),
Test / fork := true,
libraryDependencies ++= Seq(
// msgpack-core should have no external dependencies
junitInterface,
......
......@@ -18,11 +18,13 @@ package org.msgpack.core.buffer;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;
/**
* Wraps the difference of access methods to DirectBuffers between Android and others.
......@@ -30,7 +32,8 @@ import sun.misc.Unsafe;
class DirectBufferAccess
{
private DirectBufferAccess()
{}
{
}
enum DirectBufferConstructorType
{
......@@ -40,7 +43,6 @@ class DirectBufferAccess
ARGS_MB_INT_INT
}
static Method mGetAddress;
// For Java <=8, gets a sun.misc.Cleaner
static Method mCleaner;
static Method mClean;
......@@ -95,10 +97,19 @@ class DirectBufferAccess
if (byteBufferConstructor == null) {
throw new RuntimeException("Constructor of DirectByteBuffer is not found");
}
byteBufferConstructor.setAccessible(true);
mGetAddress = directByteBufferClass.getDeclaredMethod("address");
mGetAddress.setAccessible(true);
try {
byteBufferConstructor.setAccessible(true);
}
catch (RuntimeException e) {
// This is a Java9+ exception, so we need to detect it without importing it for Java8 support
if ("java.lang.reflect.InaccessibleObjectException".equals(e.getClass().getName())) {
byteBufferConstructor = null;
}
else {
throw e;
}
}
if (MessageBuffer.javaVersion <= 8) {
setupCleanerJava6(direct);
......@@ -160,6 +171,7 @@ class DirectBufferAccess
/**
* Checks if we have a usable {@link DirectByteBuffer#cleaner}.
*
* @param direct a direct buffer
* @return the method or an error
*/
......@@ -184,6 +196,7 @@ class DirectBufferAccess
/**
* Checks if we have a usable {@link sun.misc.Cleaner#clean}.
*
* @param direct a direct buffer
* @param mCleaner the {@link DirectByteBuffer#cleaner} method
* @return the method or null
......@@ -210,6 +223,7 @@ class DirectBufferAccess
/**
* Checks if we have a usable {@link Unsafe#invokeCleaner}.
*
* @param direct a direct buffer
* @return the method or an error
*/
......@@ -218,7 +232,7 @@ class DirectBufferAccess
try {
// See https://bugs.openjdk.java.net/browse/JDK-8171377
Method m = MessageBuffer.unsafe.getClass().getDeclaredMethod(
"invokeCleaner", ByteBuffer.class);
"invokeCleaner", ByteBuffer.class);
m.invoke(MessageBuffer.unsafe, direct);
return m;
}
......@@ -233,17 +247,9 @@ class DirectBufferAccess
}
}
static long getAddress(Object base)
static long getAddress(Buffer buffer)
{
try {
return (Long) mGetAddress.invoke(base);
}
catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
return ((DirectBuffer) buffer).address();
}
static void clean(Object base)
......@@ -253,7 +259,7 @@ class DirectBufferAccess
Object cleaner = mCleaner.invoke(base);
mClean.invoke(cleaner);
}
else {
else {
mInvokeCleaner.invoke(MessageBuffer.unsafe, base);
}
}
......@@ -269,6 +275,10 @@ class DirectBufferAccess
static ByteBuffer newByteBuffer(long address, int index, int length, ByteBuffer reference)
{
if (byteBufferConstructor == null) {
throw new IllegalStateException("Can't create a new DirectByteBuffer. In JDK17+, two JVM options needs to be set: " +
"--add-opens=java.base/java.nio=ALL-UNNAMED and --add-opens=java.base/sun.nio.ch=ALL-UNNAMED");
}
try {
switch (directBufferConstructorType) {
case ARGS_LONG_INT_REF:
......
//
// MessagePack for Java
//
// Licensed 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.msgpack.core.buffer
import wvlet.airspec.AirSpec
import java.nio.ByteBuffer
class DirectBufferAccessTest extends AirSpec {
test("instantiate DirectBufferAccess") {
val bb = ByteBuffer.allocateDirect(1)
val addr = DirectBufferAccess.getAddress(bb)
}
}
......@@ -2,7 +2,7 @@ import xerial.sbt.Sonatype._
ThisBuild / sonatypeProfileName := "org.msgpack"
ThisBuild / homepage := Some(url("https://msgpack.org/"))
ThisBuild / licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/msgpack/msgpack-java"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment