Created
August 16, 2016 11:53
-
-
Save vext01/4006dcf4e6c1ae23b9b3dc57196bfb9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/truffle/src/main/java/org/jruby/truffle/RubyContext.java b/truffle/src/main/java/org/jruby/truffle/RubyContext.java | |
index b0cbb23..d0691aa 100644 | |
--- a/truffle/src/main/java/org/jruby/truffle/RubyContext.java | |
+++ b/truffle/src/main/java/org/jruby/truffle/RubyContext.java | |
@@ -56,6 +56,8 @@ import java.io.PrintStream; | |
import java.io.UnsupportedEncodingException; | |
import java.nio.charset.StandardCharsets; | |
+import jnr.ffi.LibraryLoader; | |
+ | |
public class RubyContext extends ExecutionContext { | |
private static volatile RubyContext latestInstance; | |
@@ -92,6 +94,8 @@ public class RubyContext extends ExecutionContext { | |
private final PrintStream debugStandardOut; | |
private final CoverageManager coverageManager; | |
+ private final LibKrunTime libKrunTime; | |
+ | |
private final Object classVariableDefinitionLock = new Object(); | |
private final AttachmentsManager attachmentsManager; | |
@@ -161,6 +165,10 @@ public class RubyContext extends ExecutionContext { | |
final PrintStream configStandardOut = jrubyRuntime.getInstanceConfig().getOutput(); | |
debugStandardOut = (configStandardOut == System.out) ? null : configStandardOut; | |
+ final LibraryLoader<LibKrunTime> libKrunTimeLoader = LibraryLoader.create(LibKrunTime.class); | |
+ libKrunTimeLoader.library("kruntime"); | |
+ libKrunTime = libKrunTimeLoader.load(); | |
+ | |
if (options.INSTRUMENTATION_SERVER_PORT != 0) { | |
instrumentationServerManager = new InstrumentationServerManager(this, options.INSTRUMENTATION_SERVER_PORT); | |
instrumentationServerManager.start(); | |
@@ -348,4 +356,7 @@ public class RubyContext extends ExecutionContext { | |
return coreExceptions; | |
} | |
+ public LibKrunTime getLibKrunTime() { | |
+ return libKrunTime; | |
+ } | |
} | |
diff --git a/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java b/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java | |
index 50a155d..cfe1d27 100644 | |
--- a/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java | |
+++ b/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java | |
@@ -9,6 +9,8 @@ | |
*/ | |
package org.jruby.truffle.core.kernel; | |
+import org.jruby.RubyBignum; | |
+ | |
import com.oracle.truffle.api.CallTarget; | |
import com.oracle.truffle.api.CompilerDirectives; | |
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | |
@@ -1985,4 +1987,49 @@ public abstract class KernelNodes { | |
} | |
+ @CoreMethod(names = "read_ts_reg_start", needsSelf=false) | |
+ public abstract static class ReadTSRegStartNode extends CoreMethodArrayArgumentsNode { | |
+ | |
+ private static BigInteger negAdjust = BigInteger(1).shiftLeft(64); // 2^64 | |
+ | |
+ public ReadTSRegStartNode(RubyContext context, SourceSection sourceSection) { | |
+ super(context, sourceSection); | |
+ } | |
+ | |
+ @TruffleBoundary | |
+ @Specialization | |
+ public RubyBignum ReadTSRegStart() { | |
+ long u64_in_s64 = getContext().getLibKrunTime().read_ts_reg_start(); | |
+ | |
+ BigInteger bi = BigInteger(u64_in_s64); | |
+ if (u64_in_s64 < 0) { | |
+ bi = bi.add(ReadTSRegStartNode.negAdjust); | |
+ } | |
+ | |
+ return RubyBignum.newBignum(RunTime.getRuntime(), bi); | |
+ } | |
+ } | |
+ | |
+ @CoreMethod(names = "read_ts_reg_stop", needsSelf=false) | |
+ public abstract static class ReadTSRegStopNode extends CoreMethodArrayArgumentsNode { | |
+ | |
+ private static BigInteger negAdjust = BigInteger(1).shiftLeft(64); // 2^64 | |
+ | |
+ public ReadTSRegStopNode(RubyContext context, SourceSection sourceSection) { | |
+ super(context, sourceSection); | |
+ } | |
+ | |
+ @TruffleBoundary | |
+ @Specialization | |
+ public long ReadTSRegStop() { | |
+ long u64_in_s64 = getContext().getLibKrunTime().read_ts_reg_stop(); | |
+ | |
+ BigInteger bi = BigInteger(u64_in_s64); | |
+ if (u64_in_s64 < 0) { | |
+ bi = bi.add(ReadTSRegStopNode.negAdjust); | |
+ } | |
+ | |
+ return RubyBignum.newBignum(RunTime.getRuntime(), bi); | |
+ } | |
+ } | |
} | |
diff --git a/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java b/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java | |
new file mode 100644 | |
index 0000000..3aa02af | |
--- /dev/null | |
+++ b/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java | |
@@ -0,0 +1,7 @@ | |
+package org.jruby.truffle; | |
+ | |
+public interface LibKrunTime { | |
+ // these actually return u_int64_t | |
+ long read_ts_reg_start(); | |
+ long read_ts_reg_stop(); | |
+} |
Author
vext01
commented
Aug 16, 2016
diff --git a/truffle/src/main/java/org/jruby/truffle/RubyContext.java b/truffle/src/main/java/org/jruby/truffle/RubyContext.java
index b0cbb23..d0691aa 100644
--- a/truffle/src/main/java/org/jruby/truffle/RubyContext.java
+++ b/truffle/src/main/java/org/jruby/truffle/RubyContext.java
@@ -56,6 +56,8 @@ import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
+import jnr.ffi.LibraryLoader;
+
public class RubyContext extends ExecutionContext {
private static volatile RubyContext latestInstance;
@@ -92,6 +94,8 @@ public class RubyContext extends ExecutionContext {
private final PrintStream debugStandardOut;
private final CoverageManager coverageManager;
+ private final LibKrunTime libKrunTime;
+
private final Object classVariableDefinitionLock = new Object();
private final AttachmentsManager attachmentsManager;
@@ -161,6 +165,10 @@ public class RubyContext extends ExecutionContext {
final PrintStream configStandardOut = jrubyRuntime.getInstanceConfig().getOutput();
debugStandardOut = (configStandardOut == System.out) ? null : configStandardOut;
+ final LibraryLoader<LibKrunTime> libKrunTimeLoader = LibraryLoader.create(LibKrunTime.class);
+ libKrunTimeLoader.library("kruntime");
+ libKrunTime = libKrunTimeLoader.load();
+
if (options.INSTRUMENTATION_SERVER_PORT != 0) {
instrumentationServerManager = new InstrumentationServerManager(this, options.INSTRUMENTATION_SERVER_PORT);
instrumentationServerManager.start();
@@ -348,4 +356,7 @@ public class RubyContext extends ExecutionContext {
return coreExceptions;
}
+ public LibKrunTime getLibKrunTime() {
+ return libKrunTime;
+ }
}
diff --git a/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java b/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java
index 50a155d..0234ef7 100644
--- a/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java
+++ b/truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java
@@ -141,6 +141,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.math.BigInteger;
@CoreClass("Kernel")
public abstract class KernelNodes {
@@ -1985,4 +1986,49 @@ public abstract class KernelNodes {
}
+ @CoreMethod(names = "read_ts_reg_start", needsSelf=false)
+ public abstract static class ReadTSRegStartNode extends CoreMethodArrayArgumentsNode {
+
+ private static final BigInteger negAdjust = BigInteger.ONE.shiftLeft(64); // 2^64
+
+ public ReadTSRegStartNode(RubyContext context, SourceSection sourceSection) {
+ super(context, sourceSection);
+ }
+
+ @TruffleBoundary
+ @Specialization
+ public DynamicObject readTSRegStart() {
+ final long u64_in_s64 = getContext().getLibKrunTime().read_ts_reg_start();
+
+ BigInteger bi = BigInteger.valueOf(u64_in_s64);
+ if (u64_in_s64 < 0) {
+ bi = bi.add(ReadTSRegStartNode.negAdjust);
+ }
+
+ return createBignum(bi);
+ }
+ }
+
+ @CoreMethod(names = "read_ts_reg_stop", needsSelf=false)
+ public abstract static class ReadTSRegStopNode extends CoreMethodArrayArgumentsNode {
+
+ private static final BigInteger negAdjust = BigInteger.ONE.shiftLeft(64); // 2^64
+
+ public ReadTSRegStopNode(RubyContext context, SourceSection sourceSection) {
+ super(context, sourceSection);
+ }
+
+ @TruffleBoundary
+ @Specialization
+ public DynamicObject readTSRegStop() {
+ final long u64_in_s64 = getContext().getLibKrunTime().read_ts_reg_stop();
+
+ BigInteger bi = BigInteger.valueOf(u64_in_s64);
+ if (u64_in_s64 < 0) {
+ bi = bi.add(ReadTSRegStopNode.negAdjust);
+ }
+
+ return createBignum(bi);
+ }
+ }
}
diff --git a/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java b/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java
new file mode 100644
index 0000000..3aa02af
--- /dev/null
+++ b/truffle/src/main/java/org/jruby/truffle/core/kernel/LibKrunTime.java
@@ -0,0 +1,7 @@
+package org.jruby.truffle;
+
+public interface LibKrunTime {
+ // these actually return u_int64_t
+ long read_ts_reg_start();
+ long read_ts_reg_stop();
+}
@chrisseaton This will create a Bignum in Fixnum range, that would trigger an assertion if they are enabled.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment