Claims
- 1. A method for reducing dynamic memory allocation, comprising:
designing a software program using a dynamic memory allocation module for allocating memory; analyzing said software program to determine a bound on dynamic memory allocation in said software program; and modifying said program based on said analyzing.
- 2. The method of claim 1 wherein said modifying further comprises modifying said program to use static memory allocation in lieu of dynamic memory allocation based on said analyzing.
- 3. The method of claim 1 wherein said modifying further comprises modifying at least one dynamic memory allocation request in said program based on said analyzing.
- 4. The method of claim 3 wherein said modifying further comprises rewriting the “size” parameter of a dynamic memory allocation request procedure call to refer to an index into a table of at least one pre-allocated memory block address, the size of said at least one pre-allocated memory block based on said analyzing.
- 5. The method of claim 3 wherein said modifying further comprises rewriting a dynamic memory allocation request to refer to the address of a pre-allocated memory block.
- 6. The method of claim 1 wherein said analyzing comprises determining dynamic memory allocation in at least one initialization procedure of said plurality of modules, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 7. The method of claim 1 wherein said analyzing comprises determining dynamic memory allocation outside an initialization procedure of a module, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 8. The method of claim 7 wherein
said method further comprises receiving a specification and an implementation corresponding to said software program; and said analyzing further comprises:
analyzing said program implementation to determine a first bound on dynamic memory allocation; analyzing said program specification to determine a second bound on dynamic memory allocation; and indicating a bound on said program, said bound based upon said first bound and said second bound.
- 9. The method of claim 8 wherein said indicating a bound further comprises indicating said bound comprises said first bound if said second bound is not derivable from said specification.
- 10. The method of claim 8 wherein said indicating a bound further comprises indicating an error if said second bound is greater than said first bound.
- 11. The method of claim 8 wherein said indicating a bound further comprises indicating said bound comprises said second bound if said second bound is derivable from said specification.
- 12. The method of claim 8 wherein said analyzing said implementation further comprises:
using a call graph of said program to perform control flow analysis and data flow analysis; determining lifetime estimates of dynamic memory allocation requests based on said control flow analysis; ascertaining bounds on dynamic memory allocation sizes based upon input parameters in the main module of said program using said data flow analysis; using said specification to establish bounds for at least one non-overlapping region of said dynamic memory allocation requests; and merging said non-overlapping regions using the largest bound of said at least one non-overlapping region as the bound for said at least one non-overlapping region.
- 13. The method of claim 12, further comprising indicating an error if said bounds from said specification are greater than said bounds from said implementation.
- 14. The method of claim 8 wherein said analyzing said implementation further comprises basing said first bound upon data type information for at least one variable belonging to said data type, said variable used to specify the amount of dynamically allocated memory, said data type information comprising a range of permissible values for each variable belonging to said data type.
- 15. The method of claim 8 wherein at least part of said specification is embedded within said implementation.
- 16. The method of claim 1 wherein said analyzing is performed by a compiler.
- 17. The method of claim 1 wherein said modifying is performed automatically by a tool.
- 18. The method of claim 8, further comprising repeating said analyzing and said modifying until said first bound and said second bound converge.
- 19. The method of claim 1 wherein said program is executed on a resource-constrained device.
- 20. The method of claim 8 wherein said analyzing an implementation of said program further includes flagging at least one unbound dynamic memory allocation.
- 21. The method of claim 8, further comprising inserting said first bound in said program specification if said first bound is determinable from said program implementation and if said second bound is undeterminable from said program specification.
- 22. The method of claim 1 wherein said method further comprises annotating said software program to indicate whether a dynamic memory allocation should be modified based on said analyzing.
- 23. A program storage device readable by a machine, embodying a stored program of instructions executable by the machine to perform a method for reducing dynamic memory allocation, the method comprising:
analyzing an input software program to determine a bound on dynamic memory allocation in said input software program, said input program designed using a dynamic memory allocation module for allocating memory; and modifying said input software program based on said analyzing.
- 24. The program storage device of claim 23 wherein said modifying further comprises modifying said input software program to use static memory allocation in lieu of dynamic memory allocation based on said analyzing.
- 25. The program storage device of claim 23 wherein said modifying further comprises modifying at least one dynamic memory allocation request in said input software program based on said analyzing.
- 26. The program storage device of claim 25 wherein said modifying further comprises rewriting the “size” parameter of a dynamic memory allocation request procedure call to refer to an index into a table of at least one pre-allocated memory block address, the size of said at least one pre-allocated memory block based on said analyzing.
- 27. The program storage device of claim 25 wherein said modifying further comprises rewriting a dynamic memory allocation request to refer to the address of a pre-allocated memory block.
- 28. The program storage device of claim 23 wherein said analyzing comprises determining dynamic memory allocation in at least one initialization procedure of said plurality of modules, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 29. The program storage device of claim 23 wherein said analyzing comprises determining dynamic memory allocation outside an initialization procedure of a module, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 30. The program storage device of claim 29 wherein
said method further comprises receiving a specification and an implementation corresponding to said software program; and said analyzing further comprises:
analyzing said program implementation to determine a first bound on dynamic memory allocation; analyzing said program specification to determine a second bound on dynamic memory allocation; and indicating a bound on said program, said bound based upon said first bound and said second bound.
- 31. The program storage device of claim 30 wherein said indicating a bound further comprises indicating said bound comprises said first bound if said second bound is not derivable from said specification.
- 32. The program storage device of claim 30 wherein said indicating a bound further comprises indicating an error if said second bound is greater than said first bound.
- 33. The program storage device of claim 30 wherein said indicating a bound further comprises indicating said bound comprises said second bound if said second bound is derivable from said specification.
- 34. The program storage device of claim 30 wherein said analyzing said implementation further comprises:
using a call graph of said input software program to perform control flow analysis and data flow analysis; determining lifetime estimates of dynamic memory allocation requests based on said control flow analysis; ascertaining bounds on dynamic memory allocation sizes based upon input parameters in the main module of said input software program using said data flow analysis; using said specification to establish bounds for at least one non-overlapping region of said dynamic memory allocation requests; and merging said non-overlapping regions using the largest bound of said at least one non-overlapping region as the bound for said at least one non-overlapping region.
- 35. The program storage device of claim 34 wherein said method further comprises indicating an error if said bounds from said specification are greater than said bounds from said implementation.
- 36. The program storage device of claim 30 wherein said analyzing said implementation further comprises basing said first bound upon data type information for at least one variable belonging to said data type, said variable used to specify the amount of dynamically allocated memory, said data type information comprising a range of permissible values for each variable belonging to said data type.
- 37. The program storage device of claim 30, further comprising repeating said analyzing and said modifying until said first bound and said second bound converge.
- 38. The program storage device of claim 30 wherein said analyzing an implementation of said input software program further includes flagging at least one unbound dynamic memory allocation.
- 39. The program storage device of claim 30 wherein said method further comprises inserting said first bound in said input software program specification if said first bound is determinable from said program implementation and if said second bound is undeterminable from said input software program specification.
- 40. The program storage device of claim 23 wherein said method further comprises:
annotating said input software program to indicate which dynamic memory allocations should not be optimized; and performing said analyzing and said modifying for unannotated dynamic memory allocations in said input software program.
- 41. An apparatus for reducing dynamic memory allocation, comprising:
means for receiving a software program designed using a dynamic memory allocation module for allocating memory; means for analyzing said software program to determine a bound on dynamic memory allocation in said software program; and means for modifying said program based on said analyzing.
- 42. The apparatus of claim 41 wherein said means for modifying further comprises means for modifying said program to use static memory allocation in lieu of dynamic memory allocation based on said analyzing.
- 43. The apparatus of claim 41 wherein said modifying further comprises means for modifying at least one dynamic memory allocation request in said program based on said analyzing.
- 44. The apparatus of claim 43 wherein said means for modifying further comprises means for rewriting the “size” parameter of a dynamic memory allocation request procedure call to refer to an index into a table of at least one pre-allocated memory block address, the size of said at least one pre-allocated memory block based on said analyzing.
- 45. The apparatus of claim 43 wherein said means for modifying further comprises means for rewriting a dynamic memory allocation request to refer to the address of a pre-allocated memory block.
- 46. The apparatus of claim 41 wherein said means for analyzing comprises means for determining dynamic memory allocation in at least one initialization procedure of said plurality of modules, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 47. The apparatus of claim 41 wherein said means for analyzing comprises means for determining dynamic memory allocation outside an initialization procedure of a module, said initialization procedure configured to execute prior to execution of any other procedure of the same module.
- 48. The apparatus of claim 47 wherein
said apparatus further comprises means for receiving a specification and an implementation corresponding to said software program; and said means for analyzing further comprises:
means for analyzing said program implementation to determine a first bound on dynamic memory allocation; means for analyzing said program specification to determine a second bound on dynamic memory allocation; and means for indicating a bound on said program, said bound based upon said first bound and said second bound.
- 49. The apparatus of claim 48 wherein said means for indicating a bound further comprises means for indicating said bound comprises said first bound if said second bound is not derivable from said specification.
- 50. The apparatus of claim 48 wherein said means for indicating a bound further comprises means for indicating an error if said second bound is greater than said first bound.
- 51. The apparatus of claim 48 wherein said means for indicating a bound further comprises means for indicating said bound comprises said second bound if said second bound is derivable from said specification.
- 52. The apparatus of claim 48 wherein said means for analyzing said implementation further comprises:
means for using a call graph of said program to perform control flow analysis and data flow analysis; means for determining lifetime estimates of dynamic memory allocation requests based on said control flow analysis; means for ascertaining bounds on dynamic memory allocation sizes based upon input parameters in the main module of said program using said data flow analysis; means for using said specification to establish bounds for at least one non-overlapping region of said dynamic memory allocation requests; and means for merging said non-overlapping regions using the largest bound of said at least one non-overlapping region as the bound for said at least one non-overlapping region.
- 53. The apparatus of claim 52, further comprising means for indicating an error if said bounds from said specification are greater than said bounds from said implementation.
- 54. The apparatus of claim 48 wherein said means for analyzing said implementation further comprises means for basing said first bound upon data type information for at least one variable belonging to said data type, said variable used to specify the amount of dynamically allocated memory, said data type information comprising a range of permissible values for each variable belonging to said data type.
- 55. The apparatus of claim 41 wherein said means for analyzing comprises a compiler.
- 56. The apparatus of claim 41 wherein said means for modifying comprises a software tool.
- 57. The apparatus of claim 48, further comprising means for repeating said analyzing and said modifying until said first bound and said second bound converge.
- 58. The apparatus of claim 48 wherein said means for analyzing an implementation of said program further includes means for flagging at least one unbound dynamic memory allocation.
- 59. The apparatus of claim 48, further comprising means for inserting said first bound in said program specification if said first bound is determinable from said program implementation and if said second bound is undeterminable from said program specification.
- 60. The apparatus of claim 41 wherein said apparatus further comprises means for annotating said software program to indicate whether a dynamic memory allocation should be modified based on said analyzing.
- 61. An apparatus for reducing dynamic memory allocation, comprising:
a dynamic memory tool configured to receive a program specification for a software program and a program implementation for said software program, said program specification comprising at least one constraint on said program implementation, said tool further configured to analyze said program implementation and said program specification to determine a bound on dynamic memory allocation in said program implementation, said tool further configured to modify said program implementation based on said analyzing.
- 62. An apparatus comprising:
a processor; and a memory coupled to said processor, said memory comprising a program, said program comprising a plurality of procedures, each of said procedures comprising at least one executable instruction, said program having been modified based on a dynamic memory bounds analysis of a program implementation associated with said program and a program specification associated with said program.
- 63. The apparatus of claim 62 wherein said apparatus comprises a smart card.
- 64. The apparatus of claim 63 wherein said smart card comprises a Java Card™ technology-enabled smart card.
CROSS REFERENCE TO RELATED APPLICATIONS
[0001] This application is related to the following:
[0002] U.S. patent application Ser. No. ______, 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”, Attorney Docket No. SUN-P6957, commonly assigned herewith.
[0003] U.S. patent application Ser. No. ______, 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”, Attorney Docket No. SUN-P6959, commonly assigned herewith.