Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jul 13, 2016
2 parents f69ff6a + dc37747 commit 3bac257
Showing 14 changed files with 289 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -83,8 +83,6 @@ RescueControllerTest:
- test_block_rescue_handler_with_argument_as_string
- test_proc_rescue_handle_with_argument
- test_proc_rescue_handle_with_argument_as_string
SendFileTest:
- test_send_file_with_action_controller_live
TestCaseTest:
- test_assert_select_with_body
- test_assert_select_without_body
6 changes: 3 additions & 3 deletions lib/ruby/truffle/jruby+truffle/lib/truffle/config.rb
Original file line number Diff line number Diff line change
@@ -178,9 +178,9 @@ def exclusion_file(gem_name)
rails_common,
stubs.fetch(:html_sanitizer),
setup: { file: { 'excluded-tests.rb' => format(dedent(<<-RUBY), exclusion_file(:actionpack)),
failures = %s
require 'truffle/exclude_rspec_examples'
Truffle.exclude_rspec_examples failures
failures = %s
require 'truffle/exclude_rspec_examples'
Truffle.exclude_rspec_examples failures
RUBY
} })

2 changes: 1 addition & 1 deletion lib/ruby/truffle/jruby+truffle/lib/truffle/runner.rb
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ module OptionBlocks
apply_pattern = -> (pattern, old, options) do
Dir.glob(pattern) do |file|
if options[:exclude_pattern].any? { |p| /#{p}/ =~ file }
log "skipped: #{file}" if verbose?
puts "skipped: #{file}"
next
end
options[:require] << File.expand_path(file)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/rubygems/core_ext/kernel_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/rubygems/core_ext/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/rubygems/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/rubygems/core_ext/' + File.basename(__FILE__)
73 changes: 73 additions & 0 deletions lib/ruby/truffle/stdlib/rubygems/core_ext/kernel_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
##
# RubyGems adds the #gem method to allow activation of specific gem versions
# and overrides the #require method on Kernel to make gems appear as if they
# live on the <code>$LOAD_PATH</code>. See the documentation of these methods
# for further detail.

module Kernel

# REFACTOR: This should be pulled out into some kind of hacks file.
remove_method :gem if 'method' == defined? gem # from gem_prelude.rb on 1.9

##
# Use Kernel#gem to activate a specific version of +gem_name+.
#
# +requirements+ is a list of version requirements that the
# specified gem must match, most commonly "= example.version.number". See
# Gem::Requirement for how to specify a version requirement.
#
# If you will be activating the latest version of a gem, there is no need to
# call Kernel#gem, Kernel#require will do the right thing for you.
#
# Kernel#gem returns true if the gem was activated, otherwise false. If the
# gem could not be found, didn't match the version requirements, or a
# different version was already activated, an exception will be raised.
#
# Kernel#gem should be called *before* any require statements (otherwise
# RubyGems may load a conflicting library version).
#
# Kernel#gem only loads prerelease versions when prerelease +requirements+
# are given:
#
# gem 'rake', '>= 1.1.a', '< 2'
#
# In older RubyGems versions, the environment variable GEM_SKIP could be
# used to skip activation of specified gems, for example to test out changes
# that haven't been installed yet. Now RubyGems defers to -I and the
# RUBYLIB environment variable to skip activation of a gem.
#
# Example:
#
# GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb

def gem(gem_name, *requirements) # :doc:
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name

if gem_name.kind_of? Gem::Dependency
unless Gem::Deprecate.skip
warn "#{Gem.location_of_caller.join ':'}:Warning: Kernel.gem no longer "\
"accepts a Gem::Dependency object, please pass the name "\
"and requirements directly"
end

requirements = gem_name.requirement
gem_name = gem_name.name
end

dep = Gem::Dependency.new(gem_name, *requirements)

loaded = Gem.loaded_specs[gem_name]

return false if loaded && dep.matches_spec?(loaded)

spec = dep.to_spec

Gem::LOADED_SPECS_MUTEX.synchronize {
spec.activate
} if spec
end

private :gem

end
139 changes: 139 additions & 0 deletions lib/ruby/truffle/stdlib/rubygems/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

require 'monitor'

module Kernel

RUBYGEMS_ACTIVATION_MONITOR = Monitor.new # :nodoc:

if defined?(gem_original_require) then
# Ruby ships with a custom_require, override its require
remove_method :require
else
##
# The Kernel#require from before RubyGems was loaded.

alias gem_original_require require
private :gem_original_require
end

##
# When RubyGems is required, Kernel#require is replaced with our own which
# is capable of loading gems on demand.
#
# When you call <tt>require 'x'</tt>, this is what happens:
# * If the file can be loaded from the existing Ruby loadpath, it
# is.
# * Otherwise, installed gems are searched for a file that matches.
# If it's found in gem 'y', that gem is activated (added to the
# loadpath).
#
# The normal <tt>require</tt> functionality of returning false if
# that file has already been loaded is preserved.

def require path
RUBYGEMS_ACTIVATION_MONITOR.enter

path = path.to_path if path.respond_to? :to_path

spec = Gem.find_unresolved_default_spec(path)
if spec
Gem.remove_unresolved_default_spec(spec)
gem(spec.name)
end

# If there are no unresolved deps, then we can use just try
# normal require handle loading a gem from the rescue below.

if Gem::Specification.unresolved_deps.empty? then
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
end

# If +path+ is for a gem that has already been loaded, don't
# bother trying to find it in an unresolved gem, just go straight
# to normal require.
#--
# TODO request access to the C implementation of this to speed up RubyGems

spec = Gem::Specification.stubs.find { |s|
s.activated? and s.contains_requirable_file? path
}

begin
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(spec.to_fullpath(path) || path)
end if spec

# Attempt to find +path+ in any unresolved gems...

found_specs = Gem::Specification.find_in_unresolved path

# If there are no directly unresolved gems, then try and find +path+
# in any gems that are available via the currently unresolved gems.
# For example, given:
#
# a => b => c => d
#
# If a and b are currently active with c being unresolved and d.rb is
# requested, then find_in_unresolved_tree will find d.rb in d because
# it's a dependency of c.
#
if found_specs.empty? then
found_specs = Gem::Specification.find_in_unresolved_tree path

found_specs.each do |found_spec|
found_spec.activate
end

# We found +path+ directly in an unresolved gem. Now we figure out, of
# the possible found specs, which one we should activate.
else

# Check that all the found specs are just different
# versions of the same gem
names = found_specs.map(&:name).uniq

if names.size > 1 then
RUBYGEMS_ACTIVATION_MONITOR.exit
raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}"
end

# Ok, now find a gem that has no conflicts, starting
# at the highest version.
valid = found_specs.select { |s| s.conflicts.empty? }.last

unless valid then
le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
le.name = names.first
RUBYGEMS_ACTIVATION_MONITOR.exit
raise le
end

valid.activate
end

RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
rescue LoadError => load_error
RUBYGEMS_ACTIVATION_MONITOR.enter

if load_error.message.start_with?("Could not find") or
(load_error.message.end_with?(path) and Gem.try_activate(path)) then
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
else
RUBYGEMS_ACTIVATION_MONITOR.exit
end

raise load_error
end

private :require

end

2 changes: 0 additions & 2 deletions lib/ruby/truffle/truffle/rubygems/core_ext/kernel_gem.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/ruby/truffle/truffle/rubygems/core_ext/kernel_require.rb

This file was deleted.

69 changes: 49 additions & 20 deletions mx.jruby/mx_jruby.py
Original file line number Diff line number Diff line change
@@ -377,32 +377,61 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
out = mx.OutputCapture()

if jt(arguments, out=out, nonZeroIsFatal=False) == 0:
data = [float(s) for s in out.data.split('\n')[1:-1]]
elapsed = [d for n, d in enumerate(data) if n % 2 == 0]
samples = [d for n, d in enumerate(data) if n % 2 == 1]
lines = out.data.split('\n')[1:-1]

if len(samples) > 1:
warmed_up_samples = [sample for n, sample in enumerate(samples) if n / float(len(samples)) >= 0.5]
if lines[-1] == 'optimised away':
data = [float(s) for s in lines[0:-2]]
elapsed = [d for n, d in enumerate(data) if n % 2 == 0]
samples = [d for n, d in enumerate(data) if n % 2 == 1]

return [{
'benchmark': benchmark,
'metric.name': 'throughput',
'metric.value': sample,
'metric.unit': 'op/s',
'metric.better': 'higher',
'metric.iteration': n,
'extra.metric.warmedup': 'false',
'extra.metric.elapsed-num': e,
'extra.metric.human': 'optimised away'
} for n, (e, sample) in enumerate(zip(elapsed, samples))] + [{
'benchmark': benchmark,
'metric.name': 'throughput',
'metric.value': 2147483647, # arbitrary high value (--simple won't run more than this many ips)
'metric.unit': 'op/s',
'metric.better': 'higher',
'metric.iteration': len(samples),
'extra.metric.warmedup': 'true',
'extra.metric.elapsed-num': elapsed[-1] + 2.0, # just put the data point beyond the last one a bit
'extra.metric.human': 'optimised away',
'extra.error': 'optimised away'
}]
else:
warmed_up_samples = samples
data = [float(s) for s in lines]
elapsed = [d for n, d in enumerate(data) if n % 2 == 0]
samples = [d for n, d in enumerate(data) if n % 2 == 1]

warmed_up_mean = sum(warmed_up_samples) / float(len(warmed_up_samples))

return [{
'benchmark': benchmark,
'metric.name': 'throughput',
'metric.value': sample,
'metric.unit': 'op/s',
'metric.better': 'higher',
'metric.iteration': n,
'extra.metric.warmedup': 'true' if n / float(len(samples)) >= 0.5 else 'false',
'extra.metric.elapsed-num': e,
'extra.metric.human': '%d/%d %f op/s' % (n, len(samples), warmed_up_mean)
} for n, (e, sample) in enumerate(zip(elapsed, samples))]
if len(samples) > 1:
warmed_up_samples = [sample for n, sample in enumerate(samples) if n / float(len(samples)) >= 0.5]
else:
warmed_up_samples = samples

warmed_up_mean = sum(warmed_up_samples) / float(len(warmed_up_samples))

return [{
'benchmark': benchmark,
'metric.name': 'throughput',
'metric.value': sample,
'metric.unit': 'op/s',
'metric.better': 'higher',
'metric.iteration': n,
'extra.metric.warmedup': 'true' if n / float(len(samples)) >= 0.5 else 'false',
'extra.metric.elapsed-num': e,
'extra.metric.human': '%d/%d %f op/s' % (n, len(samples), warmed_up_mean)
} for n, (e, sample) in enumerate(zip(elapsed, samples))]
else:
sys.stderr.write(out.data)

# TODO CS 24-Jun-16, how can we fail the wider suite?
return [{
'benchmark': benchmark,
'metric.name': 'throughput',
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/thread/keys_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.Frame;
@@ -482,6 +483,10 @@ public Object matchStart(DynamicObject regexp, DynamicObject string, int startPo
@CoreMethod(names = { "quote", "escape" }, onSingleton = true, required = 1)
public abstract static class QuoteNode extends CoreMethodArrayArgumentsNode {

@Child ToStrNode toStrNode;

abstract public DynamicObject executeQuote(VirtualFrame frame, Object raw);

@TruffleBoundary
@Specialization(guards = "isRubyString(raw)")
public DynamicObject quoteString(DynamicObject raw) {
@@ -495,6 +500,16 @@ public DynamicObject quoteSymbol(DynamicObject raw) {
return quoteString(createString(StringOperations.encodeRope(Layouts.SYMBOL.getString(raw), UTF8Encoding.INSTANCE)));
}

@Fallback
public DynamicObject quote(VirtualFrame frame, Object raw) {
if (toStrNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toStrNode = insert(ToStrNodeGen.create(getContext(), getSourceSection(), null));
}

return executeQuote(frame, toStrNode.executeToStr(frame, raw));
}

}

@NonStandard
Loading

0 comments on commit 3bac257

Please sign in to comment.