1. A method for reducing deoptimization in a virtual machine, the method comprising: compiling source code of a dynamically-typed program; recording, at a context-free type-state recorder in a memory, a first data type of a value associated with a particular named memory location within the source code; generating optimized code based on the first data type of the value being a matching data type for global values associated with the particular named memory location; type-checking that one or more global values associated with the particular named memory location is the of the same type as the first data type; recording, at the context-free type-state recorder, if one or more of the global values associated with the particular named memory location is a different data type than the first data type, one or more different data types associated with the particular named memory location; and generating optimized code based on the first data type and the one or more different data types of the values associated with the particular named memory location being matching data types for global values associated with the particular named memory location.