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

Commits on Feb 10, 2016

  1. 2
    Copy the full SHA
    e797826 View commit details
  2. Copy the full SHA
    9125773 View commit details
  3. Copy the full SHA
    0fb9f9e View commit details
  4. Copy the full SHA
    042e2f2 View commit details
2 changes: 1 addition & 1 deletion lib/ruby/truffle/jruby+truffle/lib/runner.rb
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ class JRubyTruffleRunner
'-J-agentlib:jdwp=transport=dt_socket,server=y,address=%d,suspend=y'],
truffle_bundle_path: ['--truffle-bundle-path NAME', 'Bundle path', assign_new_value, '.jruby+truffle_bundle'],
interpreter_path: ['--interpreter-path PATH', "Path to #{BRANDING} interpreter executable", assign_new_value,
File.expand_path(File.join(File.dirname(__FILE__), '../../../../bin/jruby'))],
File.expand_path(File.join(File.dirname(__FILE__), '../../../../../bin/jruby'))],
graal_path: ['--graal-path PATH', 'Path to Graal', assign_new_value, '../graalvm-jdk1.8.0/bin/java'],
mock_load_path: ['--mock-load-path PATH',
'Path of mocks & monkey-patches (prepended in $:, relative to --truffle_bundle_path)',
1 change: 0 additions & 1 deletion spec/truffle/tags/core/time/minus_tags.txt
Original file line number Diff line number Diff line change
@@ -2,4 +2,3 @@ fails:Time#- maintains microseconds precision
fails:Time#- maintains nanoseconds precision
fails:Time#- maintains subseconds precision
fails:Time#- maintains precision
fails:Time#- returns a time with the same fixed offset as self
1 change: 0 additions & 1 deletion spec/truffle/tags/core/time/plus_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Time#+ maintains subseconds precision
fails:Time#+ returns a time with the same fixed offset as self
29 changes: 18 additions & 11 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -52,13 +52,13 @@ def self.find_graal
File.executable?(location)
end
end

def self.find_graal_js
jar = ENV['GRAAL_JS_JAR']
return jar if jar
raise "couldn't find trufflejs.jar - download GraalVM as described in https://github.com/jruby/jruby/wiki/Downloading-GraalVM and find it in there"
end

def self.find_jruby
if USE_JRUBY_ECLIPSE
"#{JRUBY_DIR}/tool/jruby_eclipse"
@@ -68,7 +68,7 @@ def self.find_jruby
"#{JRUBY_DIR}/bin/jruby"
end
end

def self.find_jruby_dir
File.dirname(find_jruby)
end
@@ -430,7 +430,14 @@ def test_integration(*args)
no_gems = args.delete('--no-gems')
env_vars = {}
env_vars["PATH"] = "#{Utilities.find_jruby_dir}:#{ENV["PATH"]}"
Dir["#{JRUBY_DIR}/test/truffle/integration/*.sh"].each do |test_script|

test_names = if args.empty?
'*'
else
'{' + args.join(',') + '}'
end

Dir["#{JRUBY_DIR}/test/truffle/integration/#{test_names}.sh"].each do |test_script|
next if no_gems && File.read(test_script).include?('gem install')
sh env_vars, test_script
end
@@ -558,7 +565,7 @@ def bench(command, *args)
end
raw_sh env_vars, "ruby", *bench_args, *args
end

def metrics(command, *args)
case command
when 'alloc'
@@ -571,7 +578,7 @@ def metrics(command, *args)
raise ArgumentError, command
end
end

def metrics_alloc(*args)
samples = []
METRICS_REPS.times do
@@ -585,7 +592,7 @@ def metrics_alloc(*args)
puts if STDOUT.tty?
puts "#{human_size(samples.inject(:+)/samples.size)}, max #{human_size(samples.max)}"
end

def memory_allocated(trace)
allocated = 0
trace.lines do |line|
@@ -601,7 +608,7 @@ def memory_allocated(trace)
end
allocated
end

def metrics_minheap(*args)
# Why aren't you doing a binary search? The results seem pretty noisy so
# unless you do reps at each level I'm not sure how to make it work
@@ -625,7 +632,7 @@ def metrics_minheap(*args)
puts if STDOUT.tty?
puts "#{heap} MB"
end

def metrics_time(*args)
samples = []
METRICS_REPS.times do
@@ -644,7 +651,7 @@ def metrics_time(*args)
puts "#{region} #{(region_samples.inject(:+)/samples.size).round(2)} s"
end
end

def get_times(trace, total)
start_times = {}
times = {}
@@ -672,7 +679,7 @@ def get_times(trace, total)
times['unaccounted'] = total - accounted_for
times
end

def human_size(bytes)
if bytes < 1024
"#{bytes} B"
Original file line number Diff line number Diff line change
@@ -68,30 +68,6 @@ private DateTime now(DynamicObject timeZone) {

}

@RubiniusPrimitive(name = "time_s_dup", needsSelf = false)
public static abstract class TimeSDupPrimitiveNode extends RubiniusPrimitiveArrayArgumentsNode {

@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) {
return allocateObjectNode.allocate(
Layouts.BASIC_OBJECT.getLogicalClass(other),
Layouts.TIME.getDateTime(other),
Layouts.TIME.getNSec(other),
Layouts.TIME.getZone(other),
Layouts.TIME.getOffset(other),
Layouts.TIME.getRelativeOffset(other),
Layouts.TIME.getIsUtc(other));
}

}

@RubiniusPrimitive(name = "time_s_specific", needsSelf = false, lowerFixnumParameters = { 1 })
public static abstract class TimeSSpecificPrimitiveNode extends RubiniusPrimitiveArrayArgumentsNode {

@@ -105,7 +81,7 @@ public TimeSSpecificPrimitiveNode(RubyContext context, SourceSection sourceSecti
@Specialization(guards = { "isUTC" })
public DynamicObject timeSSpecificUTC(long seconds, int nanoseconds, boolean isUTC, Object offset) {
final long milliseconds = getMillis(seconds, nanoseconds);
return Layouts.TIME.createTime(getContext().getCoreLibrary().getTimeFactory(), time(milliseconds), nanoseconds % 1_000_000, nil(), nil(), false, isUTC);
return Layouts.TIME.createTime(getContext().getCoreLibrary().getTimeFactory(), utcTime(milliseconds), nanoseconds % 1_000_000, nil(), nil(), false, isUTC);
}

@Specialization(guards = { "!isUTC", "isNil(offset)" })
@@ -119,7 +95,7 @@ public DynamicObject timeSSpecific(VirtualFrame frame, long seconds, int nanosec
public DynamicObject timeSSpecific(VirtualFrame frame, long seconds, int nanoseconds, boolean isUTC, long offset) {
final long milliseconds = getMillis(seconds, nanoseconds);
return Layouts.TIME.createTime(getContext().getCoreLibrary().getTimeFactory(),
localtime(milliseconds, (DynamicObject) readTimeZoneNode.execute(frame)), nanoseconds % 1_000_000, nil(), offset, false, isUTC);
offsetTime(milliseconds, offset), nanoseconds % 1_000_000, nil(), nil(), false, isUTC);
}

private long getMillis(long seconds, int nanoseconds) {
@@ -133,10 +109,16 @@ private long getMillis(long seconds, int nanoseconds) {
}

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

@TruffleBoundary
private DateTime offsetTime(long milliseconds, long offset) {

return new DateTime(milliseconds, DateTimeZone.forOffsetMillis((int) offset * 1000));
}

@TruffleBoundary
private DateTime localtime(long milliseconds, DynamicObject zoneName) {
assert RubyGuards.isRubyString(zoneName);
42 changes: 42 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/time/TimeNodes.java
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.core.time;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ExactMath;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -18,6 +19,7 @@
import org.jcodings.specific.UTF8Encoding;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.*;
import org.jruby.truffle.core.rubinius.TimePrimitiveNodes;
@@ -130,6 +132,46 @@ public DateTimeZone getDateTimeZone(int offset) {

}

@CoreMethod(names = "add_internal!", required = 2, visibility = Visibility.PROTECTED)
public abstract static class AddInternalNode extends CoreMethodArrayArgumentsNode {

public AddInternalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public DynamicObject addInternal(DynamicObject time, long seconds, long nanoSeconds) {
final DateTime dateTime = Layouts.TIME.getDateTime(time);
final long addMilis = ExactMath.addExact(ExactMath.multiplyExact(seconds, 1000L), (nanoSeconds / 1_000_000));
Layouts.TIME.setDateTime(time, dateTime.plus(addMilis));
Layouts.TIME.setNSec(time, (1_000_000 + Layouts.TIME.getNSec(time) + nanoSeconds % 1_000_000) % 1_000_000);
return time;
}
}

@CoreMethod(names = "dup_internal", required = 1, visibility = Visibility.PROTECTED)
public static abstract class DupInternalNode extends CoreMethodArrayArgumentsNode {

@Child private AllocateObjectNode allocateObjectNode;

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

@Specialization
public DynamicObject dup(DynamicObject time, DynamicObject klass) {
return allocateObjectNode.allocate(
klass,
Layouts.TIME.getDateTime(time),
Layouts.TIME.getNSec(time),
Layouts.TIME.getZone(time),
Layouts.TIME.getOffset(time),
Layouts.TIME.getRelativeOffset(time),
Layouts.TIME.getIsUtc(time));
}
}

@CoreMethod(names = "gmtime")
public abstract static class GmTimeNode extends CoreMethodArrayArgumentsNode {

52 changes: 52 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/time.rb
Original file line number Diff line number Diff line change
@@ -22,4 +22,56 @@ def localtime(offset = nil)
self
end

def +(other)
raise TypeError, 'time + time?' if other.kind_of?(Time)

case other = Rubinius::Type.coerce_to_exact_num(other)
when Integer
other_sec = other
other_nsec = 0
else
other_sec, nsec_frac = other.divmod(1)
other_nsec = (nsec_frac * 1_000_000_000).to_i
end

# Don't use self.class, MRI doesn't honor subclasses here
dup_internal(Time).add_internal! other_sec, other_nsec
end

def -(other)
if other.kind_of?(Time)
return (seconds - other.seconds) + ((nsec - other.nsec) * 0.000000001)
end

case other = Rubinius::Type.coerce_to_exact_num(other)
when Integer
other_sec = other
other_nsec = 0
else
other_sec, nsec_frac = other.divmod(1)
other_nsec = (nsec_frac * 1_000_000_000 + 0.5).to_i
end

# Don't use self.class, MRI doesn't honor subclasses here
dup_internal(Time).add_internal! -other_sec, -other_nsec
end

def round(places = 0)
return dup if nsec == 0

roundable_time = (to_i + subsec.to_r).round(places)

sec = roundable_time.floor
nano = ((roundable_time - sec) * 1_000_000_000).floor

dup_internal(Time).add_internal! sec - seconds, nano - nsec
end

def dup
dup_internal self.class
end

def self.duplicate(other)
other.dup
end
end