[fpc-pascal] Virtual object methods

Marco van de Voort fpc at pascalprogramming.org
Tue Jul 2 21:34:33 CEST 2019

Op 2019-07-02 om 19:41 schreef Ryan Joseph:
>> On Jul 2, 2019, at 10:32 AM, Michael Van Canneyt <michael at freepascal.org> wrote:
>> It overwrites the first. There is no such thing as '2 VMT tables'.
> That’s what I thought. How costly is this? Not sure what it’s doing under the hood but I’d like to know more.

You'd expect a mov of a constant to a memory location, but it is a bit 
more involved, and it doesn't look very optimal. Maybe because it is 
compiler generated, the optimizer doesn't run over it? (this is -O4 code)

# [13] begin
     pushl    %ebp
     movl    %esp,%ebp
     leal -8(%esp),%esp                                           // 
creates stackspace
# Var $vmt located at ebp-4, size=OS_32
# Var $self located at ebp-8, size=OS_32
     movl    %eax,-8(%ebp)
     movl    %edx,-4(%ebp)
     leal    -4(%ebp),%edx                                     // self,
     movl    -8(%ebp),%eax
     movl    $0,%ecx
     call    fpc_help_constructor
     movl    %eax,-8(%ebp)                                // save result 
on stack.
     testl    %eax,%eax
# [14] end;
     movl    -8(%ebp),%eax                               // and reload 
that result. All instructions after call are no effective purpose.

     movl    $VMT_$P$PROGRAM_$$_TA,%edx
     movl    $U_$P$PROGRAM_$$_OBJ,%eax
     call    P$PROGRAM$_$TA_$__$$_CREATE$$LONGBOOL // tried to inline 
ta.create, not accepted.

More information about the fpc-pascal mailing list