Skip to content

Instantly share code, notes, and snippets.

@vext01
Created August 16, 2016 11:53
Show Gist options
  • Save vext01/4006dcf4e6c1ae23b9b3dc57196bfb9b to your computer and use it in GitHub Desktop.
Save vext01/4006dcf4e6c1ae23b9b3dc57196bfb9b to your computer and use it in GitHub Desktop.
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();
+}
@vext01
Copy link
Author

vext01 commented Aug 16, 2016

[INFO] ------------------------------------------------------------------------                                                                                                                           [12/1860]
[INFO] Building JRuby Truffle 9.1.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (default) @ jruby-truffle ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ jruby-truffle ---
[INFO] 
[INFO] --- antlr4-maven-plugin:4.5.1-1:antlr4 (default) @ jruby-truffle ---
[INFO] ANTLR 4: Processing source directory /home/vext01/research/warmup_experiment/work/jruby/truffle/src/main/antlr4
[INFO] Processing grammar: org/jruby/truffle/core/format/pack/Pack.g4
[INFO] Processing grammar: org/jruby/truffle/core/format/printf/PrintfLexer.g4
[INFO] Processing grammar: org/jruby/truffle/core/format/printf/PrintfParser.g4
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jruby-truffle ---
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 92 resources to /home/vext01/research/warmup_experiment/work/jruby/truffle/target/classes/jruby-truffle
[INFO] Copying 4 resources to /home/vext01/research/warmup_experiment/work/jruby/truffle/target/classes/META-INF/
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ jruby-truffle ---
[INFO] Compiling 12 source files to /home/vext01/research/warmup_experiment/work/jruby/truffle/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JRuby .............................................. SUCCESS [  0.146 s]
[INFO] JRuby Core ......................................... SUCCESS [  5.043 s]
[INFO] JRuby Lib Setup .................................... SUCCESS [  1.765 s]
[INFO] JRuby Truffle ...................................... FAILURE [  2.269 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.936 s
[INFO] Finished at: 2016-08-16T12:49:27+01:00
[INFO] Final Memory: 75M/871M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project jruby-truffle: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project jruby-truffle: Compilation failure
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:915)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :jruby-truffle

@chrisseaton
Copy link

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();
+}

@eregon
Copy link

eregon commented Aug 17, 2016

@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