Patent ID: 7937695

Claim:
A computer implemented method, performed by a processor, for compiling a computer program to generate compiled code, comprising the steps of: based on operations within an uncounted loop, the uncounted loop being a loop for which a number of iterations is not known before the loop begins executing, the uncounted loop contained in input code, the uncounted loop having at least one target exception check, generating, using the processor, one or more calculations for determining, at runtime, for each of the at least one target exception check, an expected number of iterations through which the uncounted loop can iterate prior to the uncounted loop encountering an exception corresponding to a corresponding target exception check; generating, using the processor, a copy of the uncounted loop, wherein one of the uncounted loop and the copy of the uncounted loop omits each of the at least one target exception check, and wherein an other of the uncounted loop and the copy of the uncounted loop includes each of the at least one target exception check; compiling, using the processor, the input code to form compiled code; and arranging, using the processor, within the compiled code the uncounted loop, the copy of the uncounted loop, and the one or more calculations so that at runtime a program flow will enter the one of the uncounted loop and the copy of the uncounted loop and, if a maximum number of iterations of the one of the uncounted loop and the copy of the uncounted loop is reached, the program flow will proceed from the one of the uncounted loop and the copy of the uncounted loop to the other of the uncounted loop and the copy of the uncounted loop, wherein the maximum number of iterations is no more than a smallest member of a set consisting of the expected number of iterations for each of the at least one target exception check; wherein the at least one target exception check is a plurality of target exception checks consisting of a subset of a larger plurality of exception checks contained in the uncounted loop.