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

Commits on Apr 11, 2016

  1. Copy the full SHA
    ba4a5e7 View commit details
  2. Copy the full SHA
    5c96568 View commit details
  3. Copy the full SHA
    d228b4a View commit details
  4. Copy the full SHA
    8052ceb View commit details
  5. [Truffle] Truffle.cext?

    chrisseaton committed Apr 11, 2016
    Copy the full SHA
    066e1cc View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
*.zip
*~
*.tokens
*.su

.DS_Store
.debug.properties
60 changes: 60 additions & 0 deletions bin/jruby-cext-c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env jruby

# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
# This code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# A compiler for JRuby+Truffle C extensions

require 'yaml'

MX_DIR = ENV['MX_DIR']

if MX_DIR.nil?
$stderr.puts 'You need to set MX_DIR to a checkout of the mx repository'
exit 1
end

SULONG_DIR = ENV['SULONG_DIR']

if SULONG_DIR.nil?
$stderr.puts 'You need to set SULONG_DIR to the location of a built checkout of the Sulong repository'
exit 1
end

def mx(command, *args)
`#{MX_DIR}/mx.py -p #{SULONG_DIR} --vm server #{command} #{args.join(' ')}`
end

CEXT_DIR = ARGV[0]

if CEXT_DIR.nil?
$stderr.puts 'You need to pass the directory of a C extension so I can build it'
exit 1
end

CONFIG_FILE = File.join(CEXT_DIR, '.jruby-cext-build.yml')

unless File.exist?(CONFIG_FILE)
$stderr.puts "There is no .jruby-cext-build.yml in this C extension at the moment - I don't know how to build it"
exit 1
end

CONFIG = YAML.load_file(CONFIG_FILE)

SRC = Dir[File.join(CEXT_DIR, CONFIG['src'])]
OUT = File.join(CEXT_DIR, CONFIG['out'])

LL = []

SRC.each do |src|
ll = File.join(File.dirname(src), File.basename(src, '.*') + '.ll')
mx 'su-clang', '-Ilib/ruby/truffle/cext', '-S', '-emit-llvm', src, '-o', ll
LL.push ll
end

mx 'su-link', OUT, *LL
2 changes: 2 additions & 0 deletions test/truffle/cexts/minimum/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src: ext/minimum/*.c
out: lib/minimum/minimum.su
5 changes: 5 additions & 0 deletions test/truffle/cexts/minimum/ext/minimum/minimum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

void Init_minimum() {
printf("Hello!\n");
}
12 changes: 12 additions & 0 deletions test/truffle/cexts/minimum/ext/minimum/minimum.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; ModuleID = 'test/truffle/cexts/minimum/ext/minimum/minimum.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

@.str = private unnamed_addr constant [8 x i8] c"Hello!\0A\00", align 1

define void @Init_minimum() nounwind uwtable ssp {
%1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0))
ret void
}

declare i32 @printf(i8*, ...)
1 change: 1 addition & 0 deletions test/truffle/cexts/minimum/lib/minimum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'minimum/minimum'
Empty file.
16 changes: 16 additions & 0 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -61,6 +61,12 @@ def self.find_graal_js
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_sulong_dir
dir = ENV['SULONG_DIR']
return dir if dir
raise "couldn't find the Sulong repository - you need to check it out and build it"
end

def self.jruby_eclipse?
# tool/jruby_eclipse only works on release currently
ENV["JRUBY_ECLIPSE"] == "true" && Utilities.git_branch == "master"
@@ -258,6 +264,7 @@ def help
puts 'jt run [options] args... run JRuby with -X+T and args'
puts ' --graal use Graal (set GRAAL_BIN or it will try to automagically find it)'
puts ' --js add Graal.js to the classpath (set GRAAL_JS_JAR)'
puts ' --sulong add Sulong to the classpath (set SULONG_JAR)'
puts ' --asm show assembly (implies --graal)'
puts ' --server run an instrumentation server on port 8080'
puts ' --igv make sure IGV is running and dump Graal graphs after partial escape (implies --graal)'
@@ -305,6 +312,7 @@ def help
puts ' GRAAL_BIN_...git_branch_name... GraalVM executable to use for a given branch'
puts ' branch names are mangled - eg truffle-head becomes GRAAL_BIN_TRUFFLE_HEAD'
puts ' GRAAL_JS_JAR The location of trufflejs.jar'
puts ' SULONG_DIR The location of a built checkout of the Sulong repository'
end

def checkout(branch)
@@ -360,6 +368,14 @@ def run(*args)
jruby_args << Utilities.find_graal_js
end

if args.delete('--sulong')
dir = Utilities.find_sulong_dir
jruby_args << '-J-classpath'
jruby_args << File.join(dir, 'lib', '*')
jruby_args << '-J-classpath'
jruby_args << File.join(dir, 'build', 'sulong.jar')
end

if args.delete('--asm')
jruby_args += %w[-J-XX:+UnlockDiagnosticVMOptions -J-XX:CompileCommand=print,*::callRoot]
end
6 changes: 6 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/JRubyTruffleImpl.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,12 @@ public class JRubyTruffleImpl implements JRubyTruffleInterface {
// Created by reflection from Ruby#loadTruffle

public JRubyTruffleImpl(Ruby runtime) {
try {
Class.forName("com.oracle.truffle.llvm.LLVM", true, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
// Sulong may not be on the classpath, or if it genuinely failed we'll be happy with the exception later on
}

engine = PolyglotEngine.newBuilder()
.globalSymbol(JRubyTruffleInterface.RUNTIME_SYMBOL, new JRubyContextWrapper(runtime))
.build();
4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/truffle/truffle.rb
Original file line number Diff line number Diff line change
@@ -21,6 +21,10 @@ def version
def graal?
Primitive.graal?
end

def cext?
Interop.mime_type_supported?('application/x-sulong-library')
end

# Tests if this VM is a SubstrateVM build.
def substrate?