Today continue to take everyone to explain CORECLR GC, first we continue to see this gcsample, this article is the continuation of the previous article, if there is not clear, but also please turn to me to write the last essay. Below we continue:
Initialize free Object methodtable. The GC uses a special array-like methodtable as placeholder //for collected free space. Initialize the release (object Method table), <-do not know whether the translation is correct. GC uses a very special image array like methodtable as a placeholder for collecting free space static methodtable freeobjectmt;
So what is this methodtable "sacred"? The following is only a partial list of methods;
Class Methodtable{public: uint16_t m_componentsize;//container size uint16_t m_flags; Identifier uint32_t m_basesize; Initial (minimum size, anyway I understand) methodtable * M_PRELATEDTYPE;//correlation type, is a methodtable type pointer public: void Initializefreeobject ()//Initialize "Idle" Object {//void (*) Popular Science ↓↓↓↓//http://www.zhihu.com/question/24398191?sort=created m_basesize = 3 * sizeof (void *); M_componentsize = 1; m_flags = 0; } uint32_t getbasesize () { return m_basesize; } uint16_t rawgetcomponentsize () { return m_componentsize; }}
Here we go back to the GCSample.cpp file, where the resulting initialization space is assigned to a pointer called g_pfreeobjectmethodtable, which is why?
Initialize freeobjectmt.initializefreeobject ();//Do not know why to assign it g_pfreeobjectmethodtable = &freeObjectMT;
Here's a look at this method, I don't know what it says about handle table, so there's a need to continue exploring.
Initializes the handle table ("reference" is initialized) if (! Ref_initialize ()) return-1;
Let's take a look at ref_initialize () This method, and I'm going to break it down one step at a point, we first notice contractl and Contractl_end, These 2 macros are actually defined in gcenv.base.h, that is, from this definition, we get a useful message: it is part of the GC environment variables, on different CPUs or system machines, I dare to predict, they will be from dynamic-> specific values.
The agreement begins (for the time being, it's just speculation).
Contractl
{
nothrow;//with No-throw
WRAPPER (Gc_notrigger); With No-trigger
Inject_fault (return false); If the injection fails, then return false directly
}
Contractl_end; End of agreement
We have to look at the following code, is not a sense of the impossible? Then I'll bring you to the analysis.
Sanity _asserte (g_handletablemap.pbuckets = = NULL);
From among, completely already detailed the compiler to look for code of the process, about the assert some of the text, we can self-Baidu.
About G_handletablemap, due to space and time is limited, I only talk about the G_handletablemap.pbuckets and the code, the rest, if you are interested, you can study it-the following figure shows the tolerance distortion of pbuckets.
In fact, it can be said that its internal is a handletablebucket, the following is its code, of course, I did not speak the whole, and, my foreign language level is very bad, will see it.
struct containing g_systeminfo.dwnumberofprocessors hhandletables and current table index//instead of just single Hhan Dletable for on-fly balancing and adding handles on MULTIPROC machines//structure contains the GC System Information DW Process (ptr_hhandletable), and the current table subscript//Here to say is very complex, anyway simple understanding, is a dataset, understand it; struct handletablebucket{ ptr_hhandletable ptable; uint32_t Handletableindex; BOOL Contains (objecthandle handle);};
C + + Essay: GC exploration of. NET CORECLR (4)