13. Why pt. 2
• Every talk at this conference has mentioned
some limitation of ruby.
• All limitations are limitations of the current
interpreter, not the language.
13
15. Who.
• Aki Reijonen (loop)
Evan Phoenix (evan)
• Mat Elder (mae)
Brian Ford (brixen)
• John Hornbeck (hornbeck)
Wilson Bilkovich (Defiler)
• Carsten Bormann (cabo)
Pat Eyler (pate)
• Devin Walters (defn)
Alan Hurdle (hurdlea)
• Frederick Ros (sleeper)
Thomas Lockney (tlockney)
• Alexander Kellet (lypanov)
Eero Saynatkai (rue)
• Mikko Lehtonen (scoopr)
15
16. Features and Goals
• Remember the Mantra!
• VM in C only
• Includes primitive operations
• Extensive tests and specs
• Core library in ruby
• Array#dup, Method#new, Object#instance_eval
16
17. • 1.8.5 compatible
• 98% first class
• Easy to understand, easy to extend, easy to
optimize
• MRI (Matz Ruby Interpreter) C API compatible
17
18. Timeline.
• 1.0 by October, 2007 - RubyConf
• Near 100% compatible with 1.8.5
• Able to run rails 1.2
• 2.0
• JIT
• Optimizers
18
20. CPU
• Fully bytecode based
• All bytecodes are written test first
• Leverage GCC to make help make fast
20
21. Threads
• Currently supports green threads
• Contains low level sychronization / sharing
mechanism called Channel
• A PI Calculus-like channel
• Native Thread support in a MxN scheme
• (eventually)
21
22. Primitives
• The most basic method
• Written C (for now)
• Provide most basic functionality
22
23. Compiler
• Completely written in ruby
• COMPLETELY WRITTEN IN RUBY
• Self bootstrapped from initial rubinius
prototype
• Pipeline based architecture
23
29. • Every stage is directly accessible
• Think: new parsers that output rubinius
assembly
• LISP
• Smalltalk
• Erlang
29
30. • Compiler is a normal class, which open doors...
• Compile ERB templates directly into
CompiledMethods
• Ability to remove Kernel#eval if an
application of rubinius warrants it
30
32. Infanticide
• Young objects live fast and die young (usually)
• Once an object survives for a while, it’s
promoted to the mature object space.
• Compaction keeps the memory footprint small.
32
33. The Old Guard
• Mature objects are collected 10 to 30 times
less often than young objects.
• All object access in VM is done through the
“write barrier”, which maintains the set of
mature objects that reference young objects.
• Objects themselves are not marked, making
rubinius very “fork friendly”.
33
35. def [](arg, len = nil)
if len
len = len.to_i
return nil if len 0
end
if arg.is_a? String
unless len.nil?
raise ArgumentError.new(String#[] cannot accept a second argument with a String.)
end
return (self.include?(arg) ? arg.dup : nil)
elsif arg.respond_to? :match
m = arg.match(self)
return m[len.to_i] if m len
return m[0] if m
return nil
elsif arg.respond_to?(:first) and arg.respond_to?(:last)
from = arg.first
to = arg.last
to -= 1 if arg.respond_to?(:exclude_end?) arg.exclude_end?
size = self.size
from = from + size if from 0
to += size if to 0
len = to - from + 1
self[from, len]
elsif arg and arg.respond_to?(:to_i)
arg = arg.to_i
String#[]
size = self.size
arg = arg + size if arg 0
if 0 = arg arg size
if len
len = size - arg if arg + len = size
substring(arg, len)
else
@data[arg]
end
else # invalid start index
len ? : nil
end
else
raise ArgumentError.new(String#[] cannot accept #{arg.class} objects)
end
36. def parent
a=3
ask_child(a)
puts OMG #{a} PONIES!
end
def ask_child(initial_pony_count)
ctx = MethodContext.current.sender
# Will be ctx.locals[:a] = 9 soon.
ctx.locals[2] = 9
end
parent()
39. Backtraces
vatu :: rbx-branches/event ./shotgun/rubinius ctx.rb
An exception has occured:
No method 'ask_child' on an instance of Object. (NoMethodError)
Backtrace:
NoMethodError#initialize at core/exception.rb:47
NoMethodError.new at bootstrap/class.rb:8
main.ask_child (method_missing) at bootstrap/method_missing.rb:8
main.parent at ctx.rb:3
main.__script__ at ctx.rb:12
main.load at core/compile.rb:56
main.__script__ at core/__loader.rb:95
39
40. MethodTables
class Blah
end
class Foo
def hello
puts “hello evan”
end
end
Blah.methods[:hello_also] = Foo.methods[:hello]
Blah.new.hello_also # hello evan
40
41. It’s your party.
class Mu nil
end
p Mu.instance_methods # []
p Mu.superclass # nil
you still mad? 41
46. We all know and love
introspection, so take that to the
next level...
47. • Better debbugers
• Read MethodContext objects directly
• Richer information
• Read method cache’s to find out common
classes for arguments and locals
47