Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ebc63195d82f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 44fa53913f59
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on May 27, 2015

  1. 2
    Copy the full SHA
    7cd6eec View commit details
  2. Copy the full SHA
    a3bc72e View commit details

Commits on May 28, 2015

  1. 4
    Copy the full SHA
    44fa539 View commit details
Original file line number Diff line number Diff line change
@@ -36,20 +36,12 @@ public InitializeNode(RubyContext context, SourceSection sourceSection) {
public RubyBasicObject initialize(RubyException exception, UndefinedPlaceholder message) {
CompilerDirectives.transferToInterpreter();

exception.initialize(getContext().makeString(""));
return nil();
}

@Specialization(guards = {"isNil(object)"})
public RubyBasicObject initialize(RubyException exception, RubyBasicObject object) {
CompilerDirectives.transferToInterpreter();

exception.initialize(getContext().makeString(""));
exception.initialize(nil());
return nil();
}

@Specialization
public RubyBasicObject initialize(RubyException exception, RubyString message) {
public RubyBasicObject initialize(RubyException exception, Object message) {
CompilerDirectives.transferToInterpreter();

exception.initialize(message);
@@ -111,28 +103,10 @@ public MessageNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyString message(RubyException exception) {
public Object message(RubyException exception) {
return exception.getMessage();
}

}

@CoreMethod(names = "to_s")
public abstract static class ToSNode extends CoreMethodArrayArgumentsNode {

public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyString toS(RubyException exception) {
if (exception.getMessage().length() == 0) {
return getContext().makeString(exception.getLogicalClass().getName());
} else {
return getContext().makeString(exception.getMessage().getByteList());
}
}

}

}
Original file line number Diff line number Diff line change
@@ -280,4 +280,33 @@ public RubyThread wakeup(final RubyThread thread) {

}

@CoreMethod(names = "abort_on_exception")
public abstract static class AbortOnExceptionNode extends CoreMethodArrayArgumentsNode {

public AbortOnExceptionNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public boolean abortOnException(RubyThread self) {
return self.isAbortOnException();
}

}

@CoreMethod(names = "abort_on_exception=", required = 1)
public abstract static class SetAbortOnExceptionNode extends CoreMethodArrayArgumentsNode {

public SetAbortOnExceptionNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyBasicObject setAbortOnException(RubyThread self, boolean abortOnException) {
self.setAbortOnException(abortOnException);
return nil();
}

}

}
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ public RubyContext(Ruby runtime) {

featureManager = new FeatureManager(this);
traceManager = new TraceManager();
atExitManager = new AtExitManager();
atExitManager = new AtExitManager(this);

threadManager = new ThreadManager(this);
threadManager.initialize();
Original file line number Diff line number Diff line change
@@ -19,27 +19,27 @@
*/
public class RubyException extends RubyBasicObject {

private RubyString message;
private Object message;
private Backtrace backtrace;

public RubyException(RubyClass rubyClass) {
super(rubyClass);
message = rubyClass.getContext().makeString("");
}

public RubyException(RubyClass rubyClass, RubyString message, Backtrace backtrace) {
public RubyException(RubyClass rubyClass, Object message, Backtrace backtrace) {
this(rubyClass);
initialize(message);
this.backtrace = backtrace;
}

public void initialize(RubyString message) {
public void initialize(Object message) {
assert message != null;
this.message = message;
}

// TODO (eregon 16 Apr. 2015): MRI does a dynamic calls to "message"
public RubyString getMessage() {
public Object getMessage() {
return message;
}

Original file line number Diff line number Diff line change
@@ -53,6 +53,8 @@ public class RubyThread extends RubyBasicObject {

private final List<Lock> ownedLocks = new ArrayList<>(); // Always accessed by the same underlying Java thread.

private boolean abortOnException = false;

public RubyThread(RubyClass rubyClass, ThreadManager manager) {
super(rubyClass);
this.manager = manager;
@@ -221,6 +223,14 @@ public RubyFiber getRootFiber() {
return fiberManager.getRootFiber();
}

public boolean isAbortOnException() {
return abortOnException;
}

public void setAbortOnException(boolean abortOnException) {
this.abortOnException = abortOnException;
}

public static class ThreadAllocator implements Allocator {

@Override
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@
*/
package org.jruby.truffle.runtime.subsystems;

import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyException;
import org.jruby.truffle.runtime.core.RubyProc;

import java.util.Deque;
@@ -17,9 +21,15 @@

public class AtExitManager {

private final RubyContext context;

private final Deque<RubyProc> runOnExit = new ConcurrentLinkedDeque<>();
private final Deque<RubyProc> runOnExitAlways = new ConcurrentLinkedDeque<>();

public AtExitManager(RubyContext context) {
this.context = context;
}

public void add(RubyProc block, boolean always) {
if (always) {
runOnExitAlways.push(block);
@@ -47,7 +57,17 @@ private void runExitHooks(Deque<RubyProc> stack) {
break;
}

block.rootCall();
try {
block.rootCall();
} catch (RaiseException e) {
final RubyException rubyException = e.getRubyException();

for (String line : Backtrace.DISPLAY_FORMATTER.format(context, rubyException, rubyException.getBacktrace())) {
System.err.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

10 changes: 9 additions & 1 deletion truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -216,4 +216,12 @@ def printf(fmt, *args)
ENV['USERPROFILE']
end
end
end
end

class Exception

def to_s
message.to_s
end

end
10 changes: 2 additions & 8 deletions truffle/src/main/ruby/core/thread.rb
Original file line number Diff line number Diff line change
@@ -25,17 +25,11 @@ def self.start(&block)
end

def self.abort_on_exception
false
current.abort_on_exception
end

def self.abort_on_exception=(value)
end

def abort_on_exception
false
end

def abort_on_exception=(value)
current.abort_on_exception = value
end

end