1. Technical Field
The present invention relates to computer programming and, more particularly, to runtime type verification of precompiled code in programming languages.
2. Description of the Related Art
There exist various programming languages that can be used to write application software for computer systems. Some of the more popular languages currently in use include Java, C++, and C#, to name a few. The Java programming language, for example, is capable of producing a machine-independent compiled format known as a class file. The Java programming language further provides a machine independent environment within which the compiled code (or class file) is run. This environment is known as the Java virtual machine (JVM). At runtime, the Java virtual machine utilizes a bytecode verifier to examine the contents of a class file and ensure that the contained bytecode does not violate type safety or other constraints imposed by the virtual machine.
In a traditional Java virtual machine, there are a number of verification checks that must be performed at runtime. This is often done by modeling the control flow in the method bodies, and examining the various type assumptions made by the methods. It is essential that these verification checks be performed within the appropriate runtime context (or environment). Conversely, it can be wasteful in both space and time to maintain a copy of, and redundantly verify, bytecode corresponding to a compiled method. In the context of compiling source code, for example, only implicit downcasts and class instances made in the source code need to be verified at runtime. Thus, all other checks can be performed prior to runtime in order to reduce the amount of verification necessary at runtime. This can sometimes present a problem for compilers that seek to optimize and improve execution of the program.
In Java, for example, the ability to run programs in a machine independent environment can sometimes allow the Java virtual machine to execute untrusted code. In order to maintain type safety during runtime, a Java virtual machine performs bytecode verification to emulate the actions of various bytecode instructions within a method. If the bytecode verification is successful, then the method is presumed to be type-safe. However, various situations can arise where the bytecode successfully passes verification in one context (or machine environment), but causes harmful results when the same bytecode is executed within another context.
FIG. 6 is a flow diagram illustrating one specific manner in which certain program code can be executed according to convention methods. At step 410, the program source code (or program code) is received. According to the example shown in FIG. 6, the program source code used is Java source code. At step 412, the system compiles the source code to produce Java bytecode at 414. The Java bytecode corresponds to a type of machine executable code that is specific to the Java virtual machine. At step 416, the bytecode is executed within a Java virtual machine. While in the Java virtual machine, all verification checks for the bytecode are performed at 418. Execution of the bytecode continues, and verification continues until the program ends.
At least one problem encountered when compiling and running programs according to such conventional methods is the difficultly involved in testing the program code. Since programming languages such as Java are intended to be portable, they must be able to function substantially identically on different operating systems and/or platforms. As previously discussed, however, program code that is compiled and tested in one environment can sometimes affect the security parameters within which the program is being executed when the program is moved to a different environment and/or context. This can oftentimes be the result of improper verification within the runtime environment. Furthermore, the time required to perform redundant verifications at runtime can significantly affect execution speed.