Skip to content

Commit

Permalink
Showing 40 changed files with 526 additions and 177 deletions.
73 changes: 73 additions & 0 deletions bench/java/bench_java_coll_member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'java'
require 'benchmark'

TIMES = (ARGV[0] || 5).to_i

CONTENTS = (1..36).to_a

TIMES.times do
Benchmark.bm(10) do |bm|
bm.report('ArrayList#include? hit ') do
list = java.util.ArrayList.new CONTENTS
hit = 32
1_000_000.times { list.include?(hit) }
end
bm.report('ArrayList#include? miss') do
list = java.util.ArrayList.new CONTENTS
miss = 0
1_000_000.times { list.include?(miss) }
end
bm.report('ArrayList#contains hit ') do
list = java.util.ArrayList.new CONTENTS
hit = 32
1_000_000.times { list.contains(hit) }
end
bm.report('ArrayList#contains miss') do
list = java.util.ArrayList.new CONTENTS
miss = 0
1_000_000.times { list.contains(miss) }
end

bm.report('HashSet#include? hit ') do
list = java.util.HashSet.new CONTENTS
hit = 32
1_000_000.times { list.include?(hit) }
end
bm.report('HashSet#include? miss ') do
list = java.util.HashSet.new CONTENTS
miss = 0
1_000_000.times { list.include?(miss) }
end
bm.report('HashSet#contains hit ') do
list = java.util.HashSet.new CONTENTS
hit = 32
1_000_000.times { list.contains(hit) }
end
bm.report('HashSet#contains miss ') do
list = java.util.HashSet.new CONTENTS
miss = 0
1_000_000.times { list.contains(miss) }
end

bm.report('LHashSet#include? hit ') do
list = java.util.LinkedHashSet.new CONTENTS
hit = 32
1_000_000.times { list.include?(hit) }
end
bm.report('LHashSet#include? miss ') do
list = java.util.LinkedHashSet.new CONTENTS
miss = 0
1_000_000.times { list.include?(miss) }
end
bm.report('LHashSet#contains hit ') do
list = java.util.LinkedHashSet.new CONTENTS
hit = 32
1_000_000.times { list.contains(hit) }
end
bm.report('LHashSet#contains miss ') do
list = java.util.LinkedHashSet.new CONTENTS
miss = 0
1_000_000.times { list.contains(miss) }
end
end
end
45 changes: 45 additions & 0 deletions bench/java/bench_java_list_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'java'
require 'benchmark'

TIMES = (ARGV[0] || 5).to_i

TIMES.times do
Benchmark.bm(10) do |bm|
bm.report('ArrayList') do
list = java.util.ArrayList.new
one = 1.to_java
two = 2.to_java
thr = 3.to_java
1_000_000.times do
list.clear

list << one; list << two; list << thr

list[2] = one; list[0] = two; list[1] = thr

list.index(one)
list.rindex(thr)

list.to_a
end
end
bm.report('LinkedList') do
list = java.util.LinkedList.new
one = 1.to_java
two = 2.to_java
thr = 3.to_java
1_000_000.times do
list.clear

list << one; list << two; list << thr

list[2] = one; list[0] = two; list[1] = thr

list.index(one)
list.rindex(thr)

list.to_a
end
end
end
end
5 changes: 3 additions & 2 deletions ci.hocon
Original file line number Diff line number Diff line change
@@ -298,21 +298,22 @@ 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]
${jt} [build, cexts, --no-openssl]
]

environment: {
GEM_HOME: jruby-truffle-gem-test-pack/gems
GRAAL_HOME: sulong-workspace/sulong,
SULONG_HOME: sulong-workspace/sulong,
SULONG_NO_LIBRARY: "true",
USE_SYSTEM_CLANG: "true",
HOST_VM: server,
HOST_VM_CONFIG: graal-core
}

run: [
${jt} [test, specs, --graal, ":capi"],
${jt} [test, cexts]
${jt} [test, cexts, --no-libxml, --no-openssl]
]
}

2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1899,6 +1899,8 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode) {
// We add this extra nil copy because we do not know if we have a circular defininition of
// argVar: proc { |a=a| } or proc { |a = foo(bar(a))| }.
addInstr(new CopyInstr(argVar, manager.getNil()));
// This bare build looks weird but OptArgNode is just a marker and value is either a LAsgnNode
// or a DAsgnNode. So building the value will end up having a copy(var, assignment).
build(optArg.getValue());
addInstr(new LabelInstr(variableAssigned));
}
13 changes: 13 additions & 0 deletions core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Original file line number Diff line number Diff line change
@@ -117,6 +117,19 @@ public static IRubyObject each_with_index(final ThreadContext context, final IRu
return context.nil;
}

@JRubyMethod(name = { "to_a", "entries" })
public static IRubyObject to_a(final ThreadContext context, final IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final RubyArray ary = runtime.newArray();
java.lang.Iterable iterable = unwrapJavaObject(self);
java.util.Iterator iterator = iterable.iterator();
while ( iterator.hasNext() ) {
final Object value = iterator.next();
ary.append( convertJavaToUsableRubyObject(runtime, value) );
}
return ary;
}

}

@JRubyClass(name = "Java::JavaLang::Comparable", include = "Comparable")
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java
Original file line number Diff line number Diff line change
@@ -137,6 +137,12 @@ public static IRubyObject each_with_index(final ThreadContext context, final IRu
return JavaLang.Iterable.each_with_index(context, self, block);
}

@JRubyMethod(name = { "include?", "member?" }) // @override Enumerable#include?
public static RubyBoolean include_p(final ThreadContext context, final IRubyObject self, final IRubyObject obj) {
final java.util.Collection coll = unwrapJavaObject(self);
return context.runtime.newBoolean( coll.contains( obj.toJava(java.lang.Object.class) ) );
}

// NOTE: first might conflict with some Java types (e.g. java.util.Deque) thus providing a ruby_ alias
@JRubyMethod(name = { "first", "ruby_first" }) // re-def Enumerable#first
public static IRubyObject first(final ThreadContext context, final IRubyObject self) {
@@ -165,13 +171,13 @@ public static IRubyObject append(final IRubyObject self, final IRubyObject item)
return self;
}

@JRubyMethod
@JRubyMethod(name = { "to_a", "entries" })
public static RubyArray to_a(final ThreadContext context, final IRubyObject self) {
final Object[] array = ((java.util.Collection) unwrapJavaObject(self)).toArray();
if ( IRubyObject.class.isAssignableFrom(array.getClass().getComponentType()) ) {
return RubyArray.newArrayMayCopy(context.runtime, (IRubyObject[]) array);
}
return RubyArray.newArrayMayCopy(context.runtime, convertJavaArrayToRuby(context.runtime, array));
return RubyArray.newArrayNoCopy(context.runtime, convertJavaArrayToRuby(context.runtime, array));
}

@JRubyMethod(name = "+", required = 1)
10 changes: 10 additions & 0 deletions core/src/main/ruby/jruby/java/java_ext/java.util.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,16 @@ def each_with_index(&block)
# stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

# Re-implemented for efficiency, so that we do not (`#each`) loop over the collection
# for types where its not necessary (e.g. *java.util.Set* instances), using (native) `contains`.
# @see Java::java::lang::Iterable#include?
# @return [true, false]
# @since 9.1.3
def include?(obj)
# stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end
alias member? include?

# `Enumerable#first`
# @note Might collide with *java.util.Deque#getFirst* in which case you want to alias its ruby_ name
# so that the Ruby version is used e.g. `java.util.ArrayDeque.class_eval { alias first ruby_first }`
1 change: 1 addition & 0 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@ double RFLOAT_VALUE(VALUE value);
char *RSTRING_PTR(VALUE string);
int RSTRING_LEN(VALUE string);
VALUE rb_intern_str(VALUE string);
VALUE rb_str_new(const char *string, long length);
VALUE rb_str_new_cstr(const char *string);
#define rb_str_new2 rb_str_new_cstr
void rb_str_cat(VALUE string, const char *to_concat, long length);
Original file line number Diff line number Diff line change
@@ -47,17 +47,13 @@ CookiesTest:
- test_legacy_json_signed_cookie_is_read_and_transparently_upgraded_by_signed_json_cookie_jar_if_both_secret_token_and_secret_key_base_are_set
- test_legacy_json_signed_cookie_is_read_and_transparently_upgraded_by_signed_json_hybrid_jar_if_both_secret_token_and_secret_key_base_are_set
- test_legacy_signed_cookie_is_read_and_transparently_upgraded_by_signed_cookie_jar_if_both_secret_token_and_secret_key_base_are_set
- test_wrapped_encrypted_cookie_using_json_serializer
- test_encrypted_cookie_using_json_serializer
- test_wrapped_encrypted_cookie_using_json_serializer # fails on CI
- test_encrypted_cookie_using_json_serializer # fails on CI
DebugExceptionsTest:
- test_debug_exceptions_app_shows_user_code_that_caused_the_error_in_source_view
- test_display_backtrace_on_template_missing_errors
- test_display_backtrace_when_error_type_is_SyntaxError
- test_display_backtrace_when_error_type_is_SyntaxError_wrapped_by_ActionView
- test_displays_request_and_response_info_when_a_RoutingError_occurs
- test_rescue_with_diagnostics_message
- test_rescue_with_text_error_for_xhr_request
- test_show_registered_original_exception_for_wrapped_exceptions
- test_display_backtrace_when_error_type_is_SyntaxError_wrapped_by_ActionView::Template::Error
TestRoutingMapper:
- test_redirect_modulo
@@ -72,22 +68,18 @@ CookieStoreTest:
- test_deserializes_unloaded_classes_on_get_id
- test_deserializes_unloaded_classes_on_get_value
StaticTest:
- test_serves_gzip_files_when_header_set
- test_serves_gzip_with_propper_content_type_fallback
- test_serves_gzip_files_when_header_set # fails on travis
- test_serves_gzip_with_propper_content_type_fallback # fails on travis
StaticEncodingTest:
- test_serves_gzip_files_when_header_set
- test_serves_gzip_with_propper_content_type_fallback
- test_serves_gzip_files_when_header_set # fails on travis
- test_serves_gzip_with_propper_content_type_fallback # fails on travis
TestGenerationPrefix::WithMountedEngine:
- test_[ENGINE]_absolute_path_redirect_doesn't_use_SCRIPT_NAME_from_request
- test_[ENGINE]_absolute_path_root_doesn't_use_SCRIPT_NAME_from_request
- test_[ENGINE]_relative_path_redirect_uses_SCRIPT_NAME_from_request
ActionController::LiveStreamTest:
- test_exception_callback_when_committed
- test_abort_with_full_buffer # hangs sometimes
- test_async_stream # intermittent on travis
- test_stale_without_etag # hangs sometimes
- test_async_stream # fails on travis
ApplicationIntegrationTest:
- test_missing_route_helper_after_controller_access
- test_missing_route_helper_before_controller_access
HttpDigestAuthenticationTest:
- authentication_request_with_invalid_realm # hangs sometimes
25 changes: 13 additions & 12 deletions lib/ruby/truffle/jruby+truffle/lib/truffle/config.rb
Original file line number Diff line number Diff line change
@@ -234,36 +234,37 @@ def compute_physical_processor_count


class Truffle::Runner::CIEnvironment
def rails_ci(exclude)
repository_name 'rails'
def rails_ci
declare_options debug: ['--[no-]debug', 'Run tests with remote debugging enabled.',
STORE_NEW_VALUE, false],
exclude: ['--[no-]exclude', 'Exclude known failing tests',
STORE_NEW_VALUE, true]

repository_name 'rails'

use_only_https_git_paths!

has_to_succeed setup
set_result run([%w[--require-pattern test/**/*_test.rb],
(exclude ? %w[-r excluded-tests] : []),
%w[-- -I test -e nil]].flatten(1))
set_result run([*%w[--require-pattern test/**/*_test.rb],
*(%w[-r excluded-tests] if option(:exclude)),
*(%w[--debug] if option(:debug)),
*%w[-- -I test -e nil]])
end
end

Truffle::Runner.add_ci_definition :actionpack do
declare_options exclude: ['--[no-]exclude',
'Exclude known failing tests',
STORE_NEW_VALUE,
true]
subdir 'actionpack'
rails_ci option(:exclude)
rails_ci
end

Truffle::Runner.add_ci_definition :activemodel do
subdir 'activemodel'
rails_ci false
rails_ci
end

Truffle::Runner.add_ci_definition :activesupport do
subdir 'activesupport'
rails_ci false
rails_ci
end

Truffle::Runner.add_ci_definition :algebrick do
38 changes: 38 additions & 0 deletions spec/java_integration/extensions/collection_spec.rb
Original file line number Diff line number Diff line change
@@ -79,6 +79,9 @@
coll = java.util.ArrayDeque.new(@data)
expect(coll.to_a).to eq(@data.to_a)

coll = java.util.LinkedHashSet.new(@data)
expect(coll.entries).to eq(@data.to_a)

coll = java.util.HashSet.new
expect(coll.to_a).to eq([])
end
@@ -154,6 +157,41 @@
expect( set.to_a ).to eql ['0']
end

it '#include?' do
set = java.util.LinkedHashSet.new [1, 2, 3]
expect( set.include? 1 ).to be true
expect( set.member? 2 ).to be true
expect( set.contains 3 ).to be true
set.add 4; set.add 5.to_java
expect( set.include? 4 ).to be true
expect( set.include? 5 ).to be true
expect( set.contains 4 ).to be true
expect( set.contains 5 ).to be true
expect( set.contains 4.to_java ).to be true
expect( set.contains 5.to_java ).to be true
expect( set.contains 5.to_java(:byte) ).to be false
expect( set.contains 5.to_java(:short) ).to be false
expect( set.contains 6 ).to be false
expect( set.include? 6 ).to be false
expect( set.include? 4.to_java(:byte) ).to be false
expect( set.include? 4.to_java(:short) ).to be false
expect( set.include? 2.to_java ).to be true
expect( set.include? 2.to_java(:short) ).to be false
end

it '#include? (specific)' do
pending 'due Java numeric conversion can not add to_java(:xxx) to collection'

set = java.util.LinkedHashSet.new [2]
set << 1.to_java(:short)
expect( set.include? 1.to_java ).to be true
expect( set.include? 1.to_java(:short) ).to be true

set.add 3.to_java(:short)
expect( set.contains 3.to_java ).to be true
expect( set.contains 3.to_java(:short) ).to be true
end

it "should respect to_ary objects defined on iteration" do
class Pair
def initialize(a, b)
15 changes: 15 additions & 0 deletions spec/java_integration/extensions/iterable_spec.rb
Original file line number Diff line number Diff line change
@@ -47,4 +47,19 @@
expect( paths.last ).to eq 'ITERABLE_SPEC.RB'
end

it 'converts #to_a' do
file_system = java.nio.file.FileSystems.getDefault
path = file_system.getPath(__FILE__)
expect( path.to_a ).to_not be_empty
expect( path.to_a ).to eql iterate_path(path)
end

private

def iterate_path(path)
res = [] ; it = path.iterator
while it.hasNext ; res << it.next end
res
end

end
Loading

0 comments on commit 4dfb8c7

Please sign in to comment.