This application is related to the following:
U.S. patent application Ser. No. 10/101,296 filed Mar. 18, 2002 in the name of Eduard de Jong, entitled “Method and Apparatus for Deployment of High Integrity Software Using Initialization Order and Calling Order Constraints”, commonly assigned herewith.
U.S. patent application Ser. No. 10/100,838, filed Mar. 18, 2002 in the name of Eduard de Jong and Pieter Hartel, entitled “Method and Apparatus for Deployment of High Integrity Software Using Static Procedure Return Addresses”, commonly assigned herewith.
The present invention relates to the field of computer science. More particularly, the present invention relates to a method and apparatus for deployment of high integrity software using reduced dynamic memory allocation.
High integrity software is software that must be trusted to work dependably in some critical function, and whose failure to do so may have catastrophic results, such as serious injury, loss of life or property, business failure or breach of security. Some examples include software used in safety systems of nuclear power plants, medical devices, electronic banking, air traffic control, automated manufacturing, and military systems. The importance of high quality, low defect software is apparent in such critical situations. However, high integrity software is also important in more mundane business areas where defective software is often the norm.
Formal verification is the process of checking whether a design satisfies some requirements or properties. In order to formally verify a design, it must first be converted into a more condensed, verifiable format. The design is specified as a set of interacting systems, each having a finite number of configurations or states. States and transition between states constitute finite state machines (FSMs). The entire system is a FSM that can be obtained by composing the FSMs associated with each component. The first step in verification consists of obtaining a complete FSM description of the system. Given a present state (or current configuration), the next state (or successive configuration) of a FSM can be written as a function of its present state and inputs (transition function or transition relation). Formal verification attempts to execute every possible computational path with every possible state value to prove every possible state is consistent.
A software program executing on a computer typically uses three types of memory: program memory, stack memory and heap memory. Program instructions are typically stored in program memory. Parameters, return values and variables local to procedures are typically stored in stack memory. Heap memory is typically used for dynamic memory requests made during program execution. Heap memory typically comprises a portion of the computer's random access memory (RAM). Whether static or dynamic memory allocation is used in the compiled code depends on the programming construct used by the programmer.
Turning now to
Unfortunately, dynamic allocation of memory during runtime is relatively inefficient. Runtime allocation of memory typically requires a relatively large number of processor cycles. Also, each access of the dynamically allocated memory typically requires more processor cycles than accessing a statically allocated variable because loading a dynamically allocated variable includes resolving indirect memory references. Loading a dynamically allocated variable requires loading a pointer value that contains the address of the dynamically allocated variable and then using the pointer value as an address to load the variable data.
Program verification is also complicated by dynamic memory allocation due to the many factors that can affect the size of a dynamic memory allocation. Dynamic memory allocation makes the state of a module dependent upon a runtime component that performs memory allocation. Coupling the state of the memory allocation to the state of the module that uses it complicates the state engine that is verified. This problem is especially acute for developers of programs targeted to devices having relatively tight memory constraints.
A programmer may perform static allocation of memory by hand. However, this process is particularly error-prone, typically resulting in low quality, low integrity software.
Accordingly, what is needed is a solution that increases program verifiability. A further need exists for such a solution that reduces dynamic memory allocation. Yet a further need exists for such a solution that simplifies memory management. Yet a further need exists for such a solution that automates memory management for programs targeted to devices having relatively limited memory.
A method for reducing dynamic memory allocation includes designing a software program using a memory allocation module for allocating memory, analyzing the software program to determine a bound on dynamic memory allocation and modifying the program based on the analyzing. According to one aspect, the program is modified to use static memory allocation in lieu of dynamic memory allocation based on the analyzing. According to another aspect, the program is modified to reduce the amount of dynamically allocated memory based on the analyzing.
The accompanying drawings, which are incorporated into and constitute a part of this specification, illustrate one or more embodiments of the present invention and, together with the detailed description, serve to explain the principles and implementations of the invention.
In the drawings:
Embodiments of the present invention are described herein in the context of a method and apparatus for deployment of high integrity software using reduced dynamic memory allocation. Those of ordinary skill in the art will realize that the following detailed description of the present invention is illustrative only and is not intended to be in any way limiting. Other embodiments of the present invention will readily suggest themselves to such skilled persons having the benefit of this disclosure. Reference will now be made in detail to implementations of the present invention as illustrated in the accompanying drawings. The same reference indicators will be used throughout the drawings and the following detailed description to refer to the same or like parts.
In the interest of clarity, not all of the routine features of the implementations described herein are shown and described. It will, of course, be appreciated that in the development of any such actual implementation, numerous implementation-specific decisions must be made in order to achieve the developer's specific goals, such as compliance with application- and business-related constraints, and that these specific goals will vary from one implementation to another and from one developer to another. Moreover, it will be appreciated that such a development effort might be complex and time-consuming, but would nevertheless be a routine undertaking of engineering for those of ordinary skill in the art having the benefit of this disclosure.
In the context of the present invention, the term “network” includes local area networks, wide area networks, the Internet, cable television systems, telephone systems, wireless telecommunications systems, fiber optic networks, ATM networks, frame relay networks, satellite communications systems, and the like. Such networks are well known in the art and consequently are not further described here.
In accordance with one embodiment of the present invention, the components, processes and/or data structures may be implemented using C or C++ programs running on high performance computers (such as an Enterprise 2000™ server running Sun Solaris™ as its operating system. The Enterprise 2000™ server and Sun Solaris™ operating system are products available from Sun Microsystems, Inc. of Palo Alto, Calif.). Different implementations may be used and may include other types of operating systems, computing platforms, computer programs, firmware, computer languages and/or general-purpose machines. In addition, those of ordinary skill in the art will recognize that devices of a less general purpose nature, such as hardwired devices, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), or the like, may also be used without departing from the scope and spirit of the inventive concepts disclosed herein.
According to embodiments of the present invention, a software program is analyzed to determine bounds on dynamic memory allocation. The software program is then modified to replace the bounded dynamic memory allocation with static memory allocation.
Many other devices or subsystems (not shown) may be connected in a similar manner. Also, it is not necessary for all of the devices shown in
For purposes of the present disclosure, a program specification refers to a model of a program design, expressed in terms of a strictly formalized language that is directly amenable to analysis using formal mathematical logic. A program specification may include one or more module specification that indicates other modules callable by the module. A program implementation refers to a software program written using a particular programming language.
Turning now to
Turning now to
Kernel component 410 includes executable code modules that include one or more procedures. Modules (440–460) include an initialization procedure to initialize the module (440–460). The initialization procedure must be called before other procedures within the module (440–460) are called. When apparatus 400 is reset, reset indicator 435 sends a signal to boot manager 440. Boot manager 440 calls the initialization procedure of at least one module (440–460) in a predetermined order. As shown in the example illustrated by
Calling order constraints in system 400 correspond to the initialization order constraints. A calling module may call any module that occurs before the calling module in the initialization sequence. A special case exists for embodiments where the boot manager module 440 is an actual module rather than a placeholder. If the boot manager module 440 is an actual module, it is limited to calling the initialization procedure for any module (440–460). In the example illustrated by
Still referring to
The call stack manager 450 allocates space for static, pre-allocated return addresses. The call stack manager 450 allocates the space by making a procedure call to the memory manager 445, including the memory allocation request. Since the call stack manager 450 must call or use the services of the memory manager 445, the call stack manager 450 is placed after the memory manager in the initialization sequence. Placing the call stack manager 450 formally early in the initialization sequence guarantees memory allocation for the static return addresses. It also guarantees static allocation of a memory area for a call stack. The call allows the memory manager 445 to reserve space for the static return addresses in its formal model of memory. The logic of the call stack manager is a call stack tool, which may rewrite modules to use static locations to store procedure return addresses, as disclosed in copending U.S. patent application Ser. No. 10/100,838, filed Mar. 18, 2002 in the name of Eduard de Jong and Pieter Hartel, entitled “Method and Apparatus for Deployment of High Integrity Software Using Static Procedure Return Addresses”.
Turning now to
According to one embodiment of the present invention, the number of layers is three. According to another embodiment of the present invention, the number of layers is four. Those of ordinary skill in the art will recognize a different number of layers is possible within the inventive concepts disclosed herein.
System 500 may be further organized into columns of related functionality. Four columns of related functionality (520, 525, 530, 535) are shown in
Turning now to
In the C and C++ languages, memory is dynamically allocated using the “malloc” instruction. According to one embodiment of the present invention, a C compiler generates code that forwards “malloc” calls to the dynamic memory allocation module. According to another embodiment of the present invention, a C++ compiler generates code that forwards “malloc” calls to the dynamic memory allocation module described herein.
In Java™ technology, memory is dynamically allocated using the “new” instruction. According to one embodiment of the present invention, a Java™ compiler generates code that forwards “new” calls to the dynamic memory allocation module described herein. The Java™ programming language is described in detail in Gosling et al., “The Java™ Language Specification”, August 1996, Addison-Wesley Longman, Inc.
The above illustrations with respect to the “malloc” and “new” instructions are not intended to be limiting in any way. Those of ordinary skill in the art will recognize that the invention may be applied to other compilers and their corresponding dynamic memory allocation instructions.
Still referring to
According to one embodiment of the present invention, modification of the software program includes changing code that performs a dynamic memory allocation to code that performs a static memory allocation. The modification also includes changing code that referred to a dynamically allocated variable to refer to a statically allocated variable. For example, suppose a procedure includes a dynamic allocation and that the upper bound for the allocation is an input parameter for the procedure. If the data flow and control flow analysis determines an upper bound and there is no bound found in the specification, the software program is modified to use the upper bound determined from the data flow and control flow analysis. If the specification includes a bound, the software program is modified to use the upper bound obtained from the specification.
According to one embodiment of the present invention, the dynamic memory allocation module is removed from the program if the modification results in a program with no dynamic memory allocation.
According to another embodiment of the present invention, a dynamic memory allocation request is rewritten to request only the amount of memory required based on the bounds analysis. Thus, a request for a relatively large amount of dynamically allocated memory is replaced with a request for a relatively small amount of dynamically allocated memory.
According to another embodiment of the present invention, the “size” parameter of a dynamic memory allocation request is rewritten to refer to an index into a table of preallocated memory block addresses. The operation of the memory management routine (such as the “new” routine in a Java™ program or the “malloc” routine in C or C++ program) is also changed to use the input parameter as an index into the table instead of the amount of memory requested. The size of the memory block pointed to is based on the bounds analysis.
According to another embodiment of the present invention, a dynamic memory allocation request is rewritten to refer to the address of a pre-allocated memory block. By way of example, the C or C++ statement “a=malloc (100)” could be rewritten as “a=xABCD”, where “xABCD” is the address of a pre-allocated memory block having a size that is based on the bounds analysis.
Still referring to
The call stack manager 550 allocates space for static, pre-allocated return addresses. The call stack manager 550 allocates the space by making a procedure call to the memory manager 545, including the memory allocation request. Since the call stack manager 550 must call or use the services of the memory manager 545, the call stack manager 550 is placed after the memory manager in the initialization sequence. Placing the call stack manager 550 formally early in the initialization sequence guarantees memory allocation for the static return addresses. It also guarantees static allocation of a memory area for a call stack. The call allows the memory manager 545 to reserve space for the static return addresses in its formal model of memory. The logic of the call stack manager is a call stack tool, which may rewrite modules to use static locations to store procedure return addresses, as disclosed in copending U.S. patent application Ser. No. 10/100,838, filed Mar. 18, 2002 in the name of Eduard de Jong and Pieter Hartel, entitled “Method and Apparatus for Deployment of High Integrity Software Using Static Procedure Return Addresses”.
Turning now to
Dynamic memory allocations made outside an initialization procedure are potentially unbounded. Thus, the program implementation and the program specifications are analyzed to determine bounds on dynamic memory allocation requests. This analysis includes performing control flow and data flow analysis of the implementation and the specifications to determine bounds on dynamic memory allocation. Analysis of the implementation may utilize data type information to establish an upper bound. The value of this information depends upon the particular data type. For example, if the number of dynamically allocated elements is designated by a 16-bit signed integer variable and if analysis of the implementation reveals no bound on the variable, the upper bound can be set to the maximum value of the data type. In this case, the maximum value of the data type is 32,768, making the allocation essentially unbounded.
Turning now to
Turning now to
Still referring to
Determining bounds for the variable M used to dynamically allocate memory (882) in procedure E (864) proceeds in a similar manner. Examination of procedures E (864), D (856) and A (852) reveals the maximum value for the variable M is (4*3)=12. This establishes a bound on memory allocation 882.
Turning now to
Still referring to
A program specification may include limits or bounds on dynamic memory allocation requests. This information may be used to constrain the amount of memory dynamically allocated beyond the constraints obtained by analyzing the program implementation. For example, suppose an implementation declares a variable “X” as an eight-bit signed integer and the implementation also declares an array “Y” of 16-bit integers with array index values ranging from 1 to X. Without further implementation constraints on the variable “X”, analysis of the implementation would indicate array “Y” requires 128 (2(8−1)) 16-bit words. A program specification may further constrain program values. For example, a specification for the above implementation may specify a maximum value of 10 for variable “X”. Thus, ten 16-bit words can be statically allocated for variable “Y”, instead of 128.
A program implementation is correct if the bounds derived from the implementation are at least as wide as the program specification. Bounds from the program specification may be more constrained than the corresponding bounds from the program implementation. If bounds from a program specification are less constrained, the specification is improper and the implementation may be erroneous.
According to one embodiment of the present invention, the program specification is separate from the program implementation. According to another embodiment of the present invention, the program specification is embedded within the program implementation. By way of example, the program specification may comprise a collection of program comments interspersed throughout the program implementation. A variable declaration including a dynamic memory allocation in a program implementation may include a constraint delimited by a comment character, where the constraint comprises a part of the program specification constraining the size of the variable.
The above example is presented for illustrative purposes only and is not intended to be limiting in any way. Those of ordinary skill in the art will recognize that other types of dynamic memory allocations may be converted to static memory allocations without departing from the inventive concepts disclosed herein.
Still referring to
Turning now to
According to one embodiment of the present invention, a variable is flagged if the bound analysis determines the variable is essentially unbound. The variable may be flagged, by way of example, by inserting an annotation in the source file or by generating an alert message sent to a user.
According to another embodiment of the present invention, if a bound for a variable is determinable from the program implementation but a bound for the same variable is not found in the program specification, the bound determined from the program implementation is inserted into the program specification.
According to another embodiment of the present invention, the bounds analysis and resulting software program modification are repeated until the bound obtained from analyzing the program implementation converges with the maximum bound obtained from the program specification associated with the program implementation.
Turning now to
Turning now to
According to one embodiment of the present invention, the analyzed program is targeted for execution on a resource-constrained device. Resource-constrained devices are generally considered to be those that are relatively restricted in memory and/or computing power or speed, as compared to typical desktop computers and the like. According to one embodiment of the present invention, the resource-constrained device comprises a smart card. According to another embodiment of the present invention, the smart card comprises a Java Card™ technology-enabled smart card. The invention can be used with other resource-constrained devices including, but not limited to, cellular telephones, boundary scan devices, field programmable devices, personal digital assistants (PDAs) and pagers, as well as other miniature or small-footprint devices. The invention can also be used on non-resource constrained devices.
According to one embodiment of the present invention, a dynamic memory allocation in a software program is annotated to indicate whether the dynamic memory allocation should be modified based on a dynamic memory bounds analysis of the software program. The annotation provides a mechanism by which a programmer can guarantee dynamic allocation for a variable.
Embodiments of the present invention have a number of advantages. Decreasing the amount of dynamic memory allocations increases program predictability and verifiability. Decreasing the amount of dynamic memory allocations also simplifies memory management, resulting in relatively efficient code. Additionally, decoupling the state of the memory allocation from the state of the module that uses the memory allocation simplifies verification. Also, automatic code optimization obviates the need to manually preallocate memory for dynamic allocations, thus simplifying the software development process. Automatic code optimization also liberates programmers from the need to perform manual static allocation of memory for programs targeted to devices having relatively limited memory.
While embodiments and applications of this invention have been shown and described, it would be apparent to those skilled in the art having the benefit of this disclosure that many more modifications than mentioned above are possible without departing from the inventive concepts herein. The invention, therefore, is not to be restricted except in the spirit of the appended claims.
Number | Name | Date | Kind |
---|---|---|---|
4734568 | Watanabe | Mar 1988 | A |
5107418 | Cramer et al. | Apr 1992 | A |
5384749 | Lisart et al. | Jan 1995 | A |
5423027 | Jackson | Jun 1995 | A |
5615137 | Holzmann et al. | Mar 1997 | A |
5650948 | Gafter | Jul 1997 | A |
5659754 | Grove et al. | Aug 1997 | A |
5668999 | Gosling | Sep 1997 | A |
5740441 | Yellin et al. | Apr 1998 | A |
5748964 | Gosling | May 1998 | A |
5790859 | Sarkar | Aug 1998 | A |
5802519 | de Jong | Sep 1998 | A |
5836014 | Faiman, Jr. | Nov 1998 | A |
5887161 | Cheong et al. | Mar 1999 | A |
5968169 | Pickett | Oct 1999 | A |
5974255 | Gossain et al. | Oct 1999 | A |
6038397 | Iwanishi et al. | Mar 2000 | A |
6052690 | de Jong | Apr 2000 | A |
6094656 | De Jong | Jul 2000 | A |
6282700 | Grover et al. | Aug 2001 | B1 |
6292874 | Barnett | Sep 2001 | B1 |
6349344 | Sauntry et al. | Feb 2002 | B1 |
6463581 | Bacon et al. | Oct 2002 | B1 |
6526571 | Aizikowitz et al. | Feb 2003 | B1 |
6604190 | Tran | Aug 2003 | B1 |
6684261 | Orton et al. | Jan 2004 | B1 |
6718485 | Reiser | Apr 2004 | B1 |
6735758 | Berry et al. | May 2004 | B1 |
20020019969 | Hellestrand et al. | Feb 2002 | A1 |
20020097269 | Batcha et al. | Jul 2002 | A1 |
20020147903 | Hubert et al. | Oct 2002 | A1 |
20030097581 | Zimmer | May 2003 | A1 |
20040015920 | Schmidt | Jan 2004 | A1 |
20040103416 | Orton et al. | May 2004 | A1 |
Number | Date | Country |
---|---|---|
0 390 339 | Oct 1990 | EP |
0 543 588 | May 1993 | EP |
0 605 872 | Jul 1994 | EP |
0 751 458 | Jan 1997 | EP |
0 821 305 | Jan 1998 | EP |
1 056 002 | Nov 2000 | EP |
2 806 813 | Mar 2000 | FR |
9424673 | Oct 1994 | WO |
9819237 | May 1998 | WO |
9924944 | May 1999 | WO |
Number | Date | Country | |
---|---|---|---|
20030177472 A1 | Sep 2003 | US |