High Frequency Heap

Static Variable

μš°λ¦¬λŠ” C#μ—μ„œ static (정적) λ³€μˆ˜κ°€ μžˆλ‹€λŠ”κ±Έ μ•Œκ³  μžˆμŠ΅λ‹ˆλ‹€. 그런데, 이 static λ³€μˆ˜κ°€ μ–΄λŠ λ©”λͺ¨λ¦¬ μ˜μ—­μ— μ €μž₯λ˜λŠ”μ§€λŠ” 잘 λͺ¨λ¦…λ‹ˆλ‹€. 일반적으둠 νž™μ— μ €μž₯λœλ‹€ λΌλŠ” 이야기가 많죠. 그런데, μ •ν™•ν•œ 사싀은 static λ³€μˆ˜λŠ” High-Frequency Heap μ΄λΌλŠ” 곳에 μ €μž₯(Allocate)λ©λ‹ˆλ‹€.

κ·Έλž˜μ„œ μ €λŠ” 이 μƒˆλ‘œμš΄ νž™μ— λŒ€ν•΄μ„œ 말해보렀고 ν•©λ‹ˆλ‹€.

High Frequency heap

λ§€λ‹ˆμ§€λ“œ ν”„λ‘œμ„ΈμŠ€λŠ” μ„Έκ°€μ§€μ˜ λ„λ©”μΈμœΌλ‘œ λ‚˜λ‰©λ‹ˆλ‹€.

  • System Domain

  • Shared Domain

  • Default AppDomain

이 쀑 High Frequency Heap은 System Domain에 μ†ν•΄μžˆκ΅¬μš”. 보톡 λ§ν•˜λŠ” νž™μ΄λΌλŠ”κ²ƒμ€ GC heap 을 λ§ν•˜λŠ”λ° 이 μΉœκ΅¬λŠ” appdomainμ—μ„œ λ™μž‘ν•˜λŠ” μΉœκ΅¬μ—μš”.\

Managed Process

System Domain

The SystemDomain is responsible for creating and initializing the SharedDomain and the default AppDomain. It loads the system library mscorlib.dll into SharedDomain. It also keeps process-wide string literals interned implicitly or explicitly.

String interning is an optimization feature that's a little bit heavy-handed in the .NET Framework 1.1, as the CLR does not give assemblies the opportunity to opt out of the feature. Nonetheless, it saves memory by having only a single instance of the string for a given literal across all the application domains.

SystemDomain is also responsible for generating process-wide interface IDs, which are used in creating InterfaceVtableMaps in each AppDomain. SystemDomain keeps track of all the domains in the process and implements functionality for loading and unloading the AppDomains.

Shared Domain

All of the domain-neutral code is loaded into SharedDomain. Mscorlib, the system library, is needed by the user code in all the AppDomains. It is automatically loaded into SharedDomain.

Fundamental types from the System namespace like Object, ValueType, Array, Enum, String, and Delegate get preloaded into this domain during the CLR bootstrapping process. User code can also be loaded into this domain, using LoaderOptimization attributes specified by the CLR hosting app while calling CorBindToRuntimeEx.

Console programs can load code into SharedDomain by annotating the app's Main method with a System.LoaderOptimizationAttribute. SharedDomain also manages an assembly map indexed by the base address, which acts as a lookup table for managing shared dependencies of assemblies being loaded into DefaultDomain and of other AppDomains created in managed code. DefaultDomain is where non-shared user code is loaded.

Default AppDomain

DefaultDomain is an instance of AppDomain within which application code is typically executed. While some applications require additional AppDomains to be created at runtime (such as apps that have plug-in architectures or apps doing a significant amount of run-time code generation), most applications create one domain during their lifetime.

All code that executes in this domain is context-bound at the domain level. If an application has multiple AppDomains, any cross-domain access will occur through .NET Remoting proxies. Additional intra-domain context boundaries can be created using types inherited from System.ContextBoundObject.

Each AppDomain has its own SecurityDescriptor, SecurityContext, and DefaultContext, as well as its own loader heaps (High-Frequency Heap, Low-Frequency Heap, and Stub Heap), Handle Tables (Handle Table, Large Object Heap Handle Table), Interface Vtable Map Manager, and Assembly Cache.

Summary

Loader Heap: contains CLR structures and the type system High Frequency Heap: statics, MethodTables, FieldDescs, interface map Low Frequency Heap: EEClass, ClassLoader and lookup tables Stub Heap: stubs for CAS, COM wrappers, PInvoke Large Object Heap: memory allocations that require more than 85k bytes GC Heap: user allocated heap memory private to the app JIT Code Heap: memory allocated by mscoreee (Execution Engine) and the JIT compiler for managed code Process/Base Heap: interop/unmanaged allocations, native memory, etc

#

Reference

Last updated