# US 2010/0161687 A1 · System and method for optimizing garbage collection with allocation modifiers

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2010/0161687 A1
- Document ID: US20100161687A1
- Status: Published application
- Kind: A1
- Application number: 12/343,609
- Filed: 2008-12-24
- Published: 2010-06-24
- Earliest claimed: 2008-12-24
- Assignees: International Business Machines Corporation
- Inventors: Ralf Altrichter; Dirk Heuzeroth; Gerd Kehrer; Martin Raitza
- Web page: https://patentgrep.com/patent/US20100161687A1

## CPC

- G06F 12/0253: {Garbage collection, i.e. reclamation of unreferenced memory}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A system and associated method for optimizing memory allocation and garbage collection. An allocation modifier is employed to declare a data object in a source code. The allocation modifier describes an expected lifespan of the data object being declared. The interpreter allocates the data object in an area of a heap space that is associated with the expected lifespan such that a garbage collector suffers from less overhead in scanning data objects that will survive a garbage collection cycle. Also, the heap space also has less fragmentation as the data object is allocated in the area associated with the expected lifespan such that the data object does not need to be relocated.

## Claims

### Claim 1

A method for optimizing garbage collection, the method comprising:
interpreting an intermediate code comprising a data object declared with an allocation modifier that indicates how long the data object will be used while executing the intermediate code, wherein the allocation modifier is provided by a programmer of a source code which had been compiled into the intermediate code;
determining a heap area for the data object pursuant to the allocation modifier; and
allocating the data object in the determined heap area such that a garbage collector reduces the number of objects to scan during garbage collection and minimizes the number of objects to be relocated from a first heap area to a second heap area, wherein objects in the first heap area are younger than objects in the second heap area,
wherein an interpreter of a runtime environment performs said interpreting, said determining, and said allocating, and wherein the runtime environment comprises the interpreter and the garbage collector.

### Claim 2 (depends on 1)

The method of claim 1,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of temporary and durable,
wherein the allocation modifier of temporary denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area, and
wherein the allocation modifier of durable denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 3 (depends on 1)

The method of claim 1,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of short, middle, and long,
wherein the allocation modifier of short denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area,
wherein the allocation modifier of middle denotes that the data object is expected to have a moderate lifespan and needs to be allocated in a survivor area, and
wherein the allocation modifier of long denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 4 (depends on 1)

The method of claim 1, wherein no allocation modifier for the data object in the source code is provided to indicate that a lifespan of the data object is unpredictable and the data object needs to be allocated in a short-term object area where a conventional interpreter allocates all new data objects and the garbage collector scans to discover dead objects for reuse and relocates survived objects to a survivor area.

### Claim 5 (depends on 1)

The method of claim 1, wherein the allocation modifier for the data object is determined pursuant to how the data object behaves during execution based on factors comprising a logical flow of the source code, input data, and user interactions.

### Claim 6 (depends on 1)

The method of claim 1, wherein the runtime environment is a Java Virtual Machine (JVM) and wherein the intermediate code is a Java bytecode.

### Claim 7

A computer program product, comprising a computer usable storage medium having a computer readable program code embodied therein, said computer readable program code containing instructions that when executed by a processor of a computer system implement a method for optimizing garbage collection, the method comprising:
interpreting an intermediate code comprising a data object declared with an allocation modifier that indicates how long the data object will be used while executing the intermediate code, wherein the allocation modifier is provided by a programmer of a source code which had been compiled into the intermediate code;
determining a heap area for the data object pursuant to the allocation modifier; and
allocating the data object in the determined heap area such that a garbage collector reduces the number of objects to scan during garbage collection and minimizes the number of objects to be relocated from a first heap area to a second heap area, wherein objects in the first heap area are younger than objects in the second heap area,
wherein an interpreter of a runtime environment performs said interpreting, said determining, and said allocating, and wherein the runtime environment comprises the interpreter and the garbage collector.

### Claim 8 (depends on 7)

The computer program product of claim 7,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of temporary and durable,
wherein the allocation modifier of temporary denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area, and
wherein the allocation modifier of durable denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 9 (depends on 7)

The computer program product of claim 7,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of short, middle, and long,
wherein the allocation modifier of short denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area,
wherein the allocation modifier of middle denotes that the data object is expected to have a moderate lifespan and needs to be allocated in a survivor area, and
wherein the allocation modifier of long denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 10 (depends on 7)

The computer program product of claim 7, wherein no allocation modifier for the data object in the source code is provided to indicate that a lifespan of the data object is unpredictable and the data object needs to be allocated in a short-term object area where a conventional interpreter allocates all new data objects and the garbage collector scans to discover dead objects for reuse and relocates survived objects to a survivor area.

### Claim 11 (depends on 7)

The computer program product of claim 7, wherein the allocation modifier for the data object is determined pursuant to how the data object behaves during execution based on factors comprising a logical flow of the source code, input data, and user interactions.

### Claim 12 (depends on 7)

The computer program product of claim 7, wherein the runtime environment is a Java Virtual Machine (JVM) and wherein the intermediate code is a Java bytecode.

### Claim 13

A system comprising a processor and a computer readable memory unit coupled to the processor, said memory unit containing instructions that when executed by the processor implement a method for optimizing garbage collection, the method comprising:
interpreting an intermediate code comprising a data object declared with an allocation modifier that indicates how long the data object will be used while executing the intermediate code, wherein the allocation modifier is provided by a programmer of a source code which had been compiled into the intermediate code;
determining a heap area for the data object pursuant to the allocation modifier; and
allocating the data object in the determined heap area such that a garbage collector reduces the number of objects to scan during garbage collection and minimizes the number of objects to be relocated from a first heap area to a second heap area, wherein objects in the first heap area are younger than objects in the second heap area,
wherein an interpreter of a runtime environment performs said interpreting, said determining, and said allocating, and wherein the runtime environment comprises the interpreter and the garbage collector.

### Claim 14 (depends on 13)

The system of claim 13,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of temporary and durable,
wherein the allocation modifier of temporary denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area, and
wherein the allocation modifier of durable denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 15 (depends on 13)

The system of claim 13,
wherein the allocation modifier for the data object in the source code is selected from the group consisting of short, middle, and long,
wherein the allocation modifier of short denotes that the data object is expected to have a short lifespan and needs to be allocated in a short-term object area,
wherein the allocation modifier of middle denotes that the data object is expected to have a moderate lifespan and needs to be allocated in a survivor area, and
wherein the allocation modifier of long denotes that the data object is expected to have a long lifespan and needs to be allocated in a long-term object area.

### Claim 16 (depends on 13)

The system of claim 13, wherein no allocation modifier for the data object in the source code is provided to indicate that a lifespan of the data object is unpredictable and the data object needs to be allocated in a short-term object area where a conventional interpreter allocates all new data object and the garbage collector frequently scans to discover dead objects for reuse and relocates survived objects to a survivor area.

### Claim 17 (depends on 13)

The system of claim 13, wherein the allocation modifier for the data object is determined pursuant to how the data object behaves during execution based on factors comprising a logical flow of the source code, input data, and user interactions.

### Claim 18 (depends on 13)

The system of claim 13, wherein the runtime environment is a Java Virtual Machine (JVM) and wherein the intermediate code is a Java bytecode.

### Claim 19

A method for optimizing garbage collection, the method comprising:
loading a machine code comprising a data object declared with an allocation modifier that indicates how long the data object will be used while executing the machine code, wherein the allocation modifier is provided by a programmer of the source code which had been compiled into the machine code;
determining a heap area for the data object pursuant to the allocation modifier; and
allocating the data object in the determined heap area such that a garbage collector reduces the number of objects to scan during garbage collection and minimizes the number of objects to be relocated from a first heap area to a second heap area, wherein objects in the first heap area are younger than objects in the second heap area,
wherein an execution engine of a runtime environment performs said loading, said determining, and said allocating, and wherein the runtime environment comprises the interpreter and the garbage collector.

### Claim 20 (depends on 19)

The method of claim 19, wherein the source code is selected from a group consisting of C program and C++ program.
