Skip to content

Commit

Permalink
[GR-32332] Backports for 20.2 batch 2
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/2778
  • Loading branch information
eregon committed Jul 2, 2021
2 parents 90d74f3 + c6acb0f commit f516172
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 45 deletions.
18 changes: 9 additions & 9 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"README": "This file contains definitions that are useful for the hocon and jsonnet CI files of multiple repositories.",

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

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

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

"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)",
Expand Down
4 changes: 2 additions & 2 deletions mx.truffleruby/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "regex",
"subdir": True,
"version": "dbe78abd4c604ca50f639d6a4c1eba0411166229",
"version": "371edf7da6456f063bfe2a6b35b4335364d95d7e",
"urls": [
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand All @@ -16,7 +16,7 @@
{
"name": "sulong",
"subdir": True,
"version": "dbe78abd4c604ca50f639d6a4c1eba0411166229",
"version": "371edf7da6456f063bfe2a6b35b4335364d95d7e",
"urls": [
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand Down
1 change: 1 addition & 0 deletions spec/tags/truffle/tools_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
slow:Tools --coverage is available and works
slow:Tools --coverage works for internal sources
slow:Tools --engine.TraceCompilation works and outputs to STDERR
slow:Tools --cpusampler works if Thread#kill is used
22 changes: 22 additions & 0 deletions spec/truffle/tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,26 @@
$?.should.success?
end
end

describe "--cpusampler" do
it "works if Thread#kill is used" do
code = <<~RUBY
def foo
n = 0
loop { itself { n += 1 } }
n
end
t = Thread.new { foo }
sleep 1
p :kill
t.kill
t.join
RUBY
out = ruby_exe(code, options: "--cpusampler --cpusampler.Mode=roots")
out.should.include?(":kill")
out.should.include?("block in Object#foo")
out.should_not.include?('KillException')
$?.should.success?
end
end
end
19 changes: 14 additions & 5 deletions src/main/java/org/truffleruby/core/fiber/FiberManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.CountDownLatch;

import com.oracle.truffle.api.TruffleContext;
import com.oracle.truffle.api.TruffleSafepoint;
import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.core.DummyNode;
Expand Down Expand Up @@ -357,11 +358,19 @@ public void killOtherFibers() {

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

final TruffleContext truffleContext = context.getEnv().getContext();
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
doKillOtherFibers();
return BlockingAction.SUCCESS;
});
// Disallow side-effecting safepoints, the current thread is cleaning up and terminating.
// It can no longer process any exception or guest code.
final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
boolean allowSideEffects = safepoint.setAllowSideEffects(false);
try {
final TruffleContext truffleContext = context.getEnv().getContext();
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
doKillOtherFibers();
return BlockingAction.SUCCESS;
});
} finally {
safepoint.setAllowSideEffects(allowSideEffects);
}
}

private void doKillOtherFibers() {
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/truffleruby/core/hash/HashingNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.CachedContext;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import org.truffleruby.RubyContext;
Expand All @@ -25,7 +26,6 @@
import org.truffleruby.core.symbol.SymbolNodes;
import org.truffleruby.core.string.ImmutableRubyString;
import org.truffleruby.language.RubyBaseNode;
import org.truffleruby.language.RubyGuards;
import org.truffleruby.language.dispatch.DispatchNode;

public abstract class HashingNodes {
Expand Down Expand Up @@ -58,6 +58,7 @@ protected int hashCompareByIdentity(Object key, boolean compareByIdentity,
}

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

Expand Down Expand Up @@ -109,24 +110,18 @@ protected int hashImmutableString(ImmutableRubyString value,
return (int) stringHashNode.execute(value);
}


@Specialization
protected int hashSymbol(RubySymbol value,
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
return (int) symbolHashNode.execute(value);
}

@Specialization(guards = "!isSpecialized(value)")
protected int hash(Object value,
@Fallback
protected int hashOther(Object value,
@Cached DispatchNode callHash,
@Cached HashCastResultNode cast) {
return cast.execute(callHash.call(value, "hash"));
}

protected static boolean isSpecialized(Object value) {
return RubyGuards.isPrimitive(value) || value instanceof RubyBignum || value instanceof RubyString ||
value instanceof ImmutableRubyString || value instanceof RubySymbol;
}
}

@GenerateUncached
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/org/truffleruby/core/kernel/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.concurrent.TimeUnit;

import com.oracle.truffle.api.dsl.CachedContext;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.utilities.AssumedValue;
import org.jcodings.specific.UTF8Encoding;
Expand Down Expand Up @@ -83,6 +84,7 @@
import org.truffleruby.core.support.TypeNodes.ObjectInstanceVariablesNode;
import org.truffleruby.core.support.TypeNodesFactory.ObjectInstanceVariablesNodeFactory;
import org.truffleruby.core.symbol.RubySymbol;
import org.truffleruby.core.symbol.SymbolNodes;
import org.truffleruby.core.symbol.SymbolTable;
import org.truffleruby.core.thread.GetCurrentRubyThreadNode;
import org.truffleruby.core.thread.RubyThread;
Expand Down Expand Up @@ -930,56 +932,61 @@ protected boolean isFrozen(Object self,

}

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


public static HashNode create() {
return KernelNodesFactory.HashNodeFactory.create(null);
}

public abstract Object execute(Object value);

@Specialization
protected long hash(int value) {
return HashOperations.hashLong(value, getContext(), this);
protected long hashBoolean(boolean value) {
return HashOperations.hashBoolean(value, getContext(), this);
}

@Specialization
protected long hash(long value) {
protected long hashInt(int value) {
return HashOperations.hashLong(value, getContext(), this);
}

@Specialization
protected long hash(double value) {
return HashOperations.hashDouble(value, getContext(), this);
protected long hashLong(long value) {
return HashOperations.hashLong(value, getContext(), this);
}

@Specialization
protected long hash(boolean value) {
return HashOperations.hashBoolean(value, getContext(), this);
protected long hashDouble(double value) {
return HashOperations.hashDouble(value, getContext(), this);
}

@Specialization
protected long hashBignum(RubyBignum value) {
return HashOperations.hashBignum(value, getContext(), this);
}

@TruffleBoundary
@Specialization
protected int hash(Nil self) {
return System.identityHashCode(self);
protected long hashString(RubyString value,
@Cached StringNodes.HashStringNode stringHashNode) {
return stringHashNode.execute(value);
}

@TruffleBoundary
@Specialization
protected int hashEncoding(RubyEncoding self) {
return System.identityHashCode(self);
protected long hashImmutableString(ImmutableRubyString value,
@Cached StringNodes.HashStringNode stringHashNode) {
return stringHashNode.execute(value);
}

@TruffleBoundary
@Specialization(guards = "!isRubyBignum(self)")
protected int hash(RubyDynamicObject self) {
@Specialization
protected long hashSymbol(RubySymbol value,
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
return symbolHashNode.execute(value);
}

@Fallback
protected int hashOtherUsingIdentity(Object self) {
return System.identityHashCode(self);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/truffleruby/debug/TruffleDebugNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,11 @@ public abstract static class ForeignObjectNode extends CoreMethodArrayArgumentsN

@ExportLibrary(InteropLibrary.class)
public static class ForeignObject implements TruffleObject {
@TruffleBoundary
@ExportMessage
protected TriState isIdenticalOrUndefined(Object other) {
return other instanceof ForeignObject ? TriState.valueOf(this == other) : TriState.UNDEFINED;
}

@TruffleBoundary
@ExportMessage
protected int identityHashCode() {
return System.identityHashCode(this);
Expand All @@ -567,7 +565,6 @@ protected String toDisplayString(boolean allowSideEffects) {
}
}

@TruffleBoundary
@Specialization
protected Object foreignObject() {
return new ForeignObject();
Expand Down

0 comments on commit f516172

Please sign in to comment.