Reputation: 5140
As we know Garbage collector believe in philosophy of generational collection. In which the short lived/small objects are placed on gen 0 which I believe L2 processor or core cache (correct me if I am wrong here) for faster access. With this in mind, where are the gen 1 and gen 2 are placed ?
Upvotes: 0
Views: 89
Reputation: 490108
There's no direct relationship between GC generations and cache/memory levels.
The memory manager simply starts with a block of memory, and allocates from it. The code uses it.
The processor tracks memory use, so what's been used the most recently is generally stored where the processor can access it the most quickly. Depending on usage patterns, that recently used data can come from just about any generation.
There is a tendency for recently-created objects to be used frequently and older objects to be used somewhat less frequently. This tends to lead to recently-created objects being in L1 cache, slightly older objects in L2 and still older in main memory. That's only a general tendency, not anything that's enforced by the memory manager though. At any given time, it's fairly likely that each level of cache will contain some objects from two or three different generations.
Also note that when data is loaded into cache, only the part being accessed is loaded into cache. So, if you have a large object, part of it that's been accessed recently might be in L1 cache, some other part(s) that were access less recently in L2 cache, and the remainder of it only in main memory.
Upvotes: 1