Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.forth > #22670

Re: The current object

From Andrew Haley <andrew29@littlepinkcloud.invalid>
Subject Re: The current object
Newsgroups comp.lang.forth
References (11 earlier) <2013May2.162843@mips.complang.tuwien.ac.at> <klu9fd$ifv$1@online.de> <kn0aqb$d3v$1@online.de> <R5CdndY-5plDUg7MnZ2dnUVZ_hOdnZ2d@supernews.com> <kn0udd$spc$1@online.de>
Message-ID <KvydncG8nbdXFAnMnZ2dnUVZ_rydnZ2d@supernews.com> (permalink)
Date 2013-05-16 02:24 -0500

Show all headers | View raw


Bernd Paysan <bernd.paysan@gmx.de> wrote:
> Andrew Haley wrote:
> 
>> Bernd Paysan <bernd.paysan@gmx.de> wrote:
> 
>>>> But even if vtable dispatch is somewhat better, a cacheing "virtual
>>>> function" approach is much more general-purpose, for very little
>>>> extra cost.  It is the Rosetta Stone that allows different OOP
>>>> systems, static and dynamic, to talk to each other.
>>> 
>>> The cost of misprediction is way too high.
>> 
>> I disagree.  It's only another test and branch, which may well be
>> quicker than a vtable lookup if the vtable isn't in L1 cache.
> 
> Actually, the likelyhood that the object itself (and therefore the
> class information) is not in the cache might be higher.

Well, yes.  But you've probably got to fetch the object anyway.

> There aren't that many vtables in a reasonable large Forth OOP
> program.  Maybe in Java.

What is a "Forth OOP program"?  These claims of exceptionalism aren't
working.

>>> That's one implementation option.  It has the disadvantage that any
>>> occasional polymorphic call makes the whole thing slow.
>> 
>> Not really, and if it's only occasional it's not going to make the
>> "whole thing slow", is it?
> 
> No, you didn't read that correctly: If you have a mostly monomorphic
> call, which has the occasional polymorphic call, it's going to be
> slow if you convert from monomorphic to polymorphic on the first of
> those ocassional calls, and never go back.

That's only true if the handling of a polymorphic call is particularly
slow, and I don't think it is.

> So one occasional call to another method makes all other calls to
> the usual suspect slow.

Not really, no: it would only be so if the polymorphic dispatch were
slow.

>>> So you have to optimize for polymorphic code, and take advantage of
>>> the improvements of current CPU architectures.  The monomorphic code
>>> is less likely.
>> 
>> I take your point, but even in the polymorphic case I'm not convinced
>> that vtables are the best approach when dcache effects are taken into
>> account.
> 
> Anton did some calculations, a typical Forth OOP program like MINOS
> or GLForth has about 100 classes with 50 methods each.  So the
> vtables alltogether are 5k words.  Considering that vtables are
> likely to be frequently accessed, they should at least reside in the
> L2 cache.  It is far more likely that the object itself isn't in the
> cache than that it's vtable isn't.  The vtable is hot when some
> other object of the same class was used recently.

Point taken.  I'm thinking in more general terms than small programs
that fit nicely in cache.

And it maybe explains some of the other things you've said about the
design of your system.  If the programs are that small -- small enough
to fit in a single programmer's head -- the advantages gained from
encapsulation and isolating classes from subclasses are reduced.  You
really can look at every call and see if it needs to be polymorphic in
this program.

>>> My guestimate is that a
>>> 
>>> if(class==constant) then call <method> else rewrite_polymorphic(); fi
>>> 
>>> is at least one cycle worse on a Core i7 than a predicted vtable call,
>>> because the Core i7 can't do two branches in one cycle.
>> 
>> That's not what we do.  It's
>> 
>>    mov r1, #constant
>>    call method
>>    ...
>>    mov r2, [obj]
>>    cmp r2, r1
>>    bne ...
> 
> Still two branches, still needs two cycles per invocation.  Even a
> predicted fall-through branch costs one cycle.  The order here
> doesn't really matter, it's just reducing the code size (more call
> sites than methods - but then, you need to create that code again
> for every subclass, even if that subclass doesn't change the method
> at all).

Why do you need to create the code again for every subclass?  What is
the code you're recreating?

> I hope that the polymorphic dispatch jumps right after the
> bne into the method, without double checking.

After a test succeeds, you execute code.

Andrew.

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-02 14:28 +0000
  Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 19:58 +0200
    Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-03 16:50 +0000
      Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-04 18:58 +0200
        Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-04 13:35 -0500
          Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 01:08 +0200
            Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-04 18:29 -0500
              Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 03:00 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 03:48 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:15 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:01 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 03:23 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 03:39 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:00 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 13:34 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 22:00 +0200
                Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-08 07:26 +0000
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 09:15 -0500
                Re: The current object Paul Rubin <no.email@nospam.invalid> - 2013-05-05 09:25 -0700
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 11:43 -0500
                Re: The current object Paul Rubin <no.email@nospam.invalid> - 2013-05-05 09:59 -0700
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:06 -0500
                Re: The current object Mark Wills <forthfreak@gmail.com> - 2013-05-06 00:19 -0700
                Re: The current object "WJ" <w_a_x_man@yahoo.com> - 2013-05-13 22:45 +0000
            Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
              Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:40 +0200
        Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
          Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:29 +0200
            Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:10 -0500
            Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-08 07:35 -0400
              Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-09 00:06 +0200
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-09 06:41 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-11 21:31 +0200
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-12 07:40 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-14 01:10 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-14 03:58 -0500
                Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-14 14:51 +0000
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 03:48 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-14 18:37 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-14 14:42 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 00:22 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 02:56 -0500
                Re: The current object stephenXXX@mpeforth.com (Stephen Pelc) - 2013-05-15 13:52 +0000
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 17:58 +0200
                Re: The current object albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-17 14:01 +0000
                Re: The current object johno <email@address.com> - 2013-05-15 22:38 +0100
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-14 06:27 -0400
                Re: The current object albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-09 16:06 +0000
        Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-06 16:12 +0000
          Re: The current object (was: Went open source with my GA144 ...) Alex McDonald <blog@rivadpm.com> - 2013-05-06 10:25 -0700
          Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 04:00 +0200
            Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-07 15:02 +0000
          Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 04:09 +0200
            Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 03:41 -0500
              Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:02 +0200
            Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-07 14:33 +0000
              Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:40 +0200
    Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 16:46 +0200
      Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 13:11 -0500
        Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 23:23 +0200
          Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-16 02:24 -0500
            Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-16 13:55 +0000
            Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-16 17:45 +0200
              Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 05:13 -0500
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-18 06:43 -0400
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 10:03 -0500
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-18 11:30 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-19 01:20 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-19 12:33 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-19 01:07 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-19 03:58 -0500
        OO dispatch (was: The current object) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-16 14:07 +0000
          Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 05:28 -0500
            Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-20 11:28 +0000
              Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-20 09:00 -0500
                Re: OO dispatch Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-21 01:37 +0200
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 03:21 -0500
                Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-21 12:24 +0000
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 10:18 -0500
                Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-21 16:03 +0000
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 12:55 -0500
                Re: OO dispatch Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-29 00:00 +0200
                Re: OO dispatch Mark Wills <markrobertwills@yahoo.co.uk> - 2013-05-28 15:49 -0700

csiph-web