Kernel with Objective C?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Kernel with Objective C?

Post by xvedejas »

What would be needed to add objective C to an existing kernel written in C? How would one implement basic methods like "alloc"?
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Kernel with Objective C?

Post by Colonel Kernel »

http://developer.apple.com/documentatio ... rence.html

I have to ask though: Why Objective-C? What benefit do you see it giving you for kernel development?
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Kernel with Objective C?

Post by whowhatwhere »

Point: I really wish people would SEARCH the forum before asking things such as this.

At OP: The Objective C runtime, at bare minimum is more than two orders of magnitude larger in code than that of the standard C abstract machine runtime.

In short, it's a bad idea.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Kernel with Objective C?

Post by jal »

syntropy wrote:In short, it's a bad idea.
Why? There are plenty of people having a C++ kernel. Objective-C cannot be that much more complex, right?


JAL
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Kernel with Objective C?

Post by jal »

Colonel Kernel wrote:I have to ask though: Why Objective-C? What benefit do you see it giving you for kernel development?
Because the OP is an Objective-C programmer, and not a C programmer?


JAL
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Kernel with Objective C?

Post by Solar »

Objective C vs. C for kernel space? links to Objective-C.

That should be enough answers for the OP. Anyone making an "Objective C" page in the Wiki?
Every good solution is obvious once you've found it.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Kernel with Objective C?

Post by whowhatwhere »

jal wrote:
syntropy wrote:In short, it's a bad idea.
Why? There are plenty of people having a C++ kernel. Objective-C cannot be that much more complex, right?


JAL
The runtime is over 800Kb, and requires (safe) dynamic memory allocation, as well as multitasking or some form of concurrency for message dispatch, and frankly, it's just not a good idea. The C abstract machine runtime requires one to align the stack, set up a few registers and then call into _start() or main(). This may take a few lines of assembler totalling a maximum of perhaps a few bytes. Objective-C requires this, and much, much more just to instantiate classes and get started. Objective-C really shines as a much better user space language, especially for an embedded or single purpose device. (Hence why Apple uses it on their platforms.)
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Kernel with Objective C?

Post by xvedejas »

Yeah, I've seen that one post before (*points at solar's post*) and was wondering if there was any more insight. Still, from what you guys have said, I think it will be a good idea to stick to pure C for now. Thanks anyways.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Kernel with Objective C?

Post by jal »

syntropy wrote:The runtime is over 800Kb, and requires (safe) dynamic memory allocation, as well as multitasking or some form of concurrency for message dispatch, and frankly, it's just not a good idea. The C abstract machine runtime requires one to align the stack, set up a few registers and then call into _start() or main(). This may take a few lines of assembler totalling a maximum of perhaps a few bytes. Objective-C requires this, and much, much more just to instantiate classes and get started. Objective-C really shines as a much better user space language, especially for an embedded or single purpose device. (Hence why Apple uses it on their platforms.)
It's not about C vs. Objective-C for me, but C++ vs. Objective-C. To implement C++ for a kernel, one can take a very stripped down version, and I would bet (but am in no way certain) that the same goes for Objective-C.


JAL
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Kernel with Objective C?

Post by whowhatwhere »

jal wrote:
syntropy wrote:The runtime is over 800Kb, and requires (safe) dynamic memory allocation, as well as multitasking or some form of concurrency for message dispatch, and frankly, it's just not a good idea. The C abstract machine runtime requires one to align the stack, set up a few registers and then call into _start() or main(). This may take a few lines of assembler totalling a maximum of perhaps a few bytes. Objective-C requires this, and much, much more just to instantiate classes and get started. Objective-C really shines as a much better user space language, especially for an embedded or single purpose device. (Hence why Apple uses it on their platforms.)
It's not about C vs. Objective-C for me, but C++ vs. Objective-C. To implement C++ for a kernel, one can take a very stripped down version, and I would bet (but am in no way certain) that the same goes for Objective-C.


JAL
The argument still holds for C++. After adding initialization/cleanup calls for global constructors/destructors around the call to main(), compiled C++ programs become static code paths. With Objective-C however, this does not hold because the language uses 'message dispatch' as opposed to direct function calls. These messages require concurrency which, at kernel initialization time isn't really the best option, and opens up numerous problems both in design and in implementation. It also means there is significant overhead in dispatching those messages to different objects, and in a kernel that is highly undesirable. Objective-C as a replacement for C++ is like saying apples can replace oranges because they both have skins.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Kernel with Objective C?

Post by Colonel Kernel »

syntropy wrote:With Objective-C however, this does not hold because the language uses 'message dispatch' as opposed to direct function calls. These messages require concurrency
Are you sure? What kind of concurrency? Maybe for cross-process messages that's true, but intra-process messages are basically just lookups in a method cache. It's not as fast as a v-table dispatch in C++, but it's not orders of magnitude slower either.

I agree that it's overkill for a kernel though. I just don't see the need for that much flexibility when you can achieve it in cheaper ways (function pointers or C++ virtual method calls).
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Kernel with Objective C?

Post by whowhatwhere »

Colonel Kernel wrote:
syntropy wrote:With Objective-C however, this does not hold because the language uses 'message dispatch' as opposed to direct function calls. These messages require concurrency
Are you sure? What kind of concurrency? Maybe for cross-process messages that's true, but intra-process messages are basically just lookups in a method cache. It's not as fast as a v-table dispatch in C++, but it's not orders of magnitude slower either.

I agree that it's overkill for a kernel though. I just don't see the need for that much flexibility when you can achieve it in cheaper ways (function pointers or C++ virtual method calls).
EDIT: I have no idea to be honest, it's too late at night to bother with this.
User avatar
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Kernel with Objective C?

Post by AndrewAPrice »

xvedejas wrote:How would one implement basic methods like "alloc"?
The same way you would in C.

Now, let's write a kernel in Haskell! :)
My OS is Perception.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Kernel with Objective C?

Post by whowhatwhere »

MessiahAndrw wrote:
xvedejas wrote:How would one implement basic methods like "alloc"?
The same way you would in C.

Now, let's write a kernel in Haskell! :)
Scheme is better.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Kernel with Objective C?

Post by Firestryke31 »

What about SNOBOL?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Post Reply