Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/truffle-head'
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 26, 2016
2 parents 418dc70 + 574fd07 commit 6c4e28e
Show file tree
Hide file tree
Showing 335 changed files with 41,258 additions and 1,678 deletions.
385 changes: 377 additions & 8 deletions ci.hocon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/JRubyTruffleInterface.java
Expand Up @@ -13,7 +13,7 @@ public interface JRubyTruffleInterface {

String RUNTIME_SYMBOL = "org.jruby.truffle.runtime";

Object execute(org.jruby.ast.RootNode rootNode);
int execute(String path);

void dispose();

Expand Down
33 changes: 16 additions & 17 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -556,6 +556,20 @@ public void runFromMain(InputStream inputStream, String filename) {
return;
}

if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
final JRubyTruffleInterface truffleContext = getTruffleContext();
Main.printTruffleTimeMetric("before-run");
int exitCode;
try {
exitCode = truffleContext.execute(filename);
} finally {
Main.printTruffleTimeMetric("after-run");
shutdownTruffleContextIfRunning();
}

throw new MainExitException(exitCode);
}

ParseResult parseResult = parseFromMain(filename, inputStream);

// if no DATA, we're done with the stream, shut it down
Expand Down Expand Up @@ -850,24 +864,9 @@ public IRubyObject runInterpreter(ThreadContext context, ParseResult parseResult
return interpreter.execute(this, parseResult, self);
}

public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObject self) {
public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObject self) {
assert rootNode != null : "scriptNode is not null";

if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert rootNode instanceof RootNode;
assert self == getTopSelf();
final JRubyTruffleInterface truffleContext = getTruffleContext();
Main.printTruffleTimeMetric("before-run");
try {
truffleContext.execute((RootNode) rootNode);
} finally {
Main.printTruffleTimeMetric("after-run");
shutdownTruffleContextIfRunning();
}
return getNil();
} else {
return interpreter.execute(this, rootNode, self);
}
return interpreter.execute(this, rootNode, self);
}

public IRubyObject runInterpreter(Node scriptNode) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Expand Up @@ -240,6 +240,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_PLATFORM_USE_JAVA = bool(TRUFFLE, "truffle.platform.use_java", false, "Use a pure-Java platform, so no native POSIX.");

public static final Option<Boolean> TRUFFLE_COVERAGE_GLOBAL = bool(TRUFFLE, "truffle.coverage.global", false, "Run coverage for all code and print results on exit.");
public static final Option<Boolean> TRUFFLE_INLINE_JS = bool(TRUFFLE, "truffle.inline_js", false, "Allow inline JavaScript.");

public static final Option<String> TRUFFLE_CORE_LOAD_PATH = string(TRUFFLE, "truffle.core.load_path", "truffle:/jruby-truffle", "Location to load the Truffle core library from.");
public static final Option<Boolean> TRUFFLE_CORE_PARALLEL_LOAD = bool(TRUFFLE, "truffle.core.parallel_load", false, "Load the Truffle core library in parallel.");
Expand Down Expand Up @@ -301,6 +302,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_BACKTRACES_INTERLEAVE_JAVA = bool(TRUFFLE, "truffle.backtraces.interleave_java", false, "Interleave Java stacktraces into the Ruby backtrace.");
public static final Option<Integer> TRUFFLE_BACKTRACES_LIMIT = integer(TRUFFLE, "truffle.backtraces.limit", 9999, "Limit the size of Ruby backtraces.");
public static final Option<Boolean> TRUFFLE_BACKTRACES_OMIT_UNUSED = bool(TRUFFLE, "truffle.backtraces.omit_unused", true, "Omit backtraces that should be unused as they have pure rescue expressions.");
public static final Option<Boolean> TRUFFLE_BASICOPS_INLINE = bool(TRUFFLE, "truffle.basic_ops.inline", true, "Inline basic operations (like Fixnum operators) in the AST without a call.");

public static final Option<Boolean> TRUFFLE_METRICS_TIME = bool(TRUFFLE, "truffle.metrics.time", false, "Print the time at various stages of VM operation.");
public static final Option<Boolean> TRUFFLE_METRICS_MEMORY_USED_ON_EXIT = bool(TRUFFLE, "truffle.metrics.memory_used_on_exit", false, "Print the size of heap memory in use on exit.");
Expand Down
80 changes: 67 additions & 13 deletions lib/ruby/truffle/cext/ruby.h
Expand Up @@ -32,6 +32,7 @@ extern "C" {
// Support

#define RUBY_CEXT (void *)truffle_import_cached("ruby_cext")
#define MUST_INLINE __attribute__((always_inline))

// Configuration

Expand Down Expand Up @@ -60,6 +61,13 @@ typedef VALUE ID;

NORETURN(VALUE rb_f_notimplement(int args_count, const VALUE *args, VALUE object));

// Non-standard

NORETURN(void rb_jt_error(const char *message));

void *rb_jt_to_native_handle(VALUE managed);
VALUE rb_jt_from_native_handle(void *native);

// Memory

#define xmalloc malloc
Expand Down Expand Up @@ -345,11 +353,36 @@ VALUE rb_str_new_cstr(const char *string);
VALUE rb_str_cat(VALUE string, const char *to_concat, long length);
VALUE rb_str_cat2(VALUE string, const char *to_concat);
VALUE rb_str_to_str(VALUE string);
VALUE rb_string_value(volatile VALUE *value_pointer);

MUST_INLINE VALUE rb_string_value(VALUE *value_pointer) {
VALUE value = *value_pointer;

if (!RB_TYPE_P(value, T_STRING)) {
value = rb_str_to_str(value);
*value_pointer = value;
}

return value;
}

MUST_INLINE char *rb_string_value_ptr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);
return RSTRING_PTR(string);
}

MUST_INLINE char *rb_string_value_cstr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);

if (!truffle_invoke_b(RUBY_CEXT, "rb_string_value_cstr_check", string)) {
rb_jt_error("rb_string_value_cstr failure case not implemented");
abort();
}

return RSTRING_PTR(string);
}

#define StringValue(value) rb_string_value(&(value))
#define SafeStringValue StringValue
char *rb_string_value_ptr(volatile VALUE* value_pointer);
char *rb_string_value_cstr(volatile VALUE* value_pointer);
#define StringValuePtr(string) rb_string_value_ptr(&(string))
#define StringValueCStr(string) rb_string_value_cstr(&(string))
VALUE rb_str_buf_new(long capacity);
Expand Down Expand Up @@ -432,6 +465,14 @@ void rb_warning(const char *fmt, ...);

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

MUST_INLINE int rb_jt_scan_args_02(int argc, VALUE *argv, VALUE *v1, VALUE *v2) {
if (argc >= 1) *v1 = argv[0];
if (argc >= 2) *v2 = argv[1];
return argc;
}

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

// Calls

int rb_respond_to(VALUE object, ID name);
Expand Down Expand Up @@ -614,20 +655,26 @@ void rb_thread_wait_fd(int fd);

NORETURN(void rb_eof_error(void));

// Objects

struct RBasic {
// Empty
};

// Data

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

struct RData *rb_jt_wrap_rdata(VALUE value);
struct RData *rb_jt_adapt_rdata(VALUE value);

#define RDATA(value) rb_jt_wrap_rdata(value)
#define RDATA(value) rb_jt_adapt_rdata(value)

#define DATA_PTR(value) *((volatile intptr_t*) 0)
#define DATA_PTR(value) (RDATA(value)->data)

// Typed data

Expand All @@ -646,8 +693,21 @@ struct rb_data_type_struct {
VALUE flags;
};

struct RTypedData {
struct RBasic basic;
const rb_data_type_t *type;
VALUE typed_flag;
void *data;
};

#define RUBY_TYPED_FREE_IMMEDIATELY 1

struct RTypedData *rb_jt_adapt_rtypeddata(VALUE value);

#define RTYPEDDATA(value) rb_jt_adapt_rtypeddata(value)

#define RTYPEDDATA_DATA(value) (RTYPEDDATA(value)->data)

VALUE rb_data_typed_object_wrap(VALUE ruby_class, void *data, const rb_data_type_t *data_type);

#define TypedData_Wrap_Struct(ruby_class, data_type, data) rb_data_typed_object_wrap((ruby_class), (data), (data_type))
Expand All @@ -666,8 +726,6 @@ void *rb_check_typeddata(VALUE value, const rb_data_type_t *data_type);

#define TypedData_Get_Struct(value, type, data_type, variable) ((variable) = (type *)rb_check_typeddata((value), (data_type)))

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

// VM

VALUE *rb_ruby_verbose_ptr(void);
Expand All @@ -676,10 +734,6 @@ VALUE *rb_ruby_verbose_ptr(void);
VALUE *rb_ruby_debug_ptr(void);
#define ruby_debug (*rb_ruby_debug_ptr())

// Non-standard

NORETURN(void rb_jt_error(const char *message));

#if defined(__cplusplus)
}
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/ruby/truffle/truffle/io/nonblock.rb
@@ -0,0 +1 @@
# TODO
9 changes: 5 additions & 4 deletions lib/ruby/truffle/truffle/openssl.rb
Expand Up @@ -6,14 +6,15 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

if ENV['JRUBY_TRUFFLE_NATIVE_OPENSSL']
require_relative '../openssl/openssl'
else
if ENV['JRUBY_TRUFFLE_SHIM_OPENSSL']
# If loaded directly simulate as it was not found, it can added only
# explicitly by loading openssl-stubs which makes it look like
# openssl was loaded.

load_error = LoadError.new("cannot load such file -- openssl")
load_error = LoadError.new('cannot load such file -- openssl')
load_error.instance_variable_set :@path, 'openssl'
raise load_error
else
$LOAD_PATH.unshift File.expand_path('../../openssl', __FILE__)
require_relative '../openssl/openssl.rb'
end
3 changes: 2 additions & 1 deletion mx.jruby/suite.py
Expand Up @@ -30,7 +30,8 @@ def mavenLib(mavenDep, sha1):
"suites": [
{
"name": "truffle",
"version": "387cbe478688e84d211aa534b7b93d47709cadd9",
# Must be the same as in truffle/pom.rb and ci.hocon
"version": "60fde6f5778d478411632077154bea1679839780",
"urls": [
{"url": "https://github.com/graalvm/truffle.git", "kind": "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/optional/capi/spec_helper.rb
Expand Up @@ -111,7 +111,7 @@ def compile_extension_jruby_truffle(name)
end

system "#{RbConfig::CONFIG['bindir']}/../tool/jt.rb", 'cextc', extension_path
raise "Compilation of #{extension_path} failed" unless $?.success?
raise "Compilation of #{extension_path} failed: #{$?}" unless $?.success?

output_file
ensure
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/flatten_tags.txt

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/binding/local_variable_set_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/binding/local_variables_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/complex/hash_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/encoding/replicate_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/lchmod_tags.txt
@@ -1,3 +1,2 @@
fails:File.lchmod changes the file mode of the link and not of the file
fails(linux/openbsd, not supposed to impl):File.lchmod returns false from #respond_to?
fails(linux/openbsd, not supposed to impl):File.lchmod raises a NotImplementedError when called
1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/element_reference_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/hash/to_proc_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/global_variables_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/method/hash_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/slice_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/unboundmethod/hash_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/language/alias_tags.txt
@@ -1,2 +1 @@
slow:The alias keyword on top level defines the alias on Object
fails:The alias keyword on top level defines the alias on Object
1 change: 0 additions & 1 deletion spec/truffle/tags/language/block_tags.txt

This file was deleted.

3 changes: 2 additions & 1 deletion test/truffle/compiler/attachments-optimise.sh
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

ruby -X+T -J-G:+TruffleCompilationExceptionsAreFatal test/truffle/compiler/attachments-optimise/attachments-optimise.rb
# relies on value profiling
ruby -X+T -J-G:+TruffleCompilationExceptionsAreFatal -Xtruffle.basic_ops.inline=false test/truffle/compiler/attachments-optimise/attachments-optimise.rb
2 changes: 1 addition & 1 deletion test/truffle/compiler/pe.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

ruby -X+T -J-G:+TruffleCompilationExceptionsAreThrown test/truffle/compiler/pe/pe.rb
ruby -X+T -J-G:+TruffleCompilationExceptionsAreThrown -Xtruffle.basic_ops.inline=false test/truffle/compiler/pe/pe.rb
6 changes: 3 additions & 3 deletions test/truffle/integration/js/inline-exported.rb
Expand Up @@ -11,7 +11,7 @@
exit
end

Truffle::Interop.eval('application/javascript', %{
Truffle::Interop.eval 'application/javascript', %{
function clamp(min, max, value) {
if (value < min) {
return min;
Expand All @@ -22,9 +22,9 @@
}
}
Interop.export('clamp', clamp.bind(this));
})
}

Truffle::Interop.import_method(:clamp)
Truffle::Interop.import_method :clamp

if clamp(10, 90, 46) != 46
abort 'result not as expected'
Expand Down
21 changes: 21 additions & 0 deletions test/truffle/integration/js/transparent.rb
@@ -0,0 +1,21 @@
# 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

function clamp(min, max, value) {
if (value < min) {
return min;
} else if (value > max) {
return max;
} else {
return value;
}
}

if clamp(10, 90, 46) != 46
abort 'result not as expected'
end
4 changes: 2 additions & 2 deletions test/truffle/integration/safe.sh
Expand Up @@ -28,13 +28,13 @@ unsafe -Xtruffle.platform.safe_puts=false -e "Truffle::Safe.puts 'hello, world'"

unsafe -e "puts 'hello, world'"
unsafe -e '`echo foo`'
unsafe -e 'exit!'
unsafe -e 'exit!(0)'
unsafe -e 'Rubinius::FFI::Pointer.new(1).read_int'
unsafe -e "File.open('bad.txt')"

# Check we can enable some unsafe operations if we want to

safe -Xtruffle.platform.safe.exit=true -e 'exit!'
safe -Xtruffle.platform.safe.exit=true -e 'exit!(0)'

# Check that safe_puts sanitises correctly

Expand Down

0 comments on commit 6c4e28e

Please sign in to comment.