On Sun, Apr 18, 2010 at 10:58 PM, Kyle Sluder <kyle.slu...@gmail.com> wrote:
> On Apr 18, 2010, at 6:52 PM, Michael Ash <michael....@gmail.com> wrote:
>
>> If by "indirected through the runtime" you mean "accesses one global
>> variable to get an offset". It does not, as one might take your
>> comment to indicate, actually call any runtime functions.
>
> If that's the case, how can the language support reordering instance
> variables? The only way I can see o support taking the address of an
> instance variable is to convert &ivar into a runtime call.

Why not take a look for yourself?

$ cat ivartest.m
#import <Cocoa/Cocoa.h>
@interface Foo : NSObject { id ivar; } @end
@implementation Foo
- (void)testMethod {
    ivar = nil;
}
@end
$ gcc -c ivartest.m
$ otool -tV ivartest.o
ivartest.o:
(__TEXT,__text) section
-[Foo testMethod]:
0000000000000000        pushq   %rbp
0000000000000001        movq    %rsp,%rbp
0000000000000004        movq    %rdi,0xf8(%rbp)
0000000000000008        movq    %rsi,0xf0(%rbp)
000000000000000c        movq    0xf8(%rbp),%rdx
0000000000000010        movq    _OBJC_IVAR_$_Foo.ivar(%rip),%rax
0000000000000017        movq    (%rax),%rax
000000000000001a        leaq    (%rdx,%rax),%rax
000000000000001e        movq    $-[Foo testMethod],(%rax)
0000000000000025        leave
0000000000000026        ret

As you can see, the offset of the ivar itself is referenced as a
linker symbol which will then get resolved at load time. And you can
see that no function calls take place.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to