Re: why kernel in C

From: Christopher Browne (cbbrowne_at_acm.org)
Date: 03/19/05


Date: 19 Mar 2005 04:49:32 GMT

In an attempt to throw the authorities off his trail, "David Schwartz" <davids@webmaster.com> transmitted:
> "Christopher Browne" <cbbrowne@acm.org> wrote in message
> news:3a1dghF66qk13U2@individual.net...
>
>> The difference is that in C, all you need is the machine code
>> operations generated by the compiler, whereas with Java, you also
>> need the "runtime environment" which _isn't_ part of what the
>> compiler's code generator produces.
>
> Nothing stops a person from creating a Java compiler that
> outputs whatever native code a processor uses. That native code
> could even *be* Java. I think we disagree on what it means for an OS
> to be written in a particular language. If nobody had every written
> an OS in C, would you argue that C requires a runtime environment as
> well, namely the kernel?

No, C _doesn't_ require a substantial runtime environment. At least
not in traditional K&R C form. Pointedly, K&R C does not itself need
to allocate memory at runtime to support language structures.

There are traditionally two kinds of variables:
 1. Those that are statically allocated, at compile time, and
 2. Those with the (usually omitted) "auto" modifier which are
    allocated on a stack.

Neither of those mandate any runtime library.

We _well know_ that there is no forcible need for _any_ runtime
environment for C because of its wide use for embedded systems. And
the fact that the language allocates memory in only those two ways
means that we may analytically determine that (at least vis-a-vis
memory management), C requires no particular runtime environment.

>> Much the same is true for C++ as is true for Java; C++ code needs a
>> significant additional runtime component to deal with vtables, memory
>> management, and the like.
>
> I don't agree at all. The memory management in C and C++ is essentially
> the same. The new/delete operators can be implemented as trivial wrappers on
> C's malloc/free functions.

NO, the essence is that memory management in C and C++ is COMPLETELY
DIFFERENT.

C++ requires having something like malloc/free in the runtime
environment, whilst C _doesn't_. I can write programs in C that do
not use malloc() or free() directly or indirectly. The same is not
true for C++.

Further, how about vtables? That's a substantial portion of the
runtime environment for C++ that just doesn't exist in C.

>> C++ needs less than Java does, and it's probably possible to
>> implement the runtime system using some subset of C++ that
>> _doesn't_ require much of a runtime system below it.

> Apart from garbage collection, what does Java need that's so
> onerous?

Garbage collections seems a pretty sufficient condition to me.

>> The issue that gets at the problem ISN'T that of "how you implement
>> pointers."
>>
>> It is of how you implement kmalloc()/malloc()/... out of language
>> primitives under the assumption that you are FORBIDDEN to use any
>> "lower level" runtime environment code.
>
> It's not clear to me at all why you have to. For example, a C
> compiler could compile 'malloc' into whatever magical incantations
> are needed to allocate memory in kernel space, meaning you don't
> need to implement it out of language primitives. The same could be
> true for Java. If the hardware is designed to use Java as an OS, it
> could provide memory management in hardware, taking the Java
> allocation primitives directly.

In C, malloc() doesn't need to be part of the language. Indeed, the
Linux kernel never uses it, so it is demonstrably not necessary.

C++ and Java experience the very same bootstrapping problem that they
need to _use_ malloc() (or something similar).

The point is that the kernel needs to _implement_ the infrastructure
used to _provide_ malloc() to user space. If the 'kernel'
implementation language needs it, then you essentially need some lower
level kernel implemented in some other language (such as C) to provide
such services.

-- 
output = reverse("gro.mca" "@" "enworbbc")
http://cbbrowne.com/info/nonrdbms.html
The IQ of the group is the lowest IQ of  a member of the group divided
by the number of people in the group.


Relevant Pages

  • Re: Libraries written in Ada
    ... and it seems Ada is a good choice of language for that. ... > wonder, however, whether Ada's runtime environment doesn't count as a con ... Many libraries need some initialization. ...
    (comp.lang.ada)
  • Re: overloading, template, exception handling and c
    ... to run without a runtime environment, ... the portability or simplicity of the language. ... These are mechanisms ... an effect on running it in small computers, ...
    (comp.lang.c)
  • Re: sucking up my memory
    ... You are confusing memory with disk storage space. ... In the middle of the page download the version that says Java Runtime Environment 6, The Java SE Runtime Environment allows end-users to run Java applications. ... Microsoft Works is a suite that includes a word processing program and other programs. ...
    (microsoft.public.windowsxp.general)
  • Re: C++ Garbage Collector on VMS?
    ... Global Heap for every GC and every language that can be running on a server ... And what about all of the "free" memory in the OS that hasn't ... Languages without dynamic memory allocation: ... runtime environment allocates memory from the OS ...
    (comp.os.vms)
  • Libraries written in Ada
    ... and it seems Ada is a good choice of language for that. ... wonder, however, whether Ada's runtime environment doesn't count as a con ... Many libraries need some initialization. ... But suppose I use two libs written in Ada in the same C program - will ...
    (comp.lang.ada)

Loading