What is "stack thrash"? Or "a stack thrash"? (Since I don't know the definition I'm not sure if it is a countable or uncountable term.)
Stack thrashing is like heap thrashing, but on the stack.
There, now that's explained.
Oh, you want more detail huh ?
If you emulate a stack based processor on a processor that isn't you're thrashing the stack.
If your C code malloc's and free's every other line of code, you're thrashing the heap.
The point of stack thrashing as a problem is that if you profiled your code, the CPU spending pretty much all it's time popping and pushing.
For heap thrashing that's malloc() & free() being your #1 & #2 most used functions.
Now some CPU's ( rockwell make some) actually are optimized to run a stack based language in hardware.
Oddly enough, the Java Virtual Machine is a stack based model.
Running a really dumb FORTH implementation on x86 hardware will thrash the stack. The sort of thing you might write after reading the Forth spec, so you emit x86 machine code for forth instructions and DONT optimize it. Forth guys, I apologise, I know your implmentations are a lot better.
Postscript is stack based too, which makes early postscript printers exciting: they had limited ram and slow CPU's: and ran a stack-thrashing language. I'm sure a lot of effort went into things like the original Apple Laserwriter to make it run better. It had a Motorola 68000 CPU running at (10ish) megahertz and 1Mb of ram IIRC.
Again, stack thrashers.
Did that help ?
I've seen this term used in the context of Forth, where the lack of stack frame access sometimes requires excessive use of stack manipulations ("thrashing the stack") to get to certain words to the top of the stack.
Also, This glossary defines it as "Frequent stack expansion (overflow) and contraction (underflow)". Clearly a definition in need of further explanation. Perhaps someone more familiar with the Cray X1 can explain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With