Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full set of RecyclerPool implementations #1064

Merged
merged 31 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c647bbf
Introducing BufferRecyclerPool
mariofusco Jul 19, 2023
b1eacd4
fix ReadConstrainedTextBufferTest to work with both a brand new Buffe…
mariofusco Jul 20, 2023
d5d3a14
minor refactor
mariofusco Jul 21, 2023
67459da
check performances of different object pool implementations
mariofusco Jul 24, 2023
7099315
ensure that all parsers and generators are properly closed in tests
mariofusco Jul 25, 2023
b404daf
cleanup pool implementations
mariofusco Jul 27, 2023
30dc6c3
make BufferRecycler closeable and disable the new ObjectPool by default
mariofusco Jul 27, 2023
0f8bd70
wip
mariofusco Jul 27, 2023
b09fd6e
wip
mariofusco Jul 27, 2023
d949043
javadoc + better pool management + pool decorator for debug
mariofusco Jul 28, 2023
b9c24c2
fix compilation problems after rebase
mariofusco Aug 22, 2023
44e446b
readd virtual threads friendly BufferRecyclerPool implementations
mariofusco Aug 22, 2023
835076c
add test class
mariofusco Aug 22, 2023
843648b
...
cowtowncoder Aug 27, 2023
98691fc
Fix a merge issue
cowtowncoder Aug 27, 2023
5cf738d
...
cowtowncoder Aug 27, 2023
2e64334
wip
mariofusco Aug 28, 2023
3375a0b
fix tests
mariofusco Aug 28, 2023
643e5e6
add comments
mariofusco Aug 28, 2023
454018c
remove enum of pool implementations
mariofusco Aug 28, 2023
1d01060
Merge branch '2.16' into 216_buffer_recycler_pool
cowtowncoder Aug 30, 2023
5594136
Minor tweaks: add javadoc, reduce diff from 2.16
cowtowncoder Aug 30, 2023
e3a0971
Bit more cleanup; remove addition of default recycler pool access via…
cowtowncoder Aug 30, 2023
16add03
Warnings removal
cowtowncoder Aug 30, 2023
d9e585b
Merge branch '2.16' into 216_buffer_recycler_pool
cowtowncoder Aug 30, 2023
79b2885
Refactoring, adding more Javadocs
cowtowncoder Aug 30, 2023
0f359fc
Minor change to test class
cowtowncoder Aug 30, 2023
5394156
improve tests checking that pooled BufferRecycler is properly acquire…
mariofusco Aug 30, 2023
9d53f00
add bounded pool implementation
mariofusco Aug 30, 2023
58e6f30
Adding Javadocs, minor renaming
cowtowncoder Aug 30, 2023
eb2461b
Implement sharing-retaining JDK serialization for BufferRecyclerPools.
cowtowncoder Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public JacksonFeatureSet<StreamWriteCapability> getWriteCapabilities() {
return JSON_WRITE_CAPABILITIES;
}

public IOContext _getIoContext() {
cowtowncoder marked this conversation as resolved.
Show resolved Hide resolved
return _ioContext;
}

/*
/**********************************************************
/* Shared helper methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.fasterxml.jackson.core.write;
package com.fasterxml.jackson.core.io;

import com.fasterxml.jackson.core.BaseTest;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.json.JsonGeneratorImpl;
import com.fasterxml.jackson.core.util.BufferRecycler;
import com.fasterxml.jackson.core.util.BufferRecyclerPool;

import java.io.IOException;
Expand All @@ -11,36 +13,49 @@
public class BufferRecyclerPoolTest extends BaseTest
{
public void testNoOp() {
checkBufferRecyclerPoolImpl(BufferRecyclerPool.NonRecyclingPool.shared());
// no-op pool doesn't actually pool anything, so avoid checking it
checkBufferRecyclerPoolImpl(BufferRecyclerPool.NonRecyclingPool.shared(), false);
}

public void testThreadLocal() {
checkBufferRecyclerPoolImpl(BufferRecyclerPool.ThreadLocalPool.shared());
checkBufferRecyclerPoolImpl(BufferRecyclerPool.ThreadLocalPool.shared(), true);
}

public void testLockFree() {
checkBufferRecyclerPoolImpl(BufferRecyclerPool.LockFreePool.nonShared());
checkBufferRecyclerPoolImpl(BufferRecyclerPool.LockFreePool.shared(), true);
}

public void testConcurrentDequeue() {
checkBufferRecyclerPoolImpl(BufferRecyclerPool.ConcurrentDequePool.nonShared());
checkBufferRecyclerPoolImpl(BufferRecyclerPool.ConcurrentDequePool.shared(), true);
}

private void checkBufferRecyclerPoolImpl(BufferRecyclerPool pool) {
private void checkBufferRecyclerPoolImpl(BufferRecyclerPool pool, boolean checkPooledResource) {
JsonFactory jsonFactory = JsonFactory.builder()
.bufferRecyclerPool(pool)
.build();
assertEquals(6, write("test", jsonFactory));
BufferRecycler usedBufferRecycler = write("test", jsonFactory, 6);
if (checkPooledResource) {
// acquire the pooled BufferRecycler again and check if it is the same instance used before
BufferRecycler pooledBufferRecycler = pool.acquireBufferRecycler();
try {
assertSame(usedBufferRecycler, pooledBufferRecycler);
} finally {
pooledBufferRecycler.release();
}
}
}

protected final int write(Object value, JsonFactory jsonFactory) {
protected final BufferRecycler write(Object value, JsonFactory jsonFactory, int expectedSize) {
BufferRecycler bufferRecycler;
NopOutputStream out = new NopOutputStream();
try (JsonGenerator gen = jsonFactory.createGenerator(out)) {
bufferRecycler = ((JsonGeneratorImpl) gen)._getIoContext()._bufferRecycler;
gen.writeObject(value);
} catch (IOException e) {
throw new RuntimeException(e);
}
return out.size();
assertEquals(expectedSize, out.size);
return bufferRecycler;
}

public class NopOutputStream extends OutputStream {
Expand Down