Permalink
Browse files

Add examples for JavaOne Tokyo 2012 slides

  • Loading branch information...
1 parent f5c3821 commit 5f6fb6d2816e7ffa0a0267875ce1b7b60a5fd8eb @nahi committed Apr 5, 2012
@@ -0,0 +1,9 @@
+def target
+ "Hello"
+end
+
+idx = 0
+while idx < 50000
+ target
+ idx += 1
+end
@@ -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::<init> (19 bytes) inline (hot)
+ @ 4 org.jruby.RubyString::<init> (35 bytes) inline (hot)
+ @ 3 org.jruby.RubyObject::<init> (7 bytes) inline (hot)
+ @ 3 org.jruby.RubyBasicObject::<init> (42 bytes) inline (hot)
+ @ 1 java.lang.Object::<init> (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::<init> (19 bytes) inline (hot)
+ @ 4 org.jruby.RubyString::<init> (35 bytes) inline (hot)
+ @ 3 org.jruby.RubyObject::<init> (7 bytes) inline (hot)
+ @ 3 org.jruby.RubyBasicObject::<init> (42 bytes) inline (hot)
+ @ 1 java.lang.Object::<init> (1 bytes) inline (hot)
+ @ 30 org.jruby.Ruby::isObjectSpaceEnabled (5 bytes) inline (hot)
+ @ 38 org.jruby.RubyBasicObject::addToObjectSpace (30 bytes) never executed
+
@@ -0,0 +1,9 @@
+def target
+ 10000
+end
+
+idx = 0
+while idx < 50000
+ target
+ idx += 1
+end
@@ -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)
+
@@ -0,0 +1,11 @@
+DEFAULT = 1
+
+def target
+ DEFAULT
+end
+
+idx = 0
+while idx < 50000
+ target
+ idx += 1
+end
@@ -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)
+
@@ -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
@@ -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)
+
@@ -0,0 +1,13 @@
+def stub
+ 1
+end
+
+def target
+ stub
+end
+
+idx = 0
+while idx < 50000
+ target
+ idx += 1
+end
@@ -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)
+
@@ -0,0 +1,9 @@
+def target
+ 42 - 2
+end
+
+idx = 0
+while idx < 50000
+ target
+ idx += 1
+end
@@ -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)
+
@@ -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);
+ }
+ }
+}
@@ -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();
+ }
+}
@@ -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;
+}
@@ -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)
@@ -0,0 +1,11 @@
+def process(opt)
+ opt
+end
+
+def process_options(opt)
+ process(opt.concat("?!"))
+end
+
+20000.times do
+ process_options("yes")
+end
@@ -0,0 +1,3 @@
+def target(opt)
+ process(opt.concat("?!"))
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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
@@ -0,0 +1,7 @@
+def fib(n)
+ if n < 2
+ n
+ else
+ fib(n - 2) + fib(n - 1)
+ end
+end

0 comments on commit 5f6fb6d

Please sign in to comment.