Skip to content

Commit

Permalink
Add examples for JavaOne Tokyo 2012 slides
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshi Nakamura committed Apr 5, 2012
1 parent f5c3821 commit 5f6fb6d
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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
27 changes: 27 additions & 0 deletions 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::<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

9 changes: 9 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions 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)

11 changes: 11 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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)

24 changes: 24 additions & 0 deletions 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
32 changes: 32 additions & 0 deletions 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)

13 changes: 13 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions 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)

9 changes: 9 additions & 0 deletions 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
14 changes: 14 additions & 0 deletions 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)

19 changes: 19 additions & 0 deletions 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);
}
}
}
18 changes: 18 additions & 0 deletions 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();
}
}
13 changes: 13 additions & 0 deletions 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;
}
16 changes: 16 additions & 0 deletions 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)
11 changes: 11 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions javaone-tokyo-2012/jrubycall/main_dot.rb
@@ -0,0 +1,3 @@
def target(opt)
process(opt.concat("?!"))
end
Binary file added javaone-tokyo-2012/jrubycall/process.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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

0 comments on commit 5f6fb6d

Please sign in to comment.