# US 2021/0173622 A1 · Escape analysis support for method redefinition

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

- Number: US 2021/0173622 A1
- Document ID: US20210173622A1
- Status: Published application
- Kind: A1
- Application number: 15/931,011
- Filed: 2020-05-13
- Published: 2021-06-10
- Earliest claimed: 2019-12-10
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Andrew James Craik; Vijay Sundaresan
- Web page: https://patentgrep.com/patent/US20210173622A1

## CPC

- G06F 8/4441: {Reducing the execution time required by the program code}
- G06F 9/44521: {Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading}
- G06F 8/4434: {Reducing the memory space required by the program code}
- G06F 9/45516: {Runtime code conversion or optimisation}
- G06F 9/4552: {Involving translation to a different instruction set architecture, e.g. just-in-time translation in a JVM}
- G06F 8/656: while running
- G06F 9/4488: {Object-oriented}
- G06F 11/362: Debugging of software
- G06F 11/3698: Environments for analysis, debugging or testing of software
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

An embodiment performs escape analysis of a function as a compiler optimization and stack-allocates an object referenced by the function. At runtime, the embodiment includes detecting a hot code replacement of a portion of the function while the referenced object is stored in stack memory. Responsive to detecting the hot code replacement, the embodiment includes allocating heap memory for the object and moving the object from the stack memory to the allocated heap memory. The embodiment also updates references to the object that were pointing to the object in the stack memory to instead point to the object in the heap memory.

## Claims

### Claim 1

A computer-implemented method, comprising:
allocating, responsive to an instruction that creates an object in an object oriented program, memory in a stack frame for the object;
detecting, during a runtime of the object oriented program, a hot code replacing of a portion of a function while the object is stored in the memory of the stack frame,
wherein a thread of execution running the function holds the stack frame for the function including the object stored in the memory of the stack frame, and
wherein the thread of execution runs the function at a first performance level while the object is stored in the memory of the stack frame;
allocating, responsive to the detecting of the hot code replacing of the portion of the function, memory in a heap memory of the object oriented program;
moving the object from the memory in the stack frame to the allocated memory in the heap memory of the object oriented program; and
updating a reference to the object pointing to the stack frame to instead point to the allocated memory in the heap memory,
wherein the thread of execution runs the function at a second performance level lower than the first performance level while the object is stored in the heap memory.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
generating instructions associated with a function call that are run for calling the function, wherein the instructions include a guard for detecting the hot code replacing of the portion of the function.

### Claim 3 (depends on 2)

The method of claim 2, wherein the generating of the instructions includes generating instructions to duplicate the function call and thereby generate a duplicate function call, wherein the instructions to duplicate the function call include making the function call peekable and the duplicate function call not peekable.

### Claim 4 (depends on 3)

The method of claim 3, wherein the generating of the instructions includes generating instructions to mark the duplicate function call cold.

### Claim 5 (depends on 1)

The method of claim 1, wherein the generating of the instructions to cause stack allocated objects to be conditionally moved to heap memory if the function being called undergoes hot code replacement.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
inspecting, responsive to the hot code replacing of the portion of the function, a frame of a running function to detect a stack-allocated object; and
moving the detected stack-allocated object to the heap memory.

### Claim 7 (depends on 1)

The method of claim 1, wherein the updating of the reference comprises:
initiating a stack walker during a stop-the-world program point caused by a hot cold replacement event; and
instructing, during the stop-the-world program point, a process to update the reference.

### Claim 8

A computer usable program product for data replication, the computer program product comprising one or more computer readable storage media, and program instructions collectively stored on the one or more computer readable storage media, the program instructions executable by a processor to cause the processor to perform operations comprising:
allocating, responsive to an instruction that creates an object in an object oriented program, memory in a stack frame for the object;
detecting, during a runtime of the object oriented program, a hot code replacing of a portion of a function while the object is stored in the memory of the stack frame,
wherein a thread of execution running the function holds the stack frame for the function including the object stored in the memory of the stack frame, and
wherein the thread of execution runs the function at a first performance level while the object is stored in the memory of the stack frame;
allocating, responsive to the detecting of the hot code replacing of the portion of the function, memory in a heap memory of the object oriented program;
moving the object from the memory in the stack frame to the allocated memory in the heap memory of the object oriented program; and
updating a reference to the object pointing to the stack frame to instead point to the allocated memory in the heap memory,
wherein the thread of execution runs the function at a second performance level lower than the first performance level while the object is stored in the heap memory.

### Claim 9 (depends on 8)

The computer usable program product of claim 8, wherein the stored program instructions are stored in a computer readable storage device in a data processing system, and wherein the stored program instructions are transferred over a network from a remote data processing system.

### Claim 10 (depends on 8)

The computer usable program product of claim 8, wherein the stored program instructions are stored in a computer readable storage device in a server data processing system, and wherein the stored program instructions are downloaded over a network to a remote data processing system for use in a computer readable storage device associated with the remote data processing system, further comprising:
program instructions to meter use of the computer usable code associated with the request; and
program instructions to generate an invoice based on the metered use.

### Claim 11 (depends on 8)

The computer usable program product of claim 8, further comprising:
generating instructions associated with a function call that are run for calling the function, wherein the instructions include a guard for detecting the hot code replacing of the portion of the function.

### Claim 12 (depends on 11)

The computer usable program product of claim 11, wherein the generating of the instructions includes generating instructions to duplicate the function call and thereby generate a duplicate function call, wherein the instructions to duplicate the function call include making the function call peekable and the duplicate function call not peekable.

### Claim 13 (depends on 12)

The computer usable program product of claim 12, wherein the generating of the instructions includes generating instructions to mark the duplicate function call cold.

### Claim 14 (depends on 8)

The computer usable program product of claim 8, wherein the generating of the instructions to cause stack allocated objects to be conditionally moved to heap memory if the function being called undergoes hot code replacement.

### Claim 15 (depends on 8)

The computer usable program product of claim 8, further comprising:
inspecting, responsive to the hot code replacing of the portion of the function, a frame of a running function to detect a stack-allocated object; and
moving the detected stack-allocated object to the heap memory.

### Claim 16 (depends on 8)

The computer usable program product of claim 8, wherein the updating of the reference comprises:
initiating a stack walker during a stop-the-world program point caused by a hot cold replacement event; and
instructing, during the stop-the-world program point, a process to update the reference.

### Claim 17

A computer system comprising a processor and one or more computer readable storage media, and program instructions collectively stored on the one or more computer readable storage media, the program instructions executable by the processor to cause the processor to perform operations comprising:
allocating, responsive to an instruction that creates an object in an object oriented program, memory in a stack frame for the object;
detecting, during a runtime of the object oriented program, a hot code replacing of a portion of a function while the object is stored in the memory of the stack frame,
wherein a thread of execution running the function holds the stack frame for the function including the object stored in the memory of the stack frame, and
wherein the thread of execution runs the function at a first performance level while the object is stored in the memory of the stack frame;
allocating, responsive to the detecting of the hot code replacing of the portion of the function, memory in a heap memory of the object oriented program;
moving the object from the memory in the stack frame to the allocated memory in the heap memory of the object oriented program; and
updating a reference to the object pointing to the stack frame to instead point to the allocated memory in the heap memory,
wherein the thread of execution runs the function at a second performance level lower than the first performance level while the object is stored in the heap memory.

### Claim 18 (depends on 17)

The computer system of claim 17, further comprising:
generating instructions associated with a function call that are run for calling the function, wherein the instructions include a guard for detecting the hot code replacing of the portion of the function.

### Claim 19 (depends on 17)

The computer system of claim 17, wherein the generating of the instructions includes generating instructions to duplicate the function call and thereby generate a duplicate function call, wherein the instructions to duplicate the function call include making the function call peekable and the duplicate function call not peekable.

### Claim 20 (depends on 17)

The computer system of claim 17, wherein the generating of the instructions includes generating instructions to mark the duplicate function call cold.
