Re: Kernel Development & Objective-C

From: Nicholas Miell
Date: Fri Nov 30 2007 - 19:00:58 EST



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@xxxxxxxxxxx>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/