Skip to content

Commit 5b1bb31

Browse files
committed
[GR-41453] Store FACTORY.getUncached() in static final to avoid volatile read
PullRequest: truffleruby/4529
2 parents 6ad63e3 + e051484 commit 5b1bb31

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
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/core/klass/RubyClass.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.Set;
1414

15+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1516
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
1617
import com.oracle.truffle.api.interop.InteropLibrary;
1718
import com.oracle.truffle.api.library.ExportLibrary;
@@ -41,7 +42,7 @@ public final class RubyClass extends RubyModule implements ObjectGraphNode {
4142
public final RubyDynamicObject attached;
4243
/* a RubyClass or nil for BasicObject */
4344
public final Object superclass;
44-
public final RubyClass[] ancestorClasses;
45+
@CompilationFinal(dimensions = 1) public final RubyClass[] ancestorClasses;
4546
public final ConcurrentWeakSet<RubyClass> directNonSingletonSubclasses;
4647
/** Depth from BasicObject (= 0) in the inheritance hierarchy. */
4748
public final int depth;

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)