1. A method for reducing deoptimization in a virtual machine, the method comprising: compiling source code of a dynamically-typed program; recording, during runtime, 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; wherein the context-free type-state recorder is configured to record all possible data types that may be assigned to the particular named memory location across multiple runs of the dynamically-typed program; 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 of the same type as the first data type; recording, during runtime, 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.