Skip to content

Commit f516172

Browse files
committed
[GR-32332] Backports for 20.2 batch 2
PullRequest: truffleruby/2778
2 parents 90d74f3 + c6acb0f commit f516172

File tree

8 files changed

+76
-45
lines changed

8 files changed

+76
-45
lines changed

common.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
"README": "This file contains definitions that are useful for the hocon and jsonnet CI files of multiple repositories.",
33

44
"jdks": {
5-
"openjdk8": {"name": "openjdk", "version": "8u302+02-jvmci-21.2-b02", "platformspecific": true },
6-
"oraclejdk8": {"name": "oraclejdk", "version": "8u301+05-jvmci-21.2-b02", "platformspecific": true },
7-
"oraclejdk8Debug": {"name": "oraclejdk", "version": "8u301+05-jvmci-21.2-b02-fastdebug", "platformspecific": true },
5+
"openjdk8": {"name": "openjdk", "version": "8u302+06-jvmci-21.2-b05", "platformspecific": true },
6+
"oraclejdk8": {"name": "oraclejdk", "version": "8u301+09-jvmci-21.2-b05", "platformspecific": true },
7+
"oraclejdk8Debug": {"name": "oraclejdk", "version": "8u301+09-jvmci-21.2-b05-fastdebug", "platformspecific": true },
88

99
"openjdk11": {"name": "openjdk", "version": "11.0.11+9", "platformspecific": true },
1010
"oraclejdk11": {"name": "oraclejdk", "version": "11.0.11+9", "platformspecific": true },
11-
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.11+8-jvmci-21.2-b02", "platformspecific": true },
12-
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.11+9-jvmci-21.2-b02", "platformspecific": true },
11+
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.12+5-jvmci-21.2-b05", "platformspecific": true },
12+
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.12+8-jvmci-21.2-b05", "platformspecific": true },
1313

1414
"oraclejdk16": {"name": "oraclejdk", "version": "16.0.1+4", "platformspecific": true },
15-
"labsjdk-ce-16": {"name": "labsjdk", "version": "ce-16.0.2+4-jvmci-21.2-b02", "platformspecific": true },
16-
"labsjdk-ce-16Debug": {"name": "labsjdk", "version": "ce-16.0.2+4-jvmci-21.2-b02-debug", "platformspecific": true },
17-
"labsjdk-ee-16": {"name": "labsjdk", "version": "ee-16.0.2+4-jvmci-21.2-b02", "platformspecific": true },
18-
"labsjdk-ee-16Debug": {"name": "labsjdk", "version": "ee-16.0.2+4-jvmci-21.2-b02-debug", "platformspecific": true }
15+
"labsjdk-ce-16": {"name": "labsjdk", "version": "ce-16.0.2+7-jvmci-21.2-b05", "platformspecific": true },
16+
"labsjdk-ce-16Debug": {"name": "labsjdk", "version": "ce-16.0.2+7-jvmci-21.2-b05-debug", "platformspecific": true },
17+
"labsjdk-ee-16": {"name": "labsjdk", "version": "ee-16.0.2+7-jvmci-21.2-b05", "platformspecific": true },
18+
"labsjdk-ee-16Debug": {"name": "labsjdk", "version": "ee-16.0.2+7-jvmci-21.2-b05-debug", "platformspecific": true }
1919
},
2020

2121
"COMMENT" : "The devkits versions reflect those used to build the JVMCI JDKs (e.g., see devkit_platform_revisions in <jdk>/make/conf/jib-profiles.js)",

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "dbe78abd4c604ca50f639d6a4c1eba0411166229",
10+
"version": "371edf7da6456f063bfe2a6b35b4335364d95d7e",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "dbe78abd4c604ca50f639d6a4c1eba0411166229",
19+
"version": "371edf7da6456f063bfe2a6b35b4335364d95d7e",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

spec/tags/truffle/tools_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
slow:Tools --coverage is available and works
22
slow:Tools --coverage works for internal sources
33
slow:Tools --engine.TraceCompilation works and outputs to STDERR
4+
slow:Tools --cpusampler works if Thread#kill is used

spec/truffle/tools_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,26 @@
5353
$?.should.success?
5454
end
5555
end
56+
57+
describe "--cpusampler" do
58+
it "works if Thread#kill is used" do
59+
code = <<~RUBY
60+
def foo
61+
n = 0
62+
loop { itself { n += 1 } }
63+
n
64+
end
65+
t = Thread.new { foo }
66+
sleep 1
67+
p :kill
68+
t.kill
69+
t.join
70+
RUBY
71+
out = ruby_exe(code, options: "--cpusampler --cpusampler.Mode=roots")
72+
out.should.include?(":kill")
73+
out.should.include?("block in Object#foo")
74+
out.should_not.include?('KillException')
75+
$?.should.success?
76+
end
77+
end
5678
end

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.concurrent.CountDownLatch;
1616

1717
import com.oracle.truffle.api.TruffleContext;
18+
import com.oracle.truffle.api.TruffleSafepoint;
1819
import org.truffleruby.RubyContext;
1920
import org.truffleruby.RubyLanguage;
2021
import org.truffleruby.core.DummyNode;
@@ -357,11 +358,19 @@ public void killOtherFibers() {
357358

358359
// This method might not be executed on the rootFiber Java Thread but possibly on another Java Thread.
359360

360-
final TruffleContext truffleContext = context.getEnv().getContext();
361-
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
362-
doKillOtherFibers();
363-
return BlockingAction.SUCCESS;
364-
});
361+
// Disallow side-effecting safepoints, the current thread is cleaning up and terminating.
362+
// It can no longer process any exception or guest code.
363+
final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
364+
boolean allowSideEffects = safepoint.setAllowSideEffects(false);
365+
try {
366+
final TruffleContext truffleContext = context.getEnv().getContext();
367+
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
368+
doKillOtherFibers();
369+
return BlockingAction.SUCCESS;
370+
});
371+
} finally {
372+
safepoint.setAllowSideEffects(allowSideEffects);
373+
}
365374
}
366375

367376
private void doKillOtherFibers() {

src/main/java/org/truffleruby/core/hash/HashingNodes.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.oracle.truffle.api.dsl.Cached;
1313
import com.oracle.truffle.api.dsl.CachedContext;
14+
import com.oracle.truffle.api.dsl.Fallback;
1415
import com.oracle.truffle.api.dsl.GenerateUncached;
1516
import com.oracle.truffle.api.dsl.Specialization;
1617
import org.truffleruby.RubyContext;
@@ -25,7 +26,6 @@
2526
import org.truffleruby.core.symbol.SymbolNodes;
2627
import org.truffleruby.core.string.ImmutableRubyString;
2728
import org.truffleruby.language.RubyBaseNode;
28-
import org.truffleruby.language.RubyGuards;
2929
import org.truffleruby.language.dispatch.DispatchNode;
3030

3131
public abstract class HashingNodes {
@@ -58,6 +58,7 @@ protected int hashCompareByIdentity(Object key, boolean compareByIdentity,
5858
}
5959

6060
// MRI: any_hash
61+
/** Keep consistent with {@link org.truffleruby.core.kernel.KernelNodes.HashNode} */
6162
@GenerateUncached
6263
public abstract static class ToHashByHashCode extends RubyBaseNode {
6364

@@ -109,24 +110,18 @@ protected int hashImmutableString(ImmutableRubyString value,
109110
return (int) stringHashNode.execute(value);
110111
}
111112

112-
113113
@Specialization
114114
protected int hashSymbol(RubySymbol value,
115115
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
116116
return (int) symbolHashNode.execute(value);
117117
}
118118

119-
@Specialization(guards = "!isSpecialized(value)")
120-
protected int hash(Object value,
119+
@Fallback
120+
protected int hashOther(Object value,
121121
@Cached DispatchNode callHash,
122122
@Cached HashCastResultNode cast) {
123123
return cast.execute(callHash.call(value, "hash"));
124124
}
125-
126-
protected static boolean isSpecialized(Object value) {
127-
return RubyGuards.isPrimitive(value) || value instanceof RubyBignum || value instanceof RubyString ||
128-
value instanceof ImmutableRubyString || value instanceof RubySymbol;
129-
}
130125
}
131126

132127
@GenerateUncached

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.concurrent.TimeUnit;
1818

1919
import com.oracle.truffle.api.dsl.CachedContext;
20+
import com.oracle.truffle.api.dsl.Fallback;
2021
import com.oracle.truffle.api.frame.Frame;
2122
import com.oracle.truffle.api.utilities.AssumedValue;
2223
import org.jcodings.specific.UTF8Encoding;
@@ -83,6 +84,7 @@
8384
import org.truffleruby.core.support.TypeNodes.ObjectInstanceVariablesNode;
8485
import org.truffleruby.core.support.TypeNodesFactory.ObjectInstanceVariablesNodeFactory;
8586
import org.truffleruby.core.symbol.RubySymbol;
87+
import org.truffleruby.core.symbol.SymbolNodes;
8688
import org.truffleruby.core.symbol.SymbolTable;
8789
import org.truffleruby.core.thread.GetCurrentRubyThreadNode;
8890
import org.truffleruby.core.thread.RubyThread;
@@ -930,56 +932,61 @@ protected boolean isFrozen(Object self,
930932

931933
}
932934

935+
/** Keep consistent with {@link org.truffleruby.core.hash.HashingNodes.ToHashByHashCode} */
933936
@CoreMethod(names = "hash")
934937
public abstract static class HashNode extends CoreMethodArrayArgumentsNode {
935938

936-
937939
public static HashNode create() {
938940
return KernelNodesFactory.HashNodeFactory.create(null);
939941
}
940942

941943
public abstract Object execute(Object value);
942944

943945
@Specialization
944-
protected long hash(int value) {
945-
return HashOperations.hashLong(value, getContext(), this);
946+
protected long hashBoolean(boolean value) {
947+
return HashOperations.hashBoolean(value, getContext(), this);
946948
}
947949

948950
@Specialization
949-
protected long hash(long value) {
951+
protected long hashInt(int value) {
950952
return HashOperations.hashLong(value, getContext(), this);
951953
}
952954

953955
@Specialization
954-
protected long hash(double value) {
955-
return HashOperations.hashDouble(value, getContext(), this);
956+
protected long hashLong(long value) {
957+
return HashOperations.hashLong(value, getContext(), this);
956958
}
957959

958960
@Specialization
959-
protected long hash(boolean value) {
960-
return HashOperations.hashBoolean(value, getContext(), this);
961+
protected long hashDouble(double value) {
962+
return HashOperations.hashDouble(value, getContext(), this);
961963
}
962964

963965
@Specialization
964966
protected long hashBignum(RubyBignum value) {
965967
return HashOperations.hashBignum(value, getContext(), this);
966968
}
967969

968-
@TruffleBoundary
969970
@Specialization
970-
protected int hash(Nil self) {
971-
return System.identityHashCode(self);
971+
protected long hashString(RubyString value,
972+
@Cached StringNodes.HashStringNode stringHashNode) {
973+
return stringHashNode.execute(value);
972974
}
973975

974-
@TruffleBoundary
975976
@Specialization
976-
protected int hashEncoding(RubyEncoding self) {
977-
return System.identityHashCode(self);
977+
protected long hashImmutableString(ImmutableRubyString value,
978+
@Cached StringNodes.HashStringNode stringHashNode) {
979+
return stringHashNode.execute(value);
978980
}
979981

980-
@TruffleBoundary
981-
@Specialization(guards = "!isRubyBignum(self)")
982-
protected int hash(RubyDynamicObject self) {
982+
@Specialization
983+
protected long hashSymbol(RubySymbol value,
984+
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
985+
return symbolHashNode.execute(value);
986+
}
987+
988+
@Fallback
989+
protected int hashOtherUsingIdentity(Object self) {
983990
return System.identityHashCode(self);
984991
}
985992
}

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,11 @@ public abstract static class ForeignObjectNode extends CoreMethodArrayArgumentsN
549549

550550
@ExportLibrary(InteropLibrary.class)
551551
public static class ForeignObject implements TruffleObject {
552-
@TruffleBoundary
553552
@ExportMessage
554553
protected TriState isIdenticalOrUndefined(Object other) {
555554
return other instanceof ForeignObject ? TriState.valueOf(this == other) : TriState.UNDEFINED;
556555
}
557556

558-
@TruffleBoundary
559557
@ExportMessage
560558
protected int identityHashCode() {
561559
return System.identityHashCode(this);
@@ -567,7 +565,6 @@ protected String toDisplayString(boolean allowSideEffects) {
567565
}
568566
}
569567

570-
@TruffleBoundary
571568
@Specialization
572569
protected Object foreignObject() {
573570
return new ForeignObject();

0 commit comments

Comments
 (0)