One embodiment of the present invention provides a system that predicts a result
produced by a section of code in order to support speculative program execution.
The system begins by executing the section of code using a head thread in order
to produce a result. Before the head thread produces the result, the system generates
a predicted result to be used in place of the result. Next, the system allows a
speculative thread to use the predicted result in speculatively executing subsequent
code that follows the section of code. After the head thread finishes executing
the section of code, the system determines if a difference between the predicted
result and the result generated by the head thread has affected execution of the
speculative thread. If so, the system executes the subsequent code again using
the result generated by the head thread. If not, the system performs a join operation
to merge state associated with the speculative thread with state associated with
the head thread. In one embodiment of the present invention, executing the subsequent
code again involves performing a rollback operation for the speculative thread
to undo actions performed by the speculative thread.