Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Trivial call site not inlining with invokedynamic #6280

@chrisseaton

Description

@chrisseaton

Environment Information

Provide at least:

  • jruby 9.3.0.0-SNAPSHOT (2.6.5) 2020-06-12 ccecbe8014 OpenJDK 64-Bit Server VM 14.0.1+7 on 14.0.1+7 +jit [darwin-x86_64] (master)
  • Darwin Chris-Seatons-MacBook-Pro.local 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

Expected Behavior

main.rb

require_relative 'inline'

inline.rb

class Bar
  def bar
    14
  end
end

def foo(bar)
  bar.bar
end

bar = Bar.new

while true
  foo bar
end
% bin/ruby -Xcompile.invokedynamic "-J-XX:CompileCommand=print,*::*foo*" main.rb

I'd expect the invokedynamic call from foo to bar to be fully inlined in C2.

Actual Behavior

Not inlined.

  0x000000011ca18e40:   mov    %eax,-0x14000(%rsp)
  0x000000011ca18e47:   push   %rbp
  0x000000011ca18e48:   sub    $0x20,%rsp                   ;*synchronization entry
                                                            ; - Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$foo$0@-1
  0x000000011ca18e4c:   mov    %rsi,%r11
  0x000000011ca18e4f:   mov    %rcx,%r10
  0x000000011ca18e52:   mov    0x8(%r8),%ecx                ; implicit exception: dispatches to 0x000000011ca18f11
  0x000000011ca18e56:   cmp    $0x201b37,%ecx               ;   {metadata('org/jruby/gen/RubyObject1')}
  0x000000011ca18e5c:   jne    0x000000011ca18ed8
  0x000000011ca18e5e:   mov    %r8,%rcx                     ;*checkcast {reexecute=0 rethrow=0 return_oop=0}
                                                            ; - org.jruby.RubyBasicObject::getMetaClass@1 (line 525)
                                                            ; - org.jruby.ir.targets.indy.Bootstrap::testType@2 (line 1001)
                                                            ; - java.lang.invoke.DirectMethodHandle$Holder::invokeStatic@11
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801063840::invoke@25
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@37
                                                            ; - java.lang.invoke.DelegatingMethodHandle$Holder::delegate@17
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@78
                                                            ; - java.lang.invoke.Invokers$Holder::linkToCallSite@17
                                                            ; - Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$foo$0@9 (line 8)
  0x000000011ca18e61:   mov    0x14(%rcx),%ebp              ;*getfield metaClass {reexecute=0 rethrow=0 return_oop=0}
                                                            ; - org.jruby.RubyBasicObject::getMetaClass@4 (line 525)
                                                            ; - org.jruby.ir.targets.indy.Bootstrap::testType@2 (line 1001)
                                                            ; - java.lang.invoke.DirectMethodHandle$Holder::invokeStatic@11
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801063840::invoke@25
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@37
                                                            ; - java.lang.invoke.DelegatingMethodHandle$Holder::delegate@17
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@78
                                                            ; - java.lang.invoke.Invokers$Holder::linkToCallSite@17
                                                            ; - Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$foo$0@9 (line 8)
  0x000000011ca18e64:   cmp    $0xc38372e8,%ebp             ;   {oop(a 'org/jruby/RubyClass'{0x000000061c1b9740})}
  0x000000011ca18e6a:   jne    0x000000011ca18eac           ;*if_acmpne {reexecute=0 rethrow=0 return_oop=0}
                                                            ; - org.jruby.ir.targets.indy.Bootstrap::testType@5 (line 1001)
                                                            ; - java.lang.invoke.DirectMethodHandle$Holder::invokeStatic@11
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801063840::invoke@25
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@37
                                                            ; - java.lang.invoke.DelegatingMethodHandle$Holder::delegate@17
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@78
                                                            ; - java.lang.invoke.Invokers$Holder::linkToCallSite@17
                                                            ; - Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$foo$0@9 (line 8)
  0x000000011ca18e6c:   movabs $0x61c1b76d0,%rdx            ;   {oop(a 'org/jruby/parser/StaticScope'{0x000000061c1b76d0})}
  0x000000011ca18e76:   movabs $0x6022465a8,%rdi            ;   {oop("bar"{0x00000006022465a8})}
  0x000000011ca18e80:   movabs $0x61c1b9740,%r9             ;   {oop(a 'org/jruby/RubyClass'{0x000000061c1b9740})}
  0x000000011ca18e8a:   movabs $0x600015118,%r8             ;   {oop(a 'org/jruby/runtime/Block'{0x0000000600015118})}
  0x000000011ca18e94:   data32 xchg %ax,%ax
  0x000000011ca18e97:   callq  0x0000000114dbc400           ; ImmutableOopMap {}
                                                            ;*invokestatic linkToStatic {reexecute=0 rethrow=0 return_oop=1}
                                                            ; - java.lang.invoke.DirectMethodHandle$Holder::invokeStatic@20
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801068440::invoke@50
                                                            ; - java.lang.invoke.DelegatingMethodHandle$Holder::delegate@17
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@78
                                                            ; - java.lang.invoke.DelegatingMethodHandle$Holder::delegate@17
                                                            ; - java.lang.invoke.LambdaForm$MH/0x0000000801064c40::guard@78
                                                            ; - java.lang.invoke.Invokers$Holder::linkToCallSite@17
                                                            ; - Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$foo$0@9 (line 8)
                                                            ;   {static_call Users.chrisseaton.src.github_dot_com.jruby.jruby.inline::RUBY$method$bar$0}
  0x000000011ca18e9c:   add    $0x20,%rsp
  0x000000011ca18ea0:   pop    %rbp
  0x000000011ca18ea1:   mov    0x110(%r15),%r10
  0x000000011ca18ea8:   test   %eax,(%r10)                  ;   {poll_return}
  0x000000011ca18eab:   retq   

The inlining log here is confusing - sometimes says it's inlined, sometimes says not due to The inlining log says 'unloaded signature classes'. Possibly worth looking for a deoptimisation and recompilation? Could also be related to tiering.

But whatever the logs say, bottom line seems to be there is a callq where that does not seem reasonable. (But I'm not an expert on invokedynamic.)

As discussed on Matrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions