Re: Kernel Development & Objective-C

Nicholas Miell
2007-12-01T00:00:56Z

On Sat, 2007-12-01 at 00:19 +0100, J.A. Magallón wrote:

> An vtable in C++ takes exactly the same space that the function
> table pointer present in every driver nowadays... and probably
> the virtual method call that C++ does itself with
>
> thing->do_something(with,this)
>
> like
> push thing
> push with
> push this
> call THING_vtable+indexof(do_something) // constants at compile time
>
> is much more efficient that what gcc can mangle to do with
>
> thing->do_something(with,this,thing)
>
> push with
> push this
> push thing
> get thing+offsetof(do_something) // not constant at compile time
> dereference it
> call it
>
> (that is, get a generic field on a structure and use it as jump address)
>
> In short, the kernel is object oriented, implements OO programming by
> hand, but the compiler lacks the knowledge that it is object oriented
> programming so it could do some optimizations.

struct test;
struct testVtbl
{
int (*fn1)(struct test *t, int x, int y);
int (*fn2)(struct test *t, int x, int y);
};
struct test
{
struct testVtbl *vtbl;
int x, y;
};
void testCall(struct test *t, int x, int y)
{
t->vtbl->fn1(t, x, y);
t->vtbl->fn2(t, x, y);
}

and

struct test
{
virtual int fn1(int x, int y);
virtual int fn2(int x, int y);

int x, y;
};

void testCall(struct test *t, int x, int y)
{
t->fn1(x, y);
t->fn2(x, y);
}

generate instruction-for-instruction identical code.

--
Nicholas Miell <nmiell@comcast.net>