Skip to content

Commit 3945417

Browse files
committed
[GR-41453] Store FACTORY.getUncached() in static final to avoid volatile read
1 parent 241afc9 commit 3945417

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main/java/org/truffleruby/core/array/library/ArrayStoreLibrary.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
2121
import com.oracle.truffle.api.nodes.Node;
2222
import org.truffleruby.RubyLanguage;
23+
import org.truffleruby.annotations.SuppressFBWarnings;
2324

2425
/** Library for accessing and manipulating the storage used for representing arrays. This includes reading, modifying,
2526
* and copy the storage. */
@@ -38,6 +39,7 @@ public abstract class ArrayStoreLibrary extends Library {
3839
private static final ArrayAllocator SHARED_INITIAL_ALLOCATOR = SharedArrayStorage.SHARED_ZERO_LENGTH_ARRAY_ALLOCATOR;
3940

4041
private static final LibraryFactory<ArrayStoreLibrary> FACTORY = LibraryFactory.resolve(ArrayStoreLibrary.class);
42+
private static final ArrayStoreLibrary UNCACHED = FACTORY.getUncached();
4143

4244
public static ArrayStoreLibrary createDispatched(RubyLanguage language) {
4345
return FACTORY.createDispatched(language.options.ARRAY_STRATEGY_CACHE);
@@ -47,9 +49,10 @@ public static ArrayStoreLibrary create(Object store) {
4749
return FACTORY.create(store);
4850
}
4951

52+
@SuppressFBWarnings("MS_EXPOSE_REP")
5053
public static ArrayStoreLibrary getUncached() {
5154
CompilerAsserts.neverPartOfCompilation("uncached libraries must not be used in PE code");
52-
return FACTORY.getUncached();
55+
return UNCACHED;
5356
}
5457

5558
public static ArrayStoreLibrary getUncached(Object store) {

src/main/java/org/truffleruby/interop/BoxedValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected Object send(Message message, Object[] args,
4242
"Methods should not be called on a BoxedValue as that would expose the potential Ruby object behind rather than relying on interop messages",
4343
node));
4444
}
45-
ReflectionLibrary reflection = ReflectionLibrary.getFactory().getUncached();
45+
ReflectionLibrary reflection = ReflectionLibrary.getUncached();
4646
return reflection.send(value, message, args);
4747
}
4848

0 commit comments

Comments
 (0)