Skip to content

Commit 0db6fd1

Browse files
committed
[GR-38034] Run MRI tests on native instead of JVM
PullRequest: truffleruby/3291
2 parents e7feb07 + 8bb5f67 commit 0db6fd1

File tree

9 files changed

+29
-23
lines changed

9 files changed

+29
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Bug fixes:
3737
* Fix `String#insert` to not call a subclassed string method (@bjfish).
3838
* Fix `rb_obj_call_init` to pass any block argument to the `initialize` method (#2675, @aardvark179).
3939
* Fix issue with feature loading not detecting a previously loaded feature (#2677, @bjfish).
40+
* Fix `/#{...}/o` to evaluate only once per context when splitting happens (@eregon).
4041

4142
Compatibility:
4243

ci.jsonnet

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,10 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
535535
"ruby-test-specs-darwin-aarch64-17": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
536536
"ruby-test-fast-linux-aarch64": $.platform.linux_aarch64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "45:00" },
537537
"ruby-test-fast-linux": $.platform.linux + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + { timelimit: "45:00" }, # To catch missing slow tags
538-
"ruby-test-mri-linux": $.platform.linux + $.jdk.v11 + $.env.jvm + gate + $.run.test_mri + { timelimit: "01:10:00" },
539-
"ruby-test-mri-linux-aarch64": $.platform.linux_aarch64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_mri + { timelimit: "01:10:00" },
540-
"ruby-test-mri-darwin-amd64": $.platform.darwin_amd64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_mri + { timelimit: "01:30:00" },
541-
"ruby-test-mri-darwin-aarch64": $.platform.darwin_aarch64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_mri + { timelimit: "01:30:00" },
538+
"ruby-test-mri-linux": $.platform.linux + $.jdk.v11 + $.env.native + gate + $.run.test_mri + { timelimit: "01:10:00" },
539+
"ruby-test-mri-linux-aarch64": $.platform.linux_aarch64 + $.jdk.v11 + $.env.native + gate + $.run.test_mri + { timelimit: "01:10:00" },
540+
"ruby-test-mri-darwin-amd64": $.platform.darwin_amd64 + $.jdk.v11 + $.env.native + gate + $.run.test_mri + { timelimit: "01:30:00" },
541+
"ruby-test-mri-darwin-aarch64": $.platform.darwin_aarch64 + $.jdk.v11 + $.env.native + gate + $.run.test_mri + { timelimit: "01:30:00" },
542542
"ruby-test-integration-linux": $.platform.linux + $.jdk.v11 + $.env.jvm + gate + $.run.test_integration,
543543
"ruby-test-cexts-linux": $.platform.linux + $.jdk.v11 + $.env.jvm + gate + $.use.gem_test_pack + $.use.sqlite331 + $.run.test_cexts,
544544
"ruby-test-cexts-darwin-amd64": $.platform.darwin_amd64 + $.jdk.v11 + $.env.jvm + gate + $.use.gem_test_pack + $.run.test_cexts + { timelimit: "01:20:00" },

src/main/java/org/truffleruby/core/binding/TruffleBindingNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ protected Object ofCaller() {
3333
/* When you use this method you're asking for the binding of the caller at the call site. When we get into
3434
* this method, that is then the binding of the caller of the caller. */
3535

36-
final Memo<Integer> frameCount = new Memo<>(0);
36+
final int[] frameCount = new int[]{ 0 };
3737
final Memo<SourceSection> sourceSection = new Memo<>(null);
3838

3939
final MaterializedFrame frame = Truffle.getRuntime().iterateFrames(frameInstance -> {
40-
if (frameCount.get() == 2) {
40+
if (frameCount[0] == 2) {
4141
sourceSection.set(frameInstance.getCallNode().getEncapsulatingSourceSection());
4242
return frameInstance.getFrame(FrameAccess.MATERIALIZE).materialize();
4343
} else {
44-
frameCount.set(frameCount.get() + 1);
44+
frameCount[0] += 1;
4545
return null;
4646
}
4747
});

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,16 +873,14 @@ protected Object freezeDynamicObject(Object self,
873873

874874
}
875875

876-
@ReportPolymorphism
877-
@CoreMethod(names = "frozen?")
878-
public abstract static class KernelFrozenNode extends CoreMethodArrayArgumentsNode {
879-
876+
@GenerateUncached
877+
@CoreMethod(names = "frozen?", alwaysInlined = true)
878+
public abstract static class KernelFrozenNode extends AlwaysInlinedMethodNode {
880879
@Specialization(limit = "getRubyLibraryCacheLimit()")
881-
protected boolean isFrozen(Object self,
880+
protected boolean isFrozen(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target,
882881
@CachedLibrary("self") RubyLibrary rubyLibrary) {
883882
return rubyLibrary.isFrozen(self);
884883
}
885-
886884
}
887885

888886
/** Keep consistent with {@link org.truffleruby.core.hash.HashingNodes.ToHashByHashCode} */

src/main/java/org/truffleruby/language/TruffleBootNodes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2626
import org.truffleruby.builtins.CoreMethodNode;
2727
import org.truffleruby.builtins.CoreModule;
28-
import org.truffleruby.collections.Memo;
2928
import org.truffleruby.core.array.RubyArray;
3029
import org.truffleruby.core.encoding.Encodings;
3130
import org.truffleruby.core.rope.CodeRange;
@@ -267,13 +266,13 @@ public abstract static class SourceOfCallerNode extends CoreMethodArrayArguments
267266
@TruffleBoundary
268267
@Specialization
269268
protected Object sourceOfCaller() {
270-
final Memo<Integer> frameCount = new Memo<>(0);
269+
final int[] frameCount = new int[]{ 0 };
271270

272271
final Source source = Truffle.getRuntime().iterateFrames(frameInstance -> {
273-
if (frameCount.get() == 2) {
272+
if (frameCount[0] == 2) {
274273
return frameInstance.getCallNode().getEncapsulatingSourceSection().getSource();
275274
} else {
276-
frameCount.set(frameCount.get() + 1);
275+
frameCount[0] += 1;
277276
return null;
278277
}
279278
});

src/main/java/org/truffleruby/language/control/OnceNode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,37 @@
1616
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1717
import com.oracle.truffle.api.frame.VirtualFrame;
1818

19+
import java.util.Objects;
20+
1921
/** Executes a child node just once, and uses the same value each subsequent time the node is executed. */
2022
public class OnceNode extends RubyContextSourceNode {
2123

24+
static class Holder { // Not NodeCloneable, on purpose
25+
@CompilationFinal private volatile Object cachedValue;
26+
}
27+
2228
@Child private RubyNode child;
2329

24-
@CompilationFinal private volatile Object cachedValue;
30+
// An extra indirection so with splitting we compute the value only once, and the Holder is shared across splits.
31+
private final Holder holder = new Holder();
2532

2633
public OnceNode(RubyNode child) {
2734
this.child = child;
2835
}
2936

3037
@Override
3138
public Object execute(VirtualFrame frame) {
32-
Object value = cachedValue;
39+
Object value = holder.cachedValue;
3340

3441
if (value == null) {
3542
CompilerDirectives.transferToInterpreterAndInvalidate();
3643
synchronized (this) {
3744
// Read `cachedValue` again to check if the value was updated by another thread while this thread
3845
// was waiting on the lock. If it's still null, this thread is the first one to get the lock and
3946
// must update the cache.
40-
value = cachedValue;
47+
value = holder.cachedValue;
4148
if (value == null) {
42-
value = cachedValue = child.execute(frame);
43-
assert value != null;
49+
value = holder.cachedValue = Objects.requireNonNull(child.execute(frame));
4450
}
4551
}
4652
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def self.with_synchronized_features
281281
# always called inside #with_synchronized_features
282282
def self.get_loaded_features_index
283283
unless @loaded_features_version == $LOADED_FEATURES.version
284+
raise '$LOADED_FEATURES is frozen; cannot append feature' if $LOADED_FEATURES.frozen?
284285
@loaded_features_index.clear
285286
$LOADED_FEATURES.map! do |val|
286287
val = StringValue(val)

test/mri/excludes/TestGc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
exclude :test_start_full_mark, "needs investigation"
1313
exclude :test_start_immediate_sweep, "needs investigation"
1414
exclude :test_verify_internal_consistency, "needs investigation"
15+
exclude :test_gc_disabled_start, "fails on native: GR-38054"

test/mri/tests/ruby/test_rational.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ def test_gcd_no_memory_leak
992992
assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-"end;"}", limit: 1.2, rss: true)
993993
x = (1<<121) + 1
994994
y = (1<<99) + 1
995-
1000.times{x.gcd(y)}
995+
100.times {1000.times{x.gcd(y)}}
996996
begin;
997997
100.times {1000.times{x.gcd(y)}}
998998
end;

0 commit comments

Comments
 (0)