# US 2022/0012067 A1 · Class loading method and apparatus

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

- Number: US 2022/0012067 A1
- Document ID: US20220012067A1
- Status: Published application
- Kind: A1
- Application number: 17/484,137
- Filed: 2021-09-24
- Published: 2022-01-13
- Earliest claimed: 2019-03-25
- Assignees: Huawei Technologies Co., Ltd.
- Applicants: Huawei Technologies Co., Ltd.
- Inventors: Xinjian WANG; Qinghua ZHANG; Yongyong YANG; Bin ZHANG; Wei LIU
- Web page: https://patentgrep.com/patent/US20220012067A1

## CPC

- G06F 9/44521: {Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading}
- G06F 8/41: Compilation
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

This application discloses a class loading method and apparatus. The method is applied to a computer device, the computer device includes a target binary file, the target binary file includes a correspondence between class names of a plurality of classes and full information of the plurality of classes, and the class names are in a one-to-one correspondence with the full information of the classes. The method includes: determining a class name of a to-be-loaded class required for running an application program in the computer device; obtaining full information corresponding to the class name of the to-be-loaded class based on the class name of the to-be-loaded class and the correspondence between the class names of the plurality of classes and the full information of the plurality of classes; and running the application program based on the full information corresponding to the class name of the to-be-loaded class.

## Claims

### Claim 1

A class loading method, applied to a computer device, and the method comprises:
obtaining a class name of a to-be-loaded class required for running an application program in the computer device;
obtaining full information corresponding to the class name of the to-be-loaded class based on the class name of the to-be-loaded class and the correspondence between the class names of the plurality of classes and the full information of the plurality of classes, wherein the class names are in a one-to-one correspondence with the full information of the classes and the correspondence is stored in a target binary file; and
running the application program based on the full information corresponding to the class name of the to-be-loaded class.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the target binary file further comprises class addresses of the plurality of classes and a correspondence between the class addresses of the plurality of classes and hash values of the class names of the plurality of classes, storage space indicated by a class address of a class is used to store full information of the class, and the method further comprises:
obtaining a class address corresponding to the target hash value based on a target hash value and the correspondence between the class addresses of the plurality of classes and the hash values of the class names of the plurality of classes, wherein the target hash value is a hash value of the class name of the to-be-loaded class; and
the obtaining step comprises:
searching, for the class name of the to-be-loaded class, storage space indicated by the class address corresponding to the target hash value, wherein the class name of the to-be-loaded class is a part of the full information of the to-be-loaded class; and using, as the full information of the to-be-loaded class, full information in the storage space indicated by the class address corresponding to the target hash value.

### Claim 3 (depends on 2)

The method according to claim 2, wherein one hash value corresponds to one bucket, and one bucket comprises one, or more class addresses; and the obtaining a class address corresponding to the target hash value comprises:
obtaining a bucket corresponding to the target hash value based on the target hash value and a correspondence between a plurality of buckets and the hash values of the class names of the plurality of classes, and using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value.

### Claim 4 (depends on 3)

The method according to claim 3, wherein one bucket has one start address and one end address, and before the using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value, the method further comprises:
searching start addresses and end addresses of the plurality of buckets for a start address and an end address of the bucket corresponding to the target hash value; and
reading, from storage space defined by the start address and the end address of the bucket corresponding to the target hash value, the class address comprised in the bucket corresponding to the target hash value.

### Claim 5 (depends on 1)

The method according to claim 1, wherein before the determining a class name of a to-be-loaded class required for running an application program in the computer device, the method further comprises:
loading all binary files required for running the application program from an external storage of the computer device into a memory of the computer device, wherein all the binary files comprise the target binary file.

### Claim 6 (depends on 5)

The method according to claim 5, wherein the method further comprises:
creating at least two class loaders of the application program; and
establishing a correspondence between the at least two class loaders and all the binary files, wherein the at least two class loaders comprise a first class loader, and the first class loader is used to search, for the full information of the to-be-loaded class, a binary file corresponding to the first class loader.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the method further comprises:
determining a class loader currently performing a search operation from the at least two class loaders based on a parents delegation model, to search all the binary files for the full information of the to-be-loaded class by using the determined class loader currently performing a search operation.

### Claim 8

An apparatus for class loading, wherein the apparatus comprises:
a processor, and
a memory coupled to the processor and configured to store a plurality of instructions that, when executed by the processor, causes the processor to:
obtain a class name of a to-be-loaded class required for running an application program in the computer device;
obtain full information corresponding to the class name of the to-be-loaded class based on the class name of the to-be-loaded class and the correspondence between the class names of the plurality of classes and the full information of the plurality of classes, wherein the class names are in a one-to-one correspondence with the full information of the classes and the correspondence is stored in a target binary file; and
run the application program based on the full information corresponding to the class name of the to-be-loaded class.

### Claim 9 (depends on 8)

The apparatus of claim 8, wherein the target binary file further comprises class addresses of the plurality of classes and a correspondence between the class addresses of the plurality of classes and hash values of the class names of the plurality of classes, storage space indicated by a class address of a class is used to store full information of the class, wherein the instructions further cause the processor to:
obtain a class address corresponding to the target hash value based on a target hash value and the correspondence between the class addresses of the plurality of classes and the hash values of the class names of the plurality of classes, wherein the target hash value is a hash value of the class name of the to-be-loaded class; and
when processing the obtaining step, the instructions cause the processor to:
search, for the class name of the to-be-loaded class, storage space indicated by the class address corresponding to the target hash value, wherein the class name of the to-be-loaded class is a part of the full information of the to-be-loaded class; and use, as the full information of the to-be-loaded class, full information in the storage space indicated by the class address corresponding to the target hash value.

### Claim 10 (depends on 9)

The apparatus of claim 9, wherein one hash value corresponds to one bucket, and one bucket comprises one, or more class addresses; and when processing the obtaining a class address corresponding to the target hash value step, the instructions cause the processor to:
obtain a bucket corresponding to the target hash value based on the target hash value and a correspondence between a plurality of buckets and the hash values of the class names of the plurality of classes, and using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value.

### Claim 11 (depends on 10)

The apparatus of claim 10, wherein one bucket has one start address and one end address, and before the using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value, the instructions further cause the processor to:
search start addresses and end addresses of the plurality of buckets for a start address and an end address of the bucket corresponding to the target hash value; and
read, from storage space defined by the start address and the end address of the bucket corresponding to the target hash value, the class address comprised in the bucket corresponding to the target hash value.

### Claim 12 (depends on 8)

The apparatus of claim 8, the instructions further cause the processor to:
load all binary files required for running the application program from an external storage of the computer device into a memory of the computer device, wherein all the binary files comprise the target binary file.

### Claim 13 (depends on 12)

The apparatus of claim 12, the instructions further cause the processor to:
create at least two class loaders of the application program; and
establish a correspondence between the at least two class loaders and all the binary files, wherein the at least two class loaders comprise a first class loader, and the first class loader is used to search, for the full information of the to-be-loaded class, a binary file corresponding to the first class loader.

### Claim 14 (depends on 13)

The apparatus of claim 13, the instructions further cause the processor to:
determine a class loader currently performing a search operation from the at least two class loaders based on a parents delegation model, to search all the binary files for the full information of the to-be-loaded class by using the determined class loader currently performing a search operation.

### Claim 15

A computer storage medium, wherein the computer storage medium stores computer-executable instructions, and when the computer-executable instructions are invoked by a computer, cause the computer to perform a class loading method, wherein the method comprises:
obtaining a class name of a to-be-loaded class required for running an application program in the computer device;
obtaining full information corresponding to the class name of the to-be-loaded class based on the class name of the to-be-loaded class and the correspondence between the class names of the plurality of classes and the full information of the plurality of classes, wherein the class names are in a one-to-one correspondence with the full information of the classes and the correspondence is stored in a target binary file; and
running the application program based on the full information corresponding to the class name of the to-be-loaded class.

### Claim 16 (depends on 15)

The computer storage medium of claim 15, wherein the target binary file further comprises class addresses of the plurality of classes and a correspondence between the class addresses of the plurality of classes and hash values of the class names of the plurality of classes, storage space indicated by a class address of a class is used to store full information of the class, wherein the method further comprises:
obtaining a class address corresponding to the target hash value based on a target hash value and the correspondence between the class addresses of the plurality of classes and the hash values of the class names of the plurality of classes, wherein the target hash value is a hash value of the class name of the to-be-loaded class; and
the obtaining step comprises:
searching, for the class name of the to-be-loaded class, storage space indicated by the class address corresponding to the target hash value, wherein the class name of the to-be-loaded class is a part of the full information of the to-be-loaded class; and using, as the full information of the to-be-loaded class, full information in the storage space indicated by the class address corresponding to the target hash value.

### Claim 17 (depends on 16)

The computer storage medium of claim 16, wherein one hash value corresponds to one bucket, and one bucket comprises one, or more class addresses; and w the obtaining a class address corresponding to the target hash value step comprises:
obtaining a bucket corresponding to the target hash value based on the target hash value and a correspondence between a plurality of buckets and the hash values of the class names of the plurality of classes, and using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value.

### Claim 18 (depends on 17)

The computer storage medium of claim 17, wherein one bucket has one start address and one end address, and before the using, as the class address corresponding to the target hash value, a class address comprised in the bucket corresponding to the target hash value, the method further comprises:
searching start addresses and end addresses of the plurality of buckets for a start address and an end address of the bucket corresponding to the target hash value; and
reading, from storage space defined by the start address and the end address of the bucket corresponding to the target hash value, the class address comprised in the bucket corresponding to the target hash value.

### Claim 19 (depends on 15)

The computer storage medium of claim 15, the method further comprises:
loading all binary files required for running the application program from an external storage of the computer device into a memory of the computer device, wherein all the binary files comprise the target binary file.

### Claim 20 (depends on 15)

The computer storage medium of claim 15, the method further comprises:
creating at least two class loaders of the application program; and
establishing a correspondence between the at least two class loaders and all the binary files, wherein the at least two class loaders comprise a first class loader, and the first class loader is used to search, for the full information of the to-be-loaded class, a binary file corresponding to the first class loader.
