Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ jobs:
- uses: actions/checkout@v2
- name: jcheckstyle
run: ./sbt jcheckStyle
test_jdk21:
name: Test JDK21
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '21'
- uses: actions/cache@v2
with:
path: ~/.cache
key: ${{ runner.os }}-jdk21-${{ hashFiles('**/*.sbt') }}
restore-keys: ${{ runner.os }}-jdk21-
- name: Test
run: ./sbt test
- name: Universal Buffer Test
run: ./sbt test -J-Dmsgpack.universal-buffer=true
test_jdk17:
name: Test JDK17
runs-on: ubuntu-latest
Expand All @@ -39,7 +57,7 @@ jobs:
- uses: actions/cache@v2
with:
path: ~/.cache
key: ${{ runner.os }}-jdk11-${{ hashFiles('**/*.sbt') }}
key: ${{ runner.os }}-jdk17-${{ hashFiles('**/*.sbt') }}
restore-keys: ${{ runner.os }}-jdk17-
- name: Test
run: ./sbt test
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val buildSettings = Seq[Setting[_]](
organizationName := "MessagePack",
organizationHomepage := Some(new URL("http://msgpack.org/")),
description := "MessagePack for Java",
scalaVersion := "2.13.6",
scalaVersion := "2.13.12",
Test / logBuffered := false,
// msgpack-java should be a pure-java library, so remove Scala specific configurations
autoScalaLibrary := false,
Expand All @@ -26,11 +26,11 @@ val buildSettings = Seq[Setting[_]](
// JVM options for building
scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked", "-feature"),
Test / javaOptions ++= Seq("-ea"),
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
Compile / compile / javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation"),
// Use lenient validation mode when generating Javadoc (for Java8)
doc / javacOptions := {
val opts = Seq("-source", "1.7")
val opts = Seq("-source", "1.8")
if (scala.util.Properties.isJavaAtLeast("1.8")) {
opts ++ Seq("-Xdoclint:none")
} else {
Expand Down Expand Up @@ -92,7 +92,7 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
"org.msgpack" % "msgpack" % "0.6.12" % "test",
// For integration test with Akka
"com.typesafe.akka" %% "akka-actor" % "2.6.20" % "test",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0" % "test"
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0" % "test"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private DirectBufferAccess()

enum DirectBufferConstructorType
{
ARGS_LONG_LONG,
ARGS_LONG_INT_REF,
ARGS_LONG_INT,
ARGS_INT_INT,
Expand Down Expand Up @@ -64,28 +65,35 @@ enum DirectBufferConstructorType
DirectBufferConstructorType constructorType = null;
Method mbWrap = null;
try {
// TODO We should use MethodHandle for Java7, which can avoid the cost of boxing with JIT optimization
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(long.class, int.class, Object.class);
constructorType = DirectBufferConstructorType.ARGS_LONG_INT_REF;
// JDK21 DirectByteBuffer(long, long)
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(long.class, long.class);
constructorType = DirectBufferConstructorType.ARGS_LONG_LONG;
}
catch (NoSuchMethodException e0) {
catch (NoSuchMethodException e00) {
try {
// https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/DirectByteBuffer.java
// DirectByteBuffer(long address, int capacity)
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(long.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_LONG_INT;
// TODO We should use MethodHandle for Java7, which can avoid the cost of boxing with JIT optimization
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(long.class, int.class, Object.class);
constructorType = DirectBufferConstructorType.ARGS_LONG_INT_REF;
}
catch (NoSuchMethodException e1) {
catch (NoSuchMethodException e0) {
try {
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(int.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_INT_INT;
// https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/DirectByteBuffer.java
// DirectByteBuffer(long address, int capacity)
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(long.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_LONG_INT;
}
catch (NoSuchMethodException e2) {
Class<?> aClass = Class.forName("java.nio.MemoryBlock");
mbWrap = aClass.getDeclaredMethod("wrapFromJni", int.class, long.class);
mbWrap.setAccessible(true);
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(aClass, int.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_MB_INT_INT;
catch (NoSuchMethodException e1) {
try {
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(int.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_INT_INT;
}
catch (NoSuchMethodException e2) {
Class<?> aClass = Class.forName("java.nio.MemoryBlock");
mbWrap = aClass.getDeclaredMethod("wrapFromJni", int.class, long.class);
mbWrap.setAccessible(true);
directByteBufferConstructor = directByteBufferClass.getDeclaredConstructor(aClass, int.class, int.class);
constructorType = DirectBufferConstructorType.ARGS_MB_INT_INT;
}
}
}
}
Expand Down Expand Up @@ -281,6 +289,8 @@ static ByteBuffer newByteBuffer(long address, int index, int length, ByteBuffer
}
try {
switch (directBufferConstructorType) {
case ARGS_LONG_LONG:
return (ByteBuffer) byteBufferConstructor.newInstance(address + index, (long) length);
case ARGS_LONG_INT_REF:
return (ByteBuffer) byteBufferConstructor.newInstance(address + index, length, reference);
case ARGS_LONG_INT:
Expand Down