Skip to content

Commit b8bc6c4

Browse files
[GR-24983] Backports for 20.2.0.
PullRequest: truffleruby/1791
2 parents 60d5815 + 764ad48 commit b8bc6c4

File tree

10 files changed

+61
-24
lines changed

10 files changed

+61
-24
lines changed

.gitattributes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Merge options
2-
3-
/CHANGELOG.md merge=union
4-
51
# Rules for GitHub's Linguist language-classification system. We're abusing the
62
# 'vendored' attribute to exclude files as a lot of this isn't really vendored,
73
# and a whole lot of actually vendored code isn't listed! What we want to do is

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ Compatibility:
6666
* Implemented `Digest::Instance#new` (#2040).
6767
* Implemented `ONIGENC_MBC_CASE_FOLD`.
6868
* Fixed `Thread#raise` to call the exception class' constructor with no arguments when given no message (#2045).
69-
* Fixed `refine + super` compatibility (#2039, @ssnickolay)
69+
* Fixed `refine + super` compatibility (#2039, #2048, @ssnickolay)
7070
* Make the top-level exception handler more compatible with MRI (#2047).
7171
* Implemented `rb_enc_codelen`.
7272
* Implemented `Ripper` by using the C extension (#1585).
73-
* Fixed `refine + super` compatibility (#2039, #2048, @ssnickolay)
7473

7574
Changes:
7675

spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
@frame.absolute_path.should == File.realpath(__FILE__)
1111
end
1212

13+
it 'returns an absolute path when using a relative main script path' do
14+
script = fixture(__FILE__, 'absolute_path_main.rb')
15+
Dir.chdir(File.dirname(script)) do
16+
ruby_exe('absolute_path_main.rb').should == "absolute_path_main.rb\n#{script}\n"
17+
end
18+
end
19+
1320
context "when used in eval with a given filename" do
1421
it "returns filename" do
1522
code = "caller_locations(0)[0].absolute_path"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
puts __FILE__
2+
puts caller_locations(0)[0].absolute_path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slow:Thread::Backtrace::Location#absolute_path returns an absolute path when using a relative main script path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slow:Java exceptions AssertionError in another Thread is rethrown on the main Ruby Thread

spec/truffle/java_exception_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,18 @@
6161
}
6262
end
6363

64+
it "AssertionError in another Thread is rethrown on the main Ruby Thread" do
65+
code = <<-RUBY
66+
Thread.new do
67+
Truffle::Debug.throw_assertion_error('custom_assertion_error_message')
68+
end
69+
sleep
70+
RUBY
71+
72+
out = ruby_exe(code, args: "2>&1")
73+
$?.exitstatus.should == 1
74+
out.should.include?('terminated with internal error')
75+
out.should.include?('Caused by:')
76+
out.should.include?('custom_assertion_error_message (AssertionError)')
77+
end
6478
end

src/main/java/org/truffleruby/core/thread/ThreadBacktraceLocationNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
package org.truffleruby.core.thread;
1111

12-
import java.io.File;
13-
1412
import org.jcodings.specific.UTF8Encoding;
1513
import org.truffleruby.Layouts;
1614
import org.truffleruby.RubyContext;
@@ -22,14 +20,15 @@
2220
import org.truffleruby.core.string.StringNodes;
2321
import org.truffleruby.core.string.StringOperations;
2422
import org.truffleruby.language.backtrace.Backtrace;
23+
import org.truffleruby.language.backtrace.BacktraceFormatter;
2524

2625
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2726
import com.oracle.truffle.api.TruffleStackTraceElement;
2827
import com.oracle.truffle.api.dsl.Cached;
2928
import com.oracle.truffle.api.dsl.Specialization;
3029
import com.oracle.truffle.api.object.DynamicObject;
30+
import com.oracle.truffle.api.source.Source;
3131
import com.oracle.truffle.api.source.SourceSection;
32-
import org.truffleruby.language.backtrace.BacktraceFormatter;
3332

3433
@CoreModule(value = "Thread::Backtrace::Location", isClass = true)
3534
public class ThreadBacktraceLocationNodes {
@@ -56,16 +55,17 @@ protected DynamicObject absolutePath(DynamicObject threadBacktraceLocation,
5655
if (sourceSection == null) {
5756
return coreStrings().UNKNOWN.createInstance();
5857
} else {
59-
final String path = RubyContext.getPath(sourceSection.getSource());
60-
if (new File(path).isAbsolute()) { // A normal file
58+
final Source source = sourceSection.getSource();
59+
final String path = RubyContext.getPath(source);
60+
if (source.getPath() != null) { // A normal file
6161
final String canonicalPath = getContext().getFeatureLoader().canonicalize(path);
6262
final Rope cachedRope = getContext()
6363
.getRopeCache()
6464
.getRope(StringOperations.encodeRope(canonicalPath, UTF8Encoding.INSTANCE));
6565
return makeStringNode.fromRope(cachedRope);
6666
} else { // eval()
6767
return makeStringNode
68-
.fromRope(getContext().getPathToRopeCache().getCachedPath(sourceSection.getSource()));
68+
.fromRope(getContext().getPathToRopeCache().getCachedPath(source));
6969
}
7070
}
7171
}

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,26 @@ private void threadMain(DynamicObject thread, Node currentNode, Supplier<Object>
328328
// Handlers in the same order as in FiberManager
329329
} catch (KillException e) {
330330
setThreadValue(context, thread, Nil.INSTANCE);
331-
} catch (ExitException e) {
332-
rethrowOnMainThread(currentNode, e);
333-
setThreadValue(context, thread, Nil.INSTANCE);
334331
} catch (RaiseException e) {
335332
setException(context, thread, e.getException(), currentNode);
336333
} catch (DynamicReturnException e) {
337334
setException(context, thread, context.getCoreExceptions().unexpectedReturn(currentNode), currentNode);
335+
} catch (ExitException e) {
336+
rethrowOnMainThread(currentNode, e);
337+
setThreadValue(context, thread, Nil.INSTANCE);
338+
} catch (Throwable e) {
339+
final String message = StringUtils
340+
.format("%s terminated with internal error:", Thread.currentThread().getName());
341+
final RuntimeException runtimeException = new RuntimeException(message, e);
342+
rethrowOnMainThread(currentNode, runtimeException);
343+
setThreadValue(context, thread, Nil.INSTANCE);
338344
} finally {
339345
assert Layouts.THREAD.getValue(thread) != null || Layouts.THREAD.getException(thread) != null;
340346
cleanup(thread, Thread.currentThread());
341347
}
342348
}
343349

344-
private void rethrowOnMainThread(Node currentNode, ExitException e) {
350+
private void rethrowOnMainThread(Node currentNode, RuntimeException e) {
345351
context.getSafepointManager().pauseRubyThreadAndExecute(
346352
getRootThread(),
347353
currentNode,

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ static void warning(String message) {
401401
public abstract static class ThrowJavaExceptionNode extends CoreMethodArrayArgumentsNode {
402402

403403
@TruffleBoundary
404-
@Specialization
405-
protected Object throwJavaException(Object message) {
406-
callingMethod(message.toString());
404+
@Specialization(guards = "isRubyString(message)")
405+
protected Object throwJavaException(DynamicObject message) {
406+
callingMethod(StringOperations.getString(message));
407407
return nil;
408408
}
409409

@@ -423,21 +423,32 @@ private static void throwingMethod(String message) {
423423
public abstract static class ThrowJavaExceptionWithCauseNode extends CoreMethodArrayArgumentsNode {
424424

425425
@TruffleBoundary
426-
@Specialization
427-
protected DynamicObject throwJavaExceptionWithCause(Object message) {
426+
@Specialization(guards = "isRubyString(message)")
427+
protected Object throwJavaExceptionWithCause(DynamicObject message) {
428428
throw new RuntimeException(
429-
message.toString(),
429+
StringOperations.getString(message),
430430
new RuntimeException("cause 1", new RuntimeException("cause 2")));
431431
}
432432

433433
}
434434

435+
@CoreMethod(names = "throw_assertion_error", onSingleton = true, required = 1)
436+
public abstract static class ThrowAssertionErrorNode extends CoreMethodArrayArgumentsNode {
437+
438+
@TruffleBoundary
439+
@Specialization(guards = "isRubyString(message)")
440+
protected Object throwAssertionError(DynamicObject message) {
441+
throw new AssertionError(StringOperations.getString(message));
442+
}
443+
444+
}
445+
435446
@CoreMethod(names = "assert", onSingleton = true, required = 1)
436447
public abstract static class AssertNode extends CoreMethodArrayArgumentsNode {
437448

438449
@TruffleBoundary
439450
@Specialization
440-
protected Object throwJavaException(boolean condition) {
451+
protected Object doAssert(boolean condition) {
441452
assert condition;
442453
return nil;
443454
}
@@ -805,7 +816,7 @@ protected String toDisplayString(boolean allowSideEffects) {
805816
@TruffleBoundary
806817
@Specialization(guards = "isRubyString(string)")
807818
protected Object foreignString(DynamicObject string) {
808-
return new ForeignString(string.toString());
819+
return new ForeignString(StringOperations.getString(string));
809820
}
810821

811822
}

0 commit comments

Comments
 (0)