Bug Jit-Compiler?

A

Armin Zingler

Hallo NG, (Crossposting hoffentlich angebracht)

folgender Code (VB 2003) sieht etwas chaotisch und z.T. unsinnig aus, aber
ich habe ihn absichtlich nicht entrümpelt, weil sonst das Problem nicht mehr
reproduzierbar ist. Es muss auch niemand den ganzen Code analysieren,
sondern es geht lediglich um das "Count +=1". Erklärung s.unten. Man nehme
eine neues Winforms-Projekt, füge einen Button und folgenden Code hinzu:


Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

Dim sw As Integer
Dim success As Boolean
Dim starttime, endtime, realendtime As DateTime
Dim count As Integer

Try
Try
Dim s As DateTime
Dim ee As DateTime
starttime = Now
endtime = starttime.AddSeconds(10)
Do While Now.Ticks = starttime.Ticks
Loop
s = Now
'Stop
Do
ee = Now
If ee.Ticks <> s.Ticks Then
s = ee
count += 1
End If
Loop Until count = 10 ' ee >= endtime
'realendtime = DateTime.Now
success = True
Finally
End Try
Finally
End Try

If success Then
MsgBox(sw.ToString("0.000000") & " in " _
& realendtime.Subtract(starttime).ToString)
Dim abweichung As Double
abweichung = _
realendtime.Subtract(starttime).TotalSeconds / sw
MsgBox(abweichung.ToString("0.0000000000000"))
MsgBox(count)
End If

End Sub



Problem ist nun: In der Release-Konfiguration, also mit aktivierten
Optimierungen, wird die Schleife mit "Loop Until count = 10" nie beendet.
Wie ich dann herausfand, wird die Zeile

count += 1

umgesetzt mit

mov dword ptr [ebp-18h],1

Von einer Addition ist nirgends etwas zu sehen. Ist irgendwie ein Bug, oder?
Im IL-Code wird aber noch ordnungsgemäß addiert:

//000080: count += 1
IL_0057: ldloc.0
IL_0058: ldc.i4.1
IL_0059: add
IL_005a: stloc.0


Wenn ich z.B. den unteren Block "If success Then" herausnehme und neu
kompiliere, wird daraus plötzlich ein

inc dword ptr [ebp-18h]

So sollte es eigentlich sein. Daher konnte ich den Code auch nicht
entrümpeln.



Armin
 
A

Armin Zingler

Armin Zingler said:
Hallo NG, (Crossposting hoffentlich angebracht)

Natürlich nicht. :-( Habe ich in der anderen Gruppe schon richtiggestellt.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top