[Mono-bugs] [Bug 44229][Nor] Changed - mcs does not set beforefieldinit

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 11 Mar 2004 18:53:02 -0500 (EST)

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by miguel@ximian.com.


--- shadow/44229	2003-06-29 01:42:43.000000000 -0400
+++ shadow/44229.tmp.11341	2004-03-11 18:53:02.000000000 -0500
@@ -1,16 +1,16 @@
 Bug#: 44229
-Product: Mono/MCS
+Product: Mono: Compilers
 Version: unspecified
 OS: other
 OS Details: 
-Status: NEEDINFO   
+Status: RESOLVED   
+Resolution: FIXED
 Severity: Unknown
 Priority: Normal
-Component: Misc
+Component: C#
 AssignedTo: mono-bugs@ximian.com                            
 ReportedBy: dietmar@ximian.com               
 QAContact: mono-bugs@ximian.com
 TargetMilestone: ---
@@ -75,6 +75,65 @@
 Maybe am miss-understanding the use of beforefieldinit here.
 Setting this to NEEDINFO.
+------- Additional Comments From vargaz@freemail.hu  2003-09-12 09:27 -------
+*** Bug 48428 has been marked as a duplicate of this bug. ***
+------- Additional Comments From vargaz@freemail.hu  2003-09-12 09:35 -------
+I think beforefieldinit means 'it's ok to initialize the type sometime 
+before its static fields are used', i.e. initialization does not need
+to be triggered by the first access to the type. Setting this flag
+helps the JIT to compile better code, since it can run the static
+constructor at JIT time, and does not need to generate code to call it
+(possibly lots of times) at runtime. Unfortunately, mcs does not set
+this flag for lots of classes like String. 
+csc sets this flag if the type does not have an explicit static 
+constructor. The reasoning seems to be that if there are only static
+initalizers for a type, and no static constructor, then the programmer
+does not care when this initialization happens, so beforefieldinit
+can be used.
+This bug prevents the AOT compiler from being usable, since it 
+generates so many calls to mono_runtime_class_init that the AOT code
+is much slower than the JITted code. The JITted code is faster, 
+because it does not generate these calls if the vtable is type is
+already initialized, which is true in the majority of cases. But the
+AOT compiler can't do this.
+------- Additional Comments From vargaz@freemail.hu  2003-09-22 00:16 -------
+Put this back on the radar.
+------- Additional Comments From bmaurer@users.sf.net  2003-12-24 01:14 -------
+Ok, so it is pretty clear that CSC sets beforefieldinit iff there is
+no explicit static ctor.
+It is pretty easy to make MCS act like this. One weird thing I did
+notice is that with the test case you give, without aot'ing it, the
+CSC version is actually *slower* than the mcs version (the only
+differnce in the IL is the beforefieldinit). When I passed -O=all,
+however, the perf was the same.
+With the AOT, CSC's version was faster than MCS's (though both were
+much slower than the JIT'd version).
+Also, this will require some extensive testing, so we need to do it
+when we are all back from vacation.
+------- Additional Comments From miguel@ximian.com  2004-03-11 18:53 -------
+I have changed the compiler semantics to emit BeforeFieldInit if the
+class does not have a static constructor.
+Found some further data on this here:
+But Zoltan's rationale is probably a better explanation.