Skip to content

Commit

Permalink
Showing 46 changed files with 327 additions and 263 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -1519,7 +1519,7 @@ public static IRubyObject system(ThreadContext context, IRubyObject recv, IRubyO

@JRubyMethod(name = "system", required = 1, rest = true, module = true, visibility = PRIVATE)
public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;
boolean needChdir = !runtime.getCurrentDirectory().equals(runtime.getPosix().getcwd());

if (!needChdir && runtime.getPosix().isNative() && !Platform.IS_WINDOWS) {
@@ -1560,7 +1560,7 @@ public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRub

// else old JDK logic
if (args[0] instanceof RubyHash) {
RubyHash env = (RubyHash) args[0].convertToHash();
RubyHash env = args[0].convertToHash();
if (env != null) {
runtime.getENV().merge_bang(context, env, Block.NULL_BLOCK);
}
1 change: 1 addition & 0 deletions test/mri/excludes/TestProcess.rb
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
exclude :test_fd_inheritance, "needs investigation"
exclude :test_gid_re_exchangeable_p, "unimplemented"
exclude :test_gid_sid_available?, "unimplemented"
exclude :test_no_curdir, "won't work due changed wd detection (since 1e30600bdbbf483a)"
exclude :test_popen_cloexec, "unsupported"
exclude :test_popen_noshell, "fails on linux (Travis)"
exclude :test_popen_wordsplit, "needs investigation"
12 changes: 6 additions & 6 deletions tool/truffle/java-coverage/coverage.sh
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@

set -e

curl -L -o jacoco-agent.jar 'http://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runtime.jar'
curl -L -O 'http://central.maven.org/maven2/org/ow2/asm/asm-all/5.0.4/asm-all-5.0.4.jar'
curl -L -O 'http://central.maven.org/maven2/org/jacoco/org.jacoco.core/0.7.4.201502262128/org.jacoco.core-0.7.4.201502262128.jar'
curl -L -O 'http://central.maven.org/maven2/org/jacoco/org.jacoco.ant/0.7.4.201502262128/org.jacoco.ant-0.7.4.201502262128.jar'
curl -L -O 'http://central.maven.org/maven2/org/jacoco/org.jacoco.report/0.7.4.201502262128/org.jacoco.report-0.7.4.201502262128.jar'
curl -Lo jacoco-agent.jar 'http://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runtime.jar'
curl -LO 'http://central.maven.org/maven2/org/ow2/asm/asm-all/5.0.4/asm-all-5.0.4.jar'
curl -LO 'http://central.maven.org/maven2/org/jacoco/org.jacoco.core/0.7.4.201502262128/org.jacoco.core-0.7.4.201502262128.jar'
curl -LO 'http://central.maven.org/maven2/org/jacoco/org.jacoco.ant/0.7.4.201502262128/org.jacoco.ant-0.7.4.201502262128.jar'
curl -LO 'http://central.maven.org/maven2/org/jacoco/org.jacoco.report/0.7.4.201502262128/org.jacoco.report-0.7.4.201502262128.jar'

JACOCO_AGENT=`pwd`/jacoco-agent.jar
JACOCO_LOG=`pwd`/jacoco.exec

export VERIFY_JRUBY=1
export JAVA_OPTS="-javaagent:$JACOCO_AGENT=destfile=$JACOCO_LOG"

rm jacoco.exec
rm -f jacoco.exec
bin/jruby tool/jt.rb test
ant -f tool/truffle/java-coverage/build.xml
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
@@ -27,10 +27,13 @@ public class JRubyTruffleImpl implements JRubyTruffleInterface {
// Created by reflection from Ruby#loadTruffle

public JRubyTruffleImpl(Ruby runtime) {
engine = PolyglotEngine.newBuilder().globalSymbol(JRubyTruffleInterface.RUNTIME_SYMBOL, new JRubyContextWrapper(runtime)).build();
engine = PolyglotEngine.newBuilder()
.globalSymbol(JRubyTruffleInterface.RUNTIME_SYMBOL, new JRubyContextWrapper(runtime))
.build();

try {
context = (RubyContext) engine.eval(Source.fromText("Truffle::Primitive.context", "context").withMimeType(RubyLanguage.MIME_TYPE)).get();
context = (RubyContext) engine.eval(Source.fromText("Truffle::Primitive.context", "context")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
final int required = method.required();
final int optional = method.optional();
final boolean needsCallerFrame = method.needsCallerFrame();
final boolean alwaysInline = needsCallerFrame && context.getOptions().TRUFFLE_INLINE_NEEDS_CALLER_FRAME;
final boolean alwaysInline = needsCallerFrame && context.getOptions().INLINE_NEEDS_CALLER_FRAME;

final Arity arity = new Arity(required, optional, method.rest());

@@ -247,7 +247,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails

final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, sequence, method.unsupportedOperationBehavior());

return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode, false);
}

public void allMethodInstalled() {
22 changes: 9 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.StringCachingGuards;
import org.jruby.truffle.core.string.StringCachingGuards;
import org.jruby.truffle.language.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.language.arguments.ReadPreArgumentNode;
import org.jruby.truffle.language.arguments.RubyArguments;
@@ -2242,12 +2242,10 @@ public MaxBlock(RubyContext context) {

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "max", false, null, false, false, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
}), false));
}

public FrameDescriptor getFrameDescriptor() {
@@ -2362,12 +2360,10 @@ public MinBlock(RubyContext context) {

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "min", false, null, false, false, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
}), false));
}

public FrameDescriptor getFrameDescriptor() {
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
import org.jruby.truffle.core.UnaryCoreMethodNode;
import org.jruby.truffle.core.array.ArrayHelpers;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.language.objects.ThreadLocalObject;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.locals.ReadFrameSlotNode;
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@
import org.jruby.truffle.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.RubiniusOnly;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.util.ByteList;
@@ -61,8 +63,8 @@ public DynamicObject initialize(DynamicObject self, Object source, Object destin
int[] ecflags = {0};
IRubyObject[] ecopts = {runtime.getNil()};

final IRubyObject sourceAsJRubyObj = getContext().getJRubyInterop().toJRuby(source);
final IRubyObject destinationAsJRubyObj = getContext().getJRubyInterop().toJRuby(destination);
final IRubyObject sourceAsJRubyObj = toJRuby(source);
final IRubyObject destinationAsJRubyObj = toJRuby(destination);

EncodingUtils.econvArgs(runtime.getCurrentContext(), new IRubyObject[]{sourceAsJRubyObj, destinationAsJRubyObj}, encNames, encs, ecflags, ecopts);

@@ -112,6 +114,16 @@ private int rubiniusToJRubyFlags(int flags) {
return flags;
}

private IRubyObject toJRuby(Object object) {
if (RubyGuards.isRubyString(object)) {
return getContext().getJRubyRuntime().newString(StringOperations.rope((DynamicObject) object).toByteListCopy());
} else if (RubyGuards.isRubyEncoding(object)) {
return getContext().getJRubyRuntime().getEncodingService().rubyEncodingFromObject(getContext().getJRubyRuntime().newString(Layouts.ENCODING.getName((DynamicObject) object)));
} else {
throw new UnsupportedOperationException();
}
}

}

@RubiniusOnly
Original file line number Diff line number Diff line change
@@ -91,8 +91,8 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.StringCachingGuards;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.core.string.StringCachingGuards;
import org.jruby.truffle.language.objects.ThreadLocalObject;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.backtrace.Activation;
import org.jruby.truffle.language.backtrace.Backtrace;
@@ -1295,7 +1295,7 @@ public DynamicObject method(VirtualFrame frame, Object self, DynamicObject name)
final SharedMethodInfo info = methodMissing.getSharedMethodInfo().withName(normalizedName);

final RubyNode newBody = new CallMethodMissingWithStaticName(getContext(), info.getSourceSection(), name);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), new FrameDescriptor(nil()), info, newBody);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), new FrameDescriptor(nil()), info, newBody, false);
final CallTarget newCallTarget = Truffle.getRuntime().createCallTarget(newRootNode);

final DynamicObject module = getContext().getCoreLibrary().getMetaClass(self);
Original file line number Diff line number Diff line change
@@ -264,7 +264,7 @@ protected CallTarget method2proc(DynamicObject methodObject) {
final RootNode oldRootNode = ((RootCallTarget) method.getCallTarget()).getRootNode();

final SetReceiverNode setReceiverNode = new SetReceiverNode(getContext(), sourceSection, Layouts.METHOD.getReceiver(methodObject), method.getCallTarget());
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getSharedMethodInfo(), setReceiverNode);
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getSharedMethodInfo(), setReceiverNode, false);
return Truffle.getRuntime().createCallTarget(newRootNode);
}

Original file line number Diff line number Diff line change
@@ -432,7 +432,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = SequenceNode.sequence(getContext(), sourceSection, checkArity, accessInstanceVariable);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence, false);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, accessorName, module, visibility, callTarget);

@@ -1143,7 +1143,7 @@ private DynamicObject defineMethod(DynamicObject module, String name, DynamicObj

final RubyNode body = NodeUtil.cloneNode(rootNode.getBody());
final RubyNode newBody = new CallMethodWithProcBody(getContext(), info.getSourceSection(), Layouts.PROC.getDeclarationFrame(proc), body);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), rootNode.getFrameDescriptor(), info, newBody);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), rootNode.getFrameDescriptor(), info, newBody, false);
final CallTarget newCallTarget = Truffle.getRuntime().createCallTarget(newRootNode);

final InternalMethod method = InternalMethod.fromProc(info, name, module, Visibility.PUBLIC, proc, newCallTarget);
Original file line number Diff line number Diff line change
@@ -509,7 +509,7 @@ public int accept(DynamicObject io) {
final int newFd;

try {
newFd = nativeSockets().accept(fd, getMemoryManager().newPointer(address), addressLength);
newFd = nativeSockets().accept(fd, memoryManager().newPointer(address), addressLength);
} finally {
UnsafeHolder.U.freeMemory(address);
}
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ public DynamicObject malloc(DynamicObject pointerClass, int size) {
@SuppressWarnings("restriction")
@Specialization
public DynamicObject malloc(DynamicObject pointerClass, long size) {
return allocateObjectNode.allocate(pointerClass, getMemoryManager().newPointer(UnsafeHolder.U.allocateMemory(size)));
return allocateObjectNode.allocate(pointerClass, memoryManager().newPointer(UnsafeHolder.U.allocateMemory(size)));
}

}
@@ -108,7 +108,7 @@ public long setAddress(DynamicObject pointer, int address) {

@Specialization
public long setAddress(DynamicObject pointer, long address) {
Layouts.POINTER.setPointer(pointer, getMemoryManager().newPointer(address));
Layouts.POINTER.setPointer(pointer, memoryManager().newPointer(address));
return address;
}

@@ -131,7 +131,7 @@ public DynamicObject add(DynamicObject a, int b) {

@Specialization
public DynamicObject add(DynamicObject a, long b) {
return allocateObjectNode.allocate(Layouts.BASIC_OBJECT.getLogicalClass(a), getMemoryManager().newPointer(Layouts.POINTER.getPointer(a).address() + b));
return allocateObjectNode.allocate(Layouts.BASIC_OBJECT.getLogicalClass(a), memoryManager().newPointer(Layouts.POINTER.getPointer(a).address() + b));
}

}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyCallStack;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.language.objects.ThreadLocalObject;

public class RubiniusLastStringReadNode extends RubyNode {

Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyCallStack;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.language.objects.ThreadLocalObject;
import org.jruby.truffle.language.arguments.RubyArguments;

@NodeChild(value = "value", type = RubyNode.class)
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@
import org.jcodings.exception.EncodingException;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.cast.ArrayAttributeCastNodeGen;
@@ -91,6 +92,7 @@
import org.jruby.util.ConvertBytes;
import org.jruby.util.StringSupport;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -1405,12 +1407,29 @@ public Object stringToInum(DynamicObject string, int fixBase, boolean strict) {
fixBase,
strict);

return getContext().getJRubyInterop().toTruffle(result);
return toTruffle(result);
} catch (org.jruby.exceptions.RaiseException e) {
throw new RaiseException(getContext().getJRubyInterop().toTruffle(e.getException(), this));
}
}

private Object toTruffle(IRubyObject object) {
if (object instanceof org.jruby.RubyFixnum) {
final long value = ((org.jruby.RubyFixnum) object).getLongValue();

if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
return value;
}

return (int) value;
} else if (object instanceof org.jruby.RubyBignum) {
final BigInteger value = ((org.jruby.RubyBignum) object).getBigIntegerValue();
return Layouts.BIGNUM.createBignum(getContext().getCoreLibrary().getBignumFactory(), value);
} else {
throw new UnsupportedOperationException();
}
}

}

@RubiniusPrimitive(name = "string_byte_append")
Original file line number Diff line number Diff line change
@@ -8,11 +8,12 @@
* GNU Lesser General Public License version 2.1
*/

package org.jruby.truffle.language;
package org.jruby.truffle.core.string;

import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyGuards;

public abstract class StringCachingGuards {

Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.StringCachingGuards;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
Original file line number Diff line number Diff line change
@@ -148,13 +148,9 @@ protected DynamicObject createProc(VirtualFrame frame, DynamicObject symbol) {
sourceSection, null, Arity.AT_LEAST_ONE, Layouts.SYMBOL.getString(symbol),
true, ArgumentDescriptor.ANON_REST, false, false, false);

final RubyRootNode rootNode = new RubyRootNode(
getContext(), sourceSection,
new FrameDescriptor(nil()),
sharedMethodInfo,
SequenceNode.sequence(getContext(), sourceSection,
CheckArityNode.create(getContext(), sourceSection, Arity.AT_LEAST_ONE),
new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol))));
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, SequenceNode.sequence(getContext(), sourceSection,
CheckArityNode.create(getContext(), sourceSection, Arity.AT_LEAST_ONE),
new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol))), false);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = RubyArguments.getMethod(frame.getArguments());
55 changes: 12 additions & 43 deletions truffle/src/main/java/org/jruby/truffle/interop/JRubyInterop.java
Original file line number Diff line number Diff line change
@@ -31,61 +31,22 @@ public JRubyInterop(RubyContext context) {
this.context = context;
}

@CompilerDirectives.TruffleBoundary
public IRubyObject toJRuby(Object object) {
if (object == context.getCoreLibrary().getNilObject()) {
return context.getJRubyRuntime().getNil();
} else if (object instanceof Boolean) {
return context.getJRubyRuntime().newBoolean((boolean) object);
} else if (RubyGuards.isRubyString(object)) {
return toJRubyString((DynamicObject) object);
} else if (RubyGuards.isRubyEncoding(object)) {
return context.getJRubyRuntime().getEncodingService().rubyEncodingFromObject(context.getJRubyRuntime().newString(Layouts.ENCODING.getName((DynamicObject) object)));
} else {
throw new UnsupportedOperationException();
}
}

@CompilerDirectives.TruffleBoundary
public org.jruby.RubyString toJRubyString(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return context.getJRubyRuntime().newString(StringOperations.rope(string).toByteListCopy());
}

@CompilerDirectives.TruffleBoundary
public Object toTruffle(IRubyObject object) {
if (object instanceof org.jruby.RubyFixnum) {
final long value = ((org.jruby.RubyFixnum) object).getLongValue();

if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
return value;
}

return (int) value;
} else if (object instanceof org.jruby.RubyBignum) {
final BigInteger value = ((org.jruby.RubyBignum) object).getBigIntegerValue();
return Layouts.BIGNUM.createBignum(context.getCoreLibrary().getBignumFactory(), value);
} else if (object instanceof org.jruby.RubyString) {
return StringOperations.createString(context, ((org.jruby.RubyString) object).getByteList().dup());
} else {
throw new UnsupportedOperationException();
}
}

@CompilerDirectives.TruffleBoundary
public DynamicObject toTruffle(org.jruby.RubyException jrubyException, RubyNode currentNode) {
switch (jrubyException.getMetaClass().getName()) {
case "ArgumentError":
return context.getCoreLibrary().argumentError(jrubyException.getMessage().toString(), currentNode);
case "Encodcontext.ing::CompatibilityError":
return context.getCoreLibrary().encodingCompatibilityError(jrubyException.getMessage().toString(), currentNode);
case "RegexpError":
return context.getCoreLibrary().regexpError(jrubyException.getMessage().toString(), currentNode);
}

throw new UnsupportedOperationException();
}

public String getArg0() {
return context.getJRubyRuntime().getGlobalVariables().get("$0").toString();
}

public String[] getArgv() {
final IRubyObject[] jrubyStrings = ((org.jruby.RubyArray) context.getJRubyRuntime().getObject().getConstant("ARGV")).toJavaArray();
final String[] strings = new String[jrubyStrings.length];
@@ -118,4 +79,12 @@ public String[] getOriginalLoadPath() {
return loadPath.toArray(new String[loadPath.size()]);
}

public void setVerbose(boolean verbose) {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().newBoolean(verbose));
}

public void setVerboseNil() {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().getNil());
}

}
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.StringCachingGuards;
import org.jruby.truffle.core.string.StringCachingGuards;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ public class LazyRubyRootNode extends RootNode implements InternalRootNode {
@Child private Node findContextNode;
@Child private DirectCallNode callNode;

public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source, String[] argumentNames) {
public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source,
String[] argumentNames) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
this.source = source;
this.argumentNames = argumentNames;
@@ -55,7 +56,7 @@ public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescri
@Override
public Object execute(VirtualFrame frame) {
if (findContextNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
CompilerDirectives.transferToInterpreter();
findContextNode = insert(RubyLanguage.INSTANCE.unprotectedCreateFindContextNode());
}

@@ -73,14 +74,19 @@ public Object execute(VirtualFrame frame) {
final SourceSection sourceSection = (SourceSection) frame.getArguments()[getIndex("section")];
final DynamicObject block = (DynamicObject) frame.getArguments()[getIndex("block")];

final RootNode rootNode = new AttachmentsManager.AttachmentRootNode(RubyLanguage.class, cachedContext, sourceSection, null, block);
final RootNode rootNode = new AttachmentsManager.AttachmentRootNode(RubyLanguage.class, cachedContext,
sourceSection, null, block);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

callNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget));
callNode.forceInlining();
} else {
final TranslatorDriver translator = new TranslatorDriver(context);
final RubyRootNode rootNode = translator.parse(context, source, UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, argumentNames, null, true, null);

final RubyRootNode rootNode = translator.parse(context, source, UTF8Encoding.INSTANCE,
ParserContext.TOP_LEVEL, argumentNames, null, true, null);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

callNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget));
@@ -93,12 +99,14 @@ public Object execute(VirtualFrame frame) {
}

if (method == null) {
final MaterializedFrame callerFrame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();
final MaterializedFrame callerFrame = Truffle.getRuntime().getCallerFrame()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();

return callNode.call(frame, new Object[] { callerFrame });
}

return callNode.call(frame,
RubyArguments.pack(null, null, method, DeclarationContext.TOP_LEVEL, null, mainObject, null, frame.getArguments()));
return callNode.call(frame, RubyArguments.pack(null, null, method, DeclarationContext.TOP_LEVEL, null,
mainObject, null, frame.getArguments()));
}

private int getIndex(String name) {
80 changes: 41 additions & 39 deletions truffle/src/main/java/org/jruby/truffle/language/Options.java
Original file line number Diff line number Diff line change
@@ -9,70 +9,72 @@
*/
package org.jruby.truffle.language;

import static org.jruby.util.cli.Options.*;

public class Options {

// Features

public final boolean COVERAGE = org.jruby.util.cli.Options.TRUFFLE_COVERAGE.load();
public final boolean COVERAGE_GLOBAL = org.jruby.util.cli.Options.TRUFFLE_COVERAGE_GLOBAL.load();
public final boolean COVERAGE = TRUFFLE_COVERAGE.load();
public final boolean COVERAGE_GLOBAL = TRUFFLE_COVERAGE_GLOBAL.load();

// Resources

public final String CORE_LOAD_PATH = org.jruby.util.cli.Options.TRUFFLE_CORE_LOAD_PATH.load();
public final boolean PLATFORM_USE_JAVA = org.jruby.util.cli.Options.TRUFFLE_PLATFORM_USE_JAVA.load();
public final String CORE_LOAD_PATH = TRUFFLE_CORE_LOAD_PATH.load();
public final boolean PLATFORM_USE_JAVA = TRUFFLE_PLATFORM_USE_JAVA.load();

// Data structures

public final int ARRAY_UNINITIALIZED_SIZE = org.jruby.util.cli.Options.TRUFFLE_ARRAY_UNINITIALIZED_SIZE.load();
public final int ARRAY_SMALL = org.jruby.util.cli.Options.TRUFFLE_ARRAY_SMALL.load();
public final int ARRAY_UNINITIALIZED_SIZE = TRUFFLE_ARRAY_UNINITIALIZED_SIZE.load();
public final int ARRAY_SMALL = TRUFFLE_ARRAY_SMALL.load();

public final int HASH_PACKED_ARRAY_MAX = org.jruby.util.cli.Options.TRUFFLE_HASH_PACKED_ARRAY_MAX.load();
public final int HASH_PACKED_ARRAY_MAX = TRUFFLE_HASH_PACKED_ARRAY_MAX.load();

// Caches

public final int METHOD_LOOKUP_CACHE = org.jruby.util.cli.Options.TRUFFLE_METHOD_LOOKUP_CACHE.load();
public final int DISPATCH_CACHE = org.jruby.util.cli.Options.TRUFFLE_DISPATCH_CACHE.load();
public final int YIELD_CACHE = org.jruby.util.cli.Options.TRUFFLE_YIELD_CACHE.load();
public final int METHOD_TO_PROC_CACHE = org.jruby.util.cli.Options.TRUFFLE_METHOD_TO_PROC_CACHE.load();
public final int IS_A_CACHE = org.jruby.util.cli.Options.TRUFFLE_IS_A_CACHE.load();
public final int BIND_CACHE = org.jruby.util.cli.Options.TRUFFLE_BIND_CACHE.load();
public final int CONSTANT_CACHE = org.jruby.util.cli.Options.TRUFFLE_CONSTANT_CACHE.load();
public final int INSTANCE_VARIABLE_CACHE = org.jruby.util.cli.Options.TRUFFLE_INSTANCE_VARIABLE_CACHE.load();
public final int BINDING_LOCAL_VARIABLE_CACHE = org.jruby.util.cli.Options.TRUFFLE_BINDING_LOCAL_VARIABLE_CACHE.load();
public final int SYMBOL_TO_PROC_CACHE = org.jruby.util.cli.Options.TRUFFLE_SYMBOL_TO_PROC_CACHE.load();
public final int ALLOCATE_CLASS_CACHE = org.jruby.util.cli.Options.TRUFFLE_ALLOCATE_CLASS_CACHE.load();
public final int PACK_CACHE = org.jruby.util.cli.Options.TRUFFLE_PACK_CACHE.load();
public final int UNPACK_CACHE = org.jruby.util.cli.Options.TRUFFLE_UNPACK_CACHE.load();
public final int EVAL_CACHE = org.jruby.util.cli.Options.TRUFFLE_EVAL_CACHE.load();
public final int ENCODING_COMPATIBILE_QUERY_CACHE = org.jruby.util.cli.Options.TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE.load();
public final int METHOD_LOOKUP_CACHE = TRUFFLE_METHOD_LOOKUP_CACHE.load();
public final int DISPATCH_CACHE = TRUFFLE_DISPATCH_CACHE.load();
public final int YIELD_CACHE = TRUFFLE_YIELD_CACHE.load();
public final int METHOD_TO_PROC_CACHE = TRUFFLE_METHOD_TO_PROC_CACHE.load();
public final int IS_A_CACHE = TRUFFLE_IS_A_CACHE.load();
public final int BIND_CACHE = TRUFFLE_BIND_CACHE.load();
public final int CONSTANT_CACHE = TRUFFLE_CONSTANT_CACHE.load();
public final int INSTANCE_VARIABLE_CACHE = TRUFFLE_INSTANCE_VARIABLE_CACHE.load();
public final int BINDING_LOCAL_VARIABLE_CACHE = TRUFFLE_BINDING_LOCAL_VARIABLE_CACHE.load();
public final int SYMBOL_TO_PROC_CACHE = TRUFFLE_SYMBOL_TO_PROC_CACHE.load();
public final int ALLOCATE_CLASS_CACHE = TRUFFLE_ALLOCATE_CLASS_CACHE.load();
public final int PACK_CACHE = TRUFFLE_PACK_CACHE.load();
public final int UNPACK_CACHE = TRUFFLE_UNPACK_CACHE.load();
public final int EVAL_CACHE = TRUFFLE_EVAL_CACHE.load();
public final int ENCODING_COMPATIBILE_QUERY_CACHE = TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE.load();

// Cloning and inlining

public final boolean CORE_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_CORE_ALWAYS_CLONE.load();
public final boolean TRUFFLE_INLINE_NEEDS_CALLER_FRAME = org.jruby.util.cli.Options.TRUFFLE_INLINE_NEEDS_CALLER_FRAME.load();
public final boolean YIELD_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_YIELD_ALWAYS_CLONE.load();
public final boolean YIELD_ALWAYS_INLINE = org.jruby.util.cli.Options.TRUFFLE_YIELD_ALWAYS_INLINE.load();
public final boolean METHODMISSING_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_METHODMISSING_ALWAYS_CLONE.load();
public final boolean METHODMISSING_ALWAYS_INLINE = org.jruby.util.cli.Options.TRUFFLE_METHODMISSING_ALWAYS_INLINE.load();
public final boolean CORE_ALWAYS_CLONE = TRUFFLE_CORE_ALWAYS_CLONE.load();
public final boolean INLINE_NEEDS_CALLER_FRAME = TRUFFLE_INLINE_NEEDS_CALLER_FRAME.load();
public final boolean YIELD_ALWAYS_CLONE = TRUFFLE_YIELD_ALWAYS_CLONE.load();
public final boolean YIELD_ALWAYS_INLINE = TRUFFLE_YIELD_ALWAYS_INLINE.load();
public final boolean METHODMISSING_ALWAYS_CLONE = TRUFFLE_METHODMISSING_ALWAYS_CLONE.load();
public final boolean METHODMISSING_ALWAYS_INLINE = TRUFFLE_METHODMISSING_ALWAYS_INLINE.load();

// Other tuning parameteres

public final int PACK_UNROLL_LIMIT = org.jruby.util.cli.Options.TRUFFLE_PACK_UNROLL_LIMIT.load();
public final int PACK_RECOVER_LOOP_MIN = org.jruby.util.cli.Options.TRUFFLE_PACK_RECOVER_LOOP_MIN.load();
public final int PACK_UNROLL_LIMIT = TRUFFLE_PACK_UNROLL_LIMIT.load();
public final int PACK_RECOVER_LOOP_MIN = TRUFFLE_PACK_RECOVER_LOOP_MIN.load();

// Debugging

public final int INSTRUMENTATION_SERVER_PORT = org.jruby.util.cli.Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load();
public final boolean EXCEPTIONS_PRINT_JAVA = org.jruby.util.cli.Options.TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public final boolean EXCEPTIONS_PRINT_UNCAUGHT_JAVA = org.jruby.util.cli.Options.TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA.load();
public final boolean BACKTRACES_HIDE_CORE_FILES = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_HIDE_CORE_FILES.load();
public final int BACKTRACES_LIMIT = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_LIMIT.load();
public final boolean BACKTRACES_OMIT_UNUSED = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_OMIT_UNUSED.load();
public final boolean INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = org.jruby.util.cli.Options.TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC.load();
public final int INSTRUMENTATION_SERVER_PORT = TRUFFLE_INSTRUMENTATION_SERVER_PORT.load();
public final boolean EXCEPTIONS_PRINT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public final boolean EXCEPTIONS_PRINT_UNCAUGHT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA.load();
public final boolean BACKTRACES_HIDE_CORE_FILES = TRUFFLE_BACKTRACES_HIDE_CORE_FILES.load();
public final int BACKTRACES_LIMIT = TRUFFLE_BACKTRACES_LIMIT.load();
public final boolean BACKTRACES_OMIT_UNUSED = TRUFFLE_BACKTRACES_OMIT_UNUSED.load();
public final boolean INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC.load();

// Call graph

public final boolean CALL_GRAPH = org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH.load();
public final String CALL_GRAPH_WRITE = org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH_WRITE.load();
public final boolean CALL_GRAPH = TRUFFLE_CALL_GRAPH.load();
public final String CALL_GRAPH_WRITE = TRUFFLE_CALL_GRAPH_WRITE.load();

}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.objects.ThreadLocalObject;

public abstract class RubyGuards {

59 changes: 21 additions & 38 deletions truffle/src/main/java/org/jruby/truffle/language/RubyNode.java
Original file line number Diff line number Diff line change
@@ -34,12 +34,6 @@
public abstract class RubyNode extends Node {

private final RubyContext context;

// This field is a hack, used to transmit the information
// supplied by the JRuby parser in the form of a special
// node in the parse tree. The right thing to do is to
// add a special information node when the AST is constructed,
// which can then be removed.
private boolean atNewline = false;

public RubyNode(RubyContext context, SourceSection sourceSection) {
@@ -52,16 +46,14 @@ public RubyNode(RubyContext context, SourceSection sourceSection) {

public abstract Object execute(VirtualFrame frame);

public Object isDefined(VirtualFrame frame) {
return create7BitString("expression", UTF8Encoding.INSTANCE);
}

// Execute without returning the result

public void executeVoid(VirtualFrame frame) {
execute(frame);
}

public Object isDefined(VirtualFrame frame) {
return create7BitString("expression", UTF8Encoding.INSTANCE);
}

// Utility methods to execute and expect a particular type

public NotProvided executeNotProvided(VirtualFrame frame) throws UnexpectedResultException {
@@ -144,25 +136,28 @@ protected boolean isRubiniusUndefined(Object value) {
return value == getContext().getCoreLibrary().getRubiniusUndefined();
}

protected DynamicObjectFactory getInstanceFactory(DynamicObject rubyClass) {
return Layouts.CLASS.getInstanceFactory(rubyClass);
}

// Helpers methods for terseness

protected DynamicObject nil() {
return getContext().getCoreLibrary().getNilObject();
}

public DynamicObject getSymbol(String name) {
protected DynamicObject getSymbol(String name) {
return getContext().getSymbolTable().getSymbol(name);
}

public DynamicObject getSymbol(ByteList name) {
protected DynamicObject getSymbol(ByteList name) {
return getContext().getSymbolTable().getSymbol(name);
}

public DynamicObject getSymbol(Rope name) {
protected DynamicObject getSymbol(Rope name) {
return getContext().getSymbolTable().getSymbol(name);
}

/** Creates a String from the ByteList, with unknown CR */
protected DynamicObject createString(ByteList bytes) {
return StringOperations.createString(getContext(), bytes);
}
@@ -183,22 +178,16 @@ protected Sockets nativeSockets() {
return getContext().getNativePlatform().getSockets();
}

// Helper methods for caching

protected DynamicObjectFactory getInstanceFactory(DynamicObject rubyClass) {
return Layouts.CLASS.getInstanceFactory(rubyClass);
}

public void setAtNewline() {
atNewline = true;
protected MemoryManager memoryManager() {
return getContext().getNativePlatform().getMemoryManager();
}

public boolean isAtNewline() {
return atNewline;
protected Object ruby(String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, expression, arguments);
}

public RubyNode getNonProxyNode() {
return this;
protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, frame, expression, arguments);
}

// Accessors
@@ -207,18 +196,12 @@ public RubyContext getContext() {
return context;
}

public MemoryManager getMemoryManager() {
return jnr.ffi.Runtime.getSystemRuntime().getMemoryManager();
}

// ruby() helper

protected Object ruby(String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, expression, arguments);
public void setAtNewline() {
atNewline = true;
}

protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, frame, expression, arguments);
public boolean isAtNewline() {
return atNewline;
}

}
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ public String toString(DynamicObject object) {
} else if (RubyGuards.isRubyModule(object)) {
return Layouts.MODULE.getFields(object).toString();
} else {
return String.format("DynamicObject@%x<logicalClass=%s>", System.identityHashCode(object), Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName());
return String.format("DynamicObject@%x<logicalClass=%s>", System.identityHashCode(object),
Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName());
}
}

58 changes: 26 additions & 32 deletions truffle/src/main/java/org/jruby/truffle/language/RubyRootNode.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.language;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.ExecutionContext;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -20,36 +19,37 @@
import org.jruby.truffle.RubyLanguage;
import org.jruby.truffle.language.methods.SharedMethodInfo;

/**
* The root node in an AST for a method. Unlike {@link RubyNode}, this has a single entry point,
* {@link #execute}, which Truffle knows about and can create a {@link CallTarget} from.
*/
public class RubyRootNode extends RootNode {

private final RubyContext context;
private final SharedMethodInfo sharedMethodInfo;
@Child private RubyNode body;
private final boolean needsDeclarationFrame;

public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body) {
this(context, sourceSection, frameDescriptor, sharedMethodInfo, body, false);
}
@Child private RubyNode body;

public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body, boolean needsDeclarationFrame) {
public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor,
SharedMethodInfo sharedMethodInfo, RubyNode body, boolean needsDeclarationFrame) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
assert body != null;
this.context = context;
this.body = body;
this.sharedMethodInfo = sharedMethodInfo;
this.needsDeclarationFrame = needsDeclarationFrame;
this.body = body;

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(this);
}
}

public RubyRootNode withBody(RubyNode body) {
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, body, needsDeclarationFrame);
@Override
public Object execute(VirtualFrame frame) {
context.getSafepointManager().poll(this);
return body.execute(frame);
}

@Override
public ExecutionContext getExecutionContext() {
return context;
}

@Override
@@ -58,16 +58,26 @@ public boolean isCloningAllowed() {
}

@Override
public Object execute(VirtualFrame frame) {
context.getSafepointManager().poll(this);
return body.execute(frame);
public Node copy() {
final RubyRootNode cloned = (RubyRootNode) super.copy();

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(cloned);
}

return cloned;
}

@Override
public String toString() {
return sharedMethodInfo.toString();
}

public RubyRootNode withBody(RubyNode body) {
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, body,
needsDeclarationFrame);
}

public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}
@@ -76,24 +86,8 @@ public RubyNode getBody() {
return body;
}

@Override
public ExecutionContext getExecutionContext() {
return context;
}

public boolean needsDeclarationFrame() {
return needsDeclarationFrame;
}

@Override
public Node copy() {
final RubyRootNode cloned = (RubyRootNode) super.copy();

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(cloned);
}

return cloned;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.language.objects.ThreadLocalObject;

/**
* If a child node produces a {@link ThreadLocal}, get the value from it. If the value is not a {@code ThreadLocal},
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ThreadLocalObjectNode;
import org.jruby.truffle.language.objects.ThreadLocalObjectNode;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNodeGen;

Original file line number Diff line number Diff line change
@@ -9,10 +9,9 @@
*/
package org.jruby.truffle.language.globals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

@@ -26,15 +25,20 @@ public UpdateVerbosityNode(RubyContext context, SourceSection sourceSection, Rub
}

public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreter();

final Object childValue = child.execute(frame);

final IRubyObject jrubyValue = getContext().getJRubyInterop().toJRuby(childValue);

getContext().getJRubyRuntime().setVerbose(jrubyValue);

setVerbose(childValue);
return childValue;
}

@TruffleBoundary
private void setVerbose(Object childValue) {
if (childValue instanceof Boolean) {
getContext().getJRubyInterop().setVerbose((boolean) childValue);
} else if (childValue == nil()) {
getContext().getJRubyInterop().setVerboseNil();
} else {
throw new UnsupportedOperationException();
}
}

}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ThreadLocalObject;
import org.jruby.truffle.language.objects.ThreadLocalObject;

/**
* Wrap a child value in a new {@link ThreadLocal} so that a value can be stored in a location such as a frame without
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ public Object execute(TranslatorDriver.ParserContext parserContext, DeclarationC
}

public Object execute(final org.jruby.ast.RootNode rootNode) {
context.getCoreLibrary().getGlobalVariablesObject().define("$0", context.getJRubyInterop().toTruffle(context.getJRubyRuntime().getGlobalVariables().get("$0")), 0);
context.getCoreLibrary().getGlobalVariablesObject().define("$0", StringOperations.createString(context, ByteList.create(context.getJRubyInterop().getArg0())), 0);

String inputFile = rootNode.getPosition().getFile();
final Source source;
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.ShapeCachingGuards;

/**
* Reads the internal metaclass of an object.
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.ShapeCachingGuards;

@ImportStatic(ShapeCachingGuards.class)
public abstract class ReadHeadObjectFieldNode extends Node {
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
* GNU Lesser General Public License version 2.1
*/

package org.jruby.truffle.language;
package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.object.DynamicObject;
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.language;
package org.jruby.truffle.language.objects;

import org.jruby.truffle.RubyContext;

Original file line number Diff line number Diff line change
@@ -7,13 +7,14 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.language;
package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;

public class ThreadLocalObjectNode extends RubyNode {

Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.ShapeCachingGuards;

@ImportStatic(ShapeCachingGuards.class)
public abstract class WriteHeadObjectFieldNode extends Node {
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@
import org.jruby.truffle.language.LexicalScope;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.ThreadLocalObjectNode;
import org.jruby.truffle.language.objects.ThreadLocalObjectNode;
import org.jruby.truffle.language.arguments.ArrayIsAtLeastAsLargeAsNode;
import org.jruby.truffle.language.arguments.IsRubiniusUndefinedNode;
import org.jruby.truffle.language.constants.ReadConstantWithLexicalScopeNode;
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.platform;

import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import org.jruby.truffle.core.queue.ArrayBlockingQueueLocksConditions;
import org.jruby.truffle.core.queue.LinkedBlockingQueueLocksConditions;
@@ -18,6 +19,8 @@ public interface NativePlatform {

POSIX getPosix();

MemoryManager getMemoryManager();

SignalManager getSignalManager();

ProcessName getProcessName();
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
package org.jruby.truffle.platform.darwin;

import jnr.ffi.LibraryLoader;
import jnr.ffi.Runtime;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.jruby.truffle.RubyContext;
@@ -31,6 +33,7 @@
public class DarwinPlatform implements NativePlatform {

private final POSIX posix;
private final MemoryManager memoryManager;
private final SignalManager signalManager;
private final ProcessName processName;
private final Sockets sockets;
@@ -39,6 +42,7 @@ public class DarwinPlatform implements NativePlatform {

public DarwinPlatform(RubyContext context) {
posix = POSIXFactory.getNativePOSIX(new TrufflePOSIXHandler(context));
memoryManager = Runtime.getSystemRuntime().getMemoryManager();
signalManager = new SunMiscSignalManager();
processName = new DarwinProcessName();
sockets = LibraryLoader.create(Sockets.class).library("c").load();
@@ -53,6 +57,11 @@ public POSIX getPosix() {
return posix;
}

@Override
public MemoryManager getMemoryManager() {
return memoryManager;
}

@Override
public SignalManager getSignalManager() {
return signalManager;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.platform.java;

import jnr.ffi.Pointer;
import jnr.ffi.provider.InAccessibleMemoryIO;
import jnr.ffi.provider.MemoryManager;
import jnr.ffi.provider.NullMemoryIO;

import java.nio.ByteBuffer;

public class JavaMemoryManager implements MemoryManager {

@Override
public Pointer allocate(int size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateDirect(int size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateDirect(int size, boolean clear) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateTemporary(int size, boolean clear) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newPointer(ByteBuffer buffer) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newPointer(long address) {
if (address == 0) {
return new NullMemoryIO(null);
} else {
throw new UnsupportedOperationException();
}
}

@Override
public Pointer newPointer(long address, long size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newOpaquePointer(long address) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.platform.java;

import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.jruby.truffle.RubyContext;
@@ -30,6 +31,7 @@
public class JavaPlatform implements NativePlatform {

private final POSIX posix;
private final MemoryManager memoryManager;
private final SignalManager signalManager;
private final ProcessName processName;
private final Sockets sockets;
@@ -38,6 +40,7 @@ public class JavaPlatform implements NativePlatform {

public JavaPlatform(RubyContext context) {
posix = new TruffleJavaPOSIX(context, POSIXFactory.getJavaPOSIX(new TrufflePOSIXHandler(context)));
memoryManager = new JavaMemoryManager();
signalManager = new SunMiscSignalManager();
processName = new JavaProcessName();
sockets = new JavaSockets();
@@ -52,6 +55,11 @@ public POSIX getPosix() {
return posix;
}

@Override
public MemoryManager getMemoryManager() {
return memoryManager;
}

@Override
public SignalManager getSignalManager() {
return signalManager;
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
package org.jruby.truffle.platform.linux;

import jnr.ffi.LibraryLoader;
import jnr.ffi.Runtime;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.jruby.truffle.RubyContext;
@@ -31,6 +33,7 @@
public class LinuxPlatform implements NativePlatform {

private final POSIX posix;
private final MemoryManager memoryManager;
private final SignalManager signalManager;
private final ProcessName processName;
private final Sockets sockets;
@@ -39,6 +42,7 @@ public class LinuxPlatform implements NativePlatform {

public LinuxPlatform(RubyContext context) {
posix = POSIXFactory.getNativePOSIX(new TrufflePOSIXHandler(context));
memoryManager = Runtime.getSystemRuntime().getMemoryManager();
signalManager = new SunMiscSignalManager();
processName = new JavaProcessName();
sockets = LibraryLoader.create(Sockets.class).library("c").load();
@@ -53,6 +57,11 @@ public POSIX getPosix() {
return posix;
}

@Override
public MemoryManager getMemoryManager() {
return memoryManager;
}

@Override
public SignalManager getSignalManager() {
return signalManager;
31 changes: 15 additions & 16 deletions truffle/src/main/java/org/jruby/truffle/stdlib/BigDecimalNodes.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,6 @@
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.UnreachableCodeBranch;
import org.jruby.truffle.language.constants.ReadConstantNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
@@ -98,7 +97,7 @@ public static RoundingMode toRoundingMode(int constValue) {
case 7:
return RoundingMode.HALF_EVEN;
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -729,7 +728,7 @@ public Object negSpecial(VirtualFrame frame, DynamicObject value) {
case NAN:
return value;
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -797,7 +796,7 @@ protected Object multSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicO
return createBigDecimal(frame, Type.POSITIVE_INFINITY);
}
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -824,7 +823,7 @@ protected Object multSpecial(VirtualFrame frame, DynamicObject a, DynamicObject
return bType == Type.POSITIVE_INFINITY ? a : createBigDecimal(frame, (Type.POSITIVE_INFINITY));
}

throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -921,7 +920,7 @@ private Object divBigDecimalWithProfile(DynamicObject a, DynamicObject b, MathCo
case -1:
return Type.NEGATIVE_INFINITY;
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
} else {
return divBigDecimal(aBigDecimal, bBigDecimal, mathContext);
@@ -967,7 +966,7 @@ protected Object divNormalSpecial(VirtualFrame frame, DynamicObject a, DynamicOb
return createBigDecimal(frame, BigDecimal.ZERO);
}
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -1001,7 +1000,7 @@ protected Object divSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicOb
return createBigDecimal(frame, Type.POSITIVE_INFINITY);
}
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -1405,7 +1404,7 @@ public Object moduloSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b
return createBigDecimal(frame, a);
}

throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -1483,7 +1482,7 @@ public Object power(VirtualFrame frame, DynamicObject a, int exponent, Object un
case NEGATIVE_ZERO:
return createBigDecimal(frame, Integer.signum(exponent) == 1 ? BigDecimal.ZERO : Type.NAN);
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}
}
@@ -1544,7 +1543,7 @@ public Object sqrtSpecial(VirtualFrame frame, DynamicObject a, int precision) {
case NEGATIVE_ZERO:
return createBigDecimal(frame, sqrt(BigDecimal.ZERO, new MathContext(precision, getRoundMode(frame))));
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}
}
@@ -1749,7 +1748,7 @@ public int signSpecial(VirtualFrame frame, DynamicObject value) {
case NAN:
return sign.executeGetIntegerConstant(frame, getBigDecimalClass(), "SIGN_NaN");
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -1833,7 +1832,7 @@ public Object absSpecial(VirtualFrame frame, DynamicObject value) {
case NAN:
return createBigDecimal(frame, type);
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -1906,7 +1905,7 @@ public Object roundSpecial(VirtualFrame frame, DynamicObject value, NotProvided
throw new RaiseException(getContext().getCoreLibrary().
floatDomainError("Computation results to 'NaN'(Not a Number)", this));
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();

}
}
@@ -2017,7 +2016,7 @@ public double toFSpecial(DynamicObject value) {
case NAN:
return Double.NaN;
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}

@@ -2081,7 +2080,7 @@ public int toISpecial(DynamicObject value) {
case NEGATIVE_ZERO:
return 0;
default:
throw new UnreachableCodeBranch();
throw new UnsupportedOperationException();
}
}
}

0 comments on commit 38e1f20

Please sign in to comment.