Patent ID: 7873943

Claim:
A method, comprising: determining a location to insert stack clearing code into a method to be executed in an execution environment of a computer system; inserting the stack clearing code into the location of the method; and executing the stack clearing code during execution of the method to clear a stack; wherein determining a location to insert stack clearing code includes an insertion policy selected from the group consisting of 1) inject code into a prologue method or an epilogue method, where an overhead per method is T+C*P; 2) inject code into both a prologue method and an epilogue method, where an overhead per method is 2*(T+C*P); or 3) inject code at a loop back-edge, where an overhead would be L*(T+C*P), wherein an average loop count is L and overheads from good timing, for clearing( ) and do stack clearing( ) are T and C respectively, and a probability for good timing for clearing( ) to return true is P.