6

At the bottom of pg 86 in Pro .NET Performance - Optimize Your C# Applications, it talks about the implementaton of ValueType.Equals() and says this:

The definition of CanCompareBits and FastEqualsCheck is deferred to the CLR, they are "internal calls", not implemented in IL

What exactly are "internal calls" and what language are they implemented in if not IL?

David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • 6
    With the merged .NET Core source code, you can now see the internals in just a simple code search, https://github.com/dotnet/runtime/search?q=CanCompareBits&unscoped_q=CanCompareBits – Lex Li Dec 15 '19 at 02:35
  • 1
    Most of internal code of CLR and GC is written on C++ – Pavel Anikhouski Dec 15 '19 at 10:20
  • 1
    Well, all of it. Too little assembly to matter. [This Q+A](https://stackoverflow.com/questions/8870442/how-is-math-pow-implemented-in-net-framework) talks about the mechanism. – Hans Passant Dec 15 '19 at 10:30

2 Answers2

3

Methods, like mentioned CanCompareBits or FastEqualsCheck are marked with [MethodImpl(MethodImplOptions.InternalCall)], which informs clr that it needs to find implementation in it's internals. In terms of CLR it's called FCall, see Calling from managed to native code

Since coreclr is opensourced it's easy to find actual implementation on github. For FastEqualsCheck see comutilnative.cpp. CoreCLR is written with C++ as well as Mono, so all code for all such internal calls is C/C++.

In runtime, in opposite to regular .net code which will produce IL (Intermediate language), such internal calls is platform-dependent assember instructions

-4

The language the Common Language Runtime is written in or compiled into. Unfortunately as there are many different Runtimes/Interpreters for IL Code, I can not tell you any more precise without you telling me wich specific one we are talking about.

.NET Programms are compiled into the Intermediate Language. The IL is then run by the CLR. If you think that sounds like Java Bytecode being executed by the Java Application - you are damn right! It was most definitely an inspiration. It is a step up too, however.

For several points of view, .NET Programms are as interpreted as a Batch File, Java ByteCode, JavaScript or PHP/Python script. There are some things all of those can do, that they will not make available for Programms running in them.

David Klempfner
  • 8,700
  • 20
  • 73
  • 153
Christopher
  • 9,634
  • 2
  • 17
  • 31
  • @MickyD: I answer it in my first sentence. The rest is just explanations of why it is like that. – Christopher Dec 15 '19 at 02:29
  • 3
    Additionally, .NET is a _compiled_ language not _"interpreted"_. Just because it is JIT'd or requires the CLR doesn't put it on the same level as _GW Basic_ and certainly not a _"Batch File"_. –  Dec 15 '19 at 02:30
  • 3
    The OP already knows that it is _"The language the Common Language Runtime is written"_ but `what` exactly is it? –  Dec 15 '19 at 02:31
  • @MickyD "The OP already knows that it is "The language the Common Language Runtime is written" but what exactly is it?" Depends on the CLR implementation you are running. – Christopher Dec 15 '19 at 02:32
  • @MickyD "Additionally, .NET is a compiled language not "interpreted"." There are only two kinds of Programming ways: 1. The Sourcecode is compiled into Machine Code. 2. The Sourcecode - or something generated from it - is Interpreted. | And IL is sure has heck **not** machine code. It is very close but still needs a interpreter, as much as Java and Batchfiles do. A interpreter called the .NET Runtime. – Christopher Dec 15 '19 at 02:34
  • 1
    There are only two kinds of Programming ways: 1. compiled (which includes JIT) 2. interpreted. _[JIT and NGEN looks like assembler to me](https://blogs.msdn.microsoft.com/abhinaba/2014/09/29/net-just-in-time-compilation-and-warming-up-your-system/)_. .NET is nothing like interpreted languages of the past where they where a line was re-interpreted every single time it was hit in the same process lifetime –  Dec 15 '19 at 02:46
  • @MickyD Yes, interpreters are usually written in Machine Language. Otherwise you would need a interpreter for your Interpreter, and that would just be stupid. – Christopher Dec 15 '19 at 02:47
  • @MickyD: Also make a Machine Code Executeable that does not need the Interpreter is quite *literally* what NGEN is designed to do. Indeed, that is what the N stands for: "The Native Image Generator, or simply NGen, is the ahead-of-time compilation (AOT) service of the .NET Framework. It allows a CLI assembly to be pre-compiled instead of letting the Common Language Runtime (CLR) do a just-in-time compilation (JIT) at runtime. In some cases the execution will be significantly faster than with JIT. " - https://en.wikipedia.org/wiki/Native_Image_Generator – Christopher Dec 15 '19 at 03:03
  • What is with this Malicious Downvoting? – Christopher Dec 16 '19 at 15:15