# US 9,436,462 B2 · Identifying singleton classes

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

- Number: US 9,436,462 B2
- Document ID: US9436462B2
- Status: Granted
- Kind: B2
- Application number: 14/181,258
- Filed: 2014-02-14
- Published: 2015-08-20
- Granted: 2016-09-06
- Earliest claimed: 2014-02-14
- Assignees: Red Hat, Inc.
- Applicants: Red Hat, Inc.
- Inventors: David H. Malcolm
- Web page: https://patentgrep.com/patent/US9436462B2

## CPC

- G06F 8/72: Code refactoring
- G06F 8/443: {Optimisation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A compiler system analyzes source code for an application. The compiler system determines whether a class in the source code uses a singleton pattern even though the class is not defined as singleton class. The compiler system may optionally convert the class to a singleton class. The compiler system may also perform one or more optimizations when generating the application based on the source code.

## Claims

### Claim 1

A method, comprising:
analyzing, by a processing device, source code associated with an application;
determining, in view of the analysis, that a class defined by the source code will be instantiated, wherein the class is instantiated at most once, and wherein the determining is performed during a linking phase of a generation of the application, the generation of the application comprising a compiling phase, an assembling phase, and the linking phase; and
converting, by the processing device, the class to a singleton class.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
performing one or more optimizations during the generation of the application.

### Claim 3 (depends on 2)

The method of claim 2, wherein performing the one or more optimizations comprises:
de-virtualizing one or more virtual function calls.

### Claim 4 (depends on 2)

The method of claim 2, wherein performing the one or more optimizations comprises:
removing a reference to an instance of the class from an application binary interface, wherein the application binary interface defines an operation to a data member of the instance of the class.

### Claim 5 (depends on 2)

The method of claim 2, wherein performing the one or more optimizations comprises:
removing a reference to an instance of the class from an application binary interface, wherein the application binary interface comprises a call to a function of the class.

### Claim 6 (depends on 2)

The method of claim 2, further comprising:
receiving data indicating the one or more optimizations to be performed.

### Claim 7 (depends on 1)

The method of claim 1, wherein determining that the class defined by the source code will be instantiated at most once comprises:
analyzing a plurality of constructors functions used in the application; and
determining that a first constructor function is called at most once in the application.

### Claim 8

An apparatus, comprising;
a memory to store source code associated with an application;
a processing device, operatively coupled to the memory, the processing device to:
analyze the source code;
determine, in view of the analysis, that a class defined by the source code will be instantiated, wherein the class is instantiated at most once, and wherein the determination is performed during a linking phase of a generation of the application, the generation of the application comprising a compiling phase, an assembling phase, and the linking phase; and
convert the class to a singleton class.

### Claim 9 (depends on 8)

The apparatus of claim 8, wherein the processing device is further to:
perform one or more optimizations during the generation of the application.

### Claim 10 (depends on 9)

The apparatus of claim 9, wherein to perform one or more optimizations, the processing device is further to:
de-virtualize one or more virtual function calls.

### Claim 11 (depends on 9)

The apparatus of claim 9, wherein to perform one or more optimizations, the processing device is further to:
remove a reference to an instance of the class from an application binary interface, wherein the application binary interface defines an operation to a data member of the instance of the class.

### Claim 12 (depends on 9)

The apparatus of claim 9, wherein to perform one or more optimizations, the processing device is further to:
remove a reference to an instance of the class from an application binary interface, wherein the application binary interface comprises a call to a function of the class.

### Claim 13 (depends on 8)

The apparatus of claim 8, wherein to determine that the class defined by the source code will be instantiated at most once, the processing device is further to:
analyze a plurality of constructors functions used in the application; and
determine that a first constructor function is called at most once in the application.

### Claim 14

A non-transitory computer readable storage medium comprising instructions that, when executed by a processing device, cause the processing device to:
analyze source code associated with an application;
determine, in view of the analysis, that a class defined by the source code will be instantiated, wherein the class is instantiated at most once, and wherein the determination is performed during a linking phase of a generation of the application, the generation of the application comprising a compiling phase, an assembling phase, and the linking phase; and
convert the class to a singleton class.

### Claim 15 (depends on 14)

The non-transitory computer readable storage medium of claim 14, wherein the processing device further to:
perform one or more optimizations during the generation of the application.

### Claim 16 (depends on 15)

The non-transitory computer readable storage medium of claim 15, wherein to perform the one or more optimizations, the processing device to:
de-virtualize-one or more virtual function calls.

### Claim 17 (depends on 15)

The non-transitory computer readable storage medium of claim 15, wherein to perform the one or more optimizations, the processing device to:
remove a reference to an instance of the class from an application binary interface, wherein the application binary interface defines an operation to a data member of the instance of the class.

### Claim 18 (depends on 15)

The non-transitory computer readable storage medium of claim 15, wherein to perform the one or more optimizations, the processing device to:
remove a reference to an instance of the class from an application binary interface, wherein the application binary interface comprises a call to a function of the class.
