Skip to content

Commit 58e2729

Browse files
committed
[GR-16164] Fix sharing with the benchmark harness, RubyLauncher and IO buffers.
PullRequest: truffleruby/881
2 parents 9b445b0 + 4dcffb3 commit 58e2729

22 files changed

+106
-55
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 20.0.0 beta 2
2+
3+
Bug fixes:
4+
5+
* Sharing for thread-safety of objects is now triggered later as intended, e.g., when a second `Thread` is started.
6+
17
# 20.0.0 beta 1
28

39
Bug fixes:

bench/benchmark-interface/lib/benchmark-interface/backends/bips.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Bips
1313
LONG_ITERATION_THRESHOLD = 0.1 # seconds
1414

1515
def self.run(benchmark_set, names, options)
16-
BeckhmarkInterface.require_rubygems
16+
BenchmarkInterface.require_rubygems
1717
benchmark_interface_original_require 'benchmark/ips'
1818

1919
unless options['--no-scale']

bench/benchmark-interface/lib/benchmark-interface/backends/deep.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def self.run(benchmark_set, names, options)
1414
unless names.size == 1
1515
abort 'The deep backend only works when you run just one benchmark at a time - specify the name on the command line'
1616
end
17-
18-
BeckhmarkInterface.require_rubygems
17+
18+
BenchmarkInterface.require_rubygems
1919
benchmark_interface_original_require 'deep-bench/backend'
2020

2121
benchmark = benchmark_set.benchmark(names.first)

bench/benchmark-interface/lib/benchmark-interface/benchmark-set.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@ class BenchmarkSet
1414
def initialize
1515
@benchmarks = []
1616
@counter = 0
17-
@@current = self
17+
Thread.current[:benchmark_interface_benchmark_set] = self
1818
@iterations = 1
1919
end
2020

2121
def load_benchmarks(path)
2222
@path = path
23-
@@current = self
2423
load(path)
2524
end
2625

2726
def load_inlined_benchmark(code)
2827
@path = '-e'
29-
@@current = self
3028
TOPLEVEL_BINDING.eval(code)
3129
end
3230

3331
def load_mri_benchmarks(path, options)
3432
@path = path
35-
@@current = self
3633
Frontends::MRI.load_mri path, options
3734
end
3835

@@ -84,10 +81,8 @@ def benchmark(name)
8481
benchmarks([name]).first
8582
end
8683

87-
@@current = nil
88-
8984
def self.current
90-
@@current
85+
Thread.current[:benchmark_interface_benchmark_set]
9186
end
9287

9388
end

bench/benchmark-interface/lib/benchmark-interface/frontends/benchmark.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def self.realtime(name=nil, &block)
3434
def self.benchmark(caption='', label_width=nil, format=nil, *labels)
3535
yield BenchmarkInterface::BenchmarkContext.new
3636
end
37-
38-
def self.realtime(name=nil, &block)
39-
BenchmarkInterface.benchmark name, &block
40-
end
4137

4238
def self.bm(label_width=0, *labels)
4339
yield BenchmarkInterface::BenchmarkContext.new

bench/benchmark-interface/lib/benchmark-interface/require.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# GNU General Public License version 2, or
77
# GNU Lesser General Public License version 2.1.
88

9-
module BeckhmarkInterface
9+
module BenchmarkInterface
1010

1111
def self.require_rubygems
1212
begin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
slow:Sharing is correctly propagated for classes and constants and they are not shared until sharing is started
2+
slow:Sharing is correctly propagated for thread-local IO buffers which should not trigger sharing

spec/truffle/thread_safe_objects_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,34 @@ def wb; @wb; end
255255
shared?(new_hash).should == true
256256
end
257257

258+
it "Fiber local variables which do not share the value" do
259+
thread = Thread.current
260+
shared?(thread).should == true
261+
262+
obj = Object.new
263+
thread[:sharing_spec] = obj
264+
begin
265+
shared?(obj).should == false
266+
ensure
267+
thread[:sharing_spec] = nil
268+
end
269+
end
270+
271+
it "Thread local variables which share the value (probably they should not)" do
272+
thread = Thread.current
273+
shared?(thread).should == true
274+
275+
obj = Object.new
276+
thread.thread_variable_set(:sharing_spec, obj)
277+
shared?(obj).should == true # TODO (eregon, 5 Jun 2019): this is the current non-ideal behavior
278+
end
279+
280+
it "classes and constants and they are not shared until sharing is started" do
281+
ruby_exe("p Truffle::Debug.shared?(Object)").should == "false\n"
282+
end
283+
284+
it "thread-local IO buffers which should not trigger sharing" do
285+
ruby_exe("File.read(#{__FILE__.inspect}); p Truffle::Debug.shared?(Object)").should == "false\n"
286+
end
287+
258288
end

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void initialize() {
262262

263263
// Share once everything is loaded
264264
if (options.SHARED_OBJECTS_ENABLED && options.SHARED_OBJECTS_FORCE) {
265-
sharedObjects.startSharing();
265+
sharedObjects.startSharing(OptionsCatalog.SHARED_OBJECTS_FORCE.getName() + " being true");
266266
}
267267

268268
if (isPreInitializing()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public synchronized FinalizerReference addFinalizer(Object object, FinalizerRefe
111111

112112
finalizerReference.addFinalizer(owner, action, root);
113113

114-
referenceProcessor.processReferenceQueue();
114+
referenceProcessor.processReferenceQueue(owner);
115115
return finalizerReference;
116116
}
117117

0 commit comments

Comments
 (0)