Skip to content

Commit 713a452

Browse files
author
Nicolas Laurent
committed
[GR-28450] Introduce SynchronizedArray to avoid race conditions on $LOADED_FEATURES and $LOAD_PATH.
PullRequest: truffleruby/2332
2 parents 6762616 + 83867d4 commit 713a452

File tree

6 files changed

+771
-2
lines changed

6 files changed

+771
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slow:Truffle::SynchronizedArray redefines all Array and Enumerable methods
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# truffleruby_primitives: true
2+
3+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
4+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
5+
# redistribute it and/or modify it under the terms of the:
6+
#
7+
# Eclipse Public License version 2.0, or
8+
# GNU General Public License version 2, or
9+
# GNU Lesser General Public License version 2.1.
10+
11+
require_relative '../ruby/spec_helper'
12+
13+
describe "Truffle::SynchronizedArray" do
14+
it "redefines all Array and Enumerable methods" do
15+
expected_methods = ruby_exe("puts Array.public_instance_methods(false) + Enumerable.public_instance_methods(false)")
16+
expected_methods = expected_methods.lines(chomp: true).map { |line| line.to_sym }.uniq!.sort!
17+
synchronized_methods = Truffle::SynchronizedArray.public_instance_methods(false).sort!
18+
19+
if synchronized_methods == expected_methods
20+
synchronized_methods.should == synchronized_methods
21+
else
22+
# if the fast check fails, do a slower check to determine why
23+
expected_methods.each do |m|
24+
synchronized_methods.should include(m)
25+
end
26+
synchronized_methods.each do |m|
27+
expected_methods.should include(m)
28+
end
29+
end
30+
end
31+
end

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ public boolean isTruffleBootMainMethod(SharedMethodInfo info) {
978978
"/core/truffle/platform.rb",
979979
"/core/string.rb",
980980
"/core/random.rb",
981+
"/core/truffle/synchronized_array.rb",
981982
"/core/truffle/kernel_operations.rb",
982983
"/core/truffle/exception_operations.rb",
983984
"/core/truffle/feature_loader.rb",

src/main/ruby/truffleruby/core/truffle/kernel_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def self.define_read_only_global(name, getter)
3131
define_hooked_variable(name, getter, setter)
3232
end
3333

34-
LOAD_PATH = []
35-
LOADED_FEATURES = []
34+
LOAD_PATH = Truffle::SynchronizedArray.new
35+
LOADED_FEATURES = Truffle::SynchronizedArray.new
3636

3737
define_read_only_global(:$LOAD_PATH, -> { LOAD_PATH })
3838
define_read_only_global(:$LOADED_FEATURES, -> { LOADED_FEATURES })

0 commit comments

Comments
 (0)