Skip to content

Commit 81d08ae

Browse files
committed
Add ShapeTranscoder for Shape->Shape
1 parent bf7118a commit 81d08ae

7 files changed

Lines changed: 2493 additions & 5 deletions

File tree

core/src/jmh/java/software/amazon/smithy/java/core/serde/ShapeTranscoderBenchmark.java

Lines changed: 704 additions & 0 deletions
Large diffs are not rendered by default.

core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ public final <T> T getExtension(SchemaExtensionKey<T> key) {
474474
if (key.id >= ext.length) {
475475
return null;
476476
}
477-
// Plain array read (benign race). Safe because extension objects are immutable
478-
// (records with final fields), and Java's final field semantics (JLS 17.5)
479-
// guarantee visibility once the reference is seen. Worst case: redundant computation.
477+
// Plain array read (benign race). Safe because extension objects are safely publishable,
478+
// and Java's final field semantics (JLS 17.5) guarantee visibility once the reference is
479+
// seen. Worst case: redundant computation or independent cache holders.
480480
var value = ext[key.id];
481481
if (value == NOT_COMPUTED) {
482482
value = computeExtension(key, ext);
@@ -494,8 +494,8 @@ private Object computeExtension(SchemaExtensionKey<?> key, Object[] ext) {
494494
var value = provider.provide(this);
495495
result = value != null ? value : NULL_SENTINEL;
496496
}
497-
// Plain array write (benign race). The stored object is immutable, so any thread
498-
// that later reads this element and sees the object will see all its final fields.
497+
// Plain array write (benign race). Any thread that later reads this element and sees
498+
// the safely publishable object will see all its final fields.
499499
ext[key.id] = result;
500500
return result;
501501
}

core/src/main/java/software/amazon/smithy/java/core/schema/SchemaExtensionProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public interface SchemaExtensionProvider<T> {
4343
* returns.</li>
4444
* </ul>
4545
*
46+
* <p>An extension may use thread-safe mutable state as a performance cache when the cache is held in
47+
* final fields, all cache access uses appropriate synchronization or atomic operations, and cache
48+
* contents do not affect behavior. Because concurrent extension computation can produce independent
49+
* instances, losing the contents of one such cache must only result in redundant computation.
50+
*
4651
* <p><b>Idempotency:</b> Under concurrent access, multiple threads may invoke this method
4752
* simultaneously for the same schema and key (benign race). All invocations must produce
4853
* equivalent results.

0 commit comments

Comments
 (0)