[Mono-list] JVM performance: JVM as a basis for CLR

Soeren Sandmann sandmann@daimi.au.dk
22 Jul 2001 11:15:49 +0200


Sujal Shah <sujal@sujal.net> writes:

> At the risk of sounding naive, doesn't this make sense?  The CLR and C#
> are basically the same technology as the JVM and Java.  Minor technical
> differences aside (i.e. extra/different semantics, some type
> differences, etc), the two platforms are more or less the same general
> design with some changes in the details.  The only thing I see that
> would lead me to believe that .NET had something new/better/interesting
> is that they clearly define the ability for any language to compile to
> the CLR (because of the CTS, if I understand everything correctly).

Yes, the two formats have the same fundamental properties: they are
stack based, strongly typed formats ('strongly typed' implies
'decidable type-system', no matter what Miguel says)

The type-system in CLR is richer than that in Java, ie., it includes
stack allocated records, so the programmer can write C# code like this
(modulo syntax):

struct X {
    int a, b, c;
}

class foo {
   void g (struct X ref x) {
        x.a = 100;
   }
   void f () {
        struct X x;
        g (x);
        print x.a;  // prints '100'
   }
}

In Java, you would have to allocate the struct on the heap.  Since
stack allocation in theory should be more efficient than heap
allocation, this feature should enable C# programmers to write more
efficient code.

However, a modern, generational memory subsystem makes heap allocation
almost as fast as stack allocation because allocation in the young
generation amounts essentially to moving a pointer, and the garbage
collector won't even look at the garbage in the young generation.

Whether stack allocation actually matters in practice is not clear.

There is not much doubt that CLR and C# has fixed a lot of the
mistakes made in the JVM/Java, but essentially, CLR is the same design
as the JVM.

Soeren