Does the .NET garbage collector perform predictive analysis of code?

The Garbage Collector relies on information compiled into your assembly provided by the JIT compiler that tells it what code address ranges various variables and “things” are still in use over. As such, in your code, since you no longer use the object variables GC is free to collect them. WeakReference will not prevent this, … Read more

How do generics get compiled by the JIT compiler?

I recommend reading Generics in C#, Java, and C++: A Conversation with Anders Hejlsberg. Qn 1. How do generics get compiled by the JIT compiler? From the interview: Anders Hejlsberg: […] In the CLR [Common Language Runtime], when you compile List, or any other generic type, it compiles down to IL [Intermediate Language] and metadata … Read more

Useless test instruction?

That must be the thread-local handshake poll. Look where %r11 is read from. If it is read from some offset off the %r15 (thread-local storage), that’s the guy. See the example here: 0.31% ↗ …70: movzbl 0x94(%r9),%r10d 0.19% │ …78: mov 0x108(%r15),%r11 ; read the thread-local page addr 25.62% │ …7f: add $0x1,%rbp 35.10% │ … Read more

What does a JIT compiler do?

Java code is normally distributed as bytecode, which is machine-independent pseudocode. (The same idea was previously used in UCSD-p system developed in the 70’ies.) The advantage of this is that the same application can be run in different processors and operating systems. In addition, the bytecode is often smaller than compiled application. The disadvantage is … Read more

JIT vs NGen – what is the difference?

The difference is when they occur. The JIT compilation occurs while your program is running. NGen is a typically done at installation time of your program and happens before your program is run. One of the goals of NGen is to remove the JIT penalty from application start up.

Potential .NET x86 JIT issue?

I can reproduce your behavior: R:\>csc /platform:x86 releasable.cs Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved. R:\>releasable Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Test.Program.Main(String[] args) R:\>csc /o+ /platform:x86 releasable.cs Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft … Read more

Why does JIT order affect performance?

Please note that I do not trust the “Suppress JIT optimization on module load” option, I spawn the process without debugging and attach my debugger after the JIT has run. In the version where single-line runs faster, this is Main: SingleLineTest(); 00000000 push ebp 00000001 mov ebp,esp 00000003 call dword ptr ds:[0019380Ch] MultiLineTest(); 00000009 call … Read more