Skip to content

Commit 200ee04

Browse files
authored
Fix #403: remove SmileBufferRecycler from 2.16 (#404)
1 parent 6e59271 commit 200ee04

File tree

9 files changed

+41
-274
lines changed

9 files changed

+41
-274
lines changed

release-notes/VERSION-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Active maintainers:
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.16.0 (not yet released)
18+
19+
#403: Remove Smile-specific buffer-recycling
20+
1721
2.15.3 (not yet released)
1822

1923
#384: `Smile` decoding issue with `NonBlockingByteArrayParser`, concurrency

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileBufferRecycler.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileFactory.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ public class SmileFactory extends JsonFactory
7373
protected int _smileParserFeatures;
7474
protected int _smileGeneratorFeatures;
7575

76-
/*
77-
/**********************************************************
78-
/* Smile-specific buffer recycling (moved here in 2.16)
79-
/**********************************************************
80-
81-
/**
82-
* This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference}
83-
* to a buffer recycler used to provide a low-cost
84-
* buffer recycling for Smile-specific buffers.
85-
*/
86-
final protected static ThreadLocal<SoftReference<SmileBufferRecycler>> _smileRecyclerRef
87-
= new ThreadLocal<SoftReference<SmileBufferRecycler>>();
88-
8976
/*
9077
/**********************************************************
9178
/* Factory construction, configuration
@@ -429,8 +416,7 @@ public NonBlockingByteArrayParser createNonBlockingByteArrayParser() throws IOEx
429416
// 13-Mar-2021, tatu: [dataformats-binary#252] Leave async parser with
430417
// always-canonicalizing, for now (2.13) -- to be improved in future
431418
ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChildOrPlaceholder(_factoryFeatures);
432-
return new NonBlockingByteArrayParser(ctxt, _parserFeatures, _smileParserFeatures, can,
433-
_smileBufferRecycler());
419+
return new NonBlockingByteArrayParser(ctxt, _parserFeatures, _smileParserFeatures, can);
434420
}
435421

436422
/*
@@ -447,8 +433,7 @@ protected SmileParser _createParser(InputStream in, IOContext ctxt) throws IOExc
447433
{
448434
SmileParserBootstrapper bs = new SmileParserBootstrapper(ctxt, in);
449435
return bs.constructParser(_factoryFeatures, _parserFeatures,
450-
_smileParserFeatures, _objectCodec, _byteSymbolCanonicalizer,
451-
_smileBufferRecycler());
436+
_smileParserFeatures, _objectCodec, _byteSymbolCanonicalizer);
452437
}
453438

454439
@Override
@@ -475,8 +460,7 @@ protected SmileParser _createParser(byte[] data, int offset, int len, IOContext
475460
{
476461
return new SmileParserBootstrapper(ctxt, data, offset, len).constructParser(
477462
_factoryFeatures, _parserFeatures, _smileParserFeatures,
478-
_objectCodec, _byteSymbolCanonicalizer,
479-
_smileBufferRecycler());
463+
_objectCodec, _byteSymbolCanonicalizer);
480464
}
481465

482466
@Override
@@ -526,8 +510,7 @@ protected SmileGenerator _createGenerator(OutputStream out, IOContext ctxt) thro
526510
* But should we force writing, or throw exception, if settings are in conflict?
527511
* For now, let's error out...
528512
*/
529-
SmileGenerator gen = new SmileGenerator(ctxt, _generatorFeatures, feats, _objectCodec, out,
530-
_smileBufferRecycler());
513+
SmileGenerator gen = new SmileGenerator(ctxt, _generatorFeatures, feats, _objectCodec, out);
531514
if ((feats & SmileGenerator.Feature.WRITE_HEADER.getMask()) != 0) {
532515
gen.writeHeader();
533516
} else {
@@ -546,16 +529,4 @@ protected SmileGenerator _createGenerator(OutputStream out, IOContext ctxt) thro
546529
}
547530
return gen;
548531
}
549-
550-
protected final static SmileBufferRecycler _smileBufferRecycler()
551-
{
552-
SoftReference<SmileBufferRecycler> ref = _smileRecyclerRef.get();
553-
SmileBufferRecycler br = (ref == null) ? null : ref.get();
554-
555-
if (br == null) {
556-
br = new SmileBufferRecycler();
557-
_smileRecyclerRef.set(new SoftReference<SmileBufferRecycler>(br));
558-
}
559-
return br;
560-
}
561532
}

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileGenerator.java

Lines changed: 11 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
public class SmileGenerator
2121
extends GeneratorBase
2222
{
23+
// @since 2.16
24+
protected final static int DEFAULT_NAME_BUFFER_LENGTH = 64;
25+
26+
// @since 2.16
27+
protected final static int DEFAULT_STRING_VALUE_BUFFER_LENGTH = 64;
28+
2329
/**
2430
* Enumeration that defines all togglable features for Smile generators.
2531
*/
@@ -196,12 +202,6 @@ public SharedStringNode(String value, int index, SharedStringNode next)
196202
*/
197203
protected int _formatFeatures;
198204

199-
/**
200-
* Helper object used for low-level recycling of Smile-generator
201-
* specific buffers.
202-
*/
203-
protected final SmileBufferRecycler _smileBufferRecycler;
204-
205205
/*
206206
/**********************************************************************
207207
/* Output state
@@ -288,8 +288,7 @@ public SharedStringNode(String value, int index, SharedStringNode next)
288288
* @since 2.16
289289
*/
290290
public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
291-
ObjectCodec codec, OutputStream out,
292-
SmileBufferRecycler sbr)
291+
ObjectCodec codec, OutputStream out)
293292
{
294293
super(stdFeatures, codec, ioCtxt, /*WriteContext*/ null);
295294
DupDetector dups = JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION.enabledIn(stdFeatures)
@@ -299,7 +298,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
299298
_streamWriteContext = SmileWriteContext.createRootContext(dups);
300299
_formatFeatures = smileFeatures;
301300
_streamWriteConstraints = ioCtxt.streamWriteConstraints();
302-
_smileBufferRecycler = sbr;
303301
_out = out;
304302
_bufferRecyclable = true;
305303
_outputBuffer = ioCtxt.allocWriteEncodingBuffer();
@@ -314,21 +312,15 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
314312
_seenNames = null;
315313
_seenNameCount = -1;
316314
} else {
317-
_seenNames = _smileBufferRecycler.allocSeenNamesWriteBuffer();
318-
if (_seenNames == null) {
319-
_seenNames = new SharedStringNode[SmileBufferRecycler.DEFAULT_NAME_BUFFER_LENGTH];
320-
}
315+
_seenNames = new SharedStringNode[DEFAULT_NAME_BUFFER_LENGTH];
321316
_seenNameCount = 0;
322317
}
323318

324319
if (!Feature.CHECK_SHARED_STRING_VALUES.enabledIn(smileFeatures)) {
325320
_seenStringValues = null;
326321
_seenStringValueCount = -1;
327322
} else {
328-
_seenStringValues = _smileBufferRecycler.allocSeenStringValuesWriteBuffer();
329-
if (_seenStringValues == null) {
330-
_seenStringValues = new SharedStringNode[SmileBufferRecycler.DEFAULT_STRING_VALUE_BUFFER_LENGTH];
331-
}
323+
_seenStringValues = new SharedStringNode[DEFAULT_STRING_VALUE_BUFFER_LENGTH];
332324
_seenStringValueCount = 0;
333325
}
334326
}
@@ -338,7 +330,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
338330
*/
339331
public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
340332
ObjectCodec codec, OutputStream out,
341-
SmileBufferRecycler sbr,
342333
byte[] outputBuffer, int offset, boolean bufferRecyclable)
343334
{
344335
super(stdFeatures, codec, ioCtxt, null);
@@ -349,7 +340,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
349340
_streamWriteContext = SmileWriteContext.createRootContext(dups);
350341
_formatFeatures = smileFeatures;
351342
_streamWriteConstraints = ioCtxt.streamWriteConstraints();
352-
_smileBufferRecycler = sbr;
353343
_out = out;
354344
_bufferRecyclable = bufferRecyclable;
355345
_outputTail = offset;
@@ -365,48 +355,19 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
365355
_seenNames = null;
366356
_seenNameCount = -1;
367357
} else {
368-
_seenNames = _smileBufferRecycler.allocSeenNamesWriteBuffer();
369-
if (_seenNames == null) {
370-
_seenNames = new SharedStringNode[SmileBufferRecycler.DEFAULT_NAME_BUFFER_LENGTH];
371-
}
358+
_seenNames = new SharedStringNode[DEFAULT_NAME_BUFFER_LENGTH];
372359
_seenNameCount = 0;
373360
}
374361

375362
if (!Feature.CHECK_SHARED_STRING_VALUES.enabledIn(smileFeatures)) {
376363
_seenStringValues = null;
377364
_seenStringValueCount = -1;
378365
} else {
379-
_seenStringValues = _smileBufferRecycler.allocSeenStringValuesWriteBuffer();
380-
if (_seenStringValues == null) {
381-
_seenStringValues = new SharedStringNode[SmileBufferRecycler.DEFAULT_STRING_VALUE_BUFFER_LENGTH];
382-
}
366+
_seenStringValues = new SharedStringNode[DEFAULT_STRING_VALUE_BUFFER_LENGTH];
383367
_seenStringValueCount = 0;
384368
}
385369
}
386370

387-
/**
388-
* @deprecated Since 2.16
389-
*/
390-
@Deprecated // @since 2.16
391-
public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
392-
ObjectCodec codec, OutputStream out)
393-
{
394-
this(ioCtxt, stdFeatures, smileFeatures, codec, out, new SmileBufferRecycler());
395-
}
396-
397-
/**
398-
* @deprecated Since 2.16
399-
*/
400-
@Deprecated // @since 2.16
401-
public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
402-
ObjectCodec codec, OutputStream out,
403-
byte[] outputBuffer, int offset, boolean bufferRecyclable)
404-
{
405-
this(ioCtxt, stdFeatures, smileFeatures,
406-
codec, out, new SmileBufferRecycler(),
407-
outputBuffer, offset, bufferRecyclable);
408-
}
409-
410371
/**
411372
* Method that can be called to explicitly write Smile document header.
412373
* Note that usually you do not need to call this for first document to output,
@@ -2629,35 +2590,6 @@ protected void _releaseBuffers()
26292590
_outputBuffer = null;
26302591
_ioContext.releaseWriteEncodingBuffer(buf);
26312592
}
2632-
/* Ok: since clearing up of larger arrays is much slower,
2633-
* let's only recycle default-sized buffers...
2634-
*/
2635-
{
2636-
SharedStringNode[] nameBuf = _seenNames;
2637-
if (nameBuf != null && nameBuf.length == SmileBufferRecycler.DEFAULT_NAME_BUFFER_LENGTH) {
2638-
_seenNames = null;
2639-
/* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer; and note
2640-
* that since it's a hash area, must clear all
2641-
*/
2642-
if (_seenNameCount > 0) {
2643-
Arrays.fill(nameBuf, null);
2644-
}
2645-
_smileBufferRecycler.releaseSeenNamesWriteBuffer(nameBuf);
2646-
}
2647-
}
2648-
{
2649-
SharedStringNode[] valueBuf = _seenStringValues;
2650-
if (valueBuf != null && valueBuf.length == SmileBufferRecycler.DEFAULT_STRING_VALUE_BUFFER_LENGTH) {
2651-
_seenStringValues = null;
2652-
/* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer; and note
2653-
* that since it's a hash area, must clear all
2654-
*/
2655-
if (_seenStringValueCount > 0) {
2656-
Arrays.fill(valueBuf, null);
2657-
}
2658-
_smileBufferRecycler.releaseSeenStringValuesWriteBuffer(valueBuf);
2659-
}
2660-
}
26612593
}
26622594

26632595
protected final void _flushBuffer() throws IOException

0 commit comments

Comments
 (0)