[Issue 14211] New: Compiler should devirtualize calls to members of final class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Feb 20 13:31:22 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14211

          Issue ID: 14211
           Summary: Compiler should devirtualize calls to members of final
                    class
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: r.sagitario at gmx.de

Compile with -m64 -inline -release -O:

class Mutex
{
    void lock() {}
}

final class GCMutex : Mutex
{
    //final override void lock() { super.lock(); }
}

void test()
{
    GCMutex gcLock = new GCMutex;
    gcLock.lock();
}

The disassembly for test() is:

_D4test4testFZv:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: 48 8D 0D 00 00 00  lea        
rcx,[_D4test7GCMutex7__ClassZ]
  000000000000000B: 48 83 EC 20        sub         rsp,20h
  000000000000000F: E8 00 00 00 00     call        _d_newclass
  0000000000000014: 48 83 C4 20        add         rsp,20h
  0000000000000018: 48 89 C1           mov         rcx,rax
  000000000000001B: 48 83 EC 20        sub         rsp,20h
  000000000000001F: 48 8B 01           mov         rax,qword ptr [rcx]
  0000000000000022: 48 FF 50 28        call        qword ptr [rax+28h]
  0000000000000026: 48 83 C4 20        add         rsp,20h
  000000000000002A: 5D                 pop         rbp
  000000000000002B: C3                 ret

I.e. the call to lock is still made through the virtual function table although
the class GCMutex is declared final.

If the commented code in GCMutex is enabled, the call is deviertualized, but
not inlined.

--


More information about the Digitalmars-d-bugs mailing list