Skip to content

Commit

Permalink
added Mnemonic infra. as an alternative backed allocation mechanism, …
Browse files Browse the repository at this point in the history
…note that move allocator services to the service-dist folder as the properties indicated in pom.xml.
  • Loading branch information
Wang, Gang(Gary) committed Oct 25, 2017
1 parent 8148b6d commit 9e59d4e
Show file tree
Hide file tree
Showing 10 changed files with 3,580 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ cpp/.idea/
python/.eggs/
.vscode
.idea/
java/memory/base_allocator_test.dat

9 changes: 9 additions & 0 deletions java/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-pmalloc-service</artifactId>
<version>0.9.0-incubating-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2012 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:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.buffer;

import io.netty.util.internal.PlatformDependent;

import org.apache.mnemonic.CommonAllocator;

/**
* Simplistic {@link ByteBufAllocator} implementation that does not pool anything.
*/
public final class MnemonicUnpooledByteBufAllocator<A extends CommonAllocator<A>> extends AbstractByteBufAllocator {

private A mcalloc;

/**
* Default instance
*/
// public static final UnpooledByteBufAllocator DEFAULT =
// new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());

/**
* Create a new instance
*
* @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
* a heap buffer
*/
public MnemonicUnpooledByteBufAllocator(boolean preferDirect, A mcallocator) {
super(preferDirect);
this.mcalloc = mcallocator;
}

public A getAllocator() {
return this.mcalloc;
}

@Override
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
return new UnpooledHeapByteBuf(this, initialCapacity, maxCapacity);
}

@Override
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
assert null != this.mcalloc;
ByteBuf buf;
if (PlatformDependent.hasUnsafe()) {
buf = new MnemonicUnpooledUnsafeDirectByteBuf<A>(this, initialCapacity, maxCapacity);
} else {
buf = new MnemonicUnpooledDirectByteBuf<A>(this, initialCapacity, maxCapacity);
}

return toLeakAwareBuffer(buf);
}

@Override
public boolean isDirectBufferPooled() {
return false;
}
}
Loading

0 comments on commit 9e59d4e

Please sign in to comment.