Skip to content

Commit e59e6fe

Browse files
authored
Fix #1090: remove BufferRecycler tracking option (#1091)
1 parent 5a81160 commit e59e6fe

File tree

2 files changed

+35
-88
lines changed

2 files changed

+35
-88
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ JSON library.
3838
#689: Remove existing "request payload" functionality
3939
#785: Make `JsonGenerator.writeXxx()` methods chainable
4040
#793: Rename "com.fasterxml.jackson" -> "tools.jackson"
41+
#1090: Remove `BufferRecyclers.SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS`
42+
functionality from 3.0
4143
- Rename `JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT` as `AUTO_CLOSE_CONTENT`
4244
- Add `TreeCodec.nullNode()`, `TreeNode.isNull()` methods
4345
- Change the way `JsonLocation.NA` is included in exception messages

src/main/java/tools/jackson/core/util/BufferRecyclers.java

+33-88
Original file line numberDiff line numberDiff line change
@@ -12,96 +12,9 @@
1212
*/
1313
public class BufferRecyclers
1414
{
15-
/**
16-
* System property that is checked to see if recycled buffers (see {@link BufferRecycler})
17-
* should be tracked, for purpose of forcing release of all such buffers, typically
18-
* during major classloading.
19-
*/
20-
public final static String SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
21-
= "tools.jackson.core.util.BufferRecyclers.trackReusableBuffers";
22-
23-
/*
24-
/**********************************************************
25-
/* Life-cycle
26-
/**********************************************************
27-
*/
28-
29-
/**
30-
* Flag that indicates whether {@link BufferRecycler} instances should be tracked.
31-
*/
32-
private final static ThreadLocalBufferManager _bufferRecyclerTracker;
33-
static {
34-
boolean trackReusableBuffers = false;
35-
try {
36-
trackReusableBuffers = "true".equals(System.getProperty(SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS));
37-
} catch (SecurityException e) { }
38-
39-
_bufferRecyclerTracker = trackReusableBuffers ? ThreadLocalBufferManager.instance() : null;
40-
}
41-
42-
/*
43-
/**********************************************************
44-
/* BufferRecyclers for parsers, generators
45-
/**********************************************************
46-
*/
47-
48-
/**
49-
* This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference}
50-
* to a {@link BufferRecycler} used to provide a low-cost
51-
* buffer recycling between reader and writer instances.
52-
*/
53-
final protected static ThreadLocal<SoftReference<BufferRecycler>> _recyclerRef
54-
= new ThreadLocal<SoftReference<BufferRecycler>>();
55-
56-
/**
57-
* Main accessor to call for accessing possibly recycled {@link BufferRecycler} instance.
58-
*
59-
* @return {@link BufferRecycler} to use
60-
*
61-
* @deprecated Since 2.16 should use {@link BufferRecyclerPool} abstraction instead
62-
* of calling static methods of this class
63-
*/
64-
@Deprecated // since 2.16
65-
public static BufferRecycler getBufferRecycler()
66-
{
67-
SoftReference<BufferRecycler> ref = _recyclerRef.get();
68-
BufferRecycler br = (ref == null) ? null : ref.get();
69-
70-
if (br == null) {
71-
br = new BufferRecycler();
72-
if (_bufferRecyclerTracker != null) {
73-
ref = _bufferRecyclerTracker.wrapAndTrack(br);
74-
} else {
75-
ref = new SoftReference<BufferRecycler>(br);
76-
}
77-
_recyclerRef.set(ref);
78-
}
79-
return br;
80-
}
81-
82-
/**
83-
* Specialized method that will release all recycled {@link BufferRecycler} if
84-
* (and only if) recycler tracking has been enabled
85-
* (see {@link #SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS}).
86-
* This method is usually called on shutdown of the container like Application Server
87-
* to ensure that no references are reachable via {@link ThreadLocal}s as this may cause
88-
* unintentional retention of sizable amounts of memory. It may also be called regularly
89-
* if GC for some reason does not clear up {@link SoftReference}s aggressively enough.
90-
*
91-
* @return Number of buffers released, if tracking enabled (zero or more); -1 if tracking not enabled.
92-
*
93-
* @since 2.9.6
94-
*/
95-
public static int releaseBuffers() {
96-
if (_bufferRecyclerTracker != null) {
97-
return _bufferRecyclerTracker.releaseBuffers();
98-
}
99-
return -1;
100-
}
101-
10215
/*
10316
/**********************************************************************
104-
/* Default BufferRecyclerPool implementations
17+
/* Accessor for default BufferRecyclerPool implementations
10518
/**********************************************************************
10619
*/
10720

@@ -113,6 +26,12 @@ public static BufferRecyclerPool nopRecyclerPool() {
11326
return NonRecyclingRecyclerPool.INSTANCE;
11427
}
11528

29+
/*
30+
/**********************************************************************
31+
/* Standard BufferRecyclerPool implementations
32+
/**********************************************************************
33+
*/
34+
11635
/**
11736
* Default {@link BufferRecyclerPool} implementation that uses
11837
* {@link ThreadLocal} for recycling instances.
@@ -121,8 +40,34 @@ public static class ThreadLocalRecyclerPool
12140
implements BufferRecyclerPool
12241
{
12342
private static final long serialVersionUID = 1L;
43+
44+
/**
45+
* This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference}
46+
* to a {@link BufferRecycler} used to provide a low-cost
47+
* buffer recycling between reader and writer instances.
48+
*/
49+
protected final static ThreadLocal<SoftReference<BufferRecycler>> _recyclerRef
50+
= new ThreadLocal<SoftReference<BufferRecycler>>();
51+
12452
public final static ThreadLocalRecyclerPool INSTANCE = new ThreadLocalRecyclerPool();
12553

54+
/**
55+
* Main accessor to call for accessing possibly recycled {@link BufferRecycler} instance.
56+
*
57+
* @return {@link BufferRecycler} to use
58+
*/
59+
private BufferRecycler getBufferRecycler()
60+
{
61+
SoftReference<BufferRecycler> ref = _recyclerRef.get();
62+
BufferRecycler br = (ref == null) ? null : ref.get();
63+
64+
if (br == null) {
65+
br = new BufferRecycler();
66+
_recyclerRef.set(ref);
67+
}
68+
return br;
69+
}
70+
12671
@Override
12772
public BufferRecycler acquireBufferRecycler(TokenStreamFactory forFactory) {
12873
return getBufferRecycler();

0 commit comments

Comments
 (0)