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

Commits on Feb 16, 2015

  1. [Truffle] Process is a module!

    eregon committed Feb 16, 2015
    Copy the full SHA
    049955c View commit details
  2. Copy the full SHA
    a563d9c View commit details
Original file line number Diff line number Diff line change
@@ -9,10 +9,12 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.signal.SignalOperations;

@@ -21,6 +23,69 @@
@CoreClass(name = "Process")
public abstract class ProcessNodes {

public static final int CLOCK_MONOTONIC = 1;
public static final int CLOCK_REALTIME = 2;

@CoreMethod(names = "clock_gettime", isModuleFunction = true, required = 1, optional = 1)
public abstract static class ClockGetTimeNode extends CoreMethodNode {

private final RubySymbol floatSecondSymbol;
private final RubySymbol nanosecondSymbol;

public ClockGetTimeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
floatSecondSymbol = context.newSymbol("float_second");
nanosecondSymbol = context.newSymbol("nanosecond");
}

public ClockGetTimeNode(ClockGetTimeNode prev) {
super(prev);
floatSecondSymbol = prev.floatSecondSymbol;
nanosecondSymbol = prev.nanosecondSymbol;
}

@Specialization(guards = "isMonotonic(arguments[0])")
Object clock_gettime_monotonic(int clock_id, UndefinedPlaceholder unit) {
return clock_gettime_monotonic(CLOCK_MONOTONIC, floatSecondSymbol);
}

@Specialization(guards = "isRealtime(arguments[0])")
Object clock_gettime_realtime(int clock_id, UndefinedPlaceholder unit) {
return clock_gettime_realtime(CLOCK_REALTIME, floatSecondSymbol);
}

@Specialization(guards = "isMonotonic(arguments[0])")
Object clock_gettime_monotonic(int clock_id, RubySymbol unit) {
long time = System.nanoTime();
return timeToUnit(time, unit);
}

@Specialization(guards = "isRealtime(arguments[0])")
Object clock_gettime_realtime(int clock_id, RubySymbol unit) {
long time = System.currentTimeMillis() * 1000000;
return timeToUnit(time, unit);
}

Object timeToUnit(long time, RubySymbol unit) {
if (unit == nanosecondSymbol) {
return time;
} else if (unit == floatSecondSymbol) {
return time / 1e9;
} else {
throw new UnsupportedOperationException(unit.toString());
}
}

static boolean isMonotonic(int clock_id) {
return clock_id == CLOCK_MONOTONIC;
}

static boolean isRealtime(int clock_id) {
return clock_id == CLOCK_REALTIME;
}

}

@CoreMethod(names = "kill", isModuleFunction = true, required = 2)
public abstract static class KillNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.jruby.runtime.load.LoadServiceResource;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ArrayNodes;
import org.jruby.truffle.nodes.core.ProcessNodes;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.runtime.RubyCallStack;
@@ -81,7 +82,7 @@ public class CoreLibrary {
private final RubyClass numericClass;
private final RubyClass objectClass;
private final RubyClass procClass;
private final RubyClass processClass;
private final RubyModule processModule;
private final RubyClass rangeClass;
private final RubyClass rangeErrorClass;
private final RubyClass rationalClass;
@@ -252,7 +253,7 @@ public CoreLibrary(RubyContext context) {
defineClass("Mutex", new RubyMutex.MutexAllocator());
nilClass = defineClass("NilClass");
procClass = defineClass("Proc", new RubyProc.ProcAllocator());
processClass = defineClass("Process");
processModule = defineModule("Process");
rangeClass = defineClass("Range", new RubyRange.RangeAllocator());
regexpClass = defineClass("Regexp", new RubyRegexp.RegexpAllocator());
stringClass = defineClass("String", new RubyString.StringAllocator());
@@ -388,6 +389,9 @@ private void initializeConstants() {

fileClass.setConstant(null, "PATH_SEPARATOR", RubyString.fromJavaString(stringClass, File.pathSeparator));
fileClass.setConstant(null, "FNM_SYSCASE", 0);

processModule.setConstant(null, "CLOCK_MONOTONIC", ProcessNodes.CLOCK_MONOTONIC);
processModule.setConstant(null, "CLOCK_REALTIME", ProcessNodes.CLOCK_REALTIME);
}

private void initializeSignalConstants() {