Kernel with Objective C?
Posted: Wed Aug 26, 2009 9:55 pm
What would be needed to add objective C to an existing kernel written in C? How would one implement basic methods like "alloc"?
The Place to Start for Operating System Developers
http://f.osdev.org/
Why? There are plenty of people having a C++ kernel. Objective-C cannot be that much more complex, right?syntropy wrote:In short, it's a bad idea.
Because the OP is an Objective-C programmer, and not a C programmer?Colonel Kernel wrote:I have to ask though: Why Objective-C? What benefit do you see it giving you for kernel development?
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.)jal wrote:Why? There are plenty of people having a C++ kernel. Objective-C cannot be that much more complex, right?syntropy wrote:In short, it's a bad idea.
JAL
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.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.)
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.jal wrote: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.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.)
JAL
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.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
EDIT: I have no idea to be honest, it's too late at night to bother with this.Colonel Kernel wrote: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.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
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).
The same way you would in C.xvedejas wrote:How would one implement basic methods like "alloc"?
Scheme is better.MessiahAndrw wrote:The same way you would in C.xvedejas wrote:How would one implement basic methods like "alloc"?
Now, let's write a kernel in Haskell!