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

Commits on Apr 24, 2016

  1. Copy the full SHA
    f0cc1a6 View commit details
  2. Copy the full SHA
    e3112b2 View commit details
  3. Copy the full SHA
    3c53ea0 View commit details
  4. [Truffle] jt test cexts

    chrisseaton committed Apr 24, 2016
    Copy the full SHA
    abc03a3 View commit details

Commits on Apr 25, 2016

  1. Copy the full SHA
    46d8857 View commit details
  2. Copy the full SHA
    168b208 View commit details
  3. Copy the full SHA
    66ba6d0 View commit details
  4. Copy the full SHA
    2d5cc3a View commit details
  5. Copy the full SHA
    5842c1f View commit details
  6. Copy the full SHA
    ae1c2a3 View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ reference.txt
rubyspec_temp
.polyglot.pom.rb
tool/truffle/jruby_truffle_runner/jruby+truffle_runner-*.gem
test/truffle/cexts/**/Makefile

# binaries
!bin/gem
8 changes: 1 addition & 7 deletions bin/jruby-cext-c
Original file line number Diff line number Diff line change
@@ -12,20 +12,14 @@

require 'yaml'

MX_DIR = ENV['MX_DIR']

unless MX_DIR
abort 'You need to set MX_DIR to a checkout of the mx repository'
end

SULONG_DIR = ENV['SULONG_DIR']

unless SULONG_DIR
abort 'You need to set SULONG_DIR to the location of a built checkout of the Sulong repository'
end

def mx(command, *args)
command = "#{MX_DIR}/mx.py -p #{SULONG_DIR} --vm server #{command} #{args.join(' ')}"
command = "mx -p #{SULONG_DIR} --vm server #{command} #{args.join(' ')}"
puts "$ #{command}"
`#{command}`
end
Binary file added lib/ruby/truffle/cext/ruby.su
Binary file not shown.
5 changes: 3 additions & 2 deletions maven/jruby-complete/pom.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'fileutils'

project 'JRuby Complete' do

version = File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

version = ENV['JRUBY_VERSION'] ||
File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

model_version '4.0.0'
id "org.jruby:jruby-complete:#{version}"
5 changes: 3 additions & 2 deletions maven/jruby-dist/pom.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'rubygems/package'
require 'fileutils'
project 'JRuby Dist' do

version = File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

version = ENV['JRUBY_VERSION'] ||
File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

model_version '4.0.0'
id "org.jruby:jruby-dist:#{version}"
3 changes: 2 additions & 1 deletion maven/jruby-jars/Mavenfile
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ require 'fileutils'

gemspec

version = File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip
version = ENV['JRUBY_VERSION'] ||
File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

# maven does treats prereleased version as snapshot - undo it here
ruby_version = model.version.sub( /-SNAPSHOT/, '' )
3 changes: 2 additions & 1 deletion maven/jruby-jars/jruby-jars.gemspec
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

require 'fileutils'

version = File.read( File.join( File.dirname(File.expand_path(__FILE__)), '..', '..', 'VERSION' ) ).strip
version = ENV['JRUBY_VERSION'] ||
File.read( File.join( File.dirname(File.expand_path(__FILE__)), '..', '..', 'VERSION' ) ).strip

# this regexp can be refined to work with pre, rc1, rc2 and such cases
ruby_version = version.sub( /-SNAPSHOT$/, '.SNAPSHOT' )
3 changes: 2 additions & 1 deletion maven/jruby/pom.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project 'JRuby Main Maven Artifact' do

version = File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip
version = ENV['JRUBY_VERSION'] ||
File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip

model_version '4.0.0'
id "org.jruby:jruby:#{version}"
3 changes: 2 additions & 1 deletion test/pom.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = File.read( File.join( basedir, '..', 'VERSION' ) ).strip
version = ENV['JRUBY_VERSION'] ||
File.read( File.join( basedir, '..', 'VERSION' ) ).strip

project 'JRuby Integration Tests' do

1 change: 1 addition & 0 deletions test/truffle/cexts/minimum/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!
2 changes: 2 additions & 0 deletions test/truffle/cexts/minimum/ext/minimum/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'mkmf'
create_makefile('minimum')
2 changes: 2 additions & 0 deletions test/truffle/cexts/module/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src: ext/module/*.c
out: lib/module/module.su
5 changes: 5 additions & 0 deletions test/truffle/cexts/module/bin/module
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'module'

puts defined?(ModuleExtension)
1 change: 1 addition & 0 deletions test/truffle/cexts/module/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constant
2 changes: 2 additions & 0 deletions test/truffle/cexts/module/ext/module/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'mkmf'
create_makefile('module')
7 changes: 7 additions & 0 deletions test/truffle/cexts/module/ext/module/module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

#include <ruby.h>

void Init_module() {
rb_define_module("ModuleExtension");
}
1 change: 1 addition & 0 deletions test/truffle/cexts/module/lib/module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'module/module'
Empty file.
18 changes: 18 additions & 0 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -297,6 +297,7 @@ def help
puts ' --no-java-cmd don\'t set JAVACMD - rely on bin/jruby or RUBY_BIN to have Graal already'
puts 'jt test integration [fast|long|all] runs bigger integration tests (fast is default)'
puts ' --no-gems don\'t run tests that install gems'
puts 'jt test cexts run C extension tests (set SULONG_DIR)'
puts 'jt tag spec/ruby/language tag failing specs in this directory'
puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file'
puts 'jt tag all spec/ruby/language tag all specs in this file, without running them'
@@ -458,7 +459,9 @@ def test(*args)
# test_mri # TODO (pitr-ch 29-Mar-2016): temporarily disabled
test_integration({'CI' => 'true', 'HAS_REDIS' => 'true'}, 'all')
test_compiler
test_cexts if ENV['SULONG_DIR']
when 'compiler' then test_compiler(*rest)
when 'cexts' then test_cexts(*rest)
when 'integration' then test_integration({}, *rest)
when 'specs' then test_specs('run', *rest)
when 'tck' then
@@ -504,6 +507,21 @@ def test_compiler(*args)
end
private :test_compiler

def test_cexts(*args)
output_file = 'cext-output.txt'
Dir["#{JRUBY_DIR}/test/truffle/cexts/*"].each do |dir|
sh Utilities.find_jruby, "#{JRUBY_DIR}/bin/jruby-cext-c", dir
name = File.basename(dir)
run '--sulong', '-I', File.join(dir, 'lib'), File.join(dir, 'bin', name), :out => output_file
unless File.read(output_file) == File.read(File.join(dir, 'expected.txt'))
abort "c extension #{dir} didn't work as expected"
end
end
ensure
File.delete output_file
end
private :test_cexts

def test_integration(env, *args)
no_gems = args.delete('--no-gems')

2 changes: 1 addition & 1 deletion truffle/src/main/c/cext/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src: ./*.c
out: ruby.su
out: ../../../../../lib/ruby/truffle/cext/ruby.su
10 changes: 10 additions & 0 deletions truffle/src/main/c/cext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This is the library that implements the Ruby C API for JRuby+Truffle. We
include the built version in the repository (under the lib directory) because
building it requires some complex dependencies.

To rebuild it, you need Sulong checked out and built. Then set `SULONG_DIR`
and run:

```
$ bin/jruby bin/jruby-cext-c truffle/src/main/c/cext
```
28 changes: 14 additions & 14 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -48,27 +48,27 @@ VALUE get_rb_eRuntimeError() {
}

int NUM2INT(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "num2int", value));
return truffle_invoke_i(ruby_cext, "num2int", value);
}

unsigned int NUM2UINT(VALUE value) {
return *((unsigned int*) truffle_invoke(ruby_cext, "num2uint", value));
return (unsigned int) truffle_invoke_i(ruby_cext, "num2uint", value);
}

long NUM2LONG(VALUE value) {
return *((long*) truffle_invoke(ruby_cext, "num2long", value));
return truffle_invoke_l(ruby_cext, "num2long", value);
}

int FIX2INT(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "fix2int", value));
return truffle_invoke_i(ruby_cext, "fix2int", value);
}

unsigned int FIX2UINT(VALUE value) {
return *((unsigned int*) truffle_invoke(ruby_cext, "fix2uint", value));
return (unsigned int) truffle_invoke_i(ruby_cext, "fix2uint", value);
}

long FIX2LONG(VALUE value) {
return *((long*) truffle_invoke(ruby_cext, "fix2long", value));
return truffle_invoke_l(ruby_cext, "fix2long", value);
}

VALUE INT2NUM(int value) {
@@ -92,7 +92,7 @@ VALUE LONG2FIX(long value) {
}

int FIXNUM_P(VALUE value) {
return *((int*) truffle_invoke(ruby_cext, "fixnum?", value));
return truffle_invoke_i(ruby_cext, "fixnum?", value);
}

char *RSTRING_PTR(VALUE string) {
@@ -101,7 +101,7 @@ char *RSTRING_PTR(VALUE string) {
}

int RSTRING_LEN(VALUE string) {
return *((int*) truffle_get_size(string));
return truffle_get_size(string);
}

ID rb_intern(const char *string) {
@@ -117,7 +117,7 @@ void rb_str_cat(VALUE string, char *to_concat, long length) {
}

int RARRAY_LEN(VALUE array) {
return *((int*) truffle_get_size(array));
return truffle_get_size(array);
}

VALUE *RARRAY_PTR(VALUE array) {
@@ -142,11 +142,11 @@ void rb_ary_push(VALUE array, VALUE value) {
}

void rb_ary_store(VALUE array, long index, VALUE value) {
truffle_write(array, &index, value);
truffle_write_idx(array, (int) index, value);
}

VALUE rb_ary_entry(VALUE array, long index) {
return truffle_read(array, &index);
return truffle_read_idx(array, (int) index);
}

VALUE rb_hash_aref(VALUE hash, VALUE key) {
@@ -166,11 +166,11 @@ VALUE rb_funcall(VALUE object, ID name, int argc, ...) {
}

VALUE rb_iv_get(VALUE object, const char *name) {
return truffle_read(object, (void*) name);
return truffle_read(object, name);
}

VALUE rb_iv_set(VALUE object, const char *name, VALUE value) {
truffle_write(object, (void*) name, value);
truffle_write(object, name, value);
return value;
}

@@ -199,5 +199,5 @@ void rb_define_private_method(VALUE module, char *name, void *function, int args
}

int rb_define_module_function(VALUE module, char *name, void *function, int args) {
return *((int*) truffle_invoke(ruby_cext, "define_module_function", module, name, function, args));
return truffle_invoke_i(ruby_cext, "define_module_function", module, name, function, args);
}
Original file line number Diff line number Diff line change
@@ -42,8 +42,12 @@
public class FeatureLoader {

private final RubyContext context;

private final ConcurrentHashMap<String, ReentrantLock> fileLocks = new ConcurrentHashMap<>();

private final Object cextImplementationLock = new Object();
private boolean cextImplementationLoaded = false;

public FeatureLoader(RubyContext context) {
this.context = context;
}
@@ -194,6 +198,8 @@ public Boolean block() throws InterruptedException {
} break;

case RubyLanguage.CEXT_MIME_TYPE: {
ensureCExtImplementationLoaded(frame, callNode);

final CallTarget callTarget;

try {
@@ -244,6 +250,26 @@ public Boolean block() throws InterruptedException {

}

private void ensureCExtImplementationLoaded(VirtualFrame frame, IndirectCallNode callNode) {
synchronized (cextImplementationLock) {
if (cextImplementationLoaded) {
return;
}

final CallTarget callTarget;

try {
callTarget = context.getEnv().parse(Source.fromFileName(context.getJRubyRuntime().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su"));
} catch (IOException e) {
throw new RuntimeException(e);
}

callNode.call(frame, callTarget, new Object[]{});

cextImplementationLoaded = true;
}
}

private String getBaseName(String path) {
final String name = new File(path).getName();