A method and apparatus for reducing runtime memory requirements of a
virtual machine. The invention involves analyzing object code compiled
from source code. The object code includes at least two load-units that
each contain a load-unit specific constant pool. Each load-unit is
analyzed to determine which constants are actual constants and then those
actual constants are analyzed to determine where commonality exists among
the load-units. If a constant is determined to be redundant it is
rewritten to a global constant pool. The references to the constant in
the load-unit specific constant pool are rewritten to point to the value
in the global constant pool. The memory allocated to the constant in the
individual load-unit is then reallocated, either by a programmed routine
or by memory management tools.