Skip to content

Commit

Permalink
Showing 14 changed files with 16,683 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ matrix:
- env:
- JT=check_ambiguous_arguments
- SKIP_BUILD=true
- V=1
jdk: oraclejdk8
- env: JT='test mri'
jdk: oraclejdk8
18 changes: 16 additions & 2 deletions ci.hocon
Original file line number Diff line number Diff line change
@@ -229,6 +229,12 @@ psd-benchmarks: {
] ${post-process-and-upload-results}
}

asciidoctor-benchmarks: {
run: ${setup-benchmarks} [
[mx, benchmark, asciidoctor]
] ${post-process-and-upload-results}
}

synthetic-benchmarks: {
run: ${setup-benchmarks} [
[mx, benchmark, synthetic]
@@ -298,7 +304,7 @@ test-cexts: {
[cd, ../..],
[mv, temp_mx, mx.jruby]
[mx, sclone, --kind, git, "https://github.com/jruby/jruby-truffle-gem-test-pack.git", jruby-truffle-gem-test-pack],
${jt} [build, cexts, --no-openssl]
${jt} [build, cexts]
]

environment: {
@@ -413,7 +419,15 @@ builds: [
{name: ruby-benchmarks-psd-graal-enterprise} ${common} ${graal-enterprise} ${bench-caps} ${jruby-truffle} ${psd-benchmarks},
{name: ruby-benchmarks-psd-graal-enterprise-no-om} ${common} ${graal-enterprise-no-om} ${bench-caps} ${jruby-truffle} ${psd-benchmarks},
{name: ruby-benchmarks-psd-graal-vm} ${common} ${graal-vm} ${daily-bench-caps} ${jruby-truffle} ${psd-benchmarks},


//{name: ruby-benchmarks-asciidoctor-noindy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-noindy-benchmark} ${asciidoctor-benchmarks},
//{name: ruby-benchmarks-asciidoctor-indy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-indy-benchmark} ${asciidoctor-benchmarks},
{name: ruby-benchmarks-asciidoctor-no-graal} ${common} ${no-graal} ${weekly-bench-caps} ${jruby-truffle} ${asciidoctor-benchmarks},
{name: ruby-benchmarks-asciidoctor-graal-core} ${common} ${graal-core} ${bench-caps} ${jruby-truffle} ${asciidoctor-benchmarks},
{name: ruby-benchmarks-asciidoctor-graal-enterprise} ${common} ${graal-enterprise} ${bench-caps} ${jruby-truffle} ${asciidoctor-benchmarks},
{name: ruby-benchmarks-asciidoctor-graal-enterprise-no-om} ${common} ${graal-enterprise-no-om} ${bench-caps} ${jruby-truffle} ${asciidoctor-benchmarks},
{name: ruby-benchmarks-asciidoctor-graal-vm} ${common} ${graal-vm} ${daily-bench-caps} ${jruby-truffle} ${asciidoctor-benchmarks},

//{name: ruby-benchmarks-synthetic-noindy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-noindy-benchmark} ${synthetic-benchmarks},
//{name: ruby-benchmarks-synthetic-indy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-indy-benchmark} ${synthetic-benchmarks},
{name: ruby-benchmarks-synthetic-no-graal} ${common} ${no-graal} ${weekly-bench-caps} ${jruby-truffle} ${synthetic-benchmarks},
74 changes: 71 additions & 3 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -52,8 +52,12 @@ extern "C" {

// Basic types

//typedef uint64_t VALUE;
typedef void *VALUE;
#ifdef JT_INT_VALUE
typedef uintptr_t VALUE;
#else
typedef void *VALUE;
#endif

typedef VALUE ID;

// Helpers
@@ -181,6 +185,7 @@ VALUE rb_jt_get_cTime(void);
VALUE rb_jt_get_mEnumerable(void);
VALUE rb_jt_get_mWaitReadable(void);
VALUE rb_jt_get_mWaitWritable(void);
VALUE rb_jt_get_mComparable(void);

#define rb_cObject rb_jt_get_cObject()
#define rb_cArray rb_jt_get_cArray()
@@ -191,6 +196,7 @@ VALUE rb_jt_get_mWaitWritable(void);
#define rb_mEnumerable rb_jt_get_mEnumerable()
#define rb_mWaitReadable rb_jt_get_mWaitReadable()
#define rb_mWaitWritable rb_jt_get_mWaitWritable()
#define rb_mComparable rb_jt_get_mComparable()

VALUE rb_jt_get_eException(void);
VALUE rb_jt_get_eRuntimeError(void);
@@ -240,6 +246,7 @@ ID SYM2ID(VALUE value);
VALUE ID2SYM(ID value);

#define NUM2TIMET(value) NUM2LONG(value)
#define TIMET2NUM(value) LONG2NUM(value)

// Type checks

@@ -258,7 +265,36 @@ VALUE rb_require(const char *feature);
// Object

VALUE rb_obj_dup(VALUE object);

VALUE rb_jt_obj_taint(VALUE object);
bool rb_jt_obj_taintable_p(VALUE object);
bool rb_jt_obj_tainted_p(VALUE object);
#define RB_OBJ_TAINTABLE(object) rb_jt_obj_taintable_p(object)
#define RB_OBJ_TAINTED_RAW(object) rb_jt_obj_tainted_p(object)
#define RB_OBJ_TAINTED(object) rb_jt_obj_tainted_p(object)
#define RB_OBJ_TAINT_RAW(object) rb_jt_obj_taint(object)
#define RB_OBJ_TAINT(object) rb_jt_obj_taint(object)
#define RB_OBJ_UNTRUSTED(object) rb_jt_obj_tainted_p(object)
#define RB_OBJ_UNTRUST(object) rb_jt_obj_taint(object)
#define OBJ_TAINTABLE(object) rb_jt_obj_taintable_p(object)
#define OBJ_TAINTED_RAW(object) rb_jt_obj_tainted_p(object)
#define OBJ_TAINTED(object) rb_jt_obj_tainted_p(object)
#define OBJ_TAINT_RAW(object) rb_jt_obj_taint(object)
#define OBJ_TAINT(object) rb_jt_obj_taint(object)
#define OBJ_UNTRUSTED(object) rb_jt_obj_tainted_p(object)
#define OBJ_UNTRUST(object) rb_jt_obj_tainted_p(object)

VALUE rb_obj_freeze(VALUE object);
bool rb_jt_obj_frozen_p(VALUE object);
#define rb_obj_freeze_inline(object) rb_obj_freeze(object)
#define RB_OBJ_FROZEN_RAW(x) rb_jt_obj_frozen_p(object)
#define RB_OBJ_FROZEN(x) rb_jt_obj_frozen_p(object)
#define RB_OBJ_FREEZE_RAW(object) rb_obj_freeze(object)
#define RB_OBJ_FREEZE(x) rb_obj_freeze((VALUE)x)
#define OBJ_FROZEN_RAW(object) rb_jt_obj_frozen_p(object)
#define OBJ_FROZEN(object) rb_jt_obj_frozen_p(object)
#define OBJ_FREEZE_RAW(object) rb_obj_freeze(object)
#define OBJ_FREEZE(object) rb_obj_freeze(object)

// Integer

@@ -331,6 +367,7 @@ VALUE rb_String(VALUE value);
VALUE rb_str_resize(VALUE string, long length);
#define RSTRING_GETMEM(string, data_pointer, length_pointer) ((data_pointer) = RSTRING_PTR(string), (length_pointer) = rb_str_len(string))
VALUE rb_str_split(VALUE string, const char *split);
void rb_str_modify(VALUE string);

// Symbol

@@ -368,6 +405,8 @@ VALUE rb_hash_aref(VALUE hash, VALUE key);
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE value);
VALUE rb_hash_lookup(VALUE hash, VALUE key);
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value);
VALUE rb_hash_set_ifnone(VALUE hash, VALUE if_none);
#define RHASH_SET_IFNONE(hash, if_none) rb_hash_set_ifnone((VALUE) hash, if_none)

typedef unsigned long st_data_t;
typedef st_data_t st_index_t;
@@ -406,14 +445,18 @@ VALUE rb_funcallv(VALUE object, ID name, int args_count, const VALUE *args);
VALUE rb_funcallv_public(VALUE object, ID name, int args_count, const VALUE *args);
#define rb_funcall2 rb_funcallv
#define rb_funcall3 rb_funcallv_public
VALUE rb_apply(VALUE object, ID name, VALUE args);

#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) VALUE yielded_arg, VALUE callback_arg, int args_count, const VALUE *args, VALUE block_arg
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) VALUE yielded_arg, VALUE callback_arg, int __args_count, const VALUE *__args, VALUE __block_arg
typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg));
typedef rb_block_call_func *rb_block_call_func_t;
VALUE rb_block_call(VALUE object, ID name, int args_count, const VALUE *args, rb_block_call_func_t block_call_func, VALUE data);

VALUE rb_call_super(int args_count, const VALUE *args);

int rb_block_given_p();
VALUE rb_block_proc(void);
VALUE rb_yield(VALUE value);

// Instance variables
@@ -569,8 +612,25 @@ int rb_jt_io_handle(VALUE file);

#define GetOpenFile(file, pointer) ((pointer)->fd = rb_jt_io_handle(file))

int rb_io_wait_readable(int fd);
int rb_io_wait_writable(int fd);
void rb_thread_wait_fd(int fd);

NORETURN(void rb_eof_error(void));

// Data

struct RData {
// No RBasic object header
void (*dmark)(void *data);
void (*dfree)(void *data);
void *data;
};

struct RData *rb_jt_wrap_rdata(VALUE value);

#define RDATA(value) rb_jt_wrap_rdata(value)

#define DATA_PTR(value) *((volatile intptr_t*) 0)

// Typed data
@@ -612,6 +672,14 @@ void *rb_check_typeddata(VALUE value, const rb_data_type_t *data_type);

#define RTYPEDDATA_DATA(value) *((volatile int*) 0)

// VM

VALUE *rb_ruby_verbose_ptr(void);
#define ruby_verbose (*rb_ruby_verbose_ptr())

VALUE *rb_ruby_debug_ptr(void);
#define ruby_debug (*rb_ruby_debug_ptr())

#if defined(__cplusplus)
}
#endif
26 changes: 26 additions & 0 deletions mx.jruby/mx_jruby.py
Original file line number Diff line number Diff line change
@@ -550,6 +550,31 @@ def benchmarks(self):
def time(self):
return psd_benchmark_time

asciidoctor_benchmarks = [
'asciidoctor:file-lines',
'asciidoctor:string-lines',
'asciidoctor:read-line',
'asciidoctor:restore-line',
'asciidoctor:load-string',
'asciidoctor:load-file',
'asciidoctor:quote-match',
'asciidoctor:quote-sub',
'asciidoctor:join-lines',
'asciidoctor:convert'
]

asciidoctor_benchmark_time = 120

class AsciidoctorBenchmarkSuite(AllBenchmarksBenchmarkSuite):
def name(self):
return 'asciidoctor'

def benchmarks(self):
return asciidoctor_benchmarks

def time(self):
return asciidoctor_benchmark_time

synthetic_benchmarks = [
'acid'
]
@@ -651,6 +676,7 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
mx_benchmark.add_bm_suite(ClassicBenchmarkSuite())
mx_benchmark.add_bm_suite(ChunkyBenchmarkSuite())
mx_benchmark.add_bm_suite(PSDBenchmarkSuite())
mx_benchmark.add_bm_suite(AsciidoctorBenchmarkSuite())
mx_benchmark.add_bm_suite(SyntheticBenchmarkSuite())
mx_benchmark.add_bm_suite(MicroBenchmarkSuite())
mx_benchmark.add_bm_suite(ServerBenchmarkSuite())
17 changes: 17 additions & 0 deletions test/truffle/gems/asciidoctor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

GEM_HOME=${GEM_HOME:-lib/ruby/gems/shared}

ruby -X+T $GEM_HOME/gems/asciidoctor-1.5.4/bin/asciidoctor --attribute last-update-label!= test/truffle/gems/asciidoctor/userguide.adoc

if ! cmp --silent test/truffle/gems/asciidoctor/userguide.html test/truffle/gems/asciidoctor/userguide-expected.html
then
echo Asciidoctor output was not as expected
diff -u test/truffle/gems/asciidoctor/userguide-expected.html test/truffle/gems/asciidoctor/userguide.html
rm -f test/truffle/gems/asciidoctor/userguide.html
exit 1
else
rm -f test/truffle/gems/asciidoctor/userguide.html
fi
18 changes: 18 additions & 0 deletions test/truffle/gems/asciidoctor/customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"AROUT","Around the Horn","Thomas Hardy","120 Hanover Sq.
London","(171) 555-7788"
"BERGS","Berglunds snabbkop","Christina Berglund","Berguvsvagen 8
Lulea","0921-12 34 65"
"BLAUS","Blauer See Delikatessen","Hanna Moos","Forsterstr. 57
Mannheim","0621-08460"
"BLONP","Blondel pere et fils","Frederique Citeaux","24, place Kleber
Strasbourg","88.60.15.31"
"BOLID","Bolido Comidas preparadas","Martin Sommer","C/ Araquil, 67
Madrid","(91) 555 22 82"
"BONAP","Bon app'","Laurence Lebihan","12, rue des Bouchers
Marseille","91.24.45.40"
"BOTTM","Bottom-Dollar Markets","Elizabeth Lincoln","23 Tsawassen Blvd.
Tsawassen","(604) 555-4729"
"BSBEV","B's Beverages","Victoria Ashworth","Fauntleroy Circus
London","(171) 555-1212"
"CACTU","Cactus Comidas para llevar","Patricio Simpson","Cerrito 333
Buenos Aires","(1) 135-5555"
10,370 changes: 10,370 additions & 0 deletions test/truffle/gems/asciidoctor/userguide-expected.html

Large diffs are not rendered by default.

6,046 changes: 6,046 additions & 0 deletions test/truffle/gems/asciidoctor/userguide.adoc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/truffle/gems/install-gems.sh
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ bin/jruby bin/gem install rack -v 1.6.1
bin/jruby bin/gem install tilt -v 2.0.1
bin/jruby bin/gem install rack-protection -v 1.5.3
bin/jruby bin/gem install sinatra -v 1.4.6
bin/jruby bin/gem install asciidoctor -v 1.5.4
13 changes: 7 additions & 6 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@
JEXCEPTION = "-Xtruffle.exceptions.print_java=true"
METRICS_REPS = 10

VERBOSE = ENV.include? 'V'

MAC = `uname -a`.include?('Darwin')

if MAC
@@ -331,7 +333,9 @@ def mvn(*args)
options = []
end

sh *options, './mvnw', *(['-q'] + args)
args = ['-q', *args] unless VERBOSE

sh *options, './mvnw', *args
end

def maven_options(*options)
@@ -495,20 +499,17 @@ def bootstrap(*options)
def build(*options)
maven_options, other_options = maven_options(*options)
project = other_options.first
env = {'JRUBY_BUILD_MORE_QUIET' => 'true'}
env = VERBOSE ? {} : {'JRUBY_BUILD_MORE_QUIET' => 'true'}
case project
when 'truffle'
mvn env, *maven_options, '-pl', 'truffle', 'package'
when 'cexts'
no_openssl = options.delete('--no-openssl')

cextc "#{JRUBY_DIR}/truffle/src/main/c/cext"

openssl_home = ENV['OPENSSL_HOME'] || '/usr'

unless no_openssl
cextc "#{JRUBY_DIR}/truffle/src/main/c/openssl",
'-DRUBY_EXTCONF_H="extconf.h"',
'-DJT_INT_VALUE=true',
'-Werror=implicit-function-declaration'
end
when nil
87 changes: 87 additions & 0 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -133,6 +133,10 @@ VALUE rb_jt_get_mWaitWritable(void) {
return (VALUE) truffle_read(RUBY_CEXT, "rb_mWaitWritable");
}

VALUE rb_jt_get_mComparable(void) {
return (VALUE) truffle_read(RUBY_CEXT, "rb_mComparable");
}

VALUE rb_jt_get_eException(void) {
return (VALUE) truffle_read(RUBY_CEXT, "rb_eException");
}
@@ -269,14 +273,32 @@ VALUE rb_require(const char *feature) {
abort();
}

// Object

VALUE rb_obj_dup(VALUE object) {
return (VALUE) truffle_invoke((void *)object, "dup");
}

VALUE rb_jt_obj_taint(VALUE object) {
return (VALUE) truffle_invoke((void *)object, "taint");
}

bool rb_jt_obj_taintable_p(VALUE object) {
return truffle_invoke_b(RUBY_CEXT, "RB_OBJ_TAINTED", object);
}

bool rb_jt_obj_tainted_p(VALUE object) {
return truffle_invoke_b((void *)object, "tainted?");
}

VALUE rb_obj_freeze(VALUE object) {
return (VALUE) truffle_invoke((void *)object, "freeze");
}

bool rb_jt_obj_frozen_p(VALUE object) {
return truffle_invoke_b((void *)object, "frozen?");
}

// Integer

VALUE rb_Integer(VALUE value) {
@@ -426,6 +448,10 @@ VALUE rb_str_split(VALUE string, const char *split) {
return (VALUE) truffle_invoke(string, "split", rb_str_new_cstr(split));
}

void rb_str_modify(VALUE string) {
// Does nothing because writing to the string pointer will cause necessary invalidations anyway
}

// Symbol

ID rb_intern(const char *string) {
@@ -537,6 +563,11 @@ VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value) {
return (VALUE) truffle_invoke((void *)hash, "fetch", key, default_value);
}

VALUE rb_hash_set_ifnone(VALUE hash, VALUE if_none) {
fprintf(stderr, "rb_hash_set_ifnone not implemented\n");
abort();
}

st_index_t rb_memhash(const void *data, long length) {
// Not a proper hash - just something that produces a stable result for now

@@ -631,15 +662,30 @@ VALUE rb_funcallv_public(VALUE object, ID name, int args_count, const VALUE *arg
abort();
}

VALUE rb_apply(VALUE object, ID name, VALUE args) {
fprintf(stderr, "rb_apply not implemented\n");
abort();
}

VALUE rb_block_call(VALUE object, ID name, int args_count, const VALUE *args, rb_block_call_func_t block_call_func, VALUE data) {
fprintf(stderr, "rb_block_call not implemented\n");
abort();
}

VALUE rb_call_super(int args_count, const VALUE *args) {
fprintf(stderr, "rb_call_super not implemented\n");
abort();
}

int rb_block_given_p() {
return truffle_invoke_i(RUBY_CEXT, "rb_block_given_p");
}

VALUE rb_block_proc(void) {
fprintf(stderr, "rb_block_proc not implemented\n");
abort();
}

VALUE rb_yield(VALUE value) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_yield", value);
}
@@ -991,8 +1037,33 @@ int rb_jt_io_handle(VALUE io) {
return truffle_invoke_i(RUBY_CEXT, "rb_jt_io_handle", io);
}

int rb_io_wait_readable(int fd) {
fprintf(stderr, "rb_io_wait_readable not implemented\n");
abort();
}

int rb_io_wait_writable(int fd) {
fprintf(stderr, "rb_io_wait_writable not implemented\n");
abort();
}

void rb_thread_wait_fd(int fd) {
fprintf(stderr, "rb_thread_wait_fd not implemented\n");
abort();
}

NORETURN(void rb_eof_error(void)) {
fprintf(stderr, "rb_eof_error not implemented\n");
abort();
}

// Data

struct RData *rb_jt_wrap_rdata(VALUE value) {
fprintf(stderr, "RDATA not implemented\n");
abort();
}

// Typed data

VALUE rb_data_typed_object_wrap(VALUE ruby_class, void *data, const rb_data_type_t *data_type) {
@@ -1014,3 +1085,19 @@ void *rb_check_typeddata(VALUE value, const rb_data_type_t *data_type) {
fprintf(stderr, "rb_check_typeddata not implemented\n");
abort();
}

// VM

VALUE rb_jt_ruby_verbose_ptr;

VALUE *rb_ruby_verbose_ptr(void) {
rb_jt_ruby_verbose_ptr = truffle_invoke(RUBY_CEXT, "rb_ruby_verbose_ptr");
return &rb_jt_ruby_verbose_ptr;
}

VALUE rb_jt_ruby_debug_ptr;

VALUE *rb_ruby_debug_ptr(void) {
rb_jt_ruby_debug_ptr = truffle_invoke(RUBY_CEXT, "rb_ruby_debug_ptr");
return &rb_jt_ruby_debug_ptr;
}
Original file line number Diff line number Diff line change
@@ -127,6 +127,7 @@ public Boolean block() throws InterruptedException {
@CoreMethod(names = "signal")
public abstract static class SignalNode extends UnaryCoreMethodNode {

@TruffleBoundary
@Specialization
public DynamicObject doSignal(DynamicObject conditionVariable) {
final Object condition = getCondition(conditionVariable);
@@ -141,6 +142,7 @@ public DynamicObject doSignal(DynamicObject conditionVariable) {
@CoreMethod(names = "broadcast")
public abstract static class BroadcastNode extends UnaryCoreMethodNode {

@TruffleBoundary
@Specialization
public DynamicObject doBroadcast(DynamicObject conditionVariable) {
final Object condition = getCondition(conditionVariable);
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ public Object taint(double object) {
return object;
}


@Specialization(guards = "isRubySymbol(object) || isNil(object)")
public Object taintNilOrSymbol(DynamicObject object) {
return object;
21 changes: 21 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -170,6 +170,10 @@ def rb_mWaitReadable
WaitReadable
end

def rb_mComparable
Comparable
end

def rb_mWaitWritable
WaitWritable
end
@@ -238,6 +242,15 @@ def RTEST(value)
!nil.equal?(value) && !false.equal?(value)
end

def RB_OBJ_TAINTED(object)
case object
when TrueClass, FalseClass, Fixnum, Float, NilClass, Symbol
true
else
false
end
end

def rb_float_new(value)
value.to_f
end
@@ -512,6 +525,14 @@ def rb_data_typed_object_wrap(ruby_class, data, data_type)
raise 'not implemented'
end

def rb_ruby_verbose_ptr
$VERBOSE
end

def rb_ruby_debug_ptr
$DEBUG
end

end

Truffle::Interop.export(:ruby_cext, Truffle::CExt)

0 comments on commit 65d836b

Please sign in to comment.