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: 58e1df004520
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 80b37b082b7d
Choose a head ref
  • 8 commits
  • 8 files changed
  • 1 contributor

Commits on Apr 24, 2016

  1. Copy the full SHA
    bc84bb5 View commit details
  2. Copy the full SHA
    2d29bb9 View commit details
  3. Copy the full SHA
    00b9ff1 View commit details
  4. Copy the full SHA
    4af4d1b View commit details
  5. Copy the full SHA
    bd9078a View commit details
  6. Copy the full SHA
    6913f7a View commit details
  7. [Truffle] Use DebugHelpers.eval for the last few ruby() instances in …

    …Pysch, which are really tricky to remove.
    chrisseaton committed Apr 24, 2016
    Copy the full SHA
    929a542 View commit details
  8. [Truffle] Remove ruby()

    chrisseaton committed Apr 24, 2016
    Copy the full SHA
    80b37b0 View commit details
13 changes: 12 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -218,6 +218,7 @@ public class CoreLibrary {
private final DynamicObject atomicReferenceClass;
private final DynamicObject handleClass;
private final DynamicObjectFactory handleFactory;
private final DynamicObject ioClass;

private final DynamicObject argv;
private final GlobalVariables globalVariables;
@@ -226,6 +227,8 @@ public class CoreLibrary {
private final DynamicObject rubiniusUndefined;
private final DynamicObject digestClass;

@CompilationFinal private DynamicObject eagainWaitReadable;

@CompilationFinal private ArrayNodes.MinBlock arrayMinBlock;
@CompilationFinal private ArrayNodes.MaxBlock arrayMaxBlock;

@@ -318,6 +321,10 @@ public DynamicObject getSystemCallErrorClass() {
return systemCallErrorClass;
}

public DynamicObject getEagainWaitReadable() {
return eagainWaitReadable;
}

private enum State {
INITIALIZING,
LOADING_RUBY_CORE,
@@ -529,7 +536,7 @@ public CoreLibrary(RubyContext context) {
unboundMethodClass = defineClass("UnboundMethod");
unboundMethodFactory = Layouts.UNBOUND_METHOD.createUnboundMethodShape(unboundMethodClass, unboundMethodClass);
Layouts.CLASS.setInstanceFactoryUnsafe(unboundMethodClass, unboundMethodFactory);
final DynamicObject ioClass = defineClass("IO");
ioClass = defineClass("IO");
Layouts.CLASS.setInstanceFactoryUnsafe(ioClass, Layouts.IO.createIOShape(ioClass, ioClass));
internalBufferClass = defineClass(ioClass, objectClass, "InternalBuffer");
Layouts.CLASS.setInstanceFactoryUnsafe(internalBufferClass, Layouts.IO_BUFFER.createIOBufferShape(internalBufferClass, internalBufferClass));
@@ -858,6 +865,10 @@ public void initializeAfterBasicMethodsAdded() {
} finally {
state = State.LOADED;
}

// Get some references to things defined in the Ruby core

eagainWaitReadable = (DynamicObject) Layouts.MODULE.getFields(ioClass).getConstant("EAGAINWaitReadable").getValue();
}

private void initializeRubiniusFFI() {
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@
import jnr.constants.platform.Fcntl;
import jnr.posix.DefaultNativeTimeval;
import jnr.posix.Timeval;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.array.ArrayOperations;
@@ -263,8 +264,10 @@ public Object readIfAvailable(DynamicObject file, int numberOfBytes) {
PointerPrimitiveNodes.NULL_POINTER, PointerPrimitiveNodes.NULL_POINTER, timeoutObject));

if (res == 0) {
CompilerDirectives.transferToInterpreter();
ruby("raise IO::EAGAINWaitReadable");
throw new RaiseException(
Layouts.CLASS.getInstanceFactory(coreLibrary().getEagainWaitReadable()).newInstance(
coreStrings().RESOURCE_TEMP_UNAVAIL.createInstance(),
Errno.EAGAIN.intValue()));
}

final byte[] bytes = new byte[numberOfBytes];
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ public class CoreStrings {
public final CoreString ONE_HASH_REQUIRED;
public final CoreString OUT_OF_RANGE;
public final CoreString PROC_WITHOUT_BLOCK;
public final CoreString RESOURCE_TEMP_UNAVAIL;
public final CoreString UNKNOWN;
public final CoreString SELF;
public final CoreString TIME_INTERVAL_MUST_BE_POS;
@@ -59,6 +60,7 @@ public CoreStrings(RubyContext context) {
ONE_HASH_REQUIRED = new CoreString(context, "one hash required");
OUT_OF_RANGE = new CoreString(context, "out of range");
PROC_WITHOUT_BLOCK = new CoreString(context, "tried to create Proc object without a block");
RESOURCE_TEMP_UNAVAIL = new CoreString(context, "Resource temporarily unavailable");
UNKNOWN = new CoreString(context, "(unknown)");
SELF = new CoreString(context, "self");
TIME_INTERVAL_MUST_BE_POS = new CoreString(context, "time interval must be positive");
10 changes: 8 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/debug/DebugHelpers.java
Original file line number Diff line number Diff line change
@@ -9,17 +9,23 @@
*/
package org.jruby.truffle.debug;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import org.jruby.truffle.RubyContext;

public abstract class DebugHelpers {

public static Object eval(String code) {
public static Object eval(String code, Object... arguments) {
return eval(RubyContext.getLatestInstance(), code, arguments);
}

public static Object eval(RubyContext context, String code, Object... arguments) {
CompilerAsserts.neverPartOfCompilation();
final FrameInstance currentFrameInstance = Truffle.getRuntime().getCurrentFrame();
final Frame currentFrame = currentFrameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true);
return RubyContext.getLatestInstance().getCodeLoader().inline(null, currentFrame, code);
return context.getCodeLoader().inline(null, currentFrame, code, arguments);
}

}
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.CoreStrings;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.debug.DebugHelpers;
import org.jruby.truffle.extra.AttachmentsManager;
import org.jruby.truffle.platform.posix.Sockets;
import org.jruby.truffle.platform.posix.TrufflePosix;
@@ -118,10 +119,6 @@ protected MemoryManager memoryManager() {
return getContext().getNativePlatform().getMemoryManager();
}

protected Object ruby(String expression, Object... arguments) {
return getContext().getCodeLoader().inline(this, expression, arguments);
}

// Accessors

public RubyContext getContext() {
Original file line number Diff line number Diff line change
@@ -2011,10 +2011,17 @@ public BigDecimal doBigDecimal(DynamicObject value, Object roundingMode) {
}

@Specialization(guards = { "!isRubyBignum(value)", "!isRubyBigDecimal(value)" })
public Object doOther(VirtualFrame frame, DynamicObject value, Object roundingMode) {
if (roundingMode instanceof RoundingMode && (boolean) ruby("value.is_a?(Rational)", "value", value)) {
public Object doOther(
VirtualFrame frame,
DynamicObject value,
Object roundingMode,
@Cached("new()") SnippetNode isRationalSnippet,
@Cached("createMethodCall()") CallDispatchHeadNode numeratorCallNode,
@Cached("createMethodCall()") CallDispatchHeadNode denominatorCallNode,
@Cached("createMethodCall()") CallDispatchHeadNode toFCallNode) {
if (roundingMode instanceof RoundingMode && (boolean) isRationalSnippet.execute(frame, "value.is_a?(Rational)", "value", value)) {

final Object numerator = ruby("value.numerator", "value", value);
final Object numerator = numeratorCallNode.call(frame, value, "numerator", null);

final IRubyObject numeratorValue;

@@ -2028,7 +2035,7 @@ public Object doOther(VirtualFrame frame, DynamicObject value, Object roundingMo
throw new UnsupportedOperationException(numerator.toString());
}

final Object denominator = ruby("value.denominator", "value", value);
final Object denominator = denominatorCallNode.call(frame, value, "denominator", null);

final IRubyObject denominatorValue;

@@ -2055,7 +2062,7 @@ public Object doOther(VirtualFrame frame, DynamicObject value, Object roundingMo

return rubyBigDecimalValue.getBigDecimalValue();
} else {
final Object result = ruby("value.to_f", "value", value);
final Object result = toFCallNode.call(frame, value, "to_f", null);
if (result != nil()) {
return new BigDecimal((double) result);
} else {
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@
package org.jruby.truffle.stdlib.psych;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.Encoding;
@@ -52,6 +54,7 @@
import org.jruby.truffle.core.adapaters.OutputStreamAdapter;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;
import org.yaml.snakeyaml.DumperOptions;
@@ -105,23 +108,25 @@ public DynamicObject initialize(DynamicObject emitter, DynamicObject io, NotProv
final DumperOptions options = new DumperOptions();
options.setIndent(2);
Layouts.PSYCH_EMITTER.setOptions(emitter, options);

Layouts.PSYCH_EMITTER.setIo(emitter, io);

return nil();
}

@CompilerDirectives.TruffleBoundary
@Specialization
public DynamicObject initialize(DynamicObject emitter, DynamicObject io, DynamicObject optionsSet) {
public DynamicObject initialize(
VirtualFrame frame,
DynamicObject emitter,
DynamicObject io,
DynamicObject optionsSet,
@Cached("createMethodCall()") CallDispatchHeadNode lineWidthCallNode,
@Cached("createMethodCall()") CallDispatchHeadNode canonicalCallNode,
@Cached("createMethodCall()") CallDispatchHeadNode indentationCallNode) {
final DumperOptions options = new DumperOptions();
options.setWidth((int) ruby("options_set.line_width", "options_set", optionsSet));
options.setCanonical((boolean) ruby("options_set.canonical", "options_set", optionsSet));
options.setIndent((int) ruby("options_set.indentation", "options_set", optionsSet));
options.setWidth((int) lineWidthCallNode.call(frame, optionsSet, "line_width", null));
options.setCanonical((boolean) canonicalCallNode.call(frame, optionsSet, "canonical", null));
options.setIndent((int) indentationCallNode.call(frame, optionsSet, "indentation", null));
Layouts.PSYCH_EMITTER.setOptions(emitter, options);

Layouts.PSYCH_EMITTER.setIo(emitter, io);

return nil();
}

Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@
import org.jruby.truffle.core.cast.ToStrNode;
import org.jruby.truffle.core.cast.ToStrNodeGen;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.debug.DebugHelpers;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.objects.AllocateObjectNode;
@@ -144,15 +145,15 @@ public Object parse(VirtualFrame frame, DynamicObject parserObject, DynamicObjec

@TruffleBoundary
private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicObject path, StreamReader streamReader) {
boolean tainted = (boolean) ruby("yaml.tainted? || yaml.is_a?(IO)", "yaml", yaml);
boolean tainted = (boolean) DebugHelpers.eval(getContext(), "yaml.tainted? || yaml.is_a?(IO)", "yaml", yaml);

Parser parser = new ParserImpl(streamReader);
try {
if (isNil(path) && (boolean) ruby("yaml.respond_to? :path", "yaml", yaml)) {
path = (DynamicObject) ruby("yaml.path", "yaml", yaml);
if (isNil(path) && (boolean) DebugHelpers.eval(getContext(), "yaml.respond_to? :path", "yaml", yaml)) {
path = (DynamicObject) DebugHelpers.eval(getContext(), "yaml.path", "yaml", yaml);
}

Object handler = getInstanceVariable("@handler");
Object handler = DebugHelpers.eval(getContext(), "@handler");

while (true) {
Event event = parser.getEvent();
@@ -204,7 +205,7 @@ private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicOb

private StreamReader readerFor(VirtualFrame frame, DynamicObject yaml) {
// fall back on IOInputStream, using default charset
if (!RubyGuards.isRubyString(yaml) && (boolean) ruby("yaml.respond_to? :read", "yaml", yaml)) {
if (!RubyGuards.isRubyString(yaml) && (boolean) DebugHelpers.eval(getContext(), "yaml.respond_to? :read", "yaml", yaml)) {
//final boolean isIO = (boolean) ruby("yaml.is_a? IO", "yaml", yaml);
//Encoding enc = isIO
// ? UTF8Encoding.INSTANCE // ((RubyIO)yaml).getReadEncoding()
@@ -247,7 +248,7 @@ private void handleDocumentStart(DocumentStartEvent dse, boolean tainted, Object
for (Map.Entry<String, String> tag : tagsMap.entrySet()) {
Object key = stringFor(tag.getKey(), tainted);
Object value = stringFor(tag.getValue(), tainted);
ruby("tags.push [key, value]", "tags", tags, "key", key, "value", value);
DebugHelpers.eval(getContext(), "tags.push [key, value]", "tags", tags, "key", key, "value", value);
}
}
Object notExplicit = !dse.getExplicit();
@@ -286,30 +287,19 @@ private void handleSequenceStart(SequenceStartEvent sse, boolean tainted, Object
}

private void raiseParserException(DynamicObject yaml, ReaderException re, DynamicObject rbPath) {
ruby("raise Psych::SyntaxError.new(file, line, col, offset, problem, context)",
"file", rbPath,
"line", 0,
"col", 0,
"offset", re.getPosition(),
"problem", re.getName() == null ? nil() : createString(new ByteList(re.getName().getBytes(StandardCharsets.UTF_8))),
"context", re.toString() == null ? nil() : createString(new ByteList(re.toString().getBytes(StandardCharsets.UTF_8))));
Object[] arguments = new Object[]{"file", rbPath, "line", 0, "col", 0, "offset", re.getPosition(), "problem", re.getName() == null ? nil() : createString(new ByteList(re.getName().getBytes(StandardCharsets.UTF_8))), "context", re.toString() == null ? nil() : createString(new ByteList(re.toString().getBytes(StandardCharsets.UTF_8)))};
DebugHelpers.eval(getContext(), "raise Psych::SyntaxError.new(file, line, col, offset, problem, context)", arguments);
}

private void raiseParserException(DynamicObject yaml, MarkedYAMLException mye, DynamicObject rbPath) {
final Mark mark = mye.getProblemMark();

ruby("raise Psych::SyntaxError.new(file, line, col, offset, problem, context)",
"file", rbPath,
"line", mark.getLine(),
"col", mark.getColumn(),
"offset", mark.getIndex(),
"problem", mye.getProblem() == null ? nil() : createString(new ByteList(mye.getProblem().getBytes(StandardCharsets.UTF_8))),
"context", mye.getContext() == null ? nil() : createString(new ByteList(mye.getContext().getBytes(StandardCharsets.UTF_8))));
Object[] arguments = new Object[]{"file", rbPath, "line", mark.getLine(), "col", mark.getColumn(), "offset", mark.getIndex(), "problem", mye.getProblem() == null ? nil() : createString(new ByteList(mye.getProblem().getBytes(StandardCharsets.UTF_8))), "context", mye.getContext() == null ? nil() : createString(new ByteList(mye.getContext().getBytes(StandardCharsets.UTF_8)))};
DebugHelpers.eval(getContext(), "raise Psych::SyntaxError.new(file, line, col, offset, problem, context)", arguments);
}

private Object invoke(Object receiver, String name, Object... args) {
return ruby("receiver.send(name, *args)", "receiver", receiver, "name", getSymbol(name),
"args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
return DebugHelpers.eval(getContext(), "receiver.send(name, *args)", "receiver", receiver, "name", getSymbol(name), "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

private static int translateStyle(Character style) {
@@ -361,16 +351,12 @@ private Object stringFor(String value, boolean tainted) {
Object string = createString(bytes);

if (tainted) {
ruby("string.taint", "string", string);
DebugHelpers.eval(getContext(), "string.taint", "string", string);
}

return string;
}

private Object getInstanceVariable(String name) {
return ruby(name);
}

}

}