Skip to content

Commit 6b960e7

Browse files
committed
[GR-18163] Fixes to pass the ruby2_keywords gem tests.
PullRequest: truffleruby/2403
2 parents c34c627 + 9a83da1 commit 6b960e7

File tree

18 files changed

+71
-52
lines changed

18 files changed

+71
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Performance:
6262
Changes:
6363

6464
* Standalone builds of TruffleRuby are now based on JDK11 (they used JDK8 previously). There should be no user-visible changes. Similarly, JDK11 is now used by default in development instead of JDK8.
65+
* The deprecated `Truffle::System.synchronized` has been removed.
6566

6667
# 21.0.0
6768

doc/contributor/third-party-assumptions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ so that we know why non-standard APIs have been added.
1010

1111
* `concurrent-ruby` < 1.1.0 used `Truffle::System.full_memory_barrier`,
1212
`Truffle::Primitive.logical_processors`, `Truffle::AtomicReference`, and
13-
`Truffle::System.synchronized`. `Truffle::Primitive.logical_processors`, `Truffle::System.full_memory_barrier`, and
14-
`Truffle::AtomicReference` have been removed.
13+
`Truffle::System.synchronized`. All of these have been removed.
1514

1615
* `concurrent-ruby` >= 1.1.0 uses `TruffleRuby.full_memory_barrier`,
1716
`TruffleRuby.synchronized`, and `TruffleRuby::AtomicReference`,

lib/truffle/objspace.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def trace_object_allocations
195195
module_function :trace_object_allocations
196196

197197
def trace_object_allocations_clear
198-
Truffle::System.synchronized(ALLOCATIONS) do
198+
TruffleRuby.synchronized(ALLOCATIONS) do
199199
ALLOCATIONS.clear
200200
end
201201
end
@@ -217,7 +217,7 @@ def trace_object_allocations_stop
217217
module_function :trace_object_allocations_stop
218218

219219
def allocation_class_path(object)
220-
allocation = Truffle::System.synchronized(ALLOCATIONS) do
220+
allocation = TruffleRuby.synchronized(ALLOCATIONS) do
221221
ALLOCATIONS[object]
222222
end
223223
return nil if allocation.nil?
@@ -226,7 +226,7 @@ def allocation_class_path(object)
226226
module_function :allocation_class_path
227227

228228
def allocation_generation(object)
229-
allocation = Truffle::System.synchronized(ALLOCATIONS) do
229+
allocation = TruffleRuby.synchronized(ALLOCATIONS) do
230230
ALLOCATIONS[object]
231231
end
232232
return nil if allocation.nil?
@@ -235,7 +235,7 @@ def allocation_generation(object)
235235
module_function :allocation_generation
236236

237237
def allocation_method_id(object)
238-
allocation = Truffle::System.synchronized(ALLOCATIONS) do
238+
allocation = TruffleRuby.synchronized(ALLOCATIONS) do
239239
ALLOCATIONS[object]
240240
end
241241
return nil if allocation.nil?
@@ -248,7 +248,7 @@ def allocation_method_id(object)
248248
module_function :allocation_method_id
249249

250250
def allocation_sourcefile(object)
251-
allocation = Truffle::System.synchronized(ALLOCATIONS) do
251+
allocation = TruffleRuby.synchronized(ALLOCATIONS) do
252252
ALLOCATIONS[object]
253253
end
254254
return nil if allocation.nil?
@@ -257,7 +257,7 @@ def allocation_sourcefile(object)
257257
module_function :allocation_sourcefile
258258

259259
def allocation_sourceline(object)
260-
allocation = Truffle::System.synchronized(ALLOCATIONS) do
260+
allocation = TruffleRuby.synchronized(ALLOCATIONS) do
261261
ALLOCATIONS[object]
262262
end
263263
return nil if allocation.nil?
@@ -271,7 +271,7 @@ def allocation_sourceline(object)
271271

272272
def trace_allocation(object, class_path, method_id, sourcefile, sourceline, generation)
273273
allocation = Allocation.new(class_path, method_id, sourcefile, sourceline, generation)
274-
Truffle::System.synchronized(ALLOCATIONS) do
274+
TruffleRuby.synchronized(ALLOCATIONS) do
275275
ALLOCATIONS[object] = allocation
276276
end
277277
end

lib/truffle/timeout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def self.watch_channel
123123
end
124124

125125
def self.ensure_timeout_thread_running
126-
Truffle::System.synchronized(self) do
126+
TruffleRuby.synchronized(self) do
127127
@controller ||= Thread.new { watch_channel }
128128
end
129129
end

spec/ruby/core/kernel/shared/require.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,12 @@
546546
ScratchPad.recorded.should == []
547547
end
548548

549-
it "complex, enumerator, rational and thread are already required" do
550-
provided = %w[complex enumerator rational thread]
549+
provided = %w[complex enumerator rational thread]
550+
ruby_version_is "2.7" do
551+
provided << 'ruby2_keywords'
552+
end
553+
554+
it "#{provided.join(', ')} are already required" do
551555
features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
552556
provided.each { |feature|
553557
features.should =~ /\b#{feature}\.(rb|so|jar)$/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
4+
ruby_version_is "2.7" do
5+
describe "main.ruby2_keywords" do
6+
it "is the same as Object.ruby2_keywords" do
7+
main = TOPLEVEL_BINDING.receiver
8+
main.should have_private_method(:ruby2_keywords)
9+
end
10+
end
11+
end

spec/tags/core/kernel/require_tags.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ slow:Kernel#require ($LOADED_FEATURES) unicode_normalize is part of core and not
66
slow:Kernel.require ($LOADED_FEATURES) unicode_normalize is part of core and not $LOADED_FEATURES
77
fails:Kernel#require (non-extensioned path) loads a .rb extensioned file when a C-extension file exists on an earlier load path
88
fails:Kernel#require (non-extensioned path) does not load a feature twice when $LOAD_PATH has been modified
9+
slow:Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
10+
slow:Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@
5454
import org.truffleruby.builtins.CoreModule;
5555
import org.truffleruby.builtins.Primitive;
5656
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
57-
import org.truffleruby.builtins.YieldingCoreMethodNode;
5857
import org.truffleruby.core.array.RubyArray;
59-
import org.truffleruby.core.proc.RubyProc;
6058
import org.truffleruby.core.rope.CodeRange;
6159
import org.truffleruby.core.string.RubyString;
6260
import org.truffleruby.core.string.StringNodes;
6361
import org.truffleruby.core.symbol.RubySymbol;
6462
import org.truffleruby.interop.FromJavaStringNode;
65-
import org.truffleruby.language.RubyDynamicObject;
6663
import org.truffleruby.language.control.RaiseException;
6764
import org.truffleruby.language.library.RubyStringLibrary;
6865
import org.truffleruby.platform.Platform;
@@ -207,18 +204,6 @@ protected RubyString hostOS() {
207204

208205
}
209206

210-
@CoreMethod(names = "synchronized", onSingleton = true, required = 1, needsBlock = true)
211-
public abstract static class SynchronizedPrimitiveNode extends YieldingCoreMethodNode {
212-
213-
// We must not allow to synchronize on boxed primitives.
214-
@Specialization
215-
protected Object synchronize(RubyDynamicObject object, RubyProc block) {
216-
synchronized (object) {
217-
return yield(block);
218-
}
219-
}
220-
}
221-
222207
@CoreMethod(names = "log", onSingleton = true, required = 2)
223208
public abstract static class LogNode extends CoreMethodArrayArgumentsNode {
224209

src/main/java/org/truffleruby/extra/TruffleRubyNodes.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1818
import org.truffleruby.builtins.CoreMethodNode;
1919
import org.truffleruby.builtins.CoreModule;
20+
import org.truffleruby.builtins.YieldingCoreMethodNode;
21+
import org.truffleruby.core.proc.RubyProc;
2022
import org.truffleruby.core.rope.CodeRange;
2123
import org.truffleruby.core.string.StringNodes;
2224
import org.truffleruby.extra.ffi.Pointer;
@@ -25,6 +27,7 @@
2527
import com.oracle.truffle.api.Truffle;
2628
import com.oracle.truffle.api.TruffleOptions;
2729
import com.oracle.truffle.api.dsl.Specialization;
30+
import org.truffleruby.language.RubyDynamicObject;
2831

2932
@CoreModule("TruffleRuby")
3033
public abstract class TruffleRubyNodes {
@@ -98,4 +101,17 @@ protected Object fullMemoryBarrier() {
98101

99102
}
100103

104+
@CoreMethod(names = "synchronized", onSingleton = true, required = 1, needsBlock = true)
105+
public abstract static class SynchronizedNode extends YieldingCoreMethodNode {
106+
107+
// We must not allow to synchronize on boxed primitives.
108+
@Specialization
109+
protected Object synchronize(RubyDynamicObject object, RubyProc block) {
110+
synchronized (object) {
111+
return yield(block);
112+
}
113+
}
114+
115+
}
116+
101117
}

src/main/ruby/truffleruby/core/io.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def fill(io, max = DEFAULT_READ_SIZE)
165165
#
166166
# Returns the number of bytes in the buffer.
167167
def fill_from(io, skip = nil, max = DEFAULT_READ_SIZE)
168-
Truffle::System.synchronized(self) do
168+
TruffleRuby.synchronized(self) do
169169
discard skip if skip
170170

171171
if empty?
@@ -200,7 +200,7 @@ def find(pattern, discard = nil)
200200
end
201201

202202
def unseek!(io)
203-
Truffle::System.synchronized(self) do
203+
TruffleRuby.synchronized(self) do
204204
unless empty?
205205
amount = @start - @used
206206
r = Truffle::POSIX.lseek(io.fileno, amount, IO::SEEK_CUR)
@@ -213,7 +213,7 @@ def unseek!(io)
213213
# Returns +count+ bytes from the +start+ of the buffer as a new String.
214214
# If +count+ is +nil+, returns all available bytes in the buffer.
215215
def shift(count=nil, encoding=Encoding::ASCII_8BIT)
216-
Truffle::System.synchronized(self) do
216+
TruffleRuby.synchronized(self) do
217217
total = size
218218
total = count if count and count < total
219219

@@ -250,7 +250,7 @@ def read_to_char_boundary(io, str)
250250
def getbyte(io)
251251
return if size == 0 and fill_from(io) == 0
252252

253-
Truffle::System.synchronized(self) do
253+
TruffleRuby.synchronized(self) do
254254
byte = @storage[@start]
255255
@start += 1
256256
byte
@@ -261,7 +261,7 @@ def getbyte(io)
261261
def getchar(io)
262262
return if size == 0 and fill_from(io) == 0
263263

264-
Truffle::System.synchronized(self) do
264+
TruffleRuby.synchronized(self) do
265265
char = +''
266266
while size > 0
267267
char.force_encoding Encoding::ASCII_8BIT

0 commit comments

Comments
 (0)