Search

US-12625730-B2 - Object management for managing runtime overhead

US12625730B2US 12625730 B2US12625730 B2US 12625730B2US-12625730-B2

Abstract

A computer implemented method manages a memory. A number of processor units determines a creation of an object in a program. The number of processor units determines a set of uses of the object in the program. The number of processor units add an allocation program code to allocate memory to the object in an off heap region in memory in response to the object not being within a call chain and not being assigned to a global variable. The number of processor units add a deallocation program code to deallocate the memory after each possible last use in a set of possible last uses of the object in the uses of the object in the program in response to the object not being within the call chain and not being assigned to the global variable. Additionally, a computer system and a computer program product for managing memory are provided.

Inventors

  • Michihiro Horie
  • Kazunori Ogata

Assignees

  • INTERNATIONAL BUSINESS MACHINES CORPORATION

Dates

Publication Date
20260512
Application Date
20230327

Claims (20)

  1. 1 . A computer implemented method for managing memory during compilation and execution of a program, the computer implemented method comprising: determining, by a number of processor units, a creation of an object in the program; determining, by the number of processor units, a set of uses of the object in the program; analyzing, by the number of processor units, at least one of a data flow or control flow of the program; determining, by the number of processor units, whether the object escapes a call chain and whether the object is assigned to a global variable; in response to determining that the object does not escape the call chain and is not assigned to the global variable, modifying, by the number if processor units during compilation, the program to insert allocation program code that allocates memory for the object in an off heap region of memory; and modifying, by the number if processor units during compilation, the program to insert deallocation program code that deallocates the memory after each possible last use of the object determined from the set of uses; compiling the modified program to generate an executable; and executing the executable such that the object is allocated in the off heap region and deallocated after the possible last use.
  2. 2 . The computer implemented method of claim 1 further comprising: creating, by the number of processor units, an intermediate representation graph for the program, wherein determining, by the number of processor units, the creation of the object comprises: determining, by the number of processor units, the creation of the object using the intermediate representation graph; and wherein determining, by the number of processor units, the set of uses of the object comprises: determining, by the number of processor units, the set of uses of the object in the program using the intermediate representation graph.
  3. 3 . The computer implemented method of claim 1 further comprising: determining, by the number of processor units, whether the creation of the object and the uses of the object are within the call chain; and determining, by the number of processor units, whether the object is assigned to the global variable.
  4. 4 . The computer implemented method of claim 1 , wherein determining, by the number of processor units, the set of uses further comprises: analyzing, by the number of processor units, a program execution of the program to determine the uses of the object in the program in response to the creation of the object and the uses of the object not being within the call chain and the object not being assigned to the global variable.
  5. 5 . The computer implemented method of claim 1 further comprising determining, by the number of processor units, the set of possible last uses of the object from the uses of the object in the program from analyzing a control flow for the program.
  6. 6 . The computer implemented method of claim 1 further comprising: halting, by the number of processor units, determining the creation of the object and determining uses of the object in the program that are not within the call chain in which the object is not assigned to the global variable in response to analysis time exceeding a compilation time limit for the program.
  7. 7 . The computer implemented method of claim 1 , wherein the program is a Java program and the object that is not in the call chain and not assigned to the global variable is a no escape object.
  8. 8 . The computer implemented method of claim 1 , wherein the allocation program code to allocate the memory to the object in the off heap region in the memory is added to at an object definition for the object.
  9. 9 . A computer system for managing memory during compilation and execution of a program comprising: a number of processor units, wherein the number of processor units executes program instructions to: determine a creation of an object in the program; determine a set of uses of the object in the program; analyze at least one of a data flow or control flow of the program; determine whether the object escapes a call chain and whether the object is assigned to a global variable; in response to determining that the object does not escape the call chain and is not assigned to the global variable, modifying the program during compilation to insert allocation program code that allocates memory for the object in an off heap region of memory; and modify the program during compilation to insert deallocation program code that deallocates the memory after each possible last use of the object determined from the set of uses; compiling the modified program to generate an executable; and executing the executable such that the object is allocated in the off heap region and deallocated after the possible last use.
  10. 10 . The computer system of claim 9 , wherein the number of processor units further executes the program instructions to: create an intermediate representation graph for the program, wherein in determining the creation of the object comprises, the number of processor units further executes the program instructions to: determine the creation of the object using the intermediate representation graph; and wherein determining the set of uses of the object comprises: determine the set of uses of the object in the program using the intermediate representation graph.
  11. 11 . The computer system of claim 9 , wherein the number of processor units further executes the program instructions to: determine whether the creation of the object and the uses of the object are within the call chain; and determine whether the object is assigned to the global variable.
  12. 12 . The computer system of claim 9 , wherein in determining the set of uses, the number of processor units further executes the program instructions to: analyze a program execution of the program to determine the uses of the object in the program in response to the creation of the object and the uses of the object not being within the call chain and the object not being assigned to the global variable.
  13. 13 . The computer system of claim 9 , wherein the number of processor units further executes the program instructions to: determine the set of possible last uses of the object from the uses of the object in the program from analyzing a control flow for the program.
  14. 14 . The computer system of claim 9 , wherein the number of processor units further executes the program instructions to: halt the creation of the object and determining uses of the object in the program that are not within the call chain in which the object is not assigned to the global variable in response to time analyzing the program exceeding a compilation time for the program.
  15. 15 . The computer system of claim 9 , wherein the program is a Java program and the object that is not in the call chain and not assigned to the global variable is a no escape object.
  16. 16 . The computer system of claim 9 , wherein the allocation program code to allocate the memory to the object in the off heap region in the memory is added to at an object definition for the object.
  17. 17 . A computer program product for managing memory during compilation and execution of a program, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a computer system to cause the computer system to: determine a creation of an object in the program; determine a set of uses of the object in the program; analyze at least one of a data flow or control flow of the program; determine whether the object escapes a call chain and whether the object is assigned to a global variable; in response to determining that the object does not escape the call chain and is not assigned to the global variable, modifying the program during compilation to insert allocation program code that allocates memory for the object in an off heap region of the memory and modify the program during compilation to insert deallocation program code that deallocates the memory after each possible last use of the object determined from the set of uses; compiling the modified program to generate an executable; and executing the executable such that the object is allocated in the off heap region and deallocated after the possible last use.
  18. 18 . The computer program product of claim 17 , wherein the program instructions are executable by the computer system to further cause the computer system to: create an intermediate representation graph for the program, wherein determining the creation of the object comprises: determine the creation of the object using the intermediate representation graph; and wherein determining the set of uses of the object comprises: determine the set of uses of the object in the program using the intermediate representation graph.
  19. 19 . The computer program product of claim 17 , wherein the program instructions are executable by the computer system to further cause the computer system to: determine whether the creation of the object and the uses of the object are within the call chain; and determine whether the object is assigned to the global variable.
  20. 20 . The computer program product of claim 17 , wherein the program instructions executable by the computer system to determine the set of uses further cause the computer system to: analyze a program execution of the program to determine the uses of the object in the program in response to the creation of the object and the uses of the object not being within the call chain and the object not being assigned to the global variable.

Description

BACKGROUND The disclosure relates generally to an improved computer system and more specifically to computer memory management. Java programs are designed to run on a Java virtual machine. The Java virtual machine executes the bytecode for the program and manages the memory and resources for the program. When executing a job program, Java virtual machine loads the necessary classes and runs the bytecode for the program. Class loading is a process in which the Java virtual machine loads classes needed for executing the Java program. A Java virtual machine uses a hierarchical class loading system in which classes are loaded as needed by the program. In executing a job program, the Java virtual machine interprets the bytecodes in the program. If a portion of the bytecode is executed frequently, the Java virtual machine can identify that portion of the bytecode as a hotspot and compile that bytecode into machine code using just-in-time compilation. As result, faster execution times can occur for that portion of the bytecode in the program. This type of compilation can be used for formants critical sections such as loops are frequently called methods. In some cases, static compilation can be used for Java programs. This type of compilation has been increasing the used with microservices and serverless applications. With static compilation, executable machine code is generated from the source code. This executable code includes all of the code and resources needed to run the program. As result, an intermediate runtime environment such as a Java virtual machine is unnecessary. SUMMARY According to one illustrative embodiment, a computer implemented method manages a memory. A number of processor units determine a creation of an object in a program. The number of processor units determine a set of uses of the object in the program. The number of processor units add an allocation program code to allocate the memory to the object in an off heap region in the memory in response to the object not being within a call chain and not being assigned to a global variable. The number of processor units add a deallocation program code to deallocate the memory after each possible last use in a set of possible last uses of the object in the uses of the object in the program in response to the object not being within the call chain and not being assigned to the global variable. According to other illustrative embodiments, a computer system and a computer program product for managing memory are provided. BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a block diagram of a computing environment in accordance with an illustrative embodiment; FIG. 2 is a block diagram of a memory management environment in accordance with an illustrative embodiment; FIG. 3 is a flowchart of a process of analyzing program execution of the program in accordance with an illustrative embodiment; FIG. 4 is a flowchart of a process for managing memory in accordance with an illustrative embodiment; FIG. 5 is a flowchart of a process for analyzing a program in accordance with an illustrative embodiment; FIG. 6 is a flowchart of a process for determining whether an object is suitable for memory management in accordance with an illustrative embodiment; FIG. 7 is a flowchart of process for determining uses for an object in accordance with an illustrative embodiment; FIG. 8 is a flowchart of a process for determining a set of last possible uses for an object in accordance with an illustrative embodiment; FIG. 9 is an illustration of a flowchart of a process for determining analysis of the program for memory management in accordance with an illustrative embodiment; and FIG. 10 is a block diagram of a data processing system in accordance with an illustrative embodiment. DETAILED DESCRIPTION Various aspects of the present disclosure are described by narrative text, flowcharts, block diagrams of computer systems and/or block diagrams of the machine logic included in computer program product (CPP) embodiments. With respect to any flowcharts, depending upon the technology involved, the operations can be performed in a different order than what is shown in a given flowchart. For example, again depending upon the technology involved, two operations shown in successive flowchart blocks may be performed in reverse order, as a single integrated step, concurrently, or in a manner at least partially overlapping in time. A computer program product embodiment (“CPP embodiment” or “CPP”) is a term used in the present disclosure to describe any set of one, or more, storage media (also called “mediums”) collectively included in a set of one, or more, storage devices that collectively include machine readable code corresponding to instructions and/or data for performing computer operations specified in a given CPP claim. A “storage device” is any tangible device that can retain and store instructions for use by a computer processor. Without limitation, the computer readable storage medi