8 doesn??™t create a sixth line of output
??”the static constructor for Outer
.Inner executed earlier,
producing the second line of output. To clear up any doubts, if we had a nongeneric
PlainInner class inside Outer, there would still have been one possible
Outer.PlainInner type per closed Outer type, so Outer.PlainInner would
be separate from Outer.PlainInner, with a separate set of static fields as
seen earlier.
Now that we??™ve seen just what constitutes a different type, we should think about
what the effects of that might be in terms of the amount of native code generated.
And no, it??™s not as bad as you might think??¦
Listing 3.8 Static constructors with nested generic types
Note!
Only 5 lines
of output??¦
88 CHAPTER 3 Parameterized typing with generics
3.4.2 How the JIT compiler handles generics
Given that we have all of these different closed types, the JIT??™s job is to convert the IL
of the generic type into native code so it can actually be run. In some ways, we
shouldn??™t care exactly how it does that??”beyond keeping a close eye on memory and
CPU time, we wouldn??™t see much difference if the JIT did the obvious thing and generated
native code for each closed type separately, as if each one had nothing to do with
any other type. However, the JIT authors are clever enough that it??™s worth seeing just
what they??™ve done.
Pages:
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193