What language are CLR internal calls written in?
Asked Answered
S

2

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?

Solipsism answered 15/12, 2019 at 1:55 Comment(3)
With the merged .NET Core source code, you can now see the internals in just a simple code search, github.com/dotnet/runtime/…Groundling
Most of internal code of CLR and GC is written on C++Impressionable
Well, all of it. Too little assembly to matter. This Q+A talks about the mechanism.Oates
M
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

Marotta answered 31/12, 2019 at 16:46 Comment(0)
K
-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.

Klinges answered 15/12, 2019 at 2:7 Comment(9)
@MickyD: I answer it in my first sentence. The rest is just explanations of why it is like that.Klinges
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".Spiniferous
The OP already knows that it is "The language the Common Language Runtime is written" but what exactly is it?Spiniferous
@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.Klinges
@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.Klinges
There are only two kinds of Programming ways: 1. compiled (which includes JIT) 2. interpreted. JIT and NGEN looks like assembler to me. .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 lifetimeSpiniferous
@MickyD Yes, interpreters are usually written in Machine Language. Otherwise you would need a interpreter for your Interpreter, and that would just be stupid.Klinges
@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. " - en.wikipedia.org/wiki/Native_Image_GeneratorKlinges
What is with this Malicious Downvoting?Klinges

© 2022 - 2024 — McMap. All rights reserved.