# US 2017/0364339 A9 · Generation of Specialized Methods Based on Generic Methods and Type Parameterizations

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

- Number: US 2017/0364339 A9
- Document ID: US20170364339A9
- Status: Published application
- Kind: A9
- Application number: 15/055,469
- Filed: 2016-02-26
- Published: 2017-12-21
- Earliest claimed: 2014-04-22
- Assignees: Oracle International Corporation
- Applicants: Oracle International Corporation
- Inventors: Brian Goetz; John R. Rose; Maurizio Cimadamore
- Web page: https://patentgrep.com/patent/US20170364339A9

## CPC

- G06F 9/4492: {Inheritance}
- G06F 8/24: {Object-oriented}
- G06F 8/315: {Object-oriented languages}
- G06F 8/41: Compilation
- G06F 8/437: {Type checking}
- G06F 8/443: {Optimisation}
- G06F 8/447: {Target code generation}
- G06F 8/70: Software maintenance or management
- G06F 8/71: Version control (security arrangements therefor G06F21/57); Configuration management
- G06F 8/76: Adapting program code to run in a different environment; Porting
- G06F 9/44521: {Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading}
- G06F 9/4488: {Object-oriented}
- G06F 9/449: {Object-oriented method invocation or resolution}
- G06F 9/4498: {Finite state machines}
- G06F 9/45516: {Runtime code conversion or optimisation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Generic method specialization represents the ability to specialize generic methods over various types. When implementing generic method specialization an annotated class file may include a generic method declaration that is annotated with specialization metadata indicating elements of the generic method to be adjusted during specialization. The annotated method may be usable directly as an erased method implementation (e.g., to load the method when instantiated with reference types) and may also be usable as a template for specialization. When a generic method is being prepared for execution, such as when it is first invoked during runtime, a specialization method generator function may be used to specialize the generic method based on the specialization metadata in the generic method declaration. The specialization method generator function may use the annotated generic method declaration as a template for specialization.

## Claims

### Claim 1

A non-transitory, computer-readable storage medium storing program instructions that when executed on a computing device cause the computing device to perform:
passing a generic method and specialization metadata to a specialized method generator, wherein the specialization metadata comprises information identifying one or more program elements of the generic method to be adjusted when specializing the generic method for a particular type parameterization;
generating, by the specialized method generator in response to said passing, a specialized method based, at least in part, on the generic method and the specialization metadata, wherein the specialized method is a version of the generic method specialized for the particular type parameterization; and
storing, as a result of the specialized method being generated, a handle to the specialized method, such that the handle is usable to invoke the specialized method.

### Claim 2 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein said passing, said generating and said storing are performed in response to an invocation of the generic method during runtime of an application in a virtualized runtime environment.

### Claim 3 (depends on 2)

The non-transitory, computer-readable storage medium of claim 2, wherein said passing, said generating and said storing are performed in response to determining that the generic method has not been invoked previously for the particular type parameterization.

### Claim 4 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein said storing comprises storing the handle to the specialized method in a cache configured to store handles to specialized methods.

### Claim 5 (depends on 4)

The non-transitory, computer-readable storage medium of claim 4, wherein the program instructions further cause the computing device to perform:
retrieving the handle to the specialized method from the cache in response to a subsequent invocation of the generic method for the particular type parameterization; and
invoking the generic method using the retrieved handle.

### Claim 6 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein the program instructions further cause the computing device to perform:
generating a container class, wherein said generating comprises generating the specialized method as a member of the container class;
storing the specialized method; and
treating the specialized method as if it were a member of a class to which the generic method is a member.

### Claim 7 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein said generating comprises:
determining that a class to which the generic method is a member also comprises a manually generated replacement method representing a specialization of the generic method for the particular type parameterization; and
loading the manually generated replacement method as the specialized method.

### Claim 8 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein said generating comprises specializing another generic method in response to determining a dependency relationship between the generic method and the other generic method.

### Claim 9 (depends on 1)

The non-transitory, computer-readable storage medium of claim 1, wherein the generic method comprises a plurality of specializable type variables, wherein each of the plurality of specializable type variables are specializable over a plurality of type parameterizations, and wherein the generic method was previously partially specialized such that one of the plurality of specializable type variables was specialized for one of the plurality of type parameterizations, and wherein said generating comprises specializing another of the plurality of specializable type variables over the particular type parameterization.

### Claim 10

A method, comprising:
passing, by a platform-independent, object-oriented, runtime environment implemented on one or more computing devices, a generic method and specialization metadata to a specialized method generator of the platform-independent, object-oriented, runtime environment, wherein the specialization metadata comprises information identifying one or more program elements of the generic method to be adjusted when specializing the generic method for a particular type parameterization;
generating, by the specialized method generator in response to said passing, a specialized method based, at least in part, on the generic method and the specialization metadata, wherein the specialized method is a version of the generic method specialized for the particular type parameterization; and
storing, as a result of the specialized method being generated, a handle to the specialized method, such that the handle is usable to invoke the specialized method.

### Claim 11 (depends on 10)

The method of claim 10, wherein said passing, said generating and said storing are performed in response to an invocation of the generic method during runtime of an application in the platform-independent, object-oriented, runtime environment.

### Claim 12 (depends on 11)

The method of claim 11, wherein said passing, said generating and said storing are performed in response to determining that the generic method has not been invoked previously for the particular type parameterization.

### Claim 13 (depends on 10)

The method claim 10, wherein said storing comprises storing the handle to the specialized method in a cache configured to store handles to specialized methods.

### Claim 14 (depends on 13)

The method of claim 13, further comprising:
retrieving the handle to the specialized method from the cache in response to a subsequent invocation of the generic method for the particular type parameterization; and
invoking the generic method using the retrieved handle.

### Claim 15 (depends on 10)

The method of claim 10, further comprising:
generating a container class, wherein said generating comprises generating the specialized method as a member of the container class;
storing the specialized method; and
treating the specialized method as if it were a member of a class to which the generic method is a member.

### Claim 16 (depends on 10)

The method of claim 10, wherein said generating comprises:
determining that a class to which the generic method is a member also comprises a replacement method representing a specialization of the generic method for the particular type parameterization; and
loading the replacement method as the specialized method.

### Claim 17 (depends on 10)

The method of claim 10, wherein said generating comprises specializing a generic class in response to determining a dependency relationship between the generic method and the generic class.

### Claim 18 (depends on 10)

The method of claim 10, wherein the generic method comprises a plurality of specializable type variables, wherein each of the plurality of specializable type variables are specializable over a plurality of type parameterizations, and wherein the generic method was previously partially specialized such that one of the plurality of specializable type variables was specialized for one of the plurality of type parameterizations, and wherein said generating comprises specializing another of the plurality of specializable type variables over the particular type parameterization.

### Claim 19

A non-transitory, computer-readable storage medium storing program instructions that when executed on a computing device cause the computing device to perform:
generating, by a compiler, a class file comprising a generic method declaration, wherein said generating comprises:
applying a type erasure operation to a stream of instructions in the generic method declaration, wherein the stream of instructions is configured for execution by a virtualized runtime environment, and wherein the generic method declaration includes one or more type variables;
wherein applying the type erasure operation comprises:
creating an encoded form of a program element of the generic method declaration, wherein the encoded form of the program element comprises metadata specifying specialization information regarding the program element such that the encoded form can be specialized by the virtualized runtime environment according to a particular type parameterization; and
including the encoded form of the program element in the class file, wherein the program element is usable by the virtualized runtime environment to load the program element without regard to the metadata being present in the encoded form.

### Claim 20 (depends on 19)

The non-transitory, computer-readable storage medium of claim 19, wherein the encoded form of the program element comprises a bytecode version of the stream of instructions, and wherein the metadata in the encoded form identifies one or more bytecodes to be adjusted to generate a specialized version of a method based on the generic method declaration.
