Skip to content

Commit

Permalink
Showing 5 changed files with 37 additions and 11 deletions.
7 changes: 5 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/JRubyTruffleImpl.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@
import com.oracle.truffle.api.vm.PolyglotEngine;
import org.jruby.JRubyTruffleInterface;
import org.jruby.Ruby;
import org.jruby.exceptions.MainExitException;
import org.jruby.truffle.interop.JRubyContextWrapper;
import org.jruby.truffle.language.control.ExitException;
import org.jruby.truffle.platform.Graal;
import org.jruby.util.cli.Options;

@@ -53,8 +55,9 @@ public Object execute(org.jruby.ast.RootNode rootNode) {
return engine.eval(Source.fromText("Truffle::Primitive.run_jruby_root", "run_jruby_root")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
} catch (IOException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
if (e.getCause() instanceof ExitException) {
final ExitException exit = (ExitException) e.getCause();
throw new org.jruby.exceptions.MainExitException(exit.getCode());
}

throw new RuntimeException(e);
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@
import jnr.posix.Passwd;
import jnr.posix.Times;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.exceptions.MainExitException;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.basicobject.BasicObjectNodes;
@@ -62,6 +61,7 @@
import org.jruby.truffle.core.thread.ThreadManager;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.ExitException;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.control.ThrowException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
@@ -151,7 +151,7 @@ public VMExitPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public Object vmExit(int status) {
getContext().shutdown();
throw new MainExitException(status);
throw new ExitException(status);
}

@Fallback
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.language.control;

import com.oracle.truffle.api.nodes.ControlFlowException;

public final class ExitException extends ControlFlowException {

private final int code;

public ExitException(int code) {
this.code = code;
}

public int getCode() {
return code;
}

}
Original file line number Diff line number Diff line change
@@ -13,13 +13,13 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.exceptions.MainExitException;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.cast.IntegerCastNode;
import org.jruby.truffle.core.cast.IntegerCastNodeGen;
import org.jruby.truffle.core.kernel.AtExitManager;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.ExitException;
import org.jruby.truffle.language.control.RaiseException;

public class TopLevelRaiseHandler extends RubyNode {
@@ -43,13 +43,14 @@ public Object execute(VirtualFrame frame) {
lastException = AtExitManager.handleAtExitException(getContext(), e);
} finally {
final DynamicObject atExitException = getContext().getAtExitManager().runAtExitHooks();

if (atExitException != null) {
lastException = atExitException;
}

getContext().shutdown();

throw new MainExitException(statusFromException(lastException));
throw new ExitException(statusFromException(lastException));
}
}

@@ -68,6 +69,7 @@ private int castToInt(Object value) {
CompilerDirectives.transferToInterpreter();
integerCastNode = insert(IntegerCastNodeGen.create(getContext(), getSourceSection(), null));
}

return integerCastNode.executeCastInt(value);
}

Original file line number Diff line number Diff line change
@@ -16,13 +16,11 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.exceptions.MainExitException;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.control.ThreadExitException;
import org.jruby.truffle.language.control.TruffleFatalException;

public class ExceptionTranslatingNode extends RubyNode {
@@ -57,9 +55,6 @@ public Object execute(VirtualFrame frame) {
} catch (TruffleFatalException exception) {
CompilerDirectives.transferToInterpreter();
throw exception;
} catch (org.jruby.exceptions.MainExitException exception) {
CompilerDirectives.transferToInterpreter();
throw exception;
} catch (org.jruby.exceptions.RaiseException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getJRubyInterop().toTruffle(e.getException(), this));

0 comments on commit 0e25db2

Please sign in to comment.