This invention is directed to a method and system for arranging code
blocks of a computer program to reduce paging during the execution of the
program. The system comprises an optimizer that receives a compiled
computer-executable program in binary format (binary code). After
receiving the binary code, the optimizer generates a weighted control
flow graph (CFG) and creates a ranked list of edges based on the
information disclosed by the weighted CFG. The optimizer then engages in
a partitioning process where the blocks associated with each edge are
assigned to a particular partition according to the ranking of the edge.
The partitioning process then enters into another level by treating each
partition as a code block and repartitioning the new code blocks. The
optimizer repeats the partitioning process until some threshold number of
edges belong to a single partition. Then, the optimizer rearranges the
code blocks according to the layout of the blocks in the partition and
outputs the optimized computer-executable program.