 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jason Southwell Guest
|
Posted: Wed Oct 12, 2005 7:08 pm Post subject: Possible FastMM4 w/Optimization bug |
|
|
I switched to FastMM4 from nexusMM 3 due to a problem I had in a
similar line of code with their MM and with optimizations turned on.
FastMM 4 has been working much better for me, but now I'm running into
one with it as well.
Here is a link to a movie file showing the problem...
111MB AVI: http://www.streamload.com/deadserious/FastMM4.avi
15MB Flash: http://www.streamload.com/deadserious/FastMM4.swf
You will see that the first time through, I build the project with
Optimizations turned off. When I step through a loop, I see that
TIWComboBox(c).items[i] returns the correct index from the items list.
Next you will see me turn on Optimizations and rebuild the project.
Now you will see that TIWComboBox(c).items[i] always returns the value
of TIWComboBox(c).items[0] regardless to the value of i.
I'm not beyond thinking that this is a problem is my code, but it seems
very suspect to me that simply by flipping the Optimization flag, it
will work or not work. This is almost identical to a problem I was
previously experiencing with NexusMM 3 in a different section of code
with a for loop.
FWIW, with Nexus, the problem goes away if I change the for loop to a
while loop. I haven't tried that yet with FastMM.
Also, the problem does not exist using the stock RTL MM.
At the end of the movie, I walk through the loop in the CPU window.
Any ideas?
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Joe Bain Guest
|
Posted: Wed Oct 12, 2005 7:27 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
Jason Southwell wrote:
| Quote: | I switched to FastMM4 from nexusMM 3 due to a problem I had in a
similar line of code with their MM and with optimizations turned on.
FastMM 4 has been working much better for me, but now I'm running into
one with it as well.
Here is a link to a movie file showing the problem...
111MB AVI: http://www.streamload.com/deadserious/FastMM4.avi
15MB Flash: http://www.streamload.com/deadserious/FastMM4.swf
You will see that the first time through, I build the project with
Optimizations turned off. When I step through a loop, I see that
TIWComboBox(c).items[i] returns the correct index from the items list.
Next you will see me turn on Optimizations and rebuild the project.
Now you will see that TIWComboBox(c).items[i] always returns the value
of TIWComboBox(c).items[0] regardless to the value of i.
I'm not beyond thinking that this is a problem is my code, but it
seems very suspect to me that simply by flipping the Optimization
flag, it will work or not work. This is almost identical to a
problem I was previously experiencing with NexusMM 3 in a different
section of code with a for loop.
FWIW, with Nexus, the problem goes away if I change the for loop to a
while loop. I haven't tried that yet with FastMM.
Also, the problem does not exist using the stock RTL MM.
At the end of the movie, I walk through the loop in the CPU window.
Any ideas?
|
Try it with the default Delphi memory manager and you will get the same
result. It is an optimization from the compiler. In a loop where the
index does not matter, just the number of iterations the optimizer will
change for loops from
for i := 0 to size to for i := size downto 0.
There are times that i is important that the optimizer does not
recognize. Just turn it off for that part of the code with {$O-}.
--------------
Joe Bain
www.iegsoftware.com
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Wed Oct 12, 2005 7:50 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | Try it with the default Delphi memory manager and you will get the
same result. It is an optimization from the compiler. In a loop where
the index does not matter, just the number of iterations the
optimizer will change for loops from
for i := 0 to size to for i := size downto 0.
There are times that i is important that the optimizer does not
recognize. Just turn it off for that part of the code with {$O-}.
|
As I stated in my first message, if I use the default memory manager, I
do NOT get the same result.
And the index des matter inside the loop... I'm using i to loop through
items in a string list and I'm checking the value of that indexed
string agaisnt another value then doing something with that result.
There is NO reason it should be optimized out.
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Wed Oct 12, 2005 8:00 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | And the index des matter inside the loop... I'm using i to loop
through items in a string list and I'm checking the value of that
indexed string agaisnt another value then doing something with that
result. There is NO reason it should be optimized out.
|
In fact, this is the loop if you didn't see it in the AVI. You will
see that i is certainly used within the loop...
for i := 0 to TIWComboBox(c).Items.Count-1 do
begin
if
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"
')] = '' then
begin
if TIWComboBox(c).ItemIndex < 0 then
TIWComboBox(c).ItemIndex := 0;
break;
end else
begin
if (TIWComboBox(c).ItemsHaveValues) then
begin
if TIWComboBox(c).Items.ValueFromIndex[i] =
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"
')] then
begin
TIWComboBox(c).ItemIndex := i;
sReplace := TIWComboBox(c).Items.ValueFromIndex[i];
break;
end;
end else
begin
if TIWComboBox(c).Items[i] =
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"
')] then
begin
TIWComboBox(c).ItemIndex := i;
sReplace := TIWComboBox(c).Items[i];
break;
end;
end;
end;
end;
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Pierre le Riche Guest
|
Posted: Wed Oct 12, 2005 8:18 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
Hi Jason,
your request." error, and you mentioned that the flash doesn't work so I
didn't try it.
| Quote: | I'm not beyond thinking that this is a problem is my code, but it seems
very suspect to me that simply by flipping the Optimization flag, it
will work or not work. This is almost identical to a problem I was
|
Except for the initialization code FastMM4 is written entirely in assembler,
so it shouldn't make a difference whether optimizations are on or not. The
fact that it *does* make a difference suggests to me that perhaps there is a
memory overwrite bug somewhere in the test application (or components). Have
you tried using FastMM's FullDebugMode? FullDebugMode is aimed at helping to
track down memory related bugs.
Regards,
Pierre
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Wed Oct 12, 2005 9:58 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | When I click on the avi file I get a "An error occurred while
processing your request." error, and you mentioned that the flash
doesn't work so I didn't try it.
|
The hosting site seems to be having intermitant errors. Please try
again in a bit.
| Quote: | Except for the initialization code FastMM4 is written entirely in
assembler, so it shouldn't make a difference whether optimizations
are on or not. The fact that it does make a difference suggests to me
that perhaps there is a memory overwrite bug somewhere in the test
application (or components). Have you tried using FastMM's
FullDebugMode? FullDebugMode is aimed at helping to track down memory
related bugs.
|
I have ran it with FullDebugMode and it reported no errors. Also,
there are no memory leaks outside the standard Indy memory leaks.
I had considered it was a memory overwrite issue, but there is no
direct pointer/pchar etc access in my code, so it's unlikely. It may
be happening in one of the used components... What would FullDebugMode
show if one were occurring?
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Thu Oct 13, 2005 5:26 am Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
Jason Southwell wrote:
| Quote: | You will see that the first time through, I build the project with
Optimizations turned off. When I step through a loop, I see that
TIWComboBox(c).items[i] returns the correct index from the items list.
Next you will see me turn on Optimizations and rebuild the project.
Now you will see that TIWComboBox(c).items[i] always returns the value
of TIWComboBox(c).items[0] regardless to the value of i.
|
This is just the debugger 'bug' that everyone seems to stumble across.
Delphi optimizes loops to count down, but AFAIK it keeps a separate
counter which counts upwards. The debugger shows the value counting
down. In reality it is counting up. Add logging
(outputdebugstring(inttostr(i))) to see.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Thu Oct 13, 2005 6:08 am Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | I had considered it was a memory overwrite issue, but there is no
direct pointer/pchar etc access in my code, so it's unlikely.
|
Your code uses objects however, and these are pointers.
If you store data in fields of an already freed object, you're likely
to overwrite something else, and what that "something else" will be
will depend on the MM and whatever was allocated in your code since
the object was freed (the freed memory is bound to be reused at some
point).
If what you overwrite with another MM is unused data or still-unallocated
memory, then the issue won't be visible but the overwrite is still there.
Eric
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Thu Oct 13, 2005 11:17 am Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | Your code uses objects however, and these are pointers.
|
Very true.
| Quote: | If you store data in fields of an already freed object, you're likely
to overwrite something else, and what that "something else" will be
will depend on the MM and whatever was allocated in your code since
the object was freed (the freed memory is bound to be reused at some
point).
|
Well, I can gaurantee that the TIWComboBox(c) is in fact a TIWComboBox
and it is in fact newly created. I am reusing a local variable and c
can be many different types of objects, but the correct object is newly
created into that local variable just before the loop I posted.
| Quote: | If what you overwrite with another MM is unused data or
still-unallocated memory, then the issue won't be visible but the
overwrite is still there.
|
Well, I do not free the local variable before reassigning a new object
to it. But that should not be an overwrite as it's essentially a new
variable instance at that point. The old object that was in the
variable was not freed, and should not be at this point.
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Thu Oct 13, 2005 11:19 am Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | This is just the debugger 'bug' that everyone seems to stumble
across. Delphi optimizes loops to count down, but AFAIK it keeps a
separate counter which counts upwards. The debugger shows the value
counting down. In reality it is counting up. Add logging
(outputdebugstring(inttostr(i))) to see.
|
But it's not a debugger issue. WHen you run the app outside the
debugger, 'i' still does increment, but the call to retrieve the string
at index 'i' from the string list still retrieves 0.
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Thu Oct 13, 2005 12:23 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | Well, I can gaurantee that the TIWComboBox(c) is in fact a TIWComboBox
and it is in fact newly created.
|
Can't see you code because the SWF is at too high a resolution and won't
allow scrolling, but that the object is newly created isn't enough to
shield you from side effects of overwrites completely, as dynamic
allocations and destructions will happen during object creation, as well
as usage of potentially corrupted data.
One example would be a string whose size got corrupted: it was created
with "Dummy", of Length=5, and then something replaced the 5 with
a 50... code that alters the string will now risk altering whatever
data lies beyond the initial string length, including a new object if a
new object got allocated there.
Similar issues can happen with arrays or all structures that store size
or memory references.
In your particular case, if you really want to know what happens, check
the internal list and fields in the object (size, content, raw data
content), are there really N times the same string? is it just some
corrupted bounds check clamping your index? etc.
| Quote: | The old object that was in the variable was not freed, and should
not be at this point.
|
Memory corruptions can affect parts of the code that are completely
unrelated, both in terms of logic and time occurence.
Eric
|
|
| Back to top |
|
 |
Dan Downs Guest
|
Posted: Thu Oct 13, 2005 12:33 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
Just out of curiousity, try this:
if
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"')]
= '' then
begin
if TIWComboBox(c).ItemIndex < 0 then
TIWComboBox(c).ItemIndex := 0;
// break;
end else
begin
if (TIWComboBox(c).ItemsHaveValues) then
begin
for i := 0 to TIWComboBox(c).Items.Count-1 do
begin
if TIWComboBox(c).Items.ValueFromIndex[i] =
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"')]
then
begin
TIWComboBox(c).ItemIndex := i;
sReplace := TIWComboBox(c).Items.ValueFromIndex[i];
break;
end;
end;
end else
begin
for i := 0 to TIWComboBox(c).Items.Count-1 do
begin
if TIWComboBox(c).Items[i] =
Defaults.Values[AnsiQuotedStr(dm.qryReportOptionsReplaceText.AsString,'"')]
then
begin
TIWComboBox(c).ItemIndex := i;
sReplace := TIWComboBox(c).Items[i];
break;
end;
end;
end;
end;
I just shuffled the code a bit, no retyping, just cut and paste. I'm curious
if your running into a compiler optimizing bug, since you only see it happen
when optimiziation is turned on. Why it doesn't happen with the default MM I
have no idea.
DD
|
|
| Back to top |
|
 |
Jason Southwell Guest
|
Posted: Thu Oct 13, 2005 12:46 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
Dan Downs wrote:
| Quote: | I just shuffled the code a bit, no retyping, just cut and paste. I'm
curious if your running into a compiler optimizing bug, since you
only see it happen when optimiziation is turned on. Why it doesn't
happen with the default MM I have no idea.
|
It runs into the same problem of I incrementing but the retrieval from
the stringlist always being index 0.
--
Jason Southwell
www.arcanatech.com
Delphi & IntraWeb Components
Consulting and Contracting
Incident Based Support
|
|
| Back to top |
|
 |
Dan Downs Guest
|
Posted: Thu Oct 13, 2005 1:57 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
| Quote: | I just shuffled the code a bit, no retyping, just cut and paste. I'm
curious if your running into a compiler optimizing bug, since you
only see it happen when optimiziation is turned on. Why it doesn't
happen with the default MM I have no idea.
It runs into the same problem of I incrementing but the retrieval from
the stringlist always being index 0.
|
drats.
Does it work with FastMM if you switch it to a while loop like you did for
nexus? If so, I'm still learning towards something other than the MM.
DD
|
|
| Back to top |
|
 |
Ryan Mills Guest
|
Posted: Thu Oct 13, 2005 2:18 pm Post subject: Re: Possible FastMM4 w/Optimization bug |
|
|
After reading the entire thread I was wondering if the TIWCombobox component your
using is from IntraWeb? If so what version of IW are you using?
Could this be a known issue with IW?
Ryan.
On 12 Oct 2005 12:08:58 -0700, "Jason Southwell" <jason (AT) southwell (DOT) net> wrote:
| Quote: | I switched to FastMM4 from nexusMM 3 due to a problem I had in a
similar line of code with their MM and with optimizations turned on.
FastMM 4 has been working much better for me, but now I'm running into
one with it as well.
snip |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|