A method and apparatus to guarantee type safety in multithreaded programs,
and to guarantee initialization safety in well-behaved multithreaded
programs. A plurality of bytecodes representing a program are received
and examined to identify bytecodes defining object creation operations
and object initialization operations. Upon execution of the plurality of
bytecodes, memory barrier operations are performed subsequent to the
performance of both the object creation operations and the object
initialization operations. This guarantees type safety, and further
guarantees initialization safety if the program is well-behaved.
Optimization algorithms may also be applied in the compilation of
bytecodes to improve performance.