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: 4f73123c195d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bb48a413cc28
Choose a head ref
  • 9 commits
  • 11 files changed
  • 1 contributor

Commits on Mar 4, 2015

  1. Copy the full SHA
    735f42e View commit details
  2. Copy the full SHA
    d7efedd View commit details
  3. Copy the full SHA
    ada9180 View commit details
  4. Copy the full SHA
    e4ba135 View commit details
  5. Copy the full SHA
    dfefad0 View commit details
  6. Copy the full SHA
    39e25ed View commit details
  7. Copy the full SHA
    394df3d View commit details
  8. Copy the full SHA
    a29dda4 View commit details
  9. Copy the full SHA
    bb48a41 View commit details
Original file line number Diff line number Diff line change
@@ -294,8 +294,6 @@ public Object getPackedArray(VirtualFrame frame, RubyHash hash, Object key) {

@Specialization(guards = "isBuckets")
public Object getBuckets(VirtualFrame frame, RubyHash hash, Object key) {
notDesignedForCompilation();

final HashSearchResult hashSearchResult = findEntryNode.search(frame, hash, key);

if (hashSearchResult.getEntry() != null) {
Original file line number Diff line number Diff line change
@@ -1945,10 +1945,9 @@ public SPrintfNode(SPrintfNode prev) {
super(prev);
}

@TruffleBoundary
@Specialization
public RubyString sprintf(Object[] args) {
notDesignedForCompilation();

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

final PrintStream printStream;
25 changes: 14 additions & 11 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -37,9 +37,7 @@
import org.jruby.truffle.nodes.methods.arguments.CheckArityNode;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.methods.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.objects.ReadInstanceVariableNode;
import org.jruby.truffle.nodes.objects.SelfNode;
import org.jruby.truffle.nodes.objects.WriteInstanceVariableNode;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -61,26 +59,31 @@ public abstract class ModuleNodes {
@CoreMethod(names = "===", required = 1)
public abstract static class ContainsInstanceNode extends CoreMethodNode {

@Child private MetaClassNode metaClassNode;

public ContainsInstanceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
metaClassNode = MetaClassNodeFactory.create(context, sourceSection, null);
}

public ContainsInstanceNode(ContainsInstanceNode prev) {
super(prev);
metaClassNode = prev.metaClassNode;
}

@Specialization
public boolean containsInstance(RubyModule module, RubyBasicObject instance) {
notDesignedForCompilation();

return ModuleOperations.includesModule(instance.getMetaClass(), module);
return includes(instance.getMetaClass(), module);
}

@Specialization
public boolean containsInstance(RubyModule module, Object instance) {
notDesignedForCompilation();

return ModuleOperations.includesModule(getContext().getCoreLibrary().getMetaClass(instance), module);
@Specialization(guards = "!isRubyBasicObject(arguments[1])")
public boolean containsInstance(VirtualFrame frame, RubyModule module, Object instance) {
return includes(metaClassNode.executeMetaClass(frame, instance), module);
}

@CompilerDirectives.TruffleBoundary
public boolean includes(RubyModule metaClass, RubyModule module) {
return ModuleOperations.includesModule(metaClass, module);
}
}

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

import com.oracle.truffle.api.CompilerDirectives;
import org.jruby.truffle.runtime.RubyContext;

import com.oracle.truffle.api.dsl.Specialization;
@@ -52,6 +53,7 @@ public RubyBignum pow(RubyBignum a, long b) {
}
}

@CompilerDirectives.TruffleBoundary
@Specialization
public double pow(RubyBignum a, double b) {
return Math.pow(a.bigIntegerValue().doubleValue(), b);
Original file line number Diff line number Diff line change
@@ -148,9 +148,15 @@ public Object pow(long a, long b) {
return null; // Primitive failure
} else {
// TODO CS 15-Feb-15 - what to do about this cast?
return fixnumOrBignum(BigInteger.valueOf(a).pow((int) b));
return fixnumOrBignum(bigPow(a, (int) b));
}
}

@CompilerDirectives.TruffleBoundary
public BigInteger bigPow(long a, int b) {
return BigInteger.valueOf(a).pow(b);

}

@Specialization
public Object pow(long a, double b) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2015 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.nodes.rubinius;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.ReturnException;

public class InvokeRubiniusPrimitiveNode extends RubyNode {

@Child private RubyNode primitive;

private final ConditionProfile primitiveSucceededCondition = ConditionProfile.createBinaryProfile();

public InvokeRubiniusPrimitiveNode(RubyContext context, SourceSection sourceSection, RubyNode primitive) {
super(context, sourceSection);
this.primitive = primitive;
}

@Override
public void executeVoid(VirtualFrame frame) {
}

@Override
public Object execute(VirtualFrame frame) {
final Object value = primitive.execute(frame);

if (primitiveSucceededCondition.profile(value != null)) {
// If the primitive didn't fail its value is produced

return value;
}

// Primitives may return null to indicate that they have failed, in which case we continue with the fallback

return getContext().getCoreLibrary().getNilObject();
}

}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.joda.time.DateTimeZone;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.nodes.time.ReadTimeZoneNode;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -33,20 +34,27 @@ public abstract class TimePrimitiveNodes {
@RubiniusPrimitive(name = "time_s_now")
public static abstract class TimeSNowPrimitiveNode extends RubiniusPrimitiveNode {

@Child private ReadTimeZoneNode readTimeZoneNode;

public TimeSNowPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
}

public TimeSNowPrimitiveNode(TimeSNowPrimitiveNode prev) {
super(prev);
readTimeZoneNode = prev.readTimeZoneNode;
}

@Specialization
public RubyTime timeSNow(RubyClass timeClass) {
// TODO CS 14-Feb-15 uses debug send
final DateTimeZone zone = org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(),
DebugOperations.send(getContext(), getContext().getCoreLibrary().getENV(), "[]", null, getContext().makeString("TZ")).toString());
return new RubyTime(timeClass, DateTime.now(zone), null);
public RubyTime timeSNow(VirtualFrame frame, RubyClass timeClass) {
// TODO CS 4-Mar-15 whenever we get time we have to convert lookup and time zone to a string and look it up - need to cache somehow...
return new RubyTime(timeClass, now(readTimeZoneNode.executeRubyString(frame)), null);
}

@CompilerDirectives.TruffleBoundary
private DateTime now(RubyString timeZone) {
return DateTime.now(org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
}

}
@@ -73,12 +81,16 @@ public RubyTime timeSDup(RubyTime other) {
@RubiniusPrimitive(name = "time_s_specific", needsSelf = false)
public static abstract class TimeSSpecificPrimitiveNode extends RubiniusPrimitiveNode {

@Child private ReadTimeZoneNode readTimeZoneNode;

public TimeSSpecificPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
}

public TimeSSpecificPrimitiveNode(TimeSSpecificPrimitiveNode prev) {
super(prev);
readTimeZoneNode = prev.readTimeZoneNode;
}

@Specialization(guards = "isTrue(arguments[2])")
@@ -90,22 +102,29 @@ public RubyTime timeSSpecificUTC(long seconds, long nanoseconds, boolean isUTC,
public RubyTime timeSSpecificUTC(int seconds, int nanoseconds, boolean isUTC, RubyNilClass offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = seconds * 1_000L + (nanoseconds / 1_000_000);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), new DateTime(milliseconds, DateTimeZone.UTC), null);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds), null);
}

@Specialization(guards = "!isTrue(arguments[2])")
public RubyTime timeSSpecific(long seconds, long nanoseconds, boolean isUTC, RubyNilClass offset) {
return timeSSpecific((int) seconds, (int) nanoseconds, isUTC, offset);
public RubyTime timeSSpecific(VirtualFrame frame, long seconds, long nanoseconds, boolean isUTC, RubyNilClass offset) {
return timeSSpecific(frame, (int) seconds, (int) nanoseconds, isUTC, offset);
}

@Specialization(guards = "!isTrue(arguments[2])")
public RubyTime timeSSpecific(int seconds, int nanoseconds, boolean isUTC, RubyNilClass offset) {
// TODO CS 14-Feb-15 uses debug send
final DateTimeZone zone = org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(),
DebugOperations.send(getContext(), getContext().getCoreLibrary().getENV(), "[]", null, getContext().makeString("TZ")).toString());
public RubyTime timeSSpecific(VirtualFrame frame, int seconds, int nanoseconds, boolean isUTC, RubyNilClass offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = (long) seconds * 1_000 + ((long) nanoseconds / 1_000_000);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), new DateTime(milliseconds, zone), null);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds, readTimeZoneNode.executeRubyString(frame)), null);
}

@CompilerDirectives.TruffleBoundary
public DateTime time(long milliseconds) {
return new DateTime(milliseconds, DateTimeZone.UTC);
}

@CompilerDirectives.TruffleBoundary
private DateTime time(long milliseconds, RubyString timeZone) {
return new DateTime(milliseconds, org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2015 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.nodes.time;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyString;

public class ReadTimeZoneNode extends RubyNode {

@Child private CallDispatchHeadNode hashNode;

private final RubyString TZ;

public ReadTimeZoneNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
hashNode = DispatchHeadNodeFactory.createMethodCall(context);
TZ = getContext().makeString("TZ");
}

@Override
public RubyString executeRubyString(VirtualFrame frame) {
// TODO CS 4-Mar-15 cast
return (RubyString) hashNode.call(frame, getContext().getCoreLibrary().getENV(), "[]", null, TZ);
}

@Override
public Object execute(VirtualFrame frame) {
return executeRubyString(frame);
}
}
Original file line number Diff line number Diff line change
@@ -99,6 +99,12 @@ public static void panic(RubyContext context, Node currentNode, String message)
System.exit(1);
}

public static void printBacktrace(RubyContext context, Node currentNode) {
for (String line : Backtrace.DISPLAY_FORMATTER.format(context, null, RubyCallStack.getBacktrace(currentNode))) {
System.err.println(line);
}
}

public static void printASTBacktrace(final Node currentNode) {
if (currentNode != null) {
printMethodASTBacktrace(currentNode);
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.objects.SelfNode;
import org.jruby.truffle.nodes.rubinius.CallRubiniusPrimitiveNode;
import org.jruby.truffle.nodes.rubinius.InvokeRubiniusPrimitiveNode;
import org.jruby.truffle.nodes.rubinius.RubiniusPrimitiveConstructor;
import org.jruby.truffle.nodes.rubinius.RubiniusSingleBlockArgNode;
import org.jruby.truffle.nodes.yield.YieldNode;
@@ -466,8 +467,8 @@ private RubyNode translateRubiniusInvokePrimitive(SourceSection sourceSection, C
while (childIterator.hasNext()) {
arguments.add(childIterator.next().accept(this));
}

return new CallRubiniusPrimitiveNode(context, sourceSection,
return new InvokeRubiniusPrimitiveNode(context, sourceSection,
primitive.getFactory().createNode(context, sourceSection, arguments.toArray(new RubyNode[arguments.size()])),
environment.getReturnID());
}
7 changes: 3 additions & 4 deletions truffle/src/main/ruby/core/truffle/truffle.rb
Original file line number Diff line number Diff line change
@@ -11,19 +11,18 @@
# runtime test for the program running in Truffle mode.
module Truffle

# What is the version of Truffle/Graal being used?
# The version of Truffle and Graal in use.
# @return [String] a version string such as `"0.6"`, or `"undefined"` if running on a non-Graal JVM.
def self.version
Primitive.graal_version
end

# Are we currently running on a Graal VM? If this returns false you are
# running on a conventional JVM and performance will be much lower.
# Tests if the program is using the Graal VM.
def self.graal?
Primitive.graal?
end

# Is this VM built on the SubstrateVM?
# Tests if this VM is a SubstrateVM build.
def self.substrate?
Primitive.substrate?
end