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: 30b4387996af
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 87f52a3fed8c
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 28, 2015

  1. Copy the full SHA
    db649ae View commit details
  2. Merge branch 'master' of github.com:jruby/jruby

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
    chrisseaton committed Sep 28, 2015
    Copy the full SHA
    87f52a3 View commit details
Original file line number Diff line number Diff line change
@@ -78,17 +78,16 @@ public abstract class StringNodes {
@CoreMethod(names = "allocate", constructor = true)
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {

@Child private AllocateObjectNode allocateNode;
@Child private AllocateObjectNode allocateObjectNode;

public AllocateNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return allocateNode.allocate(rubyClass, new ByteList(), StringSupport.CR_UNKNOWN, null);
return allocateObjectNode.allocate(rubyClass, new ByteList(), StringSupport.CR_UNKNOWN, null);
}

}
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -30,10 +32,6 @@ public static DateTime getDateTime(DynamicObject time) {
return Layouts.TIME.getDateTime(time);
}

public static DynamicObject createRubyTime(DynamicObject timeClass, DateTime dateTime, Object offset) {
return Layouts.TIME.createTime(Layouts.CLASS.getInstanceFactory(timeClass), dateTime, offset);
}

// We need it to copy the internal data for a call to Kernel#clone.
@CoreMethod(names = "initialize_copy", required = 1)
public abstract static class InitializeCopyNode extends CoreMethodArrayArgumentsNode {
@@ -126,13 +124,16 @@ public Object internalSetOffset(DynamicObject time, Object offset) {
@CoreMethod(names = "allocate", constructor = true)
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {

@Child private AllocateObjectNode allocateObjectNode;

public AllocateNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return createRubyTime(rubyClass, ZERO, getContext().getCoreLibrary().getNilObject());
return allocateObjectNode.allocate(rubyClass, ZERO, getContext().getCoreLibrary().getNilObject());
}

}
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@
import org.jruby.RubyString;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.core.TimeNodes;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.nodes.time.ReadTimeZoneNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -37,17 +39,19 @@ public abstract class TimePrimitiveNodes {
@RubiniusPrimitive(name = "time_s_now")
public static abstract class TimeSNowPrimitiveNode extends RubiniusPrimitiveNode {

@Child private AllocateObjectNode allocateObjectNode;
@Child private ReadTimeZoneNode readTimeZoneNode;

public TimeSNowPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
}

@Specialization
public DynamicObject timeSNow(VirtualFrame frame, DynamicObject 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 TimeNodes.createRubyTime(timeClass, now((DynamicObject) readTimeZoneNode.execute(frame)), nil());
return allocateObjectNode.allocate(timeClass, now((DynamicObject) readTimeZoneNode.execute(frame)), nil());
}

@TruffleBoundary
@@ -61,14 +65,16 @@ private DateTime now(DynamicObject timeZone) {
@RubiniusPrimitive(name = "time_s_dup", needsSelf = false)
public static abstract class TimeSDupPrimitiveNode extends RubiniusPrimitiveNode {

@Child private AllocateObjectNode allocateObjectNode;

public TimeSDupPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
public DynamicObject timeSDup(DynamicObject other) {
final DynamicObject time = TimeNodes.createRubyTime(getContext().getCoreLibrary().getTimeClass(), TimeNodes.getDateTime(other), Layouts.TIME.getOffset(other));
return time;
return allocateObjectNode.allocate(Layouts.BASIC_OBJECT.getLogicalClass(other), TimeNodes.getDateTime(other), Layouts.TIME.getOffset(other));
}

}
@@ -87,14 +93,14 @@ public TimeSSpecificPrimitiveNode(RubyContext context, SourceSection sourceSecti
public DynamicObject timeSSpecificUTC(long seconds, int nanoseconds, boolean isUTC, Object offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = getMillis(seconds, nanoseconds);
return TimeNodes.createRubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds), nil());
return Layouts.TIME.createTime(getContext().getCoreLibrary().getTimeFactory(), time(milliseconds), nil());
}

@Specialization(guards = { "!isUTC", "isNil(offset)" })
public DynamicObject timeSSpecific(VirtualFrame frame, long seconds, int nanoseconds, boolean isUTC, Object offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = getMillis(seconds, nanoseconds);
return TimeNodes.createRubyTime(getContext().getCoreLibrary().getTimeClass(), localtime(milliseconds, (DynamicObject) readTimeZoneNode.execute(frame)), offset);
return Layouts.TIME.createTime(getContext().getCoreLibrary().getTimeFactory(), localtime(milliseconds, (DynamicObject) readTimeZoneNode.execute(frame)), offset);
}

private long getMillis(long seconds, int nanoseconds) {
@@ -214,10 +220,12 @@ public DynamicObject timeStrftime(DynamicObject time, DynamicObject format) {
public static abstract class TimeSFromArrayPrimitiveNode extends RubiniusPrimitiveNode {

@Child ReadTimeZoneNode readTimeZoneNode;
@Child AllocateObjectNode allocateObjectNode;

public TimeSFromArrayPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
@@ -263,7 +271,7 @@ private DynamicObject buildTime(VirtualFrame frame, DynamicObject timeClass, int

if (isdst == -1) {
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, zone);
return TimeNodes.createRubyTime(timeClass, dateTime, utcoffset);
return allocateObjectNode.allocate(timeClass, dateTime, utcoffset);
} else {
throw new UnsupportedOperationException(String.format("%s %s %s %s", isdst, fromutc, utcoffset, utcoffset.getClass()));
}
Original file line number Diff line number Diff line change
@@ -9,9 +9,11 @@
*/
package org.jruby.truffle.nodes.time;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.specific.UTF8Encoding;
import org.joda.time.DateTimeZone;
import org.jruby.RubyString;
@@ -23,13 +25,19 @@
import org.jruby.truffle.nodes.literal.LiteralNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;
import org.jruby.util.io.BlockingIO;

public class ReadTimeZoneNode extends RubyNode {

@Child private CallDispatchHeadNode hashNode;
@Child private ReadLiteralConstantNode envNode;


private final ConditionProfile tzNilProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile tzStringProfile = ConditionProfile.createBinaryProfile();

private static final ByteList defaultZone = RubyString.encodeBytelist(DateTimeZone.getDefault().toString(), UTF8Encoding.INSTANCE);
private final DynamicObject TZ;

public ReadTimeZoneNode(RubyContext context, SourceSection sourceSection) {
@@ -46,13 +54,13 @@ public Object execute(VirtualFrame frame) {

// TODO CS 4-May-15 not sure how TZ ends up being nil

if (tz == nil()) {
final String zone = DateTimeZone.getDefault().toString();
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), RubyString.encodeBytelist(zone, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
} else if (RubyGuards.isRubyString(tz)) {
if (tzNilProfile.profile(tz == nil())) {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), defaultZone.dup(), StringSupport.CR_UNKNOWN, null);
} else if (tzStringProfile.profile(RubyGuards.isRubyString(tz))) {
return tz;
} else {
throw new UnsupportedOperationException();
}
}

}
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ public class CoreLibrary {
private final DynamicObject threadBacktraceClass;
private final DynamicObject threadBacktraceLocationClass;
private final DynamicObject timeClass;
private final DynamicObjectFactory timeFactory;
private final DynamicObject transcodingClass;
private final DynamicObject trueClass;
private final DynamicObject tupleClass;
@@ -390,7 +391,8 @@ public CoreLibrary(RubyContext context) {
threadBacktraceLocationClass = defineClass(threadBacktraceClass, objectClass, "Location");
Layouts.CLASS.setInstanceFactoryUnsafe(threadBacktraceLocationClass, ThreadBacktraceLocationLayoutImpl.INSTANCE.createThreadBacktraceLocationShape(threadBacktraceLocationClass, threadBacktraceLocationClass));
timeClass = defineClass("Time");
Layouts.CLASS.setInstanceFactoryUnsafe(timeClass, Layouts.TIME.createTimeShape(timeClass, timeClass));
timeFactory = Layouts.TIME.createTimeShape(timeClass, timeClass);
Layouts.CLASS.setInstanceFactoryUnsafe(timeClass, timeFactory);
trueClass = defineClass("TrueClass");
unboundMethodClass = defineClass("UnboundMethod");
unboundMethodFactory = Layouts.UNBOUND_METHOD.createUnboundMethodShape(unboundMethodClass, unboundMethodClass);
@@ -1549,4 +1551,8 @@ public DynamicObjectFactory getRandomizerFactory() {
return randomizerFactory;
}

public DynamicObjectFactory getTimeFactory() {
return timeFactory;
}

}