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

Commits on May 24, 2016

  1. Copy the full SHA
    1863ad0 View commit details
  2. Copy the full SHA
    65b8816 View commit details
Original file line number Diff line number Diff line change
@@ -9,51 +9,46 @@
*/
package org.jruby.truffle.core.time;

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.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.CyclicAssumption;
import org.jcodings.specific.UTF8Encoding;
import org.joda.time.DateTimeZone;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.constants.ReadLiteralConstantNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.literal.ObjectLiteralNode;
import org.jruby.truffle.language.SnippetNode;

public class ReadTimeZoneNode extends RubyNode {
public abstract class ReadTimeZoneNode extends RubyNode {

@Child private CallDispatchHeadNode hashNode;
@Child private ReadLiteralConstantNode envNode;
protected static final CyclicAssumption TZ_UNCHANGED = new CyclicAssumption("ENV['TZ'] is unmodified");

private final ConditionProfile tzNilProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile tzStringProfile = ConditionProfile.createBinaryProfile();
public static void invalidateTZ() {
TZ_UNCHANGED.invalidate();
}

private static final Rope defaultZone = StringOperations.encodeRope(DateTimeZone.getDefault().toString(), UTF8Encoding.INSTANCE);
private final DynamicObject TZ;

public ReadTimeZoneNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
hashNode = DispatchHeadNodeFactory.createMethodCall(context);
envNode = new ReadLiteralConstantNode(context, sourceSection,
new ObjectLiteralNode(context, sourceSection, coreLibrary().getObjectClass()), "ENV");
TZ = create7BitString("TZ", UTF8Encoding.INSTANCE);
private static final Rope DEFAULT_ZONE = StringOperations.encodeRope(DateTimeZone.getDefault().toString(), UTF8Encoding.INSTANCE);

@Child SnippetNode snippetNode = new SnippetNode();

@Specialization(assumptions = "TZ_UNCHANGED.getAssumption()")
public DynamicObject getTZ(VirtualFrame frame,
@Cached("getTZValue(frame)") DynamicObject tzValue) {
return tzValue;
}

@Override
public Object execute(VirtualFrame frame) {
final Object tz = hashNode.call(frame, envNode.execute(frame), "[]", null, TZ);
protected DynamicObject getTZValue(VirtualFrame frame) {
Object tz = snippetNode.execute(frame, "ENV['TZ']");

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

if (tzNilProfile.profile(tz == nil())) {
return createString(defaultZone);
} else if (tzStringProfile.profile(RubyGuards.isRubyString(tz))) {
return tz;
if (tz == nil()) {
return createString(DEFAULT_ZONE);
} else if (RubyGuards.isRubyString(tz)) {
return (DynamicObject) tz;
} else {
throw new UnsupportedOperationException();
}
11 changes: 5 additions & 6 deletions truffle/src/main/java/org/jruby/truffle/core/time/TimeNodes.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.core.time;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ExactMath;
import com.oracle.truffle.api.dsl.Cached;
@@ -99,7 +98,7 @@ public abstract static class LocalTimeNode extends CoreMethodArrayArgumentsNode

public LocalTimeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
readTimeZoneNode = ReadTimeZoneNodeGen.create();
}

@Specialization
@@ -224,7 +223,7 @@ public static abstract class TimeSNowPrimitiveNode extends PrimitiveArrayArgumen
public TimeSNowPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
readTimeZoneNode = ReadTimeZoneNodeGen.create();
}

@Specialization
@@ -248,7 +247,7 @@ public static abstract class TimeSSpecificPrimitiveNode extends PrimitiveArrayAr

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

@Specialization(guards = { "isUTC" })
@@ -326,7 +325,7 @@ public static abstract class TimeDecomposePrimitiveNode extends PrimitiveArrayAr

public TimeDecomposePrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
readTimeZoneNode = ReadTimeZoneNodeGen.create();
}

@TruffleBoundary
@@ -389,7 +388,7 @@ public static abstract class TimeSFromArrayPrimitiveNode extends PrimitiveArrayA

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

Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.truffle.core.rope.RopeNodesFactory;
import org.jruby.truffle.extra.ffi.PointerPrimitiveNodes;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.time.ReadTimeZoneNode;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.control.RaiseException;
@@ -283,7 +284,11 @@ public abstract static class SetenvNode extends CoreMethodArrayArgumentsNode {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = { "isRubyString(name)", "isRubyString(value)" })
public int setenv(DynamicObject name, DynamicObject value, int overwrite) {
return posix().setenv(decodeUTF8(name), decodeUTF8(value), overwrite);
final String nameString = decodeUTF8(name);
if (nameString.equals("TZ")) {
ReadTimeZoneNode.invalidateTZ();
}
return posix().setenv(nameString, decodeUTF8(value), overwrite);
}

}
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ public Object taint(
}

if (isFrozenNode.executeIsFrozen(object)) {
frozen(object);
throw new RaiseException(coreExceptions().frozenError(object, this));
}
}

@@ -87,8 +87,4 @@ protected WriteObjectFieldNode createWriteTaintNode() {
return WriteObjectFieldNodeGen.create(Layouts.TAINTED_IDENTIFIER);
}

private Object frozen(Object object) {
throw new RaiseException(coreExceptions().frozenError(object, this));
}

}