This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add a ByteBuffer based implementation of Buffer #37
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9570982
Add a ByteBuffer based implementation of Buffer
chrisvest ff66723
Make test-compilation and test-running pass
chrisvest 6a6ecde
Use release version of Netty build
chrisvest eebdae8
Make sure checkstyle dependencies are in the docker layer cache
chrisvest 56a131a
Fix test-compile
chrisvest 1bf9429
Fix warning printed at test time
chrisvest 66fbc44
Update docker layer cache workflow thing
chrisvest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package io.netty.buffer.api; | ||
|
||
import java.util.ServiceLoader; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* The MemoryManagers interface is the handle through which {@link BufferAllocator buffer allocators} access the low | ||
* level memory management APIs. | ||
* <p> | ||
* This is hidden behind this interface in order to make allocation and pool agnostic and reusable across buffer and | ||
* memory implementations. | ||
*/ | ||
public interface MemoryManagers { | ||
/** | ||
* Get the default, or currently configured, memory managers instance. | ||
* @return A MemoryManagers instance. | ||
*/ | ||
static MemoryManagers getManagers() { | ||
return MemoryManagersOverride.getManagers(); | ||
} | ||
|
||
/** | ||
* Temporarily override the default configured memory managers instance. | ||
* <p> | ||
* Calls to {@link #getManagers()} from within the given supplier will get the given managers instance. | ||
* | ||
* @param managers Override the default configured managers instance with this instance. | ||
* @param supplier The supplier function to be called while the override is in place. | ||
* @param <T> The result type from the supplier. | ||
* @return The result from the supplier. | ||
*/ | ||
static <T> T using(MemoryManagers managers, Supplier<T> supplier) { | ||
return MemoryManagersOverride.using(managers, supplier); | ||
} | ||
|
||
/** | ||
* Get a lazy-loading stream of all available memory managers. | ||
* | ||
* @return A stream of providers of memory managers instances. | ||
*/ | ||
static Stream<ServiceLoader.Provider<MemoryManagers>> getAllManagers() { | ||
var loader = ServiceLoader.load(MemoryManagers.class); | ||
return loader.stream(); | ||
} | ||
|
||
/** | ||
* Get a {@link MemoryManager} instance that is suitable for allocating on-heap {@link Buffer} instances. | ||
* | ||
* @return An on-heap {@link MemoryManager}. | ||
*/ | ||
MemoryManager getHeapMemoryManager(); | ||
|
||
/** | ||
* Get a {@link MemoryManager} instance that is suitable for allocating off-heap {@link Buffer} instances. | ||
* | ||
* @return An off-heap {@link MemoryManager}. | ||
*/ | ||
MemoryManager getNativeMemoryManager(); | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/io/netty/buffer/api/MemoryManagersOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package io.netty.buffer.api; | ||
|
||
import io.netty.buffer.api.memseg.SegmentMemoryManagers; | ||
|
||
import java.util.Collections; | ||
import java.util.IdentityHashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Supplier; | ||
|
||
final class MemoryManagersOverride { | ||
private static final MemoryManagers DEFAULT = new SegmentMemoryManagers(); | ||
private static final AtomicInteger OVERRIDES_AVAILABLE = new AtomicInteger(); | ||
private static final Map<Thread, MemoryManagers> OVERRIDES = Collections.synchronizedMap(new IdentityHashMap<>()); | ||
|
||
private MemoryManagersOverride() { | ||
} | ||
|
||
static MemoryManagers getManagers() { | ||
if (OVERRIDES_AVAILABLE.get() > 0) { | ||
return OVERRIDES.getOrDefault(Thread.currentThread(), DEFAULT); | ||
} | ||
return DEFAULT; | ||
} | ||
|
||
static <T> T using(MemoryManagers managers, Supplier<T> supplier) { | ||
Thread thread = Thread.currentThread(); | ||
OVERRIDES.put(thread, managers); | ||
OVERRIDES_AVAILABLE.incrementAndGet(); | ||
try { | ||
return supplier.get(); | ||
} finally { | ||
OVERRIDES_AVAILABLE.decrementAndGet(); | ||
OVERRIDES.remove(thread); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be placed in
compilerArgs
instead of the varioustestCompiler*
configurations, because the latter cannot correctly handle space-separated argument-value pairs.This is a
maven-compiler-plugin
limitation, that apache/maven-compiler-plugin#27 will hopefully solve.