diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml
index 3795cb9..a192034 100644
--- a/.github/workflows/ci-workflow.yml
+++ b/.github/workflows/ci-workflow.yml
@@ -1,4 +1,4 @@
-name: CI Build
+name: Build
# Controls when the action will run.
on:
@@ -13,14 +13,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
-# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
- # This workflow contains a single job called "build"
- build:
- # The type of runner that the job will run on
+ java17:
runs-on: ubuntu-latest
-
- # Steps represent a sequence of tasks that will be executed as part of the job
steps:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Create Cache Key
@@ -50,7 +45,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: '**/target/surefire-reports/TEST-*.xml'
commit: ${{ github.event.workflow_run.head_commit.id }}
- check_name: Build test reports
+ check_name: java17 test reports
- name: Upload build artefacts
uses: actions/upload-artifact@v2
if: ${{ failure() }}
@@ -60,3 +55,34 @@ jobs:
# Make room for the docker layer caching to package up layers
- name: Cleanup
run: rm -fr *
+ java11:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Java 11
+ uses: actions/setup-java@v2
+ with:
+ distribution: 'adopt' # See 'Supported distributions' for available options
+ java-version: '11'
+ - uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Maven build
+ run: mvn verify -B -C -T1C -fae
+ - name: Publish Test Report
+ uses: scacap/action-surefire-report@v1.0.9
+ if: ${{ always() }}
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ report_paths: '**/target/surefire-reports/TEST-*.xml'
+ commit: ${{ github.event.workflow_run.head_commit.id }}
+ check_name: java11 test reports
+ - name: Upload build artefacts
+ uses: actions/upload-artifact@v2
+ if: ${{ failure() }}
+ with:
+ name: artifacts
+ path: target/
diff --git a/Dockerfile b/Dockerfile
index 3b35ae9..b55f483 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,8 +29,12 @@ RUN git clone --depth 1 -b master https://github.com/netty/netty.git netty \
&& rm -fr netty
# Prepare our own build
+RUN mkdir buffer-api && mkdir buffer-memseg && mkdir buffer-tests
COPY pom.xml pom.xml
-RUN mvn dependency:go-offline surefire:test checkstyle:check -ntp
+COPY buffer-api/pom.xml buffer-api/pom.xml
+COPY buffer-memseg/pom.xml buffer-memseg/pom.xml
+COPY buffer-tests/pom.xml buffer-tests/pom.xml
+RUN mvn install dependency:go-offline surefire:test checkstyle:check -ntp
# Copy over the project code and run our build
COPY . .
diff --git a/Makefile b/Makefile
index 905ad57..d168424 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,9 @@ build: image
docker start -a build-container || (docker cp build-container:/home/build target/container-output && false)
docker wait build-container || (docker cp build-container:/home/build target/container-output && false)
docker cp build-container:/home/build/target .
+ docker cp build-container:/home/build/buffer-api/target .
+ docker cp build-container:/home/build/buffer-memseg/target .
+ docker cp build-container:/home/build/buffer-tests/target .
docker rm build-container
rebuild: clean clean-layer-cache build
diff --git a/README.adoc b/README.adoc
index c8edfa4..9533796 100644
--- a/README.adoc
+++ b/README.adoc
@@ -6,9 +6,9 @@ See the xref:RATIONALE.adoc[RATIONALE] document for more background.
== Building and Testing
-Short version: just run `make`.
+Short version: just run `make` if you want to build on Java 17, otherwise run `mvn install` if you want to build with Java 11, and without support for the `jdk.incubator.foreign` APIs.
-The project currently relies on snapshot versions of the https://github.com/openjdk/panama-foreign[Panama Foreign] fork of OpenJDK.
+The project (specifically, the `buffer-memseg` module) currently relies on snapshot versions of the https://github.com/openjdk/panama-foreign[Panama Foreign] fork of OpenJDK.
This allows us to test out the most recent version of the `jdk.incubator.foreign` APIs, but also make building, and local development more involved.
To simplify things, we have a Docker based build, controlled via a Makefile with the following commands:
diff --git a/buffer-api/pom.xml b/buffer-api/pom.xml
new file mode 100644
index 0000000..a78b473
--- /dev/null
+++ b/buffer-api/pom.xml
@@ -0,0 +1,43 @@
+
+
+
+ 4.0.0
+
+
+ io.netty.incubator
+ netty-incubator-buffer-parent
+ 0.0.1.Final-SNAPSHOT
+
+
+ netty-incubator-buffer-api
+ 0.0.1.Final-SNAPSHOT
+ Netty/Incubator/Buffer
+ jar
+
+
+
+ io.netty
+ netty-common
+
+
+ io.netty
+ netty-buffer
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/netty/buffer/api/AllocatorControl.java b/buffer-api/src/main/java/io/netty/buffer/api/AllocatorControl.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/AllocatorControl.java
rename to buffer-api/src/main/java/io/netty/buffer/api/AllocatorControl.java
diff --git a/src/main/java/io/netty/buffer/api/Buffer.java b/buffer-api/src/main/java/io/netty/buffer/api/Buffer.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Buffer.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Buffer.java
diff --git a/src/main/java/io/netty/buffer/api/BufferAccessors.java b/buffer-api/src/main/java/io/netty/buffer/api/BufferAccessors.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/BufferAccessors.java
rename to buffer-api/src/main/java/io/netty/buffer/api/BufferAccessors.java
diff --git a/src/main/java/io/netty/buffer/api/BufferAllocator.java b/buffer-api/src/main/java/io/netty/buffer/api/BufferAllocator.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/BufferAllocator.java
rename to buffer-api/src/main/java/io/netty/buffer/api/BufferAllocator.java
diff --git a/src/main/java/io/netty/buffer/api/BufferHolder.java b/buffer-api/src/main/java/io/netty/buffer/api/BufferHolder.java
similarity index 97%
rename from src/main/java/io/netty/buffer/api/BufferHolder.java
rename to buffer-api/src/main/java/io/netty/buffer/api/BufferHolder.java
index e17600d..0c0d66b 100644
--- a/src/main/java/io/netty/buffer/api/BufferHolder.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/BufferHolder.java
@@ -15,10 +15,11 @@
*/
package io.netty.buffer.api;
+import io.netty.buffer.api.internal.Statics;
+
import java.lang.invoke.VarHandle;
import java.util.Objects;
-import static io.netty.buffer.api.internal.Statics.findVarHandle;
import static java.lang.invoke.MethodHandles.lookup;
/**
@@ -36,7 +37,7 @@ import static java.lang.invoke.MethodHandles.lookup;
* @param The concrete {@link BufferHolder} type.
*/
public abstract class BufferHolder> implements Rc {
- private static final VarHandle BUF = findVarHandle(lookup(), BufferHolder.class, "buf", Buffer.class);
+ private static final VarHandle BUF = Statics.findVarHandle(lookup(), BufferHolder.class, "buf", Buffer.class);
private Buffer buf;
/**
diff --git a/src/main/java/io/netty/buffer/api/BufferRef.java b/buffer-api/src/main/java/io/netty/buffer/api/BufferRef.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/BufferRef.java
rename to buffer-api/src/main/java/io/netty/buffer/api/BufferRef.java
diff --git a/src/main/java/io/netty/buffer/api/ByteCursor.java b/buffer-api/src/main/java/io/netty/buffer/api/ByteCursor.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/ByteCursor.java
rename to buffer-api/src/main/java/io/netty/buffer/api/ByteCursor.java
diff --git a/src/main/java/io/netty/buffer/api/CompositeBuffer.java b/buffer-api/src/main/java/io/netty/buffer/api/CompositeBuffer.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/CompositeBuffer.java
rename to buffer-api/src/main/java/io/netty/buffer/api/CompositeBuffer.java
diff --git a/src/main/java/io/netty/buffer/api/Drop.java b/buffer-api/src/main/java/io/netty/buffer/api/Drop.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Drop.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Drop.java
diff --git a/src/main/java/io/netty/buffer/api/LifecycleTracer.java b/buffer-api/src/main/java/io/netty/buffer/api/LifecycleTracer.java
similarity index 99%
rename from src/main/java/io/netty/buffer/api/LifecycleTracer.java
rename to buffer-api/src/main/java/io/netty/buffer/api/LifecycleTracer.java
index 92408ef..103d984 100644
--- a/src/main/java/io/netty/buffer/api/LifecycleTracer.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/LifecycleTracer.java
@@ -15,7 +15,6 @@
*/
package io.netty.buffer.api;
-import java.io.Serial;
import java.util.ArrayDeque;
import java.util.Set;
import java.util.function.Function;
@@ -176,7 +175,6 @@ abstract class LifecycleTracer {
}
private static final class Traceback extends Throwable {
- @Serial
private static final long serialVersionUID = 941453986194634605L;
Traceback(String message) {
diff --git a/src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java b/buffer-api/src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java
rename to buffer-api/src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java
diff --git a/src/main/java/io/netty/buffer/api/MemoryManager.java b/buffer-api/src/main/java/io/netty/buffer/api/MemoryManager.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/MemoryManager.java
rename to buffer-api/src/main/java/io/netty/buffer/api/MemoryManager.java
diff --git a/src/main/java/io/netty/buffer/api/MemoryManagers.java b/buffer-api/src/main/java/io/netty/buffer/api/MemoryManagers.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/MemoryManagers.java
rename to buffer-api/src/main/java/io/netty/buffer/api/MemoryManagers.java
diff --git a/src/main/java/io/netty/buffer/api/MemoryManagersOverride.java b/buffer-api/src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
similarity index 92%
rename from src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
rename to buffer-api/src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
index 4b7cf8a..c59125b 100644
--- a/src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
@@ -15,7 +15,7 @@
*/
package io.netty.buffer.api;
-import io.netty.buffer.api.memseg.SegmentMemoryManagers;
+import io.netty.buffer.api.bytebuffer.ByteBufferMemoryManagers;
import java.util.Collections;
import java.util.IdentityHashMap;
@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
final class MemoryManagersOverride {
- private static final MemoryManagers DEFAULT = new SegmentMemoryManagers();
+ private static final MemoryManagers DEFAULT = new ByteBufferMemoryManagers();
private static final AtomicInteger OVERRIDES_AVAILABLE = new AtomicInteger();
private static final Map OVERRIDES = Collections.synchronizedMap(new IdentityHashMap<>());
diff --git a/src/main/java/io/netty/buffer/api/Owned.java b/buffer-api/src/main/java/io/netty/buffer/api/Owned.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Owned.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Owned.java
diff --git a/src/main/java/io/netty/buffer/api/Rc.java b/buffer-api/src/main/java/io/netty/buffer/api/Rc.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Rc.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Rc.java
diff --git a/src/main/java/io/netty/buffer/api/RcSupport.java b/buffer-api/src/main/java/io/netty/buffer/api/RcSupport.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/RcSupport.java
rename to buffer-api/src/main/java/io/netty/buffer/api/RcSupport.java
diff --git a/src/main/java/io/netty/buffer/api/ReadableComponent.java b/buffer-api/src/main/java/io/netty/buffer/api/ReadableComponent.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/ReadableComponent.java
rename to buffer-api/src/main/java/io/netty/buffer/api/ReadableComponent.java
diff --git a/src/main/java/io/netty/buffer/api/ReadableComponentProcessor.java b/buffer-api/src/main/java/io/netty/buffer/api/ReadableComponentProcessor.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/ReadableComponentProcessor.java
rename to buffer-api/src/main/java/io/netty/buffer/api/ReadableComponentProcessor.java
diff --git a/src/main/java/io/netty/buffer/api/ResourceDisposeFailedException.java b/buffer-api/src/main/java/io/netty/buffer/api/ResourceDisposeFailedException.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/ResourceDisposeFailedException.java
rename to buffer-api/src/main/java/io/netty/buffer/api/ResourceDisposeFailedException.java
diff --git a/src/main/java/io/netty/buffer/api/Scope.java b/buffer-api/src/main/java/io/netty/buffer/api/Scope.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Scope.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Scope.java
diff --git a/src/main/java/io/netty/buffer/api/Send.java b/buffer-api/src/main/java/io/netty/buffer/api/Send.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/Send.java
rename to buffer-api/src/main/java/io/netty/buffer/api/Send.java
diff --git a/src/main/java/io/netty/buffer/api/TransferSend.java b/buffer-api/src/main/java/io/netty/buffer/api/TransferSend.java
similarity index 91%
rename from src/main/java/io/netty/buffer/api/TransferSend.java
rename to buffer-api/src/main/java/io/netty/buffer/api/TransferSend.java
index d73e104..1b8a0f9 100644
--- a/src/main/java/io/netty/buffer/api/TransferSend.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/TransferSend.java
@@ -15,13 +15,14 @@
*/
package io.netty.buffer.api;
+import io.netty.buffer.api.internal.Statics;
+
import java.lang.invoke.VarHandle;
-import static io.netty.buffer.api.internal.Statics.findVarHandle;
import static java.lang.invoke.MethodHandles.lookup;
class TransferSend, T extends Rc> implements Send {
- private static final VarHandle RECEIVED = findVarHandle(lookup(), TransferSend.class, "received", boolean.class);
+ private static final VarHandle RECEIVED = Statics.findVarHandle(lookup(), TransferSend.class, "received", boolean.class);
private final Owned outgoing;
private final Drop drop;
private final Class> concreteType;
diff --git a/src/main/java/io/netty/buffer/api/WritableComponent.java b/buffer-api/src/main/java/io/netty/buffer/api/WritableComponent.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/WritableComponent.java
rename to buffer-api/src/main/java/io/netty/buffer/api/WritableComponent.java
diff --git a/src/main/java/io/netty/buffer/api/WritableComponentProcessor.java b/buffer-api/src/main/java/io/netty/buffer/api/WritableComponentProcessor.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/WritableComponentProcessor.java
rename to buffer-api/src/main/java/io/netty/buffer/api/WritableComponentProcessor.java
diff --git a/src/main/java/io/netty/buffer/api/adaptor/BufferIntegratable.java b/buffer-api/src/main/java/io/netty/buffer/api/adaptor/BufferIntegratable.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/adaptor/BufferIntegratable.java
rename to buffer-api/src/main/java/io/netty/buffer/api/adaptor/BufferIntegratable.java
diff --git a/src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java b/buffer-api/src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java
similarity index 99%
rename from src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java
rename to buffer-api/src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java
index 370b462..927ea26 100644
--- a/src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/adaptor/ByteBufAdaptor.java
@@ -22,8 +22,9 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.DuplicatedByteBuf;
import io.netty.buffer.SlicedByteBuf;
import io.netty.buffer.Unpooled;
-import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.internal.Statics;
+import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.RcSupport;
import io.netty.util.ByteProcessor;
import io.netty.util.IllegalReferenceCountException;
@@ -1514,7 +1515,7 @@ public final class ByteBufAdaptor extends ByteBuf {
});
ByteBuffer buffer = bufRef.get();
if (index != readerIndex() || length != readableBytes()) {
- buffer = buffer.slice(index - readerIndex(), length);
+ buffer = Statics.bbslice(buffer, index - readerIndex(), length);
}
return buffer;
} else if (writerIndex() <= index && length <= writableBytes()) {
@@ -1530,7 +1531,7 @@ public final class ByteBufAdaptor extends ByteBuf {
});
ByteBuffer buffer = bufRef.get();
if (index != writerIndex() || length != writableBytes()) {
- buffer = buffer.slice(index - writerIndex(), length);
+ buffer = Statics.bbslice(buffer, index - writerIndex(), length);
}
return buffer;
} else {
diff --git a/src/main/java/io/netty/buffer/api/adaptor/ByteBufAllocatorAdaptor.java b/buffer-api/src/main/java/io/netty/buffer/api/adaptor/ByteBufAllocatorAdaptor.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/adaptor/ByteBufAllocatorAdaptor.java
rename to buffer-api/src/main/java/io/netty/buffer/api/adaptor/ByteBufAllocatorAdaptor.java
diff --git a/src/main/java/io/netty/buffer/api/adaptor/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/adaptor/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/adaptor/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/adaptor/package-info.java
diff --git a/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java
similarity index 96%
rename from src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java
rename to buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java
index bd7bfea..f4925a0 100644
--- a/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManager.java
@@ -25,6 +25,7 @@ import java.lang.ref.Cleaner;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import static io.netty.buffer.api.internal.Statics.bbslice;
import static io.netty.buffer.api.internal.Statics.convert;
public class ByteBufferMemoryManager implements MemoryManager {
@@ -84,6 +85,6 @@ public class ByteBufferMemoryManager implements MemoryManager {
@Override
public Object sliceMemory(Object memory, int offset, int length) {
var buffer = (ByteBuffer) memory;
- return buffer.slice(offset, length);
+ return bbslice(buffer, offset, length);
}
}
diff --git a/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManagers.java b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManagers.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManagers.java
rename to buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/ByteBufferMemoryManagers.java
diff --git a/src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java
similarity index 97%
rename from src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java
rename to buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java
index 4364958..4c99a2e 100644
--- a/src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/NioBuffer.java
@@ -34,6 +34,8 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
+import static io.netty.buffer.api.internal.Statics.bbput;
+import static io.netty.buffer.api.internal.Statics.bbslice;
import static io.netty.buffer.api.internal.Statics.bufferIsClosed;
import static io.netty.buffer.api.internal.Statics.bufferIsReadOnly;
@@ -64,7 +66,7 @@ class NioBuffer extends RcSupport implements Buffer, Readable
super(new MakeInaccisbleOnDrop(new ArcDrop<>(ArcDrop.acquire(parent.unsafeGetDrop()))));
control = parent.control;
base = parent.base;
- rmem = parent.rmem.slice(0, parent.rmem.capacity()); // Need to slice to get independent byte orders.
+ rmem = bbslice(parent.rmem, 0, parent.rmem.capacity()); // Need to slice to get independent byte orders.
assert parent.wmem == CLOSED_BUFFER;
wmem = CLOSED_BUFFER;
roff = parent.roff;
@@ -193,7 +195,7 @@ class NioBuffer extends RcSupport implements Buffer, Readable
if (!isAccessible()) {
throw new IllegalStateException("This buffer is closed: " + this + '.');
}
- ByteBuffer slice = rmem.slice(offset, length);
+ ByteBuffer slice = bbslice(rmem, offset, length);
ArcDrop drop = (ArcDrop) unsafeGetDrop();
drop.increment();
Buffer sliceBuffer = new NioBuffer(base, slice, control, drop)
@@ -226,7 +228,7 @@ class NioBuffer extends RcSupport implements Buffer, Readable
"srcPos = " + srcPos + ", length = " + length + '.');
}
dest = dest.duplicate().clear();
- dest.put(destPos, rmem, srcPos, length);
+ bbput(dest, destPos, rmem, srcPos, length);
}
@Override
@@ -453,12 +455,13 @@ class NioBuffer extends RcSupport implements Buffer, Readable
}
var drop = (ArcDrop) unsafeGetDrop();
unsafeSetDrop(new ArcDrop<>(drop));
- var splitByteBuffer = rmem.slice(0, splitOffset);
+ var splitByteBuffer = bbslice(rmem, 0, splitOffset);
// TODO maybe incrementing the existing ArcDrop is enough; maybe we don't need to wrap it in another ArcDrop.
var splitBuffer = new NioBuffer(base, splitByteBuffer, control, new ArcDrop<>(drop.increment()));
splitBuffer.woff = Math.min(woff, splitOffset);
splitBuffer.roff = Math.min(roff, splitOffset);
- splitBuffer.order(order());
+ ByteOrder order = order();
+ splitBuffer.order(order);
boolean readOnly = readOnly();
if (readOnly) {
splitBuffer.makeReadOnly();
@@ -466,12 +469,13 @@ class NioBuffer extends RcSupport implements Buffer, Readable
// Note that split, unlike slice, does not deconstify, because data changes in either buffer are not visible
// in the other. The split buffers can later deconstify independently if needed.
splitBuffer.constBuffer = constBuffer;
- rmem = rmem.slice(splitOffset, rmem.capacity() - splitOffset);
+ rmem = bbslice(rmem, splitOffset, rmem.capacity() - splitOffset);
if (!readOnly) {
wmem = rmem;
}
woff = Math.max(woff, splitOffset) - splitOffset;
roff = Math.max(roff, splitOffset) - splitOffset;
+ order(order);
return splitBuffer;
}
@@ -534,7 +538,7 @@ class NioBuffer extends RcSupport implements Buffer, Readable
@Override
public ByteBuffer readableBuffer() {
- return rmem.asReadOnlyBuffer().slice(readerOffset(), readableBytes()).order(order());
+ return bbslice(rmem.asReadOnlyBuffer(), readerOffset(), readableBytes()).order(order());
}
@Override
@@ -564,7 +568,7 @@ class NioBuffer extends RcSupport implements Buffer, Readable
@Override
public ByteBuffer writableBuffer() {
- return wmem.slice(writerOffset(), writableBytes()).order(order());
+ return bbslice(wmem, writerOffset(), writableBytes()).order(order());
}
//
diff --git a/src/main/java/io/netty/buffer/api/bytebuffer/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/bytebuffer/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/bytebuffer/package-info.java
diff --git a/src/main/java/io/netty/buffer/api/internal/ArcDrop.java b/buffer-api/src/main/java/io/netty/buffer/api/internal/ArcDrop.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/internal/ArcDrop.java
rename to buffer-api/src/main/java/io/netty/buffer/api/internal/ArcDrop.java
diff --git a/src/main/java/io/netty/buffer/api/internal/CleanerDrop.java b/buffer-api/src/main/java/io/netty/buffer/api/internal/CleanerDrop.java
similarity index 98%
rename from src/main/java/io/netty/buffer/api/internal/CleanerDrop.java
rename to buffer-api/src/main/java/io/netty/buffer/api/internal/CleanerDrop.java
index 225a067..75eae0c 100644
--- a/src/main/java/io/netty/buffer/api/internal/CleanerDrop.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/internal/CleanerDrop.java
@@ -17,7 +17,6 @@ package io.netty.buffer.api.internal;
import io.netty.buffer.api.Drop;
-import java.io.Serial;
import java.lang.ref.Cleaner;
import java.util.concurrent.atomic.AtomicReference;
@@ -62,7 +61,6 @@ public final class CleanerDrop implements Drop {
}
private static final class GatedRunner extends AtomicReference implements Runnable {
- @Serial
private static final long serialVersionUID = 2685535951915798850L;
final Drop drop;
diff --git a/buffer-api/src/main/java/io/netty/buffer/api/internal/Statics.java b/buffer-api/src/main/java/io/netty/buffer/api/internal/Statics.java
new file mode 100644
index 0000000..f6ab7a1
--- /dev/null
+++ b/buffer-api/src/main/java/io/netty/buffer/api/internal/Statics.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2020 The Netty Project
+ *
+ * The Netty Project 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:
+ *
+ * https://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 io.netty.buffer.api.internal;
+
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.Drop;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.VarHandle;
+import java.lang.ref.Cleaner;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.concurrent.atomic.LongAdder;
+
+public interface Statics {
+ LongAdder MEM_USAGE_NATIVE = new LongAdder();
+ Cleaner CLEANER = Cleaner.create();
+ Drop NO_OP_DROP = new Drop() {
+ @Override
+ public void drop(Buffer obj) {
+ }
+
+ @Override
+ public String toString() {
+ return "NO_OP_DROP";
+ }
+ };
+ MethodHandle BB_SLICE_OFFSETS = getByteBufferSliceOffsetsMethodHandle();
+ MethodHandle BB_PUT_OFFSETS = getByteBufferPutOffsetsMethodHandle();
+
+ static MethodHandle getByteBufferSliceOffsetsMethodHandle() {
+ try {
+ Lookup lookup = MethodHandles.lookup();
+ MethodType type = MethodType.methodType(ByteBuffer.class, int.class, int.class);
+ return lookup.findVirtual(ByteBuffer.class, "slice", type);
+ } catch (Exception ignore) {
+ return null;
+ }
+ }
+
+ static MethodHandle getByteBufferPutOffsetsMethodHandle() {
+ try {
+ Lookup lookup = MethodHandles.lookup();
+ MethodType type = MethodType.methodType(ByteBuffer.class, int.class, ByteBuffer.class, int.class, int.class);
+ return lookup.findVirtual(ByteBuffer.class, "put", type);
+ } catch (Exception ignore) {
+ return null;
+ }
+ }
+
+ static VarHandle findVarHandle(Lookup lookup, Class> recv, String name, Class> type) {
+ try {
+ return lookup.findVarHandle(recv, name, type);
+ } catch (Exception e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ static Drop convert(Drop drop) {
+ return (Drop) drop;
+ }
+
+ static void copyToViaReverseCursor(Buffer src, int srcPos, Buffer dest, int destPos, int length) {
+ // Iterate in reverse to account for src and dest buffer overlap.
+ var itr = src.openReverseCursor(srcPos + length - 1, length);
+ ByteOrder prevOrder = dest.order();
+ // We read longs in BE, in reverse, so they need to be flipped for writing.
+ dest.order(ByteOrder.LITTLE_ENDIAN);
+ try {
+ while (itr.readLong()) {
+ long val = itr.getLong();
+ length -= Long.BYTES;
+ dest.setLong(destPos + length, val);
+ }
+ while (itr.readByte()) {
+ dest.setByte(destPos + --length, itr.getByte());
+ }
+ } finally {
+ dest.order(prevOrder);
+ }
+ }
+
+ /**
+ * The ByteBuffer slice-with-offset-and-length method is only available from Java 13 and onwards, but we need to
+ * support Java 11.
+ */
+ static ByteBuffer bbslice(ByteBuffer buffer, int fromOffset, int length) {
+ if (BB_SLICE_OFFSETS != null) {
+ return bbsliceJdk13(buffer, fromOffset, length);
+ }
+ return bbsliceFallback(buffer, fromOffset, length);
+ }
+
+ private static ByteBuffer bbsliceJdk13(ByteBuffer buffer, int fromOffset, int length) {
+ try {
+ return (ByteBuffer) BB_SLICE_OFFSETS.invokeExact(buffer, fromOffset, length);
+ } catch (RuntimeException re) {
+ throw re;
+ } catch (Throwable throwable) {
+ throw new LinkageError("Unexpected exception from ByteBuffer.slice(int,int).", throwable);
+ }
+ }
+
+ private static ByteBuffer bbsliceFallback(ByteBuffer buffer, int fromOffset, int length) {
+ if (fromOffset < 0) {
+ throw new IndexOutOfBoundsException("The fromOffset must be positive: " + fromOffset + '.');
+ }
+ int newLimit = fromOffset + length;
+ if (newLimit > buffer.capacity()) {
+ throw new IndexOutOfBoundsException(
+ "The limit of " + newLimit + " would be greater than capacity: " + buffer.capacity() + '.');
+ }
+ try {
+ return buffer.position(fromOffset).limit(newLimit).slice();
+ } finally {
+ buffer.clear();
+ }
+ }
+
+ /**
+ * The ByteBuffer put-buffer-with-offset-and-length method is not available in Java 11.
+ */
+ static void bbput(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int length) {
+ if (BB_PUT_OFFSETS != null) {
+ bbputJdk16(dest, destPos, src, srcPos, length);
+ } else {
+ bbputFallback(dest, destPos, src, srcPos, length);
+ }
+ }
+
+ private static void bbputJdk16(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int length) {
+ try {
+ @SuppressWarnings("unused") // We need to cast the return type in order to invokeExact.
+ ByteBuffer ignore = (ByteBuffer) BB_PUT_OFFSETS.invokeExact(dest, destPos, src, srcPos, length);
+ } catch (RuntimeException re) {
+ throw re;
+ } catch (Throwable throwable) {
+ throw new LinkageError("Unexpected exception from ByteBuffer.put(int,ByteBuffer,int,int).", throwable);
+ }
+ }
+
+ private static void bbputFallback(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int length) {
+ dest.position(destPos).put(bbslice(src, srcPos, length));
+ }
+
+ static IllegalStateException bufferIsClosed() {
+ return new IllegalStateException("This buffer is closed.");
+ }
+
+ static IllegalStateException bufferIsReadOnly() {
+ return new IllegalStateException("This buffer is read-only.");
+ }
+}
diff --git a/src/main/java/io/netty/buffer/api/internal/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/internal/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/internal/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/internal/package-info.java
diff --git a/src/main/java/io/netty/buffer/api/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/package-info.java
diff --git a/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetricProvider.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetricProvider.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetricProvider.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/BufferAllocatorMetricProvider.java
diff --git a/src/main/java/io/netty/buffer/api/pool/LongLongHashMap.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/LongLongHashMap.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/LongLongHashMap.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/LongLongHashMap.java
diff --git a/src/main/java/io/netty/buffer/api/pool/LongPriorityQueue.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/LongPriorityQueue.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/LongPriorityQueue.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/LongPriorityQueue.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolArena.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArena.java
similarity index 92%
rename from src/main/java/io/netty/buffer/api/pool/PoolArena.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArena.java
index 5d5c085..fa4cc90 100644
--- a/src/main/java/io/netty/buffer/api/pool/PoolArena.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArena.java
@@ -20,6 +20,8 @@ import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.MemoryManager;
import io.netty.util.internal.StringUtil;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -29,6 +31,7 @@ import static io.netty.buffer.api.pool.PoolChunk.isSubpage;
import static java.lang.Math.max;
class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl {
+ private static final VarHandle SUBPAGE_ARRAY = MethodHandles.arrayElementVarHandle(PoolSubpage[].class);
enum SizeClass {
Small,
Normal
@@ -76,9 +79,6 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
numSmallSubpagePools = nSubpages;
smallSubpagePools = newSubpagePoolArray(numSmallSubpagePools);
- for (int i = 0; i < smallSubpagePools.length; i ++) {
- smallSubpagePools[i] = newSubpagePoolHead();
- }
q100 = new PoolChunkList(this, null, 100, Integer.MAX_VALUE, chunkSize);
q075 = new PoolChunkList(this, q100, 75, 100, chunkSize);
@@ -135,7 +135,7 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
* Synchronize on the head. This is needed as {@link PoolChunk#allocateSubpage(int)} and
* {@link PoolChunk#free(long)} may modify the doubly linked list as well.
*/
- final PoolSubpage head = smallSubpagePools[sizeIdx];
+ PoolSubpage head = findSubpagePoolHead(sizeIdx);
final boolean needsNormalAllocation;
synchronized (head) {
final PoolSubpage s = head.next;
@@ -246,7 +246,15 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
}
PoolSubpage findSubpagePoolHead(int sizeIdx) {
- return smallSubpagePools[sizeIdx];
+ PoolSubpage head = (PoolSubpage) SUBPAGE_ARRAY.getVolatile(smallSubpagePools, sizeIdx);
+ if (head == null) {
+ head = newSubpagePoolHead();
+ if (!SUBPAGE_ARRAY.compareAndSet(smallSubpagePools, sizeIdx, null, head)) {
+ // We lost the race. Read the winning value.
+ head = (PoolSubpage) SUBPAGE_ARRAY.getVolatile(smallSubpagePools, sizeIdx);
+ }
+ }
+ return head;
}
@Override
@@ -288,8 +296,9 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
private static List subPageMetricList(PoolSubpage[] pages) {
List metrics = new ArrayList<>();
- for (PoolSubpage head : pages) {
- if (head.next == head) {
+ for (int i = 0, len = pages.length; i < len; i++) {
+ PoolSubpage head = (PoolSubpage) SUBPAGE_ARRAY.getVolatile(pages, i);
+ if (head == null || head.next == head) {
continue;
}
PoolSubpage s = head.next;
@@ -311,11 +320,6 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
return allocationsSmall.longValue() + allocsNormal + allocationsHuge.longValue();
}
- @Override
- public long numTinyAllocations() {
- return 0;
- }
-
@Override
public long numSmallAllocations() {
return allocationsSmall.longValue();
@@ -335,11 +339,6 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
return deallocs + deallocationsHuge.longValue();
}
- @Override
- public long numTinyDeallocations() {
- return 0;
- }
-
@Override
public synchronized long numSmallDeallocations() {
return deallocationsSmall;
@@ -442,8 +441,8 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
private static void appendPoolSubPages(StringBuilder buf, PoolSubpage[] subpages) {
for (int i = 0; i < subpages.length; i ++) {
- PoolSubpage head = subpages[i];
- if (head.next == head) {
+ PoolSubpage head = (PoolSubpage) SUBPAGE_ARRAY.getVolatile(subpages, i);
+ if (head == null || head.next == head) {
continue;
}
@@ -459,8 +458,11 @@ class PoolArena extends SizeClasses implements PoolArenaMetric, AllocatorControl
}
public void close() {
- for (PoolSubpage page : smallSubpagePools) {
- page.destroy();
+ for (int i = 0, len = smallSubpagePools.length; i < len; i++) {
+ PoolSubpage page = (PoolSubpage) SUBPAGE_ARRAY.getVolatile(smallSubpagePools, i);
+ if (page != null) {
+ page.destroy();
+ }
}
for (PoolChunkList list : new PoolChunkList[] {qInit, q000, q025, q050, q100}) {
list.destroy();
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java
similarity index 87%
rename from src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java
index c5c2f26..754dd7d 100644
--- a/src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolArenaMetric.java
@@ -52,14 +52,6 @@ public interface PoolArenaMetric extends SizeClassesMetric {
*/
long numAllocations();
- /**
- * Return the number of tiny allocations done via the arena.
- *
- * @deprecated Tiny allocations have been merged into small allocations.
- */
- @Deprecated
- long numTinyAllocations();
-
/**
* Return the number of small allocations done via the arena.
*/
@@ -80,14 +72,6 @@ public interface PoolArenaMetric extends SizeClassesMetric {
*/
long numDeallocations();
- /**
- * Return the number of tiny deallocations done via the arena.
- *
- * @deprecated Tiny deallocations have been merged into small deallocations.
- */
- @Deprecated
- long numTinyDeallocations();
-
/**
* Return the number of small deallocations done via the arena.
*/
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolChunk.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunk.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolChunk.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunk.java
index 78b07ed..7b98ade 100644
--- a/src/main/java/io/netty/buffer/api/pool/PoolChunk.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunk.java
@@ -15,12 +15,12 @@
*/
package io.netty.buffer.api.pool;
+import io.netty.buffer.api.internal.CleanerDrop;
import io.netty.buffer.api.AllocatorControl.UntetheredMemory;
import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.Drop;
import io.netty.buffer.api.MemoryManager;
import io.netty.buffer.api.internal.ArcDrop;
-import io.netty.buffer.api.internal.CleanerDrop;
import io.netty.buffer.api.internal.Statics;
import java.util.PriorityQueue;
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolChunkList.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkList.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolChunkList.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkList.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolChunkListMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkListMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolChunkListMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkListMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolChunkMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolChunkMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolChunkMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolSubpage.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolSubpage.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolSubpage.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolSubpage.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolSubpageMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolSubpageMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolSubpageMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolSubpageMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PoolThreadCache.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PoolThreadCache.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PoolThreadCache.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PoolThreadCache.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PooledAllocatorControl.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PooledAllocatorControl.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PooledAllocatorControl.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PooledAllocatorControl.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java
similarity index 97%
rename from src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java
index 8052f28..c8ae60b 100644
--- a/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocator.java
@@ -431,22 +431,22 @@ public class PooledBufferAllocator implements BufferAllocator, BufferAllocatorMe
protected void onRemoval(PoolThreadCache threadCache) {
threadCache.free();
}
+ }
- private static PoolArena leastUsedArena(PoolArena[] arenas) {
- if (arenas == null || arenas.length == 0) {
- return null;
- }
-
- PoolArena minArena = arenas[0];
- for (int i = 1; i < arenas.length; i++) {
- PoolArena arena = arenas[i];
- if (arena.numThreadCaches.get() < minArena.numThreadCaches.get()) {
- minArena = arena;
- }
- }
-
- return minArena;
+ static PoolArena leastUsedArena(PoolArena[] arenas) {
+ if (arenas == null || arenas.length == 0) {
+ return null;
}
+
+ PoolArena minArena = arenas[0];
+ for (int i = 1; i < arenas.length; i++) {
+ PoolArena arena = arenas[i];
+ if (arena.numThreadCaches.get() < minArena.numThreadCaches.get()) {
+ minArena = arena;
+ }
+ }
+
+ return minArena;
}
@Override
diff --git a/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocatorMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocatorMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PooledBufferAllocatorMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PooledBufferAllocatorMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/PooledDrop.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/PooledDrop.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/PooledDrop.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/PooledDrop.java
diff --git a/src/main/java/io/netty/buffer/api/pool/SizeClasses.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/SizeClasses.java
similarity index 56%
rename from src/main/java/io/netty/buffer/api/pool/SizeClasses.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/SizeClasses.java
index 8ad00ad..534cdf1 100644
--- a/src/main/java/io/netty/buffer/api/pool/SizeClasses.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/pool/SizeClasses.java
@@ -15,7 +15,7 @@
*/
package io.netty.buffer.api.pool;
-import static io.netty.buffer.api.pool.PoolThreadCache.*;
+import java.util.concurrent.ConcurrentHashMap;
/**
* SizeClasses requires {@code pageShifts} to be defined prior to inclusion,
@@ -79,13 +79,14 @@ import static io.netty.buffer.api.pool.PoolThreadCache.*;
* ( 76, 24, 22, 1, yes, no, no)
*/
abstract class SizeClasses implements SizeClassesMetric {
+ private static final ConcurrentHashMap CACHE =
+ new ConcurrentHashMap();
static final int LOG2_QUANTUM = 4;
private static final int LOG2_SIZE_CLASS_GROUP = 2;
private static final int LOG2_MAX_LOOKUP_SIZE = 12;
- private static final int INDEX_IDX = 0;
private static final int LOG2GROUP_IDX = 1;
private static final int LOG2DELTA_IDX = 2;
private static final int NDELTA_IDX = 3;
@@ -101,20 +102,17 @@ abstract class SizeClasses implements SizeClassesMetric {
this.chunkSize = chunkSize;
this.directMemoryCacheAlignment = directMemoryCacheAlignment;
- int group = log2(chunkSize) + 1 - LOG2_QUANTUM;
-
- //generate size classes
- //[index, log2Group, log2Delta, nDelta, isMultiPageSize, isSubPage, log2DeltaLookup]
- sizeClasses = new short[group << LOG2_SIZE_CLASS_GROUP][7];
- nSizes = sizeClasses();
-
- //generate lookup table
- sizeIdx2sizeTab = new int[nSizes];
- pageIdx2sizeTab = new int[nPSizes];
- idx2SizeTab(sizeIdx2sizeTab, pageIdx2sizeTab);
-
- size2idxTab = new int[lookupMaxSize >> LOG2_QUANTUM];
- size2idxTab(size2idxTab);
+ SizeClassValue value = CACHE.computeIfAbsent(
+ new SizeClassKey(pageSize, pageShifts, chunkSize, directMemoryCacheAlignment),
+ SizeClassValue::new);
+ nSizes = value.nSizes;
+ nSubpages = value.nSubpages;
+ nPSizes = value.nPSizes;
+ smallMaxSizeIdx = value.smallMaxSizeIdx;
+ lookupMaxSize = value.lookupMaxSize;
+ pageIdx2sizeTab = value.pageIdx2sizeTab;
+ sizeIdx2sizeTab = value.sizeIdx2sizeTab;
+ size2idxTab = value.size2idxTab;
}
protected final int pageSize;
@@ -123,15 +121,11 @@ abstract class SizeClasses implements SizeClassesMetric {
protected final int directMemoryCacheAlignment;
final int nSizes;
- int nSubpages;
- int nPSizes;
-
- int smallMaxSizeIdx;
-
- private int lookupMaxSize;
-
- private final short[][] sizeClasses;
+ final int nSubpages;
+ final int nPSizes;
+ final int smallMaxSizeIdx;
+ private final int lookupMaxSize;
private final int[] pageIdx2sizeTab;
// lookup table for sizeIdx <= smallMaxSizeIdx
@@ -141,125 +135,6 @@ abstract class SizeClasses implements SizeClassesMetric {
// spacing is 1 << LOG2_QUANTUM, so the size of array is lookupMaxclass >> LOG2_QUANTUM
private final int[] size2idxTab;
- private int sizeClasses() {
- int normalMaxSize = -1;
-
- int index = 0;
- int size = 0;
-
- int log2Group = LOG2_QUANTUM;
- int log2Delta = LOG2_QUANTUM;
- int ndeltaLimit = 1 << LOG2_SIZE_CLASS_GROUP;
-
- //First small group, nDelta start at 0.
- //first size class is 1 << LOG2_QUANTUM
- int nDelta = 0;
- while (nDelta < ndeltaLimit) {
- size = sizeClass(index++, log2Group, log2Delta, nDelta++);
- }
- log2Group += LOG2_SIZE_CLASS_GROUP;
-
- //All remaining groups, nDelta start at 1.
- while (size < chunkSize) {
- nDelta = 1;
-
- while (nDelta <= ndeltaLimit && size < chunkSize) {
- size = sizeClass(index++, log2Group, log2Delta, nDelta++);
- normalMaxSize = size;
- }
-
- log2Group++;
- log2Delta++;
- }
-
- //chunkSize must be normalMaxSize
- assert chunkSize == normalMaxSize;
-
- //return number of size index
- return index;
- }
-
- //calculate size class
- private int sizeClass(int index, int log2Group, int log2Delta, int nDelta) {
- short isMultiPageSize;
- if (log2Delta >= pageShifts) {
- isMultiPageSize = yes;
- } else {
- int pageSize = 1 << pageShifts;
- int size = (1 << log2Group) + (1 << log2Delta) * nDelta;
-
- isMultiPageSize = size == size / pageSize * pageSize? yes : no;
- }
-
- int log2Ndelta = nDelta == 0? 0 : log2(nDelta);
-
- byte remove = 1 << log2Ndelta < nDelta? yes : no;
-
- int log2Size = log2Delta + log2Ndelta == log2Group? log2Group + 1 : log2Group;
- if (log2Size == log2Group) {
- remove = yes;
- }
-
- short isSubpage = log2Size < pageShifts + LOG2_SIZE_CLASS_GROUP? yes : no;
-
- int log2DeltaLookup = log2Size < LOG2_MAX_LOOKUP_SIZE ||
- log2Size == LOG2_MAX_LOOKUP_SIZE && remove == no
- ? log2Delta : no;
-
- short[] sz = {
- (short) index, (short) log2Group, (short) log2Delta,
- (short) nDelta, isMultiPageSize, isSubpage, (short) log2DeltaLookup
- };
-
- sizeClasses[index] = sz;
- int size = (1 << log2Group) + (nDelta << log2Delta);
-
- if (sz[PAGESIZE_IDX] == yes) {
- nPSizes++;
- }
- if (sz[SUBPAGE_IDX] == yes) {
- nSubpages++;
- smallMaxSizeIdx = index;
- }
- if (sz[LOG2_DELTA_LOOKUP_IDX] != no) {
- lookupMaxSize = size;
- }
- return size;
- }
-
- private void idx2SizeTab(int[] sizeIdx2sizeTab, int[] pageIdx2sizeTab) {
- int pageIdx = 0;
-
- for (int i = 0; i < nSizes; i++) {
- short[] sizeClass = sizeClasses[i];
- int log2Group = sizeClass[LOG2GROUP_IDX];
- int log2Delta = sizeClass[LOG2DELTA_IDX];
- int nDelta = sizeClass[NDELTA_IDX];
-
- int size = (1 << log2Group) + (nDelta << log2Delta);
- sizeIdx2sizeTab[i] = size;
-
- if (sizeClass[PAGESIZE_IDX] == yes) {
- pageIdx2sizeTab[pageIdx++] = size;
- }
- }
- }
-
- private void size2idxTab(int[] size2idxTab) {
- int idx = 0;
- int size = 0;
-
- for (int i = 0; size <= lookupMaxSize; i++) {
- int log2Delta = sizeClasses[i][LOG2DELTA_IDX];
- int times = 1 << log2Delta - LOG2_QUANTUM;
-
- while (size <= lookupMaxSize && times-- > 0) {
- size2idxTab[idx++] = i;
- size = idx + 1 << LOG2_QUANTUM;
- }
- }
- }
-
@Override
public int sizeIdx2size(int sizeIdx) {
return sizeIdx2sizeTab[sizeIdx];
@@ -318,7 +193,7 @@ abstract class SizeClasses implements SizeClassesMetric {
return size2idxTab[size - 1 >> LOG2_QUANTUM];
}
- int x = log2((size << 1) - 1);
+ int x = PoolThreadCache.log2((size << 1) - 1);
int shift = x < LOG2_SIZE_CLASS_GROUP + LOG2_QUANTUM + 1
? 0 : x - (LOG2_SIZE_CLASS_GROUP + LOG2_QUANTUM);
@@ -350,7 +225,7 @@ abstract class SizeClasses implements SizeClassesMetric {
return nPSizes;
}
- int x = log2((pageSize << 1) - 1);
+ int x = PoolThreadCache.log2((pageSize << 1) - 1);
int shift = x < LOG2_SIZE_CLASS_GROUP + pageShifts
? 0 : x - (LOG2_SIZE_CLASS_GROUP + pageShifts);
@@ -397,11 +272,207 @@ abstract class SizeClasses implements SizeClassesMetric {
}
private static int normalizeSizeCompute(int size) {
- int x = log2((size << 1) - 1);
+ int x = PoolThreadCache.log2((size << 1) - 1);
int log2Delta = x < LOG2_SIZE_CLASS_GROUP + LOG2_QUANTUM + 1
? LOG2_QUANTUM : x - LOG2_SIZE_CLASS_GROUP - 1;
int delta = 1 << log2Delta;
int delta_mask = delta - 1;
return size + delta_mask & ~delta_mask;
}
+
+ private static final class SizeClassKey {
+ final int pageSize;
+ final int pageShifts;
+ final int chunkSize;
+ final int directMemoryCacheAlignment;
+
+ private SizeClassKey(int pageSize, int pageShifts, int chunkSize, int directMemoryCacheAlignment) {
+ this.pageSize = pageSize;
+ this.pageShifts = pageShifts;
+ this.chunkSize = chunkSize;
+ this.directMemoryCacheAlignment = directMemoryCacheAlignment;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ SizeClassKey that = (SizeClassKey) o;
+
+ if (pageSize != that.pageSize) {
+ return false;
+ }
+ if (pageShifts != that.pageShifts) {
+ return false;
+ }
+ if (chunkSize != that.chunkSize) {
+ return false;
+ }
+ return directMemoryCacheAlignment == that.directMemoryCacheAlignment;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = pageSize;
+ result = 31 * result + pageShifts;
+ result = 31 * result + chunkSize;
+ result = 31 * result + directMemoryCacheAlignment;
+ return result;
+ }
+ }
+
+ private static final class SizeClassValue {
+ final SizeClassKey key;
+ final int nSizes;
+ int nSubpages;
+ int nPSizes;
+ int smallMaxSizeIdx;
+ int lookupMaxSize;
+ final short[][] sizeClasses;
+ final int[] pageIdx2sizeTab;
+ final int[] sizeIdx2sizeTab;
+ final int[] size2idxTab;
+
+ SizeClassValue(SizeClassKey key) {
+ this.key = key;
+ int group = PoolThreadCache.log2(key.chunkSize) + 1 - LOG2_QUANTUM;
+
+ //generate size classes
+ //[index, log2Group, log2Delta, nDelta, isMultiPageSize, isSubPage, log2DeltaLookup]
+ sizeClasses = new short[group << LOG2_SIZE_CLASS_GROUP][7];
+ nSizes = sizeClasses();
+
+ //generate lookup table
+ sizeIdx2sizeTab = new int[nSizes];
+ pageIdx2sizeTab = new int[nPSizes];
+ idx2SizeTab(sizeIdx2sizeTab, pageIdx2sizeTab);
+
+ size2idxTab = new int[lookupMaxSize >> LOG2_QUANTUM];
+ size2idxTab(size2idxTab);
+ }
+
+ private int sizeClasses() {
+ int normalMaxSize = -1;
+
+ int index = 0;
+ int size = 0;
+
+ int log2Group = LOG2_QUANTUM;
+ int log2Delta = LOG2_QUANTUM;
+ int ndeltaLimit = 1 << LOG2_SIZE_CLASS_GROUP;
+
+ //First small group, nDelta start at 0.
+ //first size class is 1 << LOG2_QUANTUM
+ int nDelta = 0;
+ while (nDelta < ndeltaLimit) {
+ size = sizeClass(index++, log2Group, log2Delta, nDelta++);
+ }
+ log2Group += LOG2_SIZE_CLASS_GROUP;
+
+ //All remaining groups, nDelta start at 1.
+ while (size < key.chunkSize) {
+ nDelta = 1;
+
+ while (nDelta <= ndeltaLimit && size < key.chunkSize) {
+ size = sizeClass(index++, log2Group, log2Delta, nDelta++);
+ normalMaxSize = size;
+ }
+
+ log2Group++;
+ log2Delta++;
+ }
+
+ //chunkSize must be normalMaxSize
+ assert key.chunkSize == normalMaxSize;
+
+ //return number of size index
+ return index;
+ }
+
+ //calculate size class
+ private int sizeClass(int index, int log2Group, int log2Delta, int nDelta) {
+ short isMultiPageSize;
+ if (log2Delta >= key.pageShifts) {
+ isMultiPageSize = yes;
+ } else {
+ int pageSize = 1 << key.pageShifts;
+ int size = (1 << log2Group) + (1 << log2Delta) * nDelta;
+
+ isMultiPageSize = size == size / pageSize * pageSize? yes : no;
+ }
+
+ int log2Ndelta = nDelta == 0? 0 : PoolThreadCache.log2(nDelta);
+
+ byte remove = 1 << log2Ndelta < nDelta? yes : no;
+
+ int log2Size = log2Delta + log2Ndelta == log2Group? log2Group + 1 : log2Group;
+ if (log2Size == log2Group) {
+ remove = yes;
+ }
+
+ short isSubpage = log2Size < key.pageShifts + LOG2_SIZE_CLASS_GROUP? yes : no;
+
+ int log2DeltaLookup = log2Size < LOG2_MAX_LOOKUP_SIZE ||
+ log2Size == LOG2_MAX_LOOKUP_SIZE && remove == no
+ ? log2Delta : no;
+
+ short[] sz = {
+ (short) index, (short) log2Group, (short) log2Delta,
+ (short) nDelta, isMultiPageSize, isSubpage, (short) log2DeltaLookup
+ };
+
+ sizeClasses[index] = sz;
+ int size = (1 << log2Group) + (nDelta << log2Delta);
+
+ if (sz[PAGESIZE_IDX] == yes) {
+ nPSizes++;
+ }
+ if (sz[SUBPAGE_IDX] == yes) {
+ nSubpages++;
+ smallMaxSizeIdx = index;
+ }
+ if (sz[LOG2_DELTA_LOOKUP_IDX] != no) {
+ lookupMaxSize = size;
+ }
+ return size;
+ }
+
+ private void idx2SizeTab(int[] sizeIdx2sizeTab, int[] pageIdx2sizeTab) {
+ int pageIdx = 0;
+
+ for (int i = 0; i < nSizes; i++) {
+ short[] sizeClass = sizeClasses[i];
+ int log2Group = sizeClass[LOG2GROUP_IDX];
+ int log2Delta = sizeClass[LOG2DELTA_IDX];
+ int nDelta = sizeClass[NDELTA_IDX];
+
+ int size = (1 << log2Group) + (nDelta << log2Delta);
+ sizeIdx2sizeTab[i] = size;
+
+ if (sizeClass[PAGESIZE_IDX] == yes) {
+ pageIdx2sizeTab[pageIdx++] = size;
+ }
+ }
+ }
+
+ private void size2idxTab(int[] size2idxTab) {
+ int idx = 0;
+ int size = 0;
+
+ for (int i = 0; size <= lookupMaxSize; i++) {
+ int log2Delta = sizeClasses[i][LOG2DELTA_IDX];
+ int times = 1 << log2Delta - LOG2_QUANTUM;
+
+ while (size <= lookupMaxSize && times-- > 0) {
+ size2idxTab[idx++] = i;
+ size = idx + 1 << LOG2_QUANTUM;
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/io/netty/buffer/api/pool/SizeClassesMetric.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/SizeClassesMetric.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/SizeClassesMetric.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/SizeClassesMetric.java
diff --git a/src/main/java/io/netty/buffer/api/pool/UnpooledUnthetheredMemory.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/UnpooledUnthetheredMemory.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/UnpooledUnthetheredMemory.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/UnpooledUnthetheredMemory.java
diff --git a/src/main/java/io/netty/buffer/api/pool/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/pool/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/pool/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/pool/package-info.java
diff --git a/src/main/java/io/netty/buffer/api/unsafe/CleanerDrop.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/CleanerDrop.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/unsafe/CleanerDrop.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/CleanerDrop.java
diff --git a/src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java
similarity index 99%
rename from src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java
index bdbe06c..a40c743 100644
--- a/src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java
+++ b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeBuffer.java
@@ -15,9 +15,9 @@
*/
package io.netty.buffer.api.unsafe;
+import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.AllocatorControl;
import io.netty.buffer.api.Buffer;
-import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.ByteCursor;
import io.netty.buffer.api.Drop;
import io.netty.buffer.api.Owned;
@@ -34,6 +34,7 @@ import java.lang.ref.Reference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import static io.netty.buffer.api.internal.Statics.bbslice;
import static io.netty.buffer.api.internal.Statics.bufferIsClosed;
import static io.netty.buffer.api.internal.Statics.bufferIsReadOnly;
import static io.netty.util.internal.PlatformDependent.BIG_ENDIAN_NATIVE_ORDER;
@@ -596,7 +597,7 @@ class UnsafeBuffer extends RcSupport implements Buffer, Re
public ByteBuffer readableBuffer() {
final ByteBuffer buf;
if (hasReadableArray()) {
- buf = ByteBuffer.wrap(readableArray()).slice(readableArrayOffset(), readableArrayLength());
+ buf = bbslice(ByteBuffer.wrap(readableArray()), readableArrayOffset(), readableArrayLength());
} else {
buf = PlatformDependent.directBuffer(address + roff, readableBytes());
}
@@ -640,7 +641,7 @@ class UnsafeBuffer extends RcSupport implements Buffer, Re
public ByteBuffer writableBuffer() {
final ByteBuffer buf;
if (hasWritableArray()) {
- buf = ByteBuffer.wrap(writableArray()).slice(writableArrayOffset(), writableArrayLength());
+ buf = bbslice(ByteBuffer.wrap(writableArray()), writableArrayOffset(), writableArrayLength());
} else {
buf = PlatformDependent.directBuffer(address + woff, writableBytes());
}
diff --git a/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemory.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemory.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/unsafe/UnsafeMemory.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemory.java
diff --git a/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManager.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManager.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManager.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManager.java
diff --git a/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManagers.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManagers.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManagers.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/UnsafeMemoryManagers.java
diff --git a/src/main/java/io/netty/buffer/api/unsafe/package-info.java b/buffer-api/src/main/java/io/netty/buffer/api/unsafe/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/unsafe/package-info.java
rename to buffer-api/src/main/java/io/netty/buffer/api/unsafe/package-info.java
diff --git a/buffer-api/src/main/java/module-info.java b/buffer-api/src/main/java/module-info.java
new file mode 100644
index 0000000..ee28484
--- /dev/null
+++ b/buffer-api/src/main/java/module-info.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 The Netty Project
+ *
+ * The Netty Project 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:
+ *
+ * https://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.
+ */
+import io.netty.buffer.api.MemoryManagers;
+import io.netty.buffer.api.bytebuffer.ByteBufferMemoryManagers;
+import io.netty.buffer.api.unsafe.UnsafeMemoryManagers;
+
+module netty.incubator.buffer {
+ requires io.netty.common;
+ requires io.netty.buffer;
+
+ // Optional dependencies, needed for some examples.
+ requires static java.logging;//todo remove
+
+ exports io.netty.buffer.api;
+ exports io.netty.buffer.api.adaptor;
+
+ exports io.netty.buffer.api.internal to
+ netty.incubator.buffer.memseg,
+ netty.incubator.buffer.tests;
+
+ uses MemoryManagers;
+
+ // Permit reflective access to non-public members.
+ // Also means we don't have to make all test methods etc. public for JUnit to access them.
+ opens io.netty.buffer.api;//todo remove
+
+ provides MemoryManagers with
+ ByteBufferMemoryManagers,
+ UnsafeMemoryManagers;
+}
diff --git a/buffer-memseg-dummy/pom.xml b/buffer-memseg-dummy/pom.xml
new file mode 100644
index 0000000..1c1a759
--- /dev/null
+++ b/buffer-memseg-dummy/pom.xml
@@ -0,0 +1,30 @@
+
+
+
+ 4.0.0
+
+
+ io.netty.incubator
+ netty-incubator-buffer-parent
+ 0.0.1.Final-SNAPSHOT
+
+
+ netty-incubator-buffer-memseg-dummy
+ 0.0.1.Final-SNAPSHOT
+
diff --git a/buffer-memseg-dummy/src/main/java/module-info.java b/buffer-memseg-dummy/src/main/java/module-info.java
new file mode 100644
index 0000000..bc63aed
--- /dev/null
+++ b/buffer-memseg-dummy/src/main/java/module-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2021 The Netty Project
+ *
+ * The Netty Project 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:
+ *
+ * https://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 netty.incubator.buffer.memseg {
+ // Java 11 compatible stand-in module for the memory segment implementation.
+ // We need this module in order for the tests module to pull in the memseg module.
+}
diff --git a/buffer-memseg/pom.xml b/buffer-memseg/pom.xml
new file mode 100644
index 0000000..215d02c
--- /dev/null
+++ b/buffer-memseg/pom.xml
@@ -0,0 +1,72 @@
+
+
+ 4.0.0
+
+
+ io.netty.incubator
+ netty-incubator-buffer-parent
+ 0.0.1.Final-SNAPSHOT
+
+
+ netty-incubator-buffer-memseg
+ 0.0.1.Final-SNAPSHOT
+ Netty/Incubator/Buffer MemorySegment
+ jar
+
+
+
+ io.netty.incubator
+ netty-incubator-buffer-api
+
+
+ io.netty
+ netty-common
+
+
+ io.netty
+ netty-buffer
+
+
+ org.openjdk.jmh
+ jmh-core
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+
+
+
+
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ true
+ ${java.compatibility}
+ ${java.compatibility}
+ ${java.version}
+ true
+ true
+ true
+ true
+ -Xlint:-options
+ 256m
+ 1024m
+
+ --add-modules
+ jdk.incubator.foreign
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java
similarity index 89%
rename from src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java
index 1aabd96..df68f16 100644
--- a/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java
+++ b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java
@@ -15,23 +15,22 @@
*/
package io.netty.buffer.api.memseg;
+import io.netty.buffer.api.internal.ArcDrop;
+import io.netty.buffer.api.internal.Statics;
import io.netty.buffer.api.AllocatorControl;
import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.Drop;
import io.netty.buffer.api.MemoryManager;
-import io.netty.buffer.api.internal.ArcDrop;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.lang.ref.Cleaner;
-import static io.netty.buffer.api.internal.Statics.convert;
-
public abstract class AbstractMemorySegmentManager implements MemoryManager {
@Override
public Buffer allocateShared(AllocatorControl allocatorControl, long size, Drop drop, Cleaner cleaner) {
var segment = createSegment(size, cleaner);
- return new MemSegBuffer(segment, segment, convert(drop), allocatorControl);
+ return new MemSegBuffer(segment, segment, Statics.convert(drop), allocatorControl);
}
@Override
@@ -45,7 +44,7 @@ public abstract class AbstractMemorySegmentManager implements MemoryManager {
@Override
public Drop drop() {
- return convert(MemSegBuffer.SEGMENT_CLOSE);
+ return Statics.convert(MemSegBuffer.SEGMENT_CLOSE);
}
@Override
@@ -71,7 +70,7 @@ public abstract class AbstractMemorySegmentManager implements MemoryManager {
@Override
public Buffer recoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop drop) {
var segment = (MemorySegment) recoverableMemory;
- return new MemSegBuffer(segment, segment, convert(ArcDrop.acquire(drop)), allocatorControl);
+ return new MemSegBuffer(segment, segment, Statics.convert(ArcDrop.acquire(drop)), allocatorControl);
}
@Override
diff --git a/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java
diff --git a/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java
similarity index 98%
rename from src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java
index 426f99b..7b04aff 100644
--- a/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java
+++ b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java
@@ -17,6 +17,11 @@ package io.netty.buffer.api.memseg;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.adaptor.BufferIntegratable;
+import io.netty.buffer.api.adaptor.ByteBufAdaptor;
+import io.netty.buffer.api.adaptor.ByteBufAllocatorAdaptor;
+import io.netty.buffer.api.internal.ArcDrop;
+import io.netty.buffer.api.internal.Statics;
import io.netty.buffer.api.AllocatorControl;
import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.ByteCursor;
@@ -27,19 +32,12 @@ import io.netty.buffer.api.WritableComponentProcessor;
import io.netty.buffer.api.Drop;
import io.netty.buffer.api.Owned;
import io.netty.buffer.api.RcSupport;
-import io.netty.buffer.api.adaptor.BufferIntegratable;
-import io.netty.buffer.api.adaptor.ByteBufAdaptor;
-import io.netty.buffer.api.adaptor.ByteBufAllocatorAdaptor;
-import io.netty.buffer.api.internal.ArcDrop;
-import io.netty.buffer.api.internal.Statics;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import static io.netty.buffer.api.internal.Statics.bufferIsClosed;
-import static io.netty.buffer.api.internal.Statics.bufferIsReadOnly;
import static jdk.incubator.foreign.MemoryAccess.getByteAtOffset;
import static jdk.incubator.foreign.MemoryAccess.getCharAtOffset;
import static jdk.incubator.foreign.MemoryAccess.getDoubleAtOffset;
@@ -56,7 +54,7 @@ import static jdk.incubator.foreign.MemoryAccess.setLongAtOffset;
import static jdk.incubator.foreign.MemoryAccess.setShortAtOffset;
class MemSegBuffer extends RcSupport implements Buffer, ReadableComponent, WritableComponent,
- BufferIntegratable {
+ BufferIntegratable {
private static final MemorySegment CLOSED_SEGMENT;
static final Drop SEGMENT_CLOSE;
@@ -325,7 +323,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re
private void copyInto(int srcPos, MemorySegment dest, int destPos, int length) {
if (seg == CLOSED_SEGMENT) {
- throw bufferIsClosed();
+ throw Statics.bufferIsClosed();
}
if (srcPos < 0) {
throw new IllegalArgumentException("The srcPos cannot be negative: " + srcPos + '.');
@@ -360,7 +358,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re
@Override
public ByteCursor openCursor(int fromOffset, int length) {
if (seg == CLOSED_SEGMENT) {
- throw bufferIsClosed();
+ throw Statics.bufferIsClosed();
}
if (fromOffset < 0) {
throw new IllegalArgumentException("The fromOffset cannot be negative: " + fromOffset + '.');
@@ -430,7 +428,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re
@Override
public ByteCursor openReverseCursor(int fromOffset, int length) {
if (seg == CLOSED_SEGMENT) {
- throw bufferIsClosed();
+ throw Statics.bufferIsClosed();
}
if (fromOffset < 0) {
throw new IllegalArgumentException("The fromOffset cannot be negative: " + fromOffset + '.');
@@ -508,7 +506,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re
throw new IllegalArgumentException("The minimum growth cannot be negative: " + minimumGrowth + '.');
}
if (seg != wseg) {
- throw bufferIsReadOnly();
+ throw Statics.bufferIsReadOnly();
}
if (writableBytes() >= size) {
// We already have enough space.
@@ -1172,27 +1170,27 @@ class MemSegBuffer extends RcSupport implements Buffer, Re
private RuntimeException checkWriteState(IndexOutOfBoundsException ioobe) {
if (seg == CLOSED_SEGMENT) {
- return bufferIsClosed();
+ return Statics.bufferIsClosed();
}
if (wseg != seg) {
- return bufferIsReadOnly();
+ return Statics.bufferIsReadOnly();
}
return ioobe;
}
private RuntimeException readAccessCheckException(int index) {
if (seg == CLOSED_SEGMENT) {
- throw bufferIsClosed();
+ throw Statics.bufferIsClosed();
}
return outOfBounds(index);
}
private RuntimeException writeAccessCheckException(int index) {
if (seg == CLOSED_SEGMENT) {
- throw bufferIsClosed();
+ throw Statics.bufferIsClosed();
}
if (wseg != seg) {
- return bufferIsReadOnly();
+ return Statics.bufferIsReadOnly();
}
return outOfBounds(index);
}
diff --git a/src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java
similarity index 91%
rename from src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java
index 1575ff6..55b1c8c 100644
--- a/src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java
+++ b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/NativeMemorySegmentManager.java
@@ -15,18 +15,17 @@
*/
package io.netty.buffer.api.memseg;
+import io.netty.buffer.api.internal.Statics;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.lang.ref.Cleaner;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.LongAdder;
import java.util.function.Function;
import static jdk.incubator.foreign.ResourceScope.newSharedScope;
public class NativeMemorySegmentManager extends AbstractMemorySegmentManager {
- public static final LongAdder MEM_USAGE_NATIVE = new LongAdder();
private static final ConcurrentHashMap CLEANUP_ACTIONS = new ConcurrentHashMap<>();
private static final Function CLEANUP_ACTION_MAKER = s -> new ReduceNativeMemoryUsage(s);
@@ -43,7 +42,7 @@ public class NativeMemorySegmentManager extends AbstractMemorySegmentManager {
@Override
public void run() {
- MEM_USAGE_NATIVE.add(-size);
+ Statics.MEM_USAGE_NATIVE.add(-size);
}
@Override
@@ -62,7 +61,7 @@ public class NativeMemorySegmentManager extends AbstractMemorySegmentManager {
final ResourceScope scope = cleaner == null ? newSharedScope() : newSharedScope(cleaner);
scope.addCloseAction(getCleanupAction(size));
var segment = MemorySegment.allocateNative(size, scope);
- MEM_USAGE_NATIVE.add(size);
+ Statics.MEM_USAGE_NATIVE.add(size);
return segment;
}
}
diff --git a/src/main/java/io/netty/buffer/api/memseg/SegmentMemoryManagers.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/SegmentMemoryManagers.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/memseg/SegmentMemoryManagers.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/SegmentMemoryManagers.java
diff --git a/src/main/java/io/netty/buffer/api/memseg/package-info.java b/buffer-memseg/src/main/java/io/netty/buffer/api/memseg/package-info.java
similarity index 100%
rename from src/main/java/io/netty/buffer/api/memseg/package-info.java
rename to buffer-memseg/src/main/java/io/netty/buffer/api/memseg/package-info.java
diff --git a/src/main/java/module-info.java b/buffer-memseg/src/main/java/module-info.java
similarity index 69%
rename from src/main/java/module-info.java
rename to buffer-memseg/src/main/java/module-info.java
index 53f3187..52f0beb 100644
--- a/src/main/java/module-info.java
+++ b/buffer-memseg/src/main/java/module-info.java
@@ -13,25 +13,22 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-module netty.incubator.buffer {
+import io.netty.buffer.api.MemoryManagers;
+import io.netty.buffer.api.memseg.SegmentMemoryManagers;
+
+module netty.incubator.buffer.memseg {
requires jdk.incubator.foreign;
requires io.netty.common;
requires io.netty.buffer;
+ requires netty.incubator.buffer;
// Optional dependencies, needed for some examples.
requires static java.logging;
- exports io.netty.buffer.api;
- exports io.netty.buffer.api.adaptor;
-
- uses io.netty.buffer.api.MemoryManagers;
-
// Permit reflective access to non-public members.
// Also means we don't have to make all test methods etc. public for JUnit to access them.
- opens io.netty.buffer.api;
+ opens io.netty.buffer.api.memseg;
- provides io.netty.buffer.api.MemoryManagers with
- io.netty.buffer.api.memseg.SegmentMemoryManagers,
- io.netty.buffer.api.bytebuffer.ByteBufferMemoryManagers,
- io.netty.buffer.api.unsafe.UnsafeMemoryManagers;
+ provides MemoryManagers with
+ SegmentMemoryManagers;
}
diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemSegBufAccessBenchmark.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java
rename to buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemSegBufAccessBenchmark.java
index 757f6bd..f55b809 100644
--- a/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java
+++ b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemSegBufAccessBenchmark.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.benchmarks;
+package io.netty.buffer.api.memseg.benchmarks;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentCloseBenchmark.java b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentCloseBenchmark.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentCloseBenchmark.java
rename to buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentCloseBenchmark.java
index 083ff29..da70524 100644
--- a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentCloseBenchmark.java
+++ b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentCloseBenchmark.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.benchmarks;
+package io.netty.buffer.api.memseg.benchmarks;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentClosedByCleanerBenchmark.java
similarity index 76%
rename from src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java
rename to buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentClosedByCleanerBenchmark.java
index d719840..601400c 100644
--- a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java
+++ b/buffer-memseg/src/test/java/io/netty/buffer/api/memseg/benchmarks/MemorySegmentClosedByCleanerBenchmark.java
@@ -13,10 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.benchmarks;
+package io.netty.buffer.api.memseg.benchmarks;
import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.memseg.SegmentMemoryManagers;
import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.MemoryManagers;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@@ -41,10 +43,37 @@ import static java.util.concurrent.CompletableFuture.completedFuture;
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Benchmark)
public class MemorySegmentClosedByCleanerBenchmark {
- private static final BufferAllocator heap = BufferAllocator.heap();
- private static final BufferAllocator heapPooled = BufferAllocator.pooledHeap();
- private static final BufferAllocator direct = BufferAllocator.direct();
- private static final BufferAllocator directPooled = BufferAllocator.pooledDirect();
+ private static final BufferAllocator heap;
+ private static final BufferAllocator heapPooled;
+ private static final BufferAllocator direct;
+ private static final BufferAllocator directPooled;
+
+ static {
+ class Allocators {
+ final BufferAllocator heap;
+ final BufferAllocator pooledHeap;
+ final BufferAllocator direct;
+ final BufferAllocator pooledDirect;
+
+ Allocators(BufferAllocator heap, BufferAllocator pooledHeap,
+ BufferAllocator direct, BufferAllocator pooledDirect) {
+ this.heap = heap;
+ this.pooledHeap = pooledHeap;
+ this.direct = direct;
+ this.pooledDirect = pooledDirect;
+ }
+ }
+
+ var allocs = MemoryManagers.using(new SegmentMemoryManagers(), () -> {
+ return new Allocators(BufferAllocator.heap(), BufferAllocator.pooledHeap(),
+ BufferAllocator.direct(), BufferAllocator.pooledDirect());
+ });
+
+ heap = allocs.heap;
+ heapPooled = allocs.pooledHeap;
+ direct = allocs.direct;
+ directPooled = allocs.pooledDirect;
+ }
@Param({"heavy", "light"})
public String workload;
diff --git a/buffer-tests/pom.xml b/buffer-tests/pom.xml
new file mode 100644
index 0000000..2ed3b2d
--- /dev/null
+++ b/buffer-tests/pom.xml
@@ -0,0 +1,123 @@
+
+
+
+ 4.0.0
+
+
+ io.netty.incubator
+ netty-incubator-buffer-parent
+ 0.0.1.Final-SNAPSHOT
+
+
+ netty-incubator-buffer-tests
+ 0.0.1.Final-SNAPSHOT
+ Netty/Incubator/Buffer Tests
+ jar
+
+
+
+ io.netty.incubator
+ netty-incubator-buffer-api
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+ test
+
+
+ junit
+ junit
+ test
+
+
+ org.assertj
+ assertj-core
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+ io.netty
+ netty-build-common
+ test
+
+
+ io.netty
+ netty-handler
+ test
+
+
+ io.netty
+ netty-codec-http
+ test
+
+
+ org.openjdk.jmh
+ jmh-core
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+
+
+
+
+
+ Java 17 support
+
+ 17
+
+
+
+ io.netty.incubator
+ netty-incubator-buffer-memseg
+
+
+
+
+ Java 11 support for tests
+
+ !17
+
+
+
+ io.netty.incubator
+ netty-incubator-buffer-memseg-dummy
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer-tests/src/main/java/module-info.java b/buffer-tests/src/main/java/module-info.java
new file mode 100644
index 0000000..2560866
--- /dev/null
+++ b/buffer-tests/src/main/java/module-info.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2021 The Netty Project
+ *
+ * The Netty Project 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:
+ *
+ * https://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.
+ */
+open module netty.incubator.buffer.tests {
+ requires io.netty.common;
+ requires io.netty.buffer;
+
+ // Optional dependencies, needed for some examples.
+ requires static java.logging;
+
+ requires netty.incubator.buffer;
+ // We need to require memseg in order for its implementation to be service loaded.
+ // Just having it on the module path is not enough.
+ requires netty.incubator.buffer.memseg;
+}
diff --git a/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferBulkAccessTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferBulkAccessTest.java
index 16845a4..fd59c33 100644
--- a/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferBulkAccessTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
+import io.netty.buffer.api.Scope;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferByteOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferByteOffsettedAccessorsTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferByteOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferByteOffsettedAccessorsTest.java
index 22d8c0e..294940c 100644
--- a/src/test/java/io/netty/buffer/api/BufferByteOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferByteOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferCharOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCharOffsettedAccessorsTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferCharOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCharOffsettedAccessorsTest.java
index 2edac36..183be45 100644
--- a/src/test/java/io/netty/buffer/api/BufferCharOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCharOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferCleanerTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCleanerTest.java
similarity index 82%
rename from src/test/java/io/netty/buffer/api/BufferCleanerTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCleanerTest.java
index 7785a89..4487549 100644
--- a/src/test/java/io/netty/buffer/api/BufferCleanerTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCleanerTest.java
@@ -13,13 +13,17 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
-import io.netty.buffer.api.memseg.NativeMemorySegmentManager;
+import io.netty.buffer.api.MemoryManagers;
+import io.netty.buffer.api.internal.Statics;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.netty.buffer.api.MemoryManagers.using;
@@ -36,21 +40,23 @@ public class BufferCleanerTest extends BufferTestSupport {
Stream.Builder builder = Stream.builder();
builder.add(new Fixture(f + "/" + managers, () -> using(managers, f), f.getProperties()));
return builder.build();
- }).toList();
+ }).collect(Collectors.toList());
return fixtureCombinations(initFixtures).filter(f -> f.isDirect()).toArray(Fixture[]::new);
}
+ // Only run this one on JDK 17.
+ @DisabledForJreRange(min = JRE.JAVA_11, max = JRE.JAVA_16)
@ParameterizedTest
@MethodSource("memorySegmentAllocators")
public void bufferMustBeClosedByCleaner(Fixture fixture) throws InterruptedException {
- var initial = NativeMemorySegmentManager.MEM_USAGE_NATIVE.sum();
+ var initial = Statics.MEM_USAGE_NATIVE.sum();
int allocationSize = 1024;
allocateAndForget(fixture, allocationSize);
long sum = 0;
for (int i = 0; i < 15; i++) {
System.gc();
System.runFinalization();
- sum = NativeMemorySegmentManager.MEM_USAGE_NATIVE.sum() - initial;
+ sum = Statics.MEM_USAGE_NATIVE.sum() - initial;
if (sum < allocationSize) {
// The memory must have been cleaned.
return;
diff --git a/src/test/java/io/netty/buffer/api/BufferCompactTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompactTest.java
similarity index 95%
rename from src/test/java/io/netty/buffer/api/BufferCompactTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompactTest.java
index 8eaf4e2..ba79516 100644
--- a/src/test/java/io/netty/buffer/api/BufferCompactTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompactTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferComponentIterationTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferComponentIterationTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferComponentIterationTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferComponentIterationTest.java
index a6db788..006481e 100644
--- a/src/test/java/io/netty/buffer/api/BufferComponentIterationTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferComponentIterationTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.ByteCursor;
+import io.netty.buffer.api.CompositeBuffer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferCompositionTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompositionTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferCompositionTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompositionTest.java
index 183833b..e003b5d 100644
--- a/src/test/java/io/netty/buffer/api/BufferCompositionTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferCompositionTest.java
@@ -13,8 +13,11 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferDoubleOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferDoubleOffsettedAccessorsTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferDoubleOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferDoubleOffsettedAccessorsTest.java
index d002692..12d6ea6 100644
--- a/src/test/java/io/netty/buffer/api/BufferDoubleOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferDoubleOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferEnsureWritableTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferEnsureWritableTest.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/BufferEnsureWritableTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferEnsureWritableTest.java
index c2880d8..8626cc0 100644
--- a/src/test/java/io/netty/buffer/api/BufferEnsureWritableTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferEnsureWritableTest.java
@@ -13,8 +13,11 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferFloatOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferFloatOffsettedAccessorsTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferFloatOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferFloatOffsettedAccessorsTest.java
index fce4902..837718d 100644
--- a/src/test/java/io/netty/buffer/api/BufferFloatOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferFloatOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferIntOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferIntOffsettedAccessorsTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferIntOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferIntOffsettedAccessorsTest.java
index 3e463b4..ed41ad0 100644
--- a/src/test/java/io/netty/buffer/api/BufferIntOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferIntOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferLongOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferLongOffsettedAccessorsTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferLongOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferLongOffsettedAccessorsTest.java
index 702795e..9495bd4 100644
--- a/src/test/java/io/netty/buffer/api/BufferLongOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferLongOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferMediumOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferMediumOffsettedAccessorsTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferMediumOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferMediumOffsettedAccessorsTest.java
index 4be7196..d380fa7 100644
--- a/src/test/java/io/netty/buffer/api/BufferMediumOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferMediumOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferOffsetsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferOffsetsTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferOffsetsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferOffsetsTest.java
index 25090c6..7dd9b40 100644
--- a/src/test/java/io/netty/buffer/api/BufferOffsetsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferOffsetsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferPrimitiveRelativeAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferPrimitiveRelativeAccessorsTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferPrimitiveRelativeAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferPrimitiveRelativeAccessorsTest.java
index 6959a50..1b7c349 100644
--- a/src/test/java/io/netty/buffer/api/BufferPrimitiveRelativeAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferPrimitiveRelativeAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferReadOnlyTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReadOnlyTest.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/BufferReadOnlyTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReadOnlyTest.java
index b28ffff..152be4b 100644
--- a/src/test/java/io/netty/buffer/api/BufferReadOnlyTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReadOnlyTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
+import io.netty.buffer.api.Send;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferRefTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferRefTest.java
similarity index 95%
rename from src/test/java/io/netty/buffer/api/BufferRefTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferRefTest.java
index 7a3b271..d6f3abf 100644
--- a/src/test/java/io/netty/buffer/api/BufferRefTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferRefTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.BufferRef;
+import io.netty.buffer.api.Send;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/src/test/java/io/netty/buffer/api/BufferReferenceCountingTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReferenceCountingTest.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/BufferReferenceCountingTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReferenceCountingTest.java
index d641142..147d936 100644
--- a/src/test/java/io/netty/buffer/api/BufferReferenceCountingTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferReferenceCountingTest.java
@@ -13,13 +13,16 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
-import org.junit.jupiter.api.Disabled;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
+import java.nio.ByteOrder;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;
@@ -263,6 +266,7 @@ public class BufferReferenceCountingTest extends BufferTestSupport {
try (BufferAllocator allocator = fixture.createAllocator();
Buffer buf = allocator.allocate(8)) {
assertThrows(IllegalArgumentException.class, () -> buf.slice(0, -1));
+ assertThrows(IllegalArgumentException.class, () -> buf.slice(2, -1));
// Verify that the slice is closed properly afterwards.
assertTrue(buf.isOwned());
}
@@ -607,6 +611,23 @@ public class BufferReferenceCountingTest extends BufferTestSupport {
}
}
+ @ParameterizedTest
+ @MethodSource("allocators")
+ public void splitMustPreserveByteOrder(Fixture fixture) {
+ try (BufferAllocator allocator = fixture.createAllocator()) {
+ try (Buffer a = allocator.allocate(8).order(BIG_ENDIAN);
+ Buffer b = a.split(4)) {
+ assertThat(a.order()).isEqualTo(BIG_ENDIAN);
+ assertThat(b.order()).isEqualTo(BIG_ENDIAN);
+ }
+ try (Buffer a = allocator.allocate(8).order(LITTLE_ENDIAN);
+ Buffer b = a.split(4)) {
+ assertThat(a.order()).isEqualTo(LITTLE_ENDIAN);
+ assertThat(b.order()).isEqualTo(LITTLE_ENDIAN);
+ }
+ }
+ }
+
@ParameterizedTest
@MethodSource("allocators")
public void ensureWritableOnSplitBuffers(Fixture fixture) {
diff --git a/src/test/java/io/netty/buffer/api/BufferSendTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferSendTest.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/BufferSendTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferSendTest.java
index 168ccd9..ba71bae 100644
--- a/src/test/java/io/netty/buffer/api/BufferSendTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferSendTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.BufferRef;
+import io.netty.buffer.api.Send;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferShortOffsettedAccessorsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferShortOffsettedAccessorsTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/BufferShortOffsettedAccessorsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferShortOffsettedAccessorsTest.java
index 657f6e2..2cded12 100644
--- a/src/test/java/io/netty/buffer/api/BufferShortOffsettedAccessorsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferShortOffsettedAccessorsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/BufferTestSupport.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferTestSupport.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/BufferTestSupport.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferTestSupport.java
index a5a131b..4fc8d48 100644
--- a/src/test/java/io/netty/buffer/api/BufferTestSupport.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferTestSupport.java
@@ -13,9 +13,13 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
-import io.netty.buffer.api.Fixture.Properties;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.CompositeBuffer;
+import io.netty.buffer.api.MemoryManagers;
+import io.netty.buffer.api.RcSupport;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -35,16 +39,10 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.Stream.Builder;
-import static io.netty.buffer.api.Fixture.Properties.CLEANER;
-import static io.netty.buffer.api.Fixture.Properties.COMPOSITE;
-import static io.netty.buffer.api.Fixture.Properties.CONST;
-import static io.netty.buffer.api.Fixture.Properties.DIRECT;
-import static io.netty.buffer.api.Fixture.Properties.HEAP;
-import static io.netty.buffer.api.Fixture.Properties.POOLED;
-import static io.netty.buffer.api.MemoryManagers.using;
import static java.nio.ByteOrder.BIG_ENDIAN;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.assertj.core.api.Assertions.assertThat;
@@ -136,10 +134,10 @@ public abstract class BufferTestSupport {
static List initialAllocators() {
return List.of(
- new Fixture("heap", BufferAllocator::heap, HEAP),
- new Fixture("direct", BufferAllocator::direct, DIRECT, CLEANER),
- new Fixture("pooledHeap", BufferAllocator::pooledHeap, POOLED, HEAP),
- new Fixture("pooledDirect", BufferAllocator::pooledDirect, POOLED, DIRECT, CLEANER));
+ new Fixture("heap", BufferAllocator::heap, Fixture.Properties.HEAP),
+ new Fixture("direct", BufferAllocator::direct, Fixture.Properties.DIRECT, Fixture.Properties.CLEANER),
+ new Fixture("pooledHeap", BufferAllocator::pooledHeap, Fixture.Properties.POOLED, Fixture.Properties.HEAP),
+ new Fixture("pooledDirect", BufferAllocator::pooledDirect, Fixture.Properties.POOLED, Fixture.Properties.DIRECT, Fixture.Properties.CLEANER));
}
static List initialFixturesForEachImplementation() {
@@ -153,10 +151,10 @@ public abstract class BufferTestSupport {
initFixtures = initFixtures.stream().flatMap(f -> {
Builder builder = Stream.builder();
for (MemoryManagers managers : loadableManagers) {
- builder.add(new Fixture(f + "/" + managers, () -> using(managers, f), f.getProperties()));
+ builder.add(new Fixture(f + "/" + managers, () -> MemoryManagers.using(managers, f), f.getProperties()));
}
return builder.build();
- }).toList();
+ }).collect(Collectors.toList());
return initFixtures;
}
@@ -194,7 +192,7 @@ public abstract class BufferTestSupport {
}
}
};
- }, COMPOSITE));
+ }, Fixture.Properties.COMPOSITE));
}
}
@@ -221,7 +219,7 @@ public abstract class BufferTestSupport {
}
}
};
- }, COMPOSITE));
+ }, Fixture.Properties.COMPOSITE));
for (Fixture fixture : initFixtures) {
builder.add(new Fixture(fixture + ".ensureWritable", () -> {
@@ -269,7 +267,7 @@ public abstract class BufferTestSupport {
}
}
};
- }, COMPOSITE));
+ }, Fixture.Properties.COMPOSITE));
}
var stream = builder.build();
@@ -307,7 +305,7 @@ public abstract class BufferTestSupport {
private static Stream injectSlices(Fixture f) {
Builder builder = Stream.builder();
builder.add(f);
- var props = concat(f.getProperties(), Properties.SLICE);
+ var props = concat(f.getProperties(), Fixture.Properties.SLICE);
builder.add(new Fixture(f + ".slice(0, capacity())", () -> {
return new BufferAllocator() {
BufferAllocator allocatorBase;
@@ -351,7 +349,7 @@ public abstract class BufferTestSupport {
return builder.build();
}
- private static Properties[] concat(Properties[] props, Properties prop) {
+ private static Fixture.Properties[] concat(Fixture.Properties[] props, Fixture.Properties prop) {
props = Arrays.copyOf(props, props.length + 1);
props[props.length - 1] = prop;
return props;
diff --git a/src/test/java/io/netty/buffer/api/BufferWriteBytesCombinationsTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferWriteBytesCombinationsTest.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/BufferWriteBytesCombinationsTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferWriteBytesCombinationsTest.java
index 0d10e96..001224f 100644
--- a/src/test/java/io/netty/buffer/api/BufferWriteBytesCombinationsTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/BufferWriteBytesCombinationsTest.java
@@ -13,8 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/io/netty/buffer/api/EchoIT.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/EchoIT.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/EchoIT.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/EchoIT.java
index c9ea1fb..6009a9c 100644
--- a/src/test/java/io/netty/buffer/api/EchoIT.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/EchoIT.java
@@ -13,13 +13,15 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.adaptor.ByteBufAllocatorAdaptor;
-import io.netty.buffer.api.examples.echo.EchoServerHandler;
+import io.netty.buffer.api.tests.examples.echo.EchoServerHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
diff --git a/src/test/java/io/netty/buffer/api/Fixture.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/Fixture.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/Fixture.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/Fixture.java
index 8d0a677..97a3289 100644
--- a/src/test/java/io/netty/buffer/api/Fixture.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/Fixture.java
@@ -13,7 +13,9 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+
+import io.netty.buffer.api.BufferAllocator;
import java.util.Arrays;
import java.util.EnumSet;
diff --git a/src/test/java/io/netty/buffer/api/Memoize.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/Memoize.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/Memoize.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/Memoize.java
index bc5db8d..fbfda6b 100644
--- a/src/test/java/io/netty/buffer/api/Memoize.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/Memoize.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
import java.util.function.Supplier;
diff --git a/src/test/java/io/netty/buffer/api/ScopeTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/ScopeTest.java
similarity index 92%
rename from src/test/java/io/netty/buffer/api/ScopeTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/ScopeTest.java
index a48fa3e..3c31881 100644
--- a/src/test/java/io/netty/buffer/api/ScopeTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/ScopeTest.java
@@ -13,8 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api;
+package io.netty.buffer.api.tests;
+import io.netty.buffer.api.Drop;
+import io.netty.buffer.api.Owned;
+import io.netty.buffer.api.RcSupport;
+import io.netty.buffer.api.Scope;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
diff --git a/src/test/java/io/netty/buffer/api/adaptor/AbstractByteBufTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/AbstractByteBufTest.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/adaptor/AbstractByteBufTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/AbstractByteBufTest.java
index eaf40f7..a6b58cd 100644
--- a/src/test/java/io/netty/buffer/api/adaptor/AbstractByteBufTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/AbstractByteBufTest.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.adaptor;
+package io.netty.buffer.api.tests.adaptor;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
diff --git a/src/test/java/io/netty/buffer/api/adaptor/ByteBufAdaptorTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/ByteBufAdaptorTest.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/adaptor/ByteBufAdaptorTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/ByteBufAdaptorTest.java
index 3fdd2f3..34df8ff 100644
--- a/src/test/java/io/netty/buffer/api/adaptor/ByteBufAdaptorTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/adaptor/ByteBufAdaptorTest.java
@@ -13,9 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.adaptor;
+package io.netty.buffer.api.tests.adaptor;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.api.adaptor.ByteBufAllocatorAdaptor;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
diff --git a/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/ByteIterationBenchmark.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/ByteIterationBenchmark.java
index 4197826..f00a9b1 100644
--- a/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/ByteIterationBenchmark.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.benchmarks;
+package io.netty.buffer.api.tests.benchmarks;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
diff --git a/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/SendBenchmark.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/SendBenchmark.java
index d5c3176..4cbdd3e 100644
--- a/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/benchmarks/SendBenchmark.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.benchmarks;
+package io.netty.buffer.api.tests.benchmarks;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
diff --git a/src/test/java/io/netty/buffer/api/examples/AsyncExample.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/AsyncExample.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/examples/AsyncExample.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/AsyncExample.java
index 0c8beaa..c9d0f28 100644
--- a/src/test/java/io/netty/buffer/api/examples/AsyncExample.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/AsyncExample.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples;
+package io.netty.buffer.api.tests.examples;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
diff --git a/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/ComposingAndSlicingExample.java
similarity index 97%
rename from src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/ComposingAndSlicingExample.java
index 62315f3..946008c 100644
--- a/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/ComposingAndSlicingExample.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples;
+package io.netty.buffer.api.tests.examples;
-import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.CompositeBuffer;
import io.netty.buffer.api.Scope;
diff --git a/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/FileCopyExample.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/examples/FileCopyExample.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/FileCopyExample.java
index 214c3dd..e6cea50 100644
--- a/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/FileCopyExample.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples;
+package io.netty.buffer.api.tests.examples;
-import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.CompositeBuffer;
import io.netty.buffer.api.Send;
diff --git a/src/test/java/io/netty/buffer/api/examples/SendExample.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/SendExample.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/examples/SendExample.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/SendExample.java
index 948ac13..8fcec60 100644
--- a/src/test/java/io/netty/buffer/api/examples/SendExample.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/SendExample.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples;
+package io.netty.buffer.api.tests.examples;
-import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Buffer;
+import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.Send;
import java.util.concurrent.ExecutorService;
diff --git a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoder.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoder.java
similarity index 98%
rename from src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoder.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoder.java
index 96ae572..249095c 100644
--- a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoder.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoder.java
@@ -13,12 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples.bytetomessagedecoder;
+package io.netty.buffer.api.tests.examples.bytetomessagedecoder;
-import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.CompositeBuffer;
import io.netty.buffer.api.Send;
+import io.netty.buffer.api.Buffer;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
diff --git a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java
similarity index 96%
rename from src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java
index 64d4d83..d9584ed 100644
--- a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/AlternativeMessageDecoderTest.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples.bytetomessagedecoder;
+package io.netty.buffer.api.tests.examples.bytetomessagedecoder;
-import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.Buffer;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.jupiter.api.Test;
@@ -26,7 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.SplittableRandom;
-import static io.netty.buffer.api.BufferTestSupport.toByteArray;
+import static io.netty.buffer.api.tests.BufferTestSupport.toByteArray;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoder.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoder.java
similarity index 99%
rename from src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoder.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoder.java
index cb7a2e3..871d39c 100644
--- a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoder.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoder.java
@@ -13,12 +13,12 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples.bytetomessagedecoder;
+package io.netty.buffer.api.tests.examples.bytetomessagedecoder;
import io.netty.buffer.ByteBufAllocator;
-import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.CompositeBuffer;
+import io.netty.buffer.api.Buffer;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
diff --git a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java
similarity index 85%
rename from src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java
rename to buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java
index cbf3684..cc72823 100644
--- a/src/test/java/io/netty/buffer/api/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java
+++ b/buffer-tests/src/test/java/io/netty/buffer/api/tests/examples/bytetomessagedecoder/ByteToMessageDecoderTest.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package io.netty.buffer.api.examples.bytetomessagedecoder;
+package io.netty.buffer.api.tests.examples.bytetomessagedecoder;
-import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
+import io.netty.buffer.api.Buffer;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
@@ -30,8 +30,7 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import static io.netty.buffer.api.BufferAllocator.heap;
-import static io.netty.buffer.api.BufferTestSupport.assertEquals;
+import static io.netty.buffer.api.tests.BufferTestSupport.assertEquals;
import static io.netty.buffer.api.CompositeBuffer.compose;
import static java.nio.ByteOrder.BIG_ENDIAN;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
@@ -61,7 +60,7 @@ public class ByteToMessageDecoderTest {
}
});
- try (Buffer buf = heap().allocate(4).writeInt(0x01020304)) {
+ try (Buffer buf = BufferAllocator.heap().allocate(4).writeInt(0x01020304)) {
channel.writeInbound(buf.slice());
try (Buffer b = channel.readInbound()) {
buf.readByte();
@@ -72,7 +71,7 @@ public class ByteToMessageDecoderTest {
@Test
public void testRemoveItselfWriteBuffer() {
- final Buffer buf = heap().allocate(5, BIG_ENDIAN).writeInt(0x01020304);
+ final Buffer buf = BufferAllocator.heap().allocate(5, BIG_ENDIAN).writeInt(0x01020304);
EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
private boolean removed;
@@ -89,7 +88,7 @@ public class ByteToMessageDecoderTest {
});
channel.writeInbound(buf.slice());
- try (Buffer expected = heap().allocate(3, BIG_ENDIAN).writeShort((short) 0x0203).writeByte((byte) 0x04);
+ try (Buffer expected = BufferAllocator.heap().allocate(3, BIG_ENDIAN).writeShort((short) 0x0203).writeByte((byte) 0x04);
Buffer b = channel.readInbound();
Buffer actual = b.slice(); // Only compare readable bytes.
buf) {
@@ -103,7 +102,7 @@ public class ByteToMessageDecoderTest {
*/
@Test
public void testInternalBufferClearReadAll() {
- Buffer buf = heap().allocate(1).writeByte((byte) 'a');
+ Buffer buf = BufferAllocator.heap().allocate(1).writeByte((byte) 'a');
EmbeddedChannel channel = newInternalBufferTestChannel();
assertFalse(channel.writeInbound(buf));
assertFalse(channel.finish());
@@ -115,11 +114,11 @@ public class ByteToMessageDecoderTest {
*/
@Test
public void testInternalBufferClearReadPartly() {
- final Buffer buf = heap().allocate(2, BIG_ENDIAN).writeShort((short) 0x0102);
+ final Buffer buf = BufferAllocator.heap().allocate(2, BIG_ENDIAN).writeShort((short) 0x0102);
EmbeddedChannel channel = newInternalBufferTestChannel();
assertTrue(channel.writeInbound(buf));
assertTrue(channel.finish());
- try (Buffer expected = heap().allocate(1).writeByte((byte) 0x02);
+ try (Buffer expected = BufferAllocator.heap().allocate(1).writeByte((byte) 0x02);
Buffer b = channel.readInbound();
Buffer actual = b.slice()) {
assertEquals(expected, actual);
@@ -162,7 +161,7 @@ public class ByteToMessageDecoderTest {
byte[] bytes = new byte[1024];
ThreadLocalRandom.current().nextBytes(bytes);
- Buffer buffer = heap().allocate(bytes.length);
+ Buffer buffer = BufferAllocator.heap().allocate(bytes.length);
for (byte b : bytes) {
buffer.writeByte(b);
}
@@ -209,7 +208,7 @@ public class ByteToMessageDecoderTest {
}
}
});
- Buffer buf = heap().allocate(2, BIG_ENDIAN).writeShort((short) 0x0102);
+ Buffer buf = BufferAllocator.heap().allocate(2, BIG_ENDIAN).writeShort((short) 0x0102);
assertFalse(channel.writeInbound(buf));
channel.finish();
assertEquals(1, queue.take());
@@ -242,7 +241,7 @@ public class ByteToMessageDecoderTest {
}
});
- try (Buffer buf = heap().allocate(4, BIG_ENDIAN).writeInt(0x01020304)) {
+ try (Buffer buf = BufferAllocator.heap().allocate(4, BIG_ENDIAN).writeInt(0x01020304)) {
assertTrue(channel.writeInbound(buf.slice()));
try (Buffer expected = buf.slice(1, 3);
Buffer b = channel.readInbound();
@@ -267,7 +266,7 @@ public class ByteToMessageDecoderTest {
byte[] bytes = new byte[1024];
ThreadLocalRandom.current().nextBytes(bytes);
- try (Buffer buf = heap().allocate(bytes.length)) {
+ try (Buffer buf = BufferAllocator.heap().allocate(bytes.length)) {
for (byte b : bytes) {
buf.writeByte(b);
}
@@ -308,7 +307,7 @@ public class ByteToMessageDecoderTest {
});
byte[] bytes = new byte[1024];
ThreadLocalRandom.current().nextBytes(bytes);
- try (Buffer buf = heap().allocate(bytes.length, BIG_ENDIAN);
+ try (Buffer buf = BufferAllocator.heap().allocate(bytes.length, BIG_ENDIAN);
Buffer part1 = buf.slice(0, bytes.length - 1);
Buffer part2 = buf.slice(bytes.length - 1, 1)) {
for (byte b : bytes) {
@@ -333,8 +332,8 @@ public class ByteToMessageDecoderTest {
@Override
protected void decode(ChannelHandlerContext ctx, Buffer in) { }
});
- assertFalse(channel.writeInbound(heap().allocate(8).writeByte((byte) 1).makeReadOnly()));
- assertFalse(channel.writeInbound(heap().allocate(1).writeByte((byte) 2)));
+ assertFalse(channel.writeInbound(BufferAllocator.heap().allocate(8).writeByte((byte) 1).makeReadOnly()));
+ assertFalse(channel.writeInbound(BufferAllocator.heap().allocate(1).writeByte((byte) 2)));
assertFalse(channel.finish());
}
@@ -342,11 +341,11 @@ public class ByteToMessageDecoderTest {
public void releaseWhenMergeCumulateThrows() {
Buffer oldCumulation = writeFailingCumulation(1, 64);
oldCumulation.writeByte((byte) 0);
- Buffer in = heap().allocate(12, BIG_ENDIAN).writerOffset(12);
+ Buffer in = BufferAllocator.heap().allocate(12, BIG_ENDIAN).writerOffset(12);
Throwable thrown = null;
try {
- ByteToMessageDecoder.MERGE_CUMULATOR.cumulate(heap(), oldCumulation, in);
+ ByteToMessageDecoder.MERGE_CUMULATOR.cumulate(BufferAllocator.heap(), oldCumulation, in);
} catch (Throwable t) {
thrown = t;
}
@@ -358,7 +357,7 @@ public class ByteToMessageDecoderTest {
}
private static Buffer writeFailingCumulation(int untilFailure, int capacity) {
- Buffer realBuffer = heap().allocate(capacity, BIG_ENDIAN);
+ Buffer realBuffer = BufferAllocator.heap().allocate(capacity, BIG_ENDIAN);
Answer