Skip to content

Commit 0cc15b8

Browse files
committed
Remove redundant locking in FeatureLoader
* The called methods already synchronize themselves. * This could lead to deadlocks since TruffleRuby.synchronized uses a ReentrantLock and no longer the object's monitor.
1 parent 73c2fab commit 0cc15b8

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121
import java.util.concurrent.locks.ReentrantLock;
2222

23-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2423
import org.jcodings.Encoding;
2524
import org.jcodings.specific.UTF8Encoding;
2625
import org.truffleruby.RubyContext;
@@ -40,7 +39,6 @@
4039
import org.truffleruby.language.RubyConstant;
4140
import org.truffleruby.language.control.RaiseException;
4241
import org.truffleruby.language.dispatch.DispatchNode;
43-
import org.truffleruby.language.globals.GlobalVariables;
4442
import org.truffleruby.language.library.RubyStringLibrary;
4543
import org.truffleruby.platform.NativeConfiguration;
4644
import org.truffleruby.platform.Platform;
@@ -79,8 +77,6 @@ public class FeatureLoader {
7977
private NativeFunction getcwd;
8078
private static final int PATH_MAX = 1024; // jnr-posix hard codes this value
8179

82-
@CompilationFinal private RubyArray loadedFeatures = null;
83-
8480
private static final String[] EXTENSIONS = new String[]{ TruffleRuby.EXTENSION, RubyLanguage.CEXT_EXTENSION };
8581

8682
public FeatureLoader(RubyContext context, RubyLanguage language) {
@@ -491,13 +487,4 @@ public Object loadCExtLibrary(String feature, String path, Node currentNode) {
491487
Metrics.printTime("after-load-cext-" + feature);
492488
}
493489
}
494-
495-
public Object getLoadedFeaturesLock() {
496-
if (loadedFeatures == null) {
497-
CompilerDirectives.transferToInterpreterAndInvalidate();
498-
GlobalVariables globals = context.getCoreLibrary().globalVariables;
499-
loadedFeatures = (RubyArray) globals.getStorage("$LOADED_FEATURES").getValue();
500-
}
501-
return loadedFeatures;
502-
}
503490
}

src/main/java/org/truffleruby/language/loader/RequireNode.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,13 @@ private String getBaseName(String path) {
388388
}
389389

390390
public boolean isFeatureLoaded(Object feature) {
391-
final Object included;
392-
synchronized (getContext().getFeatureLoader().getLoadedFeaturesLock()) {
393-
included = isInLoadedFeatures
394-
.call(coreLibrary().truffleFeatureLoaderModule, "feature_provided?", feature, true);
395-
}
391+
final Object included = isInLoadedFeatures
392+
.call(coreLibrary().truffleFeatureLoaderModule, "feature_provided?", feature, true);
396393
return booleanCastNode.executeToBoolean(included);
397394
}
398395

399396
private void addToLoadedFeatures(Object feature) {
400-
synchronized (getContext().getFeatureLoader().getLoadedFeaturesLock()) {
401-
addToLoadedFeatures.call(coreLibrary().truffleFeatureLoaderModule, "provide_feature", feature);
402-
}
397+
addToLoadedFeatures.call(coreLibrary().truffleFeatureLoaderModule, "provide_feature", feature);
403398
}
404399

405400
private void warnCircularRequire(String path) {

0 commit comments

Comments
 (0)