diff --git a/javaone-tokyo-2012/indy_inline/1_string.rb b/javaone-tokyo-2012/indy_inline/1_string.rb new file mode 100644 index 0000000..8671933 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/1_string.rb @@ -0,0 +1,9 @@ +def target + "Hello" +end + +idx = 0 +while idx < 50000 + target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/1_string.txt b/javaone-tokyo-2012/indy_inline/1_string.txt new file mode 100644 index 0000000..fd3ab3d --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/1_string.txt @@ -0,0 +1,27 @@ +$1_string::method__0$RUBY$target (7 bytes) + @ 1 java.lang.invoke.MethodHandle::invokeExact (12 bytes) inline (hot) + @ 5 org.jruby.runtime.invokedynamic.InvokeDynamicSupport::newString (10 bytes) inline (hot) + @ 6 org.jruby.RubyString::newStringShared (22 bytes) inline (hot) + @ 6 org.jruby.Ruby::getString (5 bytes) inline (hot) + @ 11 org.jruby.RubyString:: (19 bytes) inline (hot) + @ 4 org.jruby.RubyString:: (35 bytes) inline (hot) + @ 3 org.jruby.RubyObject:: (7 bytes) inline (hot) + @ 3 org.jruby.RubyBasicObject:: (42 bytes) inline (hot) + @ 1 java.lang.Object:: (1 bytes) inline (hot) + @ 30 org.jruby.Ruby::isObjectSpaceEnabled (5 bytes) inline (hot) + @ 38 org.jruby.RubyBasicObject::addToObjectSpace (30 bytes) never executed + +$1_string::method__0$RUBY$target (8 bytes) + @ 4 org.jruby.ast.executable.AbstractScript::getString0 (11 bytes) inline (hot) + @ 7 org.jruby.ast.executable.RuntimeCache::getString (14 bytes) inline (hot) + @ 6 org.jruby.ast.executable.RuntimeCache::getByteList (7 bytes) inline (hot) + @ 10 org.jruby.RubyString::newStringShared (22 bytes) inline (hot) + @ 6 org.jruby.Ruby::getString (5 bytes) inline (hot) + @ 11 org.jruby.RubyString:: (19 bytes) inline (hot) + @ 4 org.jruby.RubyString:: (35 bytes) inline (hot) + @ 3 org.jruby.RubyObject:: (7 bytes) inline (hot) + @ 3 org.jruby.RubyBasicObject:: (42 bytes) inline (hot) + @ 1 java.lang.Object:: (1 bytes) inline (hot) + @ 30 org.jruby.Ruby::isObjectSpaceEnabled (5 bytes) inline (hot) + @ 38 org.jruby.RubyBasicObject::addToObjectSpace (30 bytes) never executed + diff --git a/javaone-tokyo-2012/indy_inline/2_literal.rb b/javaone-tokyo-2012/indy_inline/2_literal.rb new file mode 100644 index 0000000..533c2f7 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/2_literal.rb @@ -0,0 +1,9 @@ +def target + 10000 +end + +idx = 0 +while idx < 50000 + target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/2_literal.txt b/javaone-tokyo-2012/indy_inline/2_literal.txt new file mode 100644 index 0000000..ac01688 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/2_literal.txt @@ -0,0 +1,12 @@ +$2_literal::method__0$RUBY$target (7 bytes) + @ 1 java.lang.invoke.MethodHandle::invokeExact (9 bytes) inline (hot) + @ 2 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + + + + @ 36 $2_literal$method__0$RUBY$target::call (13 bytes) inline (hot) + @ 9 $2_literal$method__0$RUBY$target::call (21 bytes) inline (hot) + @ 17 $2_literal::method__0$RUBY$target (9 bytes) inline (hot) + @ 5 org.jruby.ast.executable.AbstractScript::getFixnum0 (11 bytes) inline (hot) + @ 7 org.jruby.ast.executable.RuntimeCache::getFixnum (33 bytes) inline (hot) + diff --git a/javaone-tokyo-2012/indy_inline/3_constant.rb b/javaone-tokyo-2012/indy_inline/3_constant.rb new file mode 100644 index 0000000..9e49b72 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/3_constant.rb @@ -0,0 +1,11 @@ +DEFAULT = 1 + +def target + DEFAULT +end + +idx = 0 +while idx < 50000 + target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/3_constant.txt b/javaone-tokyo-2012/indy_inline/3_constant.txt new file mode 100644 index 0000000..0ed6d1e --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/3_constant.txt @@ -0,0 +1,11 @@ +$3_constant::method__0$RUBY$target (7 bytes) + @ 1 java.lang.invoke.MethodHandle::invokeExact (25 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (16 bytes) inline (hot) + @ 2 java.lang.invoke.MethodHandle::invokeExact (9 bytes) inline (hot) + @ 2 java.lang.invoke.MutableCallSite::getTarget (5 bytes) inline (hot) + @ 12 java.lang.invoke.MethodHandle::invokeExact (5 bytes) inline (hot) + @ 1 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + @ 10 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 21 java.lang.invoke.MethodHandle::invokeExact (6 bytes) inline (hot) + @ 2 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + diff --git a/javaone-tokyo-2012/indy_inline/4_ivar.rb b/javaone-tokyo-2012/indy_inline/4_ivar.rb new file mode 100644 index 0000000..378db8b --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/4_ivar.rb @@ -0,0 +1,24 @@ +module Cache + def target + @cache + end +end +class Foo + include Cache + def initialize + @cache = 1 + end +end +class Bar + include Cache + def initialize + @cache = 2 + end +end + +idx = 0 +obj = [Foo.new] +while idx < 100000 + obj.sample.target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/4_ivar.txt b/javaone-tokyo-2012/indy_inline/4_ivar.txt new file mode 100644 index 0000000..ea64f32 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/4_ivar.txt @@ -0,0 +1,32 @@ +$4_invoke::method__1$RUBY$target (7 bytes) + @ 1 java.lang.invoke.MethodHandle::invokeExact (25 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 3 org.jruby.runtime.invokedynamic.InvocationLinker::testRealClass (20 bytes) inline (hot) + @ 5 org.jruby.RubyBasicObject::getMetaClass (5 bytes) inline (hot) + @ 8 org.jruby.RubyClass::getRealClass (2 bytes) inline (hot) + @ 10 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 21 java.lang.invoke.MethodHandle::invokeExact (14 bytes) inline (hot) + @ 21 java.lang.invoke.MethodHandle::invokeExact (27 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 3 org.jruby.runtime.invokedynamic.InvocationLinker::testRealClass (20 bytes) inline (hot) + @ 5 org.jruby.RubyBasicObject::getMetaClass (5 bytes) inline (hot) + @ 8 org.jruby.RubyClass::getRealClass (2 bytes) inline (hot) + @ 10 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 23 java.lang.invoke.MethodHandle::invokeExact (14 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (8 bytes) inline (hot) + @ 10 org.jruby.javasupport.util.RuntimeHelpers::nullToNil (10 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (8 bytes) inline (hot) + @ 10 org.jruby.javasupport.util.RuntimeHelpers::nullToNil (10 bytes) inline (hot) + + +$4_invoke::method__1$RUBY$target (7 bytes) + @ 1 java.lang.invoke.MethodHandle::invokeExact (25 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 3 org.jruby.runtime.invokedynamic.InvocationLinker::testRealClass (20 bytes) inline (hot) + @ 5 org.jruby.RubyBasicObject::getMetaClass (5 bytes) inline (hot) + @ 8 org.jruby.RubyClass::getRealClass (2 bytes) inline (hot) + @ 10 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 21 java.lang.invoke.MethodHandle::invokeExact (14 bytes) inline (hot) + @ 3 java.lang.invoke.MethodHandle::invokeExact (8 bytes) inline (hot) + @ 10 org.jruby.javasupport.util.RuntimeHelpers::nullToNil (10 bytes) inline (hot) + diff --git a/javaone-tokyo-2012/indy_inline/5_invoke.rb b/javaone-tokyo-2012/indy_inline/5_invoke.rb new file mode 100644 index 0000000..c1a4a0d --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/5_invoke.rb @@ -0,0 +1,13 @@ +def stub + 1 +end + +def target + stub +end + +idx = 0 +while idx < 50000 + target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/5_invoke.txt b/javaone-tokyo-2012/indy_inline/5_invoke.txt new file mode 100644 index 0000000..0d24c23 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/5_invoke.txt @@ -0,0 +1,18 @@ +$5_invoke::method__1$RUBY$target (9 bytes) + @ 3 java.lang.invoke.MethodHandle::invokeExact (33 bytes) inline (hot) + @ 5 java.lang.invoke.MethodHandle::invokeExact (20 bytes) inline (hot) + @ 2 java.lang.invoke.MethodHandle::invokeExact (9 bytes) inline (hot) + @ 2 java.lang.invoke.MutableCallSite::getTarget (5 bytes) inline (hot) + @ 16 java.lang.invoke.MethodHandle::invokeExact (5 bytes) inline (hot) + @ 1 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + @ 12 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 29 java.lang.invoke.MethodHandle::invokeExact (35 bytes) inline (hot) + @ 5 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 3 org.jruby.runtime.invokedynamic.InvocationLinker::testMetaclass (17 bytes) inline (hot) + @ 5 org.jruby.RubyBasicObject::getMetaClass (5 bytes) inline (hot) + @ 14 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 31 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 6 $5_invoke::method__0$RUBY$stub (7 bytes) inline (hot) + @ 1 java.lang.invoke.MethodHandle::invokeExact (9 bytes) inline (hot) + @ 2 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + diff --git a/javaone-tokyo-2012/indy_inline/6_math.rb b/javaone-tokyo-2012/indy_inline/6_math.rb new file mode 100644 index 0000000..63bb187 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/6_math.rb @@ -0,0 +1,9 @@ +def target + 42 - 2 +end + +idx = 0 +while idx < 50000 + target + idx += 1 +end diff --git a/javaone-tokyo-2012/indy_inline/6_math.txt b/javaone-tokyo-2012/indy_inline/6_math.txt new file mode 100644 index 0000000..5612c70 --- /dev/null +++ b/javaone-tokyo-2012/indy_inline/6_math.txt @@ -0,0 +1,14 @@ +$6_math::method__0$RUBY$target (14 bytes) + @ 3 java.lang.invoke.MethodHandle::invokeExact (9 bytes) inline (hot) + @ 2 sun.invoke.util.ValueConversions::identity (2 bytes) inline (hot) + @ 8 java.lang.invoke.MethodHandle::invokeExact (33 bytes) inline (hot) + @ 5 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 3 org.jruby.runtime.invokedynamic.MathLinker::fixnumTest (20 bytes) inline (hot) + @ 8 org.jruby.Ruby::isFixnumReopened (5 bytes) inline (hot) + @ 12 java.lang.invoke.MethodHandle::invokeExact (10 bytes) inline (hot) + @ 29 java.lang.invoke.MethodHandle::invokeExact (7 bytes) inline (hot) + @ 29 java.lang.invoke.MethodHandle::invokeExact (11 bytes) inline (hot) + @ 7 org.jruby.runtime.invokedynamic.MathLinker::fixnumOperatorFail (109 bytes) never executed + @ 3 org.jruby.runtime.invokedynamic.MathLinker::fixnum_op_minus_two (9 bytes) inline (hot) + @ 5 org.jruby.RubyFixnum::op_minus_two (35 bytes) inline (hot) + diff --git a/javaone-tokyo-2012/java-inline/Target.java b/javaone-tokyo-2012/java-inline/Target.java new file mode 100644 index 0000000..8041165 --- /dev/null +++ b/javaone-tokyo-2012/java-inline/Target.java @@ -0,0 +1,19 @@ +public class Target { + double addAllSqrts(int max) { + double accum = 0; + for (int i = 0; i < max; i++) { + accum = addSqrt(accum, i); + } + return accum; + } + + double addSqrt(double a, int b) { + return a + Math.sqrt(b); + } + + public static void main(String[] args) { + for (int i = 0; i < 100000; ++i) { + (new Target()).addAllSqrts(10); + } + } +} diff --git a/javaone-tokyo-2012/javacall/Command.java b/javaone-tokyo-2012/javacall/Command.java new file mode 100644 index 0000000..0f20e36 --- /dev/null +++ b/javaone-tokyo-2012/javacall/Command.java @@ -0,0 +1,18 @@ +public class Command { + void processOptions(String[] options) { + boolean result; + for (String opt : options) { + result = process(opt.concat("?!")); + } + } + boolean process(String opt) { ... } + + void run() { + String[] options = { "yes", "no", "maybe" }; + processOptions(options); + } + + public static void main(String[] args) { + (new Main()).run(); + } +} diff --git a/javaone-tokyo-2012/jrubycall/main.dot b/javaone-tokyo-2012/jrubycall/main.dot new file mode 100644 index 0000000..b859e10 --- /dev/null +++ b/javaone-tokyo-2012/jrubycall/main.dot @@ -0,0 +1,13 @@ +digraph AST { +1451324290 [label="def: target"]; +10775091 [label="arg: opt"]; +1264572433 [label="call: process"]; +1477525092 [label="call: concat"]; +698782006 [label="Local: opt"]; +622466907 [label="Str: '?!'"]; +1451324290 -> 10775091; +1451324290 -> 1264572433; +1264572433 -> 1477525092; +1477525092 -> 698782006; +1477525092 -> 622466907; +} diff --git a/javaone-tokyo-2012/jrubycall/main.rb b/javaone-tokyo-2012/jrubycall/main.rb new file mode 100644 index 0000000..4d68f45 --- /dev/null +++ b/javaone-tokyo-2012/jrubycall/main.rb @@ -0,0 +1,16 @@ +def process_options(options) + for opt in options + process(opt.concat("?!")) + end +end + +def process(opt) + puts opt +end + +mock = Object.new +def mock.concat(arg) + "tested!" +end +options = ["yes", "no", mock] +process_options(options) diff --git a/javaone-tokyo-2012/jrubycall/main_compile.rb b/javaone-tokyo-2012/jrubycall/main_compile.rb new file mode 100644 index 0000000..af1a611 --- /dev/null +++ b/javaone-tokyo-2012/jrubycall/main_compile.rb @@ -0,0 +1,11 @@ +def process(opt) + opt +end + +def process_options(opt) + process(opt.concat("?!")) +end + +20000.times do + process_options("yes") +end diff --git a/javaone-tokyo-2012/jrubycall/main_dot.rb b/javaone-tokyo-2012/jrubycall/main_dot.rb new file mode 100644 index 0000000..dfaab95 --- /dev/null +++ b/javaone-tokyo-2012/jrubycall/main_dot.rb @@ -0,0 +1,3 @@ +def target(opt) + process(opt.concat("?!")) +end diff --git a/javaone-tokyo-2012/jrubycall/process.png b/javaone-tokyo-2012/jrubycall/process.png new file mode 100644 index 0000000..a2ce6d7 Binary files /dev/null and b/javaone-tokyo-2012/jrubycall/process.png differ diff --git a/javaone-tokyo-2012/mh_example/all.rb b/javaone-tokyo-2012/mh_example/all.rb new file mode 100644 index 0000000..52bf20c --- /dev/null +++ b/javaone-tokyo-2012/mh_example/all.rb @@ -0,0 +1,30 @@ +message = "Hello" +message << name << "!" + +times = 10000 +matcher = /[A-Z][a-z]*/ + +DEFAULT = Container.new.freeze +comtainer = DEFAULT +DEFAULT = nil + +module Cache + def cache(value) + @cache = value + end +end +class Foo + include Cache +end +class Bar + include Cache +end + +$name = [:JRuby, "Ruby", 42] +def process(router) + router.say_hello($names.sample) +end + +fib(n - 2) + fib(n - 1) +display if (x >= 5) +elapsed = msec * 1000.0 diff --git a/javaone-tokyo-2012/mh_example/fib.rb b/javaone-tokyo-2012/mh_example/fib.rb new file mode 100644 index 0000000..28c6656 --- /dev/null +++ b/javaone-tokyo-2012/mh_example/fib.rb @@ -0,0 +1,7 @@ +def fib(n) + if n < 2 + n + else + fib(n - 2) + fib(n - 1) + end +end