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

Commits on May 3, 2016

  1. Copy the full SHA
    9e1de7b View commit details
  2. Copy the full SHA
    325f898 View commit details
  3. Copy the full SHA
    1ab4a99 View commit details
  4. Copy the full SHA
    26830d0 View commit details
  5. Copy the full SHA
    b1d45d4 View commit details
  6. Copy the full SHA
    82f7033 View commit details
  7. Copy the full SHA
    f4c86ce View commit details
  8. Copy the full SHA
    adb2e91 View commit details
  9. Copy the full SHA
    da0dcf5 View commit details
  10. Copy the full SHA
    bd2144d View commit details
  11. Copy the full SHA
    37b4ab9 View commit details
  12. Copy the full SHA
    52cb794 View commit details
  13. Copy the full SHA
    096e9d1 View commit details
  14. Copy the full SHA
    8bcd121 View commit details
14 changes: 7 additions & 7 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ ID rb_intern(const char *string);
VALUE rb_str_new2(const char *string);
VALUE ID2SYM(ID id);
VALUE rb_intern_str(VALUE string);
void rb_str_cat(VALUE string, char *to_concat, long length);
void rb_str_cat(VALUE string, const char *to_concat, long length);

int RARRAY_LEN(VALUE array);
VALUE *RARRAY_PTR(VALUE array);
@@ -90,7 +90,7 @@ VALUE rb_hash_new();
VALUE rb_hash_aref(VALUE hash, VALUE key);
void rb_hash_aset(VALUE hash, VALUE key, VALUE value);

void rb_scan_args(int argc, VALUE *argv, char *format, ...);
void rb_scan_args(int argc, VALUE *argv, const char *format, ...);

VALUE rb_funcall(VALUE object, ID name, int argc, ...);

@@ -101,12 +101,12 @@ VALUE rb_const_get(VALUE object, ID name);

void rb_raise(VALUE exception, const char *format, ...);

VALUE rb_define_module(char *name);
VALUE rb_define_module_under(VALUE module, char *name);
VALUE rb_define_module(const char *name);
VALUE rb_define_module_under(VALUE module, const char *name);

void rb_define_method(VALUE module, char *name, void *function, int args);
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);
void rb_define_method(VALUE module, const char *name, void *function, int args);
void rb_define_private_method(VALUE module, const char *name, void *function, int args);
int rb_define_module_function(VALUE module, const char *name, void *function, int args);

#if defined(__cplusplus)
}
Binary file modified lib/ruby/truffle/cext/ruby.su
Binary file not shown.
2 changes: 2 additions & 0 deletions test/truffle/cexts/method/.jruby-cext-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src: ext/method/*.c
out: lib/method/method.su
5 changes: 5 additions & 0 deletions test/truffle/cexts/method/bin/method
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'method'

puts MethodExtension.add(14, 2)
1 change: 1 addition & 0 deletions test/truffle/cexts/method/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
2 changes: 2 additions & 0 deletions test/truffle/cexts/method/ext/method/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'mkmf'
create_makefile('method')
10 changes: 10 additions & 0 deletions test/truffle/cexts/method/ext/method/method.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <ruby.h>

VALUE add(VALUE self, VALUE a, VALUE b) {
return INT2NUM(NUM2INT(a) + NUM2INT(b));
}

void Init_method() {
VALUE module = rb_define_module("MethodExtension");
rb_define_module_function(module, "add", &add, 2);
}
1 change: 1 addition & 0 deletions test/truffle/cexts/method/lib/method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'method/method'
Empty file.
2 changes: 0 additions & 2 deletions test/truffle/cexts/module/ext/module/module.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <stdio.h>

#include <ruby.h>

void Init_module() {
14 changes: 13 additions & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -59,6 +59,17 @@ def self.find_graal
end
raise "couldn't find graal - download it as described in https://github.com/jruby/jruby/wiki/Downloading-GraalVM and extract it into the JRuby repository or parent directory"
end

def self.find_sulong_graal(dir)
jvmci = File.join(dir, '..', 'jvmci')
Dir.entries(jvmci).each do |entry|
child = File.join(jvmci, entry)
if File.directory?(child) && entry.start_with?('jdk')
return File.join(child, 'product', 'bin', 'java')
end
end
raise "couldn't find the Java build in the Sulong repository - you need to check it out and build it"
end

def self.find_graal_js
jar = ENV['GRAAL_JS_JAR']
@@ -279,7 +290,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_DIR, implies --graal)'
puts ' --sulong add Sulong to the classpath (set SULONG_DIR, implies --graal but finds it from the SULONG_DIR)'
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)'
@@ -394,6 +405,7 @@ def run(*args)

if args.delete('--sulong')
dir = Utilities.find_sulong_dir
env_vars["JAVACMD"] = Utilities.find_sulong_graal(dir)
jruby_args << '-J-classpath'
jruby_args << File.join(dir, 'lib', '*')
jruby_args << '-J-classpath'
103 changes: 49 additions & 54 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -12,96 +12,91 @@

#include <ruby.h>

static void *ruby_cext;

__attribute__((constructor))
void truffle_ruby_load() {
ruby_cext = truffle_import("ruby_cext");
}
#define RUBY_CEXT truffle_import_cached("ruby_cext")

VALUE get_Qfalse() {
return (VALUE) truffle_read(ruby_cext, "qfalse");
return (VALUE) truffle_read(RUBY_CEXT, "Qfalse");
}

VALUE get_Qtrue() {
return (VALUE) truffle_read(ruby_cext, "qtrue");
return (VALUE) truffle_read(RUBY_CEXT, "Qtrue");
}

VALUE get_Qnil() {
return (VALUE) truffle_read(ruby_cext, "qnil");
return (VALUE) truffle_read(RUBY_CEXT, "Qnil");
}

VALUE get_rb_cObject() {
return (VALUE) truffle_read(ruby_cext, "object");
return (VALUE) truffle_read(RUBY_CEXT, "rb_cObject");
}

VALUE get_rb_cArray() {
return (VALUE) truffle_read(ruby_cext, "array");
return (VALUE) truffle_read(RUBY_CEXT, "rb_cArray");
}

VALUE get_rb_cHash() {
return (VALUE) truffle_read(ruby_cext, "hash");
return (VALUE) truffle_read(RUBY_CEXT, "rb_cHash");
}

VALUE get_rb_eRuntimeError() {
return (VALUE) truffle_read(ruby_cext, "runtime_error");
return (VALUE) truffle_read(RUBY_CEXT, "rb_eRuntimeError");
}

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

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

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

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

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

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

VALUE INT2NUM(int value) {
return (VALUE) truffle_invoke(ruby_cext, "int2num", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "INT2NUM", value);
}

VALUE INT2FIX(int value) {
return (VALUE) truffle_invoke(ruby_cext, "int2fix", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "INT2FIX", value);
}

VALUE UINT2NUM(unsigned int value) {
return (VALUE) truffle_invoke(ruby_cext, "uint2num", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "UINT2NUM", value);
}

VALUE LONG2NUM(long value) {
return (VALUE) truffle_invoke(ruby_cext, "long2num", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "LONG2NUM", value);
}

VALUE LONG2FIX(long value) {
return (VALUE) truffle_invoke(ruby_cext, "long2fix", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "LONG2FIX", value);
}

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

VALUE rb_float_new(double value) {
return (VALUE) truffle_invoke(ruby_cext, "float_new", value);
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_float_new", value);
}

char *RSTRING_PTR(VALUE string) {
// Needs to return a fake char* which actually calls back into Ruby when read or written
return (char*) truffle_invoke(ruby_cext, "string_ptr", string);
return (char*) truffle_invoke(RUBY_CEXT, "RSTRING_PTR", string);
}

int RSTRING_LEN(VALUE string) {
@@ -113,23 +108,23 @@ VALUE rb_ary_dup(VALUE array) {
}

ID rb_intern(const char *string) {
return (ID) truffle_invoke(ruby_cext, "intern", string);
return (ID) truffle_invoke(RUBY_CEXT, "rb_intern", string);
}

VALUE rb_str_new2(const char *string) {
return (VALUE) truffle_invoke(ruby_cext, "str_new2", string);
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new2", truffle_read_string(string));
}

VALUE rb_intern_str(VALUE string) {
return (VALUE) truffle_invoke(ruby_cext, "intern", string);
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_intern_str", string);
}

VALUE ID2SYM(ID id) {
return truffle_invoke(ruby_cext, "id2sym", id);
return truffle_invoke(RUBY_CEXT, "ID2SYM", id);
}

void rb_str_cat(VALUE string, char *to_concat, long length) {
truffle_invoke(ruby_cext, "string_cat", string, to_concat, length);
void rb_str_cat(VALUE string, const char *to_concat, long length) {
truffle_invoke(RUBY_CEXT, "rb_str_cat", string, truffle_read_string(to_concat), length);
}

int RARRAY_LEN(VALUE array) {
@@ -138,19 +133,19 @@ int RARRAY_LEN(VALUE array) {

VALUE *RARRAY_PTR(VALUE array) {
// Needs to return a fake VALUE* which actually calls back into Ruby when read or written
return (VALUE*) truffle_invoke(ruby_cext, "array_ptr", array);
return (VALUE*) truffle_invoke(RUBY_CEXT, "RARRAY_PTR", array);
}

VALUE rb_ary_new_capa(long capacity) {
return (VALUE) truffle_invoke(ruby_cext, "array_new_capa", capacity);
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new_capa", capacity);
}

VALUE rb_ary_new2() {
return (VALUE) truffle_invoke(ruby_cext, "array_new2");
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new2");
}

VALUE rb_ary_new() {
return (VALUE) truffle_invoke(ruby_cext, "array_new");
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_ary_new");
}

void rb_ary_push(VALUE array, VALUE value) {
@@ -170,7 +165,7 @@ int RARRAY_LENINT(VALUE array) {
}

VALUE rb_hash_new() {
return (VALUE) truffle_invoke(ruby_cext, "hash_new");
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_hash_new");
}

VALUE rb_hash_aref(VALUE hash, VALUE key) {
@@ -181,47 +176,47 @@ void rb_hash_aset(VALUE hash, VALUE key, VALUE value) {
truffle_write(hash, key, value);
}

void rb_scan_args(int argc, VALUE *argv, char *format, ...) {
truffle_invoke(ruby_cext, "scan_args", argc, argv, format /*, where to get args? */);
void rb_scan_args(int argc, VALUE *argv, const char *format, ...) {
truffle_invoke(RUBY_CEXT, "rb_scan_args", argc, argv, format /*, where to get args? */);
}

VALUE rb_funcall(VALUE object, ID name, int argc, ...) {
return truffle_invoke(object, name /*, where to get args? */);
}

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

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

VALUE rb_const_get(VALUE object, ID name) {
return truffle_invoke(ruby_cext, "const_get", object, name);
return truffle_invoke(object, "const_get", name);
}

void rb_raise(VALUE exception, const char *format, ...) {
truffle_invoke(ruby_cext, "raise", format /*, where to get args? */);
truffle_invoke(RUBY_CEXT, "rb_raise", format /*, where to get args? */);
}

VALUE rb_define_module(char *name) {
return truffle_invoke(ruby_cext, "define_module", name);
VALUE rb_define_module(const char *name) {
return truffle_invoke(RUBY_CEXT, "rb_define_module", truffle_read_string(name));
}

VALUE rb_define_module_under(VALUE module, char *name) {
return truffle_invoke(ruby_cext, "define_module_under", module, name);
VALUE rb_define_module_under(VALUE module, const char *name) {
return truffle_invoke(RUBY_CEXT, "rb_define_module_under", module, name);
}

void rb_define_method(VALUE module, char *name, void *function, int args) {
truffle_invoke(ruby_cext, "define_method", module, name, function, args);
void rb_define_method(VALUE module, const char *name, void *function, int args) {
truffle_invoke(RUBY_CEXT, "rb_define_method", module, truffle_read_string(name), function, args);
}

void rb_define_private_method(VALUE module, char *name, void *function, int args) {
truffle_invoke(ruby_cext, "define_private_method", module, name, function, args);
void rb_define_private_method(VALUE module, const char *name, void *function, int args) {
truffle_invoke(RUBY_CEXT, "rb_define_private_method", module, truffle_read_string(name), function, args);
}

int rb_define_module_function(VALUE module, char *name, void *function, int args) {
return truffle_invoke_i(ruby_cext, "define_module_function", module, name, function, args);
int rb_define_module_function(VALUE module, const char *name, void *function, int args) {
return truffle_invoke_i(RUBY_CEXT, "rb_define_module_function", module, truffle_read_string(name), function, args);
}
Original file line number Diff line number Diff line change
@@ -40,6 +40,11 @@ public NameToJavaStringNode(RubyContext context, SourceSection sourceSection) {

public abstract String executeToJavaString(VirtualFrame frame, Object name);

@Specialization
public String passThroughJavaString(String string) {
return string;
}

@Specialization(guards = "isRubySymbol(symbol)")
public String coerceRubySymbol(DynamicObject symbol) {
return Layouts.SYMBOL.getString(symbol);
@@ -50,7 +55,7 @@ public String coerceRubyString(DynamicObject string) {
return string.toString();
}

@Specialization(guards = { "!isRubySymbol(object)", "!isRubyString(object)" })
@Specialization(guards = { "!isString(object)", "!isRubySymbol(object)", "!isRubyString(object)" })
public String coerceObject(VirtualFrame frame, Object object) {
final Object coerced;
try {
111 changes: 105 additions & 6 deletions truffle/src/main/java/org/jruby/truffle/interop/CExtNodes.java
Original file line number Diff line number Diff line change
@@ -19,16 +19,115 @@
@CoreClass(name = "Truffle::CExt")
public class CExtNodes {

@CoreMethod(names = "qfalse", isModuleFunction = true, needsSelf = false)
public abstract static class QFalseNode extends CoreMethodArrayArgumentsNode {
@CoreMethod(names = "NUM2INT", isModuleFunction = true, needsSelf = false)
public abstract static class NUM2INTNode extends CoreMethodArrayArgumentsNode {

public QFalseNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@Specialization
public int num2int(int num) {
return num;
}

}

@CoreMethod(names = "NUM2UINT", isModuleFunction = true, needsSelf = false)
public abstract static class NUM2UINTNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int num2uint(int num) {
// TODO CS 2-May-16 what to do about the fact it's unsigned?
return num;
}

}

@CoreMethod(names = "NUM2LONG", isModuleFunction = true, needsSelf = false)
public abstract static class NUM2LONGNode extends CoreMethodArrayArgumentsNode {

@Specialization
public long num2long(int num) {
return num;
}

}

@CoreMethod(names = "FIX2INT", isModuleFunction = true, needsSelf = false)
public abstract static class FIX2INTNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int fix2int(int num) {
return num;
}

}

@CoreMethod(names = "FIX2UINT", isModuleFunction = true, needsSelf = false)
public abstract static class FIX2UINTNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int fix2uint(int num) {
// TODO CS 2-May-16 what to do about the fact it's unsigned?
return num;
}

}

@CoreMethod(names = "FIX2LONG", isModuleFunction = true, needsSelf = false)
public abstract static class FIX2LONGNode extends CoreMethodArrayArgumentsNode {

@Specialization
public long fix2long(int num) {
return num;
}

}

@CoreMethod(names = "INT2NUM", isModuleFunction = true, needsSelf = false)
public abstract static class INT2NUMNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int int2num(int num) {
return num;
}

}

@CoreMethod(names = "INT2FIX", isModuleFunction = true, needsSelf = false)
public abstract static class INT2FIXNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int int2fix(int num) {
return num;
}

}

@CoreMethod(names = "UINT2NUM", isModuleFunction = true, needsSelf = false)
public abstract static class UINT2NUMNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int uint2num(int num) {
// TODO CS 2-May-16 what to do about the fact it's unsigned?
return num;
}

}

@CoreMethod(names = "LONG2NUM", isModuleFunction = true, needsSelf = false)
public abstract static class LONG2NUMNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int long2num(int num) {
return num;
}

}

@CoreMethod(names = "LONG2FIX", isModuleFunction = true, needsSelf = false)
public abstract static class LONG2FIXNode extends CoreMethodArrayArgumentsNode {

@Specialization
public boolean qfalse() {
return false;
public int long2fix(int num) {
return num;
}

}
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -269,7 +269,7 @@ def self.omit(reason)

Truffle::Boot.require_core 'core/truffle/attachments'
Truffle::Boot.require_core 'core/truffle/debug'
Truffle::Boot.require_core 'core/truffle/truffle'
Truffle::Boot.require_core 'core/truffle/cext'
Truffle::Boot.require_core 'core/truffle/interop'

# Start running Ruby code outside classes
126 changes: 126 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright (c) 2015, 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

module Truffle
module CExt
module_function

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

def Qfalse
false
end

def Qtrue
true
end

def Qnil
nil
end

def rb_cObject
Object
end

def rb_cArray
Array
end

def rb_cHash
Hash
end

def rb_eRuntimeError
raise 'not implemented'
end

def FIXNUM_P(value)
value.is_a?(Fixnum)
end

def rb_float_new(value)
value.to_f
end

def RSTRING_PTR(string)
string
end

def rb_intern
raise 'not implemented'
end

def rb_str_new2(string)
string
end

def rb_intern_str(string)
string.intern
end

def ID2SYM(id)
id
end

def rb_str_cat(string, to_concat, length)
raise 'not implemented'
end

def RARRAY_PTR(array)
array
end

def rb_ary_new_capa(capacity)
[]
end

def rb_ary_new2
[]
end

def rb_ary_new
[]
end

def rb_hash_new
{}
end

def rb_scan_args
raise 'not implemented'
end

def rb_raise(object, name)
raise 'not implemented'
end

def rb_define_module(name)
Object.const_set(name, Module.new)
end

def rb_define_module_under(mod, name)
mod.const_set(name, Module.new)
end

def rb_define_method(mod, name, function, args)
raise 'not implemented'
end

def rb_define_private_method(mod, name, function, args)
raise 'not implemented'
end

def rb_define_module_function(mod, name, function, args)
raise 'not implemented'
end

end
end
15 changes: 0 additions & 15 deletions truffle/src/main/ruby/core/truffle/truffle.rb

This file was deleted.