WO2020192705A1 - 类加载方法和装置 - Google Patents

类加载方法和装置 Download PDF

Info

Publication number
WO2020192705A1
WO2020192705A1 PCT/CN2020/081220 CN2020081220W WO2020192705A1 WO 2020192705 A1 WO2020192705 A1 WO 2020192705A1 CN 2020081220 W CN2020081220 W CN 2020081220W WO 2020192705 A1 WO2020192705 A1 WO 2020192705A1
Authority
WO
WIPO (PCT)
Prior art keywords
class
loaded
classes
hash value
target
Prior art date
Application number
PCT/CN2020/081220
Other languages
English (en)
French (fr)
Inventor
王新建
张清华
杨勇勇
张斌
刘伟
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2020192705A1 publication Critical patent/WO2020192705A1/zh
Priority to US17/484,137 priority Critical patent/US11755341B2/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • G06F16/137Hash-based
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators

Definitions

  • This application relates to the field of computer technology, in particular to a class loading method and device.
  • the java virtual machine Under the framework of the java virtual machine (JVM), the java virtual machine loads the bytecode .class file describing the class data in the disk into the memory, and corrects, converts, analyzes and initializes the data, and finally forms a
  • the java type directly used by the java virtual machine is the class loading mechanism of the standard JVM.
  • the system server process and each application run on an independent Art instance.
  • the system service process or application if the class info of a certain class needs to be loaded, first find the class definition according to the class name of the class, then dynamically allocate memory and load the class Data is filled with information such as attributes and methods of the class through dynamic links.
  • the class data is information used to describe the class, such as the number of methods contained in the class. Class information includes: class attributes, methods, etc.
  • the class definition of the class to be loaded is usually first searched for according to the class name of the class to be loaded, and then the data and other information of the class to be loaded are dynamically loaded. In this way, it will lead to a longer time required for class loading.
  • the embodiments of the present application provide a class loading method and device, which help to perform class loading faster, thereby shortening the time required for class loading.
  • the embodiments of the present application provide a category loading method, which is applied to a computer device.
  • the computer device includes a target binary file.
  • the target binary file includes the correspondence between the class names of multiple classes and the full information of the multiple classes.
  • the class name corresponds to the full information of the class one-to-one.
  • the target binary file may be, for example, a Dex file, an Oat file, or a shared object (SO) file.
  • the method includes: firstly, determining the class name of the class to be loaded required when running the application in the computer device; the application may be, for example, a system service process or any application installed in the computer device.
  • the class to be loaded can be the class to which any method required to run the application belongs.
  • an application When an application is running, for example, it may be a certain moment in the startup phase of the application or a certain moment in the running phase of the application. Then, according to the correspondence between the class names of the multiple classes and the full information of the multiple classes, look up the class name of the class to be loaded among the class names of the multiple classes, and obtain the corresponding class name of the class to be loaded.
  • the full amount of information where the multiple categories include the first category, and the first category can be any one of the multiple categories.
  • the full information of the first type refers to all the information required to run the first type. For example, the total information may include the class name, class definition, class attributes, methods, etc. of the first type. Subsequently, the application can be run according to the full amount of information corresponding to the class name of the class to be loaded.
  • the process of loading a class in the technical solution provided by the embodiment of the present application is essentially a process of searching for the class name, thereby obtaining the full amount of information corresponding to the class name.
  • searching for the class definition according to the class name first, and then dynamically loading the data and other information of the class in the technical solution provided by the embodiment of this application, the full amount of information of the class can be found directly based on the class name. Therefore, it helps to load classes faster, thereby shortening the time required for class loading.
  • the target binary file further includes: the class addresses of the multiple classes, and the correspondence between the class addresses of the multiple classes and the hash values of the class names of the multiple classes; a class
  • the storage space indicated by the class address is used to store all the information of the class.
  • the class address can be generated in the static compilation stage.
  • the target binary file is an SO file
  • the class address may be generated in the process of generating the SO file from the Dex file during the static compilation phase.
  • the method further includes: according to the correspondence between the class addresses of the multiple classes and the hash values of the class names of the multiple classes, searching for the target hash value in the hash values of the class names of the multiple classes Value, and obtain the class address corresponding to the target hash value; where the target hash value is the hash value of the class name of the class to be loaded. Based on this, according to the correspondence between the class names of the plurality of classes and the full amount of information of the plurality of classes, the class names of the classes to be loaded are searched for among the class names of the classes, and the class names of the classes to be loaded are obtained.
  • the full information corresponding to the class name may include: searching for the class name of the class to be loaded in the storage space indicated by the class address corresponding to the target hash value, where the class name of the class to be loaded is the full information of the class to be loaded Part; the full amount of information in the storage space indicated by the class address corresponding to the target hash value is used as the full amount of information of the class to be loaded.
  • the embodiment of the present application supports searching for the class name of the class to be loaded by addressing, which helps to quickly find the class name of the class to be loaded from the class names of multiple classes.
  • a hash value corresponds to a bucket (ie, a hash bucket), and a bucket includes zero, one or more class addresses.
  • search for the target hash value in the hash values of the class names of the multiple classes search for the target hash value in the hash values of the class names of the multiple classes, and obtain The class address corresponding to the target hash value may include: according to the correspondence between multiple buckets and the hash values of the class names of the multiple classes, searching for the target hash value in the hash values of the class names of the multiple classes Hope value, and obtain the bucket corresponding to the target hash value, and use the class address included in the bucket corresponding to the target hash value as the class address corresponding to the target hash value. It can be seen that the embodiments of the present application support the use of hash buckets, which helps reduce the collision rate.
  • the number of buckets is determined in the static compilation stage; optionally, the class address included in each bucket is determined in the static compilation stage (that is, the correspondence between the bucket and the class address relationship).
  • the embodiment of the present application supports statically determining the number of buckets and the class addresses included in each bucket.
  • the number of buckets is determined during the startup phase or the running phase of the application; optionally, the class address included in each bucket is determined during the startup or running phase of the application.
  • the embodiment of the present application supports the dynamic determination of the number of buckets and the class addresses included in each bucket.
  • a bucket has a head address and a tail address
  • the plurality of buckets includes a first bucket
  • the first bucket may be any one of the plurality of buckets.
  • the storage space defined by the first and last addresses of the first bucket is used to store the class addresses included in the first bucket.
  • the method may further include: searching the target hash value from the first and last addresses of the multiple buckets.
  • This possible design provides a way to determine the class address.
  • the specific implementation is not limited to this.
  • the method before determining the class name of the class to be loaded when running the application in the computer device, the method further includes: adding all binary files (that is, all binary files) required to run the application ) Loaded from the external memory of the computer device to the memory of the computer device; wherein, the external memory of the computer device may be, for example, a hard disk, a magnetic disk, etc.
  • the external memory of the computer equipment can be used to store the binary files generated during the static compilation phase.
  • the full binary file includes the target binary file. For example, when the target binary file is an SO file, the full amount of binary files required to run the application program here may be all the SO files required to run the application program.
  • the full amount of binary files required to run the application may be all the Dex files required to run the application.
  • this process can occur during the application startup phase.
  • the computer device specifically the CPU of the computer device
  • the computer device can find the full amount of information of the class to be loaded from the full amount of binary files in the memory, so that the class can be loaded faster and shortened The time required for class loading.
  • the method further includes: creating at least two class loaders of the application; establishing a correspondence between the at least two class loaders and the full binary file; for example, a class loader It may correspond to one or more binary files, the at least two class loaders include a first class loader, and the first class loader may be any one of the at least two class loaders.
  • the first type loader is used to find all the information of the class to be loaded in the binary file corresponding to the first type loader. Optionally, this process may occur during the application startup phase or the application runtime phase. Based on this possible design, during class loading, the computer device can search for the full information of the class to be loaded in the corresponding binary file based on the class loader.
  • the method further includes: determining, among the at least two class loaders, the class loader currently performing the search operation according to the parental delegation mechanism, so as to pass the determined class loader currently performing the search operation , Search the full amount of information of the class to be loaded in the full amount of binary file.
  • the corresponding relationship between the class loader and the binary file includes: the corresponding relationship between the class loader and the path of the binary file, where the path of the binary file can be considered as part of the identification information of the binary file Kind of concrete realization.
  • the method further includes: according to the corresponding relationship between the at least two class loaders and the path of the full binary file, searching for the path of the binary file where the target stack frame is located in the path of the full binary file, and obtaining The class loader corresponding to the path of the binary file where the target stack frame is located, uses the determined class loader as the initial class loader used in the parent delegation mechanism; the target stack frame is the stack frame that calls the method to be loaded, and the method to be loaded Belongs to the class to be loaded. It can be seen that the embodiment of the present application supports the class loader corresponding to the path of the binary file where the target stack frame of the method to be loaded is called, and determines the technical solution of the initial class loader used in the parent delegation mechanism.
  • the method further includes: establishing the correspondence between the at least two class loaders and the classes in the full binary file; wherein the first class loader corresponds to the first class loader There is a correspondence between the classes contained in the binary file; the class loader corresponding to the class currently calling the class to be loaded is used as the initial class loader used in the parent delegation mechanism. In this way, it helps to improve class loading performance.
  • an embodiment of the present application provides a type of loading device, which includes each module used to execute the first aspect or any of the class loading methods in the first aspect.
  • the device may be a computer device or a chip, for example.
  • the embodiments of the present application provide a type of loading device, the device includes a memory and a processor, the memory is used to store computer execution instructions, when the device is running, the processor executes the computer execution instructions in the memory to
  • the hardware resources in the device are used to execute the operation steps of the first aspect or any one of the possible designs in the first aspect.
  • the device may be a computer device or a chip, for example.
  • an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored.
  • the computer program runs on a computer, the computer executes any of the first aspect or the first aspect.
  • the embodiments of the present application provide a computer program product that, when running on a computer, enables the operation steps of any possible method in the first aspect or any of the possible designs of the first aspect Be executed.
  • any type of loading device or computer readable storage medium or computer program product provided above is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding The beneficial effects of the method will not be repeated here.
  • FIG. 1 is a schematic diagram of the hardware structure of a computer device applicable to an embodiment of the present application
  • FIG. 2 is a schematic diagram of the hardware structure of another computer device applicable to the embodiments of the present application;
  • FIG. 3 is a schematic diagram of a method for establishing a hash table provided by an embodiment of the application
  • FIG. 4 is a schematic diagram of a hash table generated based on class names according to an embodiment of the application
  • FIG. 5 is a schematic diagram of steps performed by a computer device during an application startup phase provided by an embodiment of the application
  • FIG. 6 is a schematic diagram of steps executed by a computer device during an application program operation stage provided by an embodiment of the application
  • FIG. 7 is a schematic diagram of the correspondence between a class loader, an SO file, and a class loader domain provided by an embodiment of the application;
  • FIG. 8 is a comparison schematic diagram of an initial class loader used for determining a parent delegation mechanism provided by an embodiment of the application.
  • FIG. 9 is a schematic flowchart of a class loading method provided by an embodiment of the application.
  • FIG. 10 is a schematic structural diagram of a class loading device provided by an embodiment of the application.
  • Class is an abstract data type, it is an abstraction of entities with the same characteristics.
  • the classes described in the embodiments of this application generally refer to java classes. In an example, you can think of a class as a collection of multiple properties and methods.
  • Class information The class information of a class can include its class name, class definition, class attributes, methods, etc.
  • Full information of the class refers to all the information needed to execute the class.
  • the full information of a class includes all class information of the class, such as class name, class definition, class attributes, methods, and external visibility of attributes and methods.
  • the full information of a class may include various information as shown in Table 1:
  • sizeinfo Used to indicate the memory footprint of the class and its object (Object) itab Used to indicate information about the interface (Interface) method of the class
  • vtab Used to indicate the virtual (Virtual) method related information of the class classname Used to indicate the name of the class.
  • Table 1 is only an example of the full information of a class.
  • the full information of a class may include more or less information than the information shown in Table 1.
  • the class loader (classloader) is a logical unit that loads java classes into the virtual machine.
  • Binary file A binary file in a broad sense refers to a file, which is named after the storage form of the file in an external device as binary.
  • a binary file in a narrow sense is a file other than a text file.
  • Dex files, Oat files or SO files are all binary files. If no explanation is given, the following binary files are all explained using SO files as examples.
  • the Dex file is a kind of target file under the Android virtual machine, which contains all the operating instructions of the application and the data required at runtime.
  • Oat file is a kind of executable file after Dex file is compiled and optimized statically (ahead of time, AOT). Oat files can be obtained based on the static boot of the AOT compiler.
  • SO file is an executable and linking format (ELF) file, also known as dynamic library file or shared library file.
  • Bucket Also called a hash bucket, it is a virtual subgroup of the elements in the hash table.
  • the elements in the same bucket have the same hash value, and the elements in different buckets have different hash values. .
  • the elements in the bucket may be class addresses.
  • At least one (species) in the embodiments of the present application includes one (species) or more (species).
  • Multiple (species) means two (species) or more than two (species).
  • at least one of A, B and C includes: A alone, B alone, A and B simultaneously, A and C simultaneously, B and C simultaneously, and A, B and C simultaneously.
  • "/" means or, for example, A/B can mean A or B;
  • "and/or” in this document is only an association relationship describing associated objects, It means that there can be three kinds of relationships, for example, A and/or B, which can mean: A alone exists, A and B exist at the same time, and B exists alone.
  • Multiple means two or more than two.
  • words such as “first” and “second” are used to distinguish the same items or similar items with substantially the same function and effect. Those skilled in the art can understand that words such as “first” and “second” do not limit the quantity and order of execution, and words such as “first” and “second” do not limit the difference.
  • FIG. 1 it is a schematic diagram of the hardware structure of a computer device 100 applicable to the embodiments of the present application.
  • the computer device 100 shown in FIG. 1 includes: at least one processor 101, a communication line 102, a memory 103, and at least one communication interface 104. among them:
  • the processor 101 can be a general-purpose central processing unit (central processing unit, CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more programs for controlling the execution of the program of this application. integrated circuit.
  • CPU central processing unit
  • ASIC application-specific integrated circuit
  • the communication line 102 may include a path to transmit information between the aforementioned components.
  • the communication interface 104 may be any device such as a transceiver for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc. .
  • RAN radio access network
  • WLAN wireless local area networks
  • the memory 103 may be read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM), or other types that can store information and instructions
  • ROM read-only memory
  • RAM random access memory
  • the dynamic storage device can also be electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disk storage, optical disc storage (Including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or can be used to carry or store desired program codes in the form of instructions or data structures and can be used by a computer Any other media accessed, but not limited to this.
  • EEPROM electrically erasable programmable read-only memory
  • CD-ROM compact disc read-only memory
  • optical disc storage including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.
  • magnetic disk storage media or other magnetic storage devices or can be
  • the memory 103 may exist independently, and is connected to the processor 101 through a communication line 102. Alternatively, the memory 103 may be integrated with the processor 101.
  • the memory 103 provided by the embodiment of the present application may generally be non-volatile. Among them, the memory 103 is used to store computer instructions for executing the solution of the present application, and the processor 101 controls the execution.
  • the processor 101 is configured to execute computer instructions stored in the memory 103, so as to implement the method provided in the embodiment of the present application.
  • the embodiment of the present application does not limit the type of the computer device 100.
  • the computer device 100 may be a general-purpose device including the hardware structure shown in FIG. 1, or may be a special device including the hardware structure shown in FIG.
  • the computer instructions in the embodiments of the present application may also be referred to as application program codes, which are not specifically limited in the embodiments of the present application.
  • the computer device 100 may include multiple processors.
  • Each of these processors can be a single-CPU (single-CPU) processor or a multi-core (multi-CPU) processor.
  • the processor here may refer to one or more devices, circuits, and/or processing cores for processing data (for example, computer program instructions).
  • the computer device 100 may further include an output device 105 and an input device 106.
  • the output device 105 communicates with the processor 101 and can display information in a variety of ways.
  • the output device 105 may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector (projector) Wait.
  • the input device 106 communicates with the processor 101 and can receive user input in a variety of ways.
  • the input device 106 may be a mouse, a keyboard, a touch screen device, or a sensor device.
  • the memory 103 may include a main memory 1031 and an auxiliary memory 1032.
  • the processor 101 may include a main processor 1011 and an auxiliary processor 1012. among them:
  • the main memory 1031 may be a memory (memory).
  • the auxiliary storage 1032 may be an external storage or an external storage device, for example, it may be a hard disk, an optical drive, a floppy disk, or a magnetic disk.
  • the auxiliary memory 1032 can store binary files (such as SO files, etc.) compiled in the static compilation stage.
  • the main processor 1011 may be a CPU.
  • the main processor 1011 cannot directly access the auxiliary memory 1032 (such as external memory), but can only access the main memory 1031 (such as memory).
  • the auxiliary processor 1012 may be a direct memory access (DMA) processor or the like that can read data from the auxiliary memory 1032 (for example, external memory) to the main memory 1031 (for example, memory).
  • DMA direct memory access
  • the process of data from the external memory to the memory and then to the CPU can include: memory to CPU Issue read peripheral instructions, CPU transfers system bus control authority to DMA processor; DMA processor reads data from external storage into memory; CPU takes over bus control from DMA processor; CPU issues read data command to memory; The CPU performs arithmetic processing on the data, and at the same time performs necessary data exchange with the memory; after processing, if there is an external memory read operation, the CPU can send the result data to the external memory.
  • the process in which the computer device 100 runs an application program can be understood as a process in which the CPU calls a method.
  • the method called belongs to a class.
  • calling a method can be understood as calling a function. Therefore, the DMA processor can first load the class information of the class to which the method to be loaded stored in the external memory belongs to the memory, and the CPU reads the data in the memory to execute the method to be loaded.
  • the static compiler tool chain compiles the dynamic library, that is, compiles Dex files into SO files.
  • the embodiment of the present application does not limit the specific implementation manner of compiling the Dex file into the SO file.
  • the static compiler tool chain in the process of compiling the Dex file into an SO file, can generate a hash table based on the class name of the class in the Dex file. It is part of the SO file.
  • the static compiler tool chain can perform hash operations on the class names of all classes in the Dex file to be compiled to obtain the hash value of each class name, and establish a hash table.
  • the embodiment of this application does not limit the hash algorithm used when performing the hash operation.
  • it may be the BKDR hash algorithm, etc., where the BKDR hash algorithm comes from the C language programming one co-authored by Kernighan and Dennis Ritchie Book is the abbreviation of two names combined.
  • An example of using the BKDR hash algorithm for hash operation is as follows:
  • the process of establishing a hash table may include the following steps:
  • a Dex file can include one or more classes.
  • each class corresponds to a class address.
  • Class addresses can be virtual addresses (that is, logical addresses) or physical addresses. The embodiments of the present application do not specifically limit this.
  • S102 The static compiler tool chain establishes a correspondence between the class address of each class in the Dex file to be compiled and the hash value of the class name of the class. Based on this, subsequent addressing can be used to find the full amount of information about the class to be loaded.
  • S102 may include the following steps S102-1 to S102-3:
  • the static compiler tool chain distributes the class addresses of all classes in the Dex file to be compiled into different buckets through the hash value.
  • Each bucket includes class addresses with the same hash value, and different buckets include class addresses with different hash values.
  • the hash value of a class address refers to the hash value of the class name included in the class information stored in the storage space indicated by the class address.
  • the static compiler tool chain establishes the corresponding relationship between the class address and the bucket to which the class address belongs, and the corresponding relationship between the bucket and the hash value, to establish the class address of each class and the class Correspondence between the hash values of the class name.
  • a static compiler tool chain can use a fixed number of buckets, and store all buckets continuously from low to high according to the size of the hash value corresponding to the bucket.
  • the following are taken as an example for description.
  • the static compiler tool chain may number the buckets from low to high according to the size of the hash value corresponding to the bucket.
  • the following are taken as an example for description.
  • S102-2 The static compiler tool chain allocates a head address and a tail address to each bucket, where the class address included in each bucket is stored in the storage space defined by the bucket's head address and tail address.
  • the tail address is determined based on the number of class addresses contained in bucket 0; if m>0, then the first address of bucket m is determined based on the tail address of bucket m-1, and the tail address of bucket m is based on what bucket m contains
  • the number of class addresses is determined. 0 ⁇ m ⁇ M-1, M is the number of buckets, m and M are integers.
  • the class addresses contained in each bucket are continuously stored as an example for description.
  • A is an integer greater than or equal to 0.
  • the embodiments of the present application are not limited to this.
  • the static compiler tool chain creates a first field (section) and a second field of the SO file obtained after the Dex file to be compiled is compiled.
  • the first field is used to store the first addresses of all buckets included in the SO file.
  • the second field is used to store the tail addresses of all buckets included in the SO file.
  • the numbers of the buckets to which the first address stored in the first field belongs are arranged in succession from low to high, and the numbers of the buckets to which the last address stored in the second field belongs are arranged in succession from low to high.
  • Each SO file is essentially an Elf file, including an Elf header and multiple fields.
  • Each SO file includes a hash table, for example, the hash table shown in FIG. 4.
  • FIG. 4 a schematic diagram of a hash table generated based on a class name provided by an embodiment of this application.
  • the hash table shown in Figure 4 is a hash table in an SO file. Among them, 1 represents the first field of the SO file. 2 indicates the second field of the SO file. 3 means bucket 0, 4 means bucket 1; and bucket m corresponds to hash value m.
  • bucket 0 includes 11 class addresses and bucket 1 includes 10 class addresses
  • the first address "__class_hashtab_bucket_0_start___” of bucket 0 can be address 0
  • the end address "__class_hashtab_bucket_0_end__” can be address 10; correspondingly, the first address of bucket 1 "__class_hashtab_bucket_1_start__” "Can be address 11, and the end address "__class_hashtab_bucket_1_end__” can be address 21.
  • class 5 Represents the full amount of information of the class stored in the storage space indicated by the first class address in bucket 0, specifically including: class name (such as "__classinfo__Ljava_2Flang_2FString_24CaseInsensitiveComparator_3B") and other information.
  • class name such as "__classinfo__Ljava_2Flang_2FString_24CaseInsensitiveComparator_3B"
  • the hash table described in the embodiment of the present application includes each class in an SO file and the organizational relationship of the class.
  • the number of buckets is determined, for example, the number of buckets is determined according to the number of classes contained in the SO. In other embodiments, the number of buckets, the correspondence between buckets and class addresses, etc. are determined during the application startup phase or the application runtime phase. For example, an SO file that contains a large number of classes has a relatively large number of buckets. In this way, for SO files with a large number of classes, it helps to reduce the conflict rate. Among them, the more classes contained in the same bucket, the higher the conflict rate.
  • the SO file compiled in the static compilation stage is usually stored in the external memory of the computer device.
  • the computer device can perform the following steps:
  • S201 When an application program installed in a computer device is started, load all SO files (that is, all SO files) required for running the application program in the external memory into the memory.
  • SO files that is, all SO files
  • the DMA processor in the computer device loads the entire amount of SO files stored in the external memory and required to run the application program into the memory through one or more loadings.
  • the application program may include a system service process or an application (application, APP), etc.
  • S202 The computer device creates at least one class loader of the application program, for example, usually creates multiple class loaders.
  • the execution subject of S202 may specifically be a CPU in a computer device.
  • the specific implementation of creating a class loader for an application can refer to the existing technology (such as the existing technology based on the Art operating mode, etc.).
  • the computer device can also create a parent-child relationship between the multiple class loaders, and the specific implementation process can refer to the existing technology (such as existing based on Art Technology of operation mode, etc.).
  • S203 The computer device establishes a correspondence between the at least one class loader and the full SO file.
  • a class loader has a corresponding relationship with one or more SO files, and an SO file has a corresponding relationship with only one class loader; a class loader is used to find the class to be loaded in the SO file that has a corresponding relationship with itself Class information.
  • the class loader i in the at least one class loader corresponds to the Dex file j in the full Dex file
  • the class loader i corresponds to the SO file j.
  • the SO file j is the SO file obtained by compiling the Dex file j during the static compilation period.
  • I is the number of class loaders of the application created by the computer equipment
  • J is the number of all SO files (or Dex files) required by the computer equipment to run the application
  • I, J, i, and j are all integers, and I ⁇ J.
  • the computer device opens all SO files corresponding to the class loader through a system call method, and obtains the first field of each SO file (as shown in the figure) __Class_hashtab_start__ in 4) and the second field (__class_hashtabend_start__ in Figure 4), and initialize the class loader field of all classes in each SO file. This step is to prepare for class loading when the application is running.
  • the serial number of each class loader created by a computer device can be saved in the class loader list 1, the serial number starts from 0, and there may be a parent-child relationship between class loaders, as shown in the figure In the illustration 4, the parent of class loader 0 is class loader 1.
  • the class loader 0 corresponds to three SO files, such as the SO file 1, SO file 2, and SO file 3 shown in Figure 2, as examples.
  • Each SO file can contain an Elf header and a hash table, where ".class_hashtab" in Figure 7 represents a hash table.
  • the class information of each class can also include the class loader domain, as shown in Figure 7 (3).
  • the class loader to which a class belongs is the class loader corresponding to the SO file to which the class belongs.
  • the foregoing S201 to S204 can be considered as a preparation stage for executing the class loading method.
  • the subsequent class loading method executed is specifically a method of querying classes in memory.
  • the search (or class loading) efficiency can be improved, thereby shortening the search (or class loading) time.
  • the class loading method can be executed during the startup phase and/or the running phase of the application, and the following descriptions are made in the running phase of the application as an example.
  • the computer device can perform the following steps:
  • S301 The computer device determines the method that needs to be called currently (that is, the method to be loaded), and uses the class to which the method belongs as the class to be loaded.
  • S302 The computer device performs a hash operation on the class name of the class to be loaded according to the hash algorithm to obtain the target hash value.
  • the hash algorithm used in S302 is the same as the hash algorithm used in the static compilation phase described above.
  • S303 The computer device determines the initial class loader of the class to be loaded in the at least one class loader of the application program.
  • the initial class loader may be explicitly indicated, such as indicated to the computer device by the user.
  • the embodiments of the present application provide the following implementation manners:
  • Manner 1 The computer device determines the class loader corresponding to the SO file where the target stack frame of the call stack of the method to be loaded is located according to the corresponding relationship between the at least one class loader and the full SO file, and the determined The class loader serves as the initial class loader of the class to be loaded.
  • the target stack frame is the stack frame that calls (such as directly or indirectly) the method to be loaded.
  • Method A is a call stack
  • each method in the call stack is a stack frame of the call stack. If the method to be loaded is method C, then the target stack frame can be the stack frame that directly calls method C, that is, method B, or the stack frame that calls method C, that is, method A indirectly.
  • the correspondence between at least one class loader of the application program and the full amount of SO files required to run the application program has been established in the above S203.
  • the path of the SO file can be used as the identification information of the SO file. Therefore, in an implementation manner, the correspondence between a class loader and an SO file may include: the class loader and the SO file The corresponding relationship between the paths. Based on this, method 1 can be described as: the computer device determines the class loader corresponding to the path of the SO file where the target stack frame is located according to the corresponding relationship between the at least one class loader and the path of the full SO file, and The determined class loader serves as the initial class loader.
  • Manner 2 The computer device uses the class loader corresponding to the caller of the class to be loaded as the initial class loader of the class to be loaded.
  • the caller of the class to be loaded refers to the class that currently calls the class to be loaded.
  • the class loader domains of all classes in each SO file have been initialized, that is, the correspondence between the at least one class loader and the classes in the full SO file has been established; where, There is a correspondence between a class loader and the classes contained in the SO file corresponding to the loader.
  • the class loader indicated by the class loader field corresponding to the caller of the class to be loaded can be used as the initial class loader of the class to be loaded.
  • the initial class loading is usually obtained through a back stack, where the back stack is to obtain a certain stack in the call stack of the currently to-be-loaded method.
  • stackback has a certain time overhead. Therefore, in the embodiment of the present application, the class loader corresponding to the caller of the class to be loaded is directly used as the initial class loader, which can prevent the application from triggering the stackback at runtime. The time cost to come. If the back-stack trigger frequency is higher, using method 2 can save more CPU running time.
  • the specific class loader domain is the class loader domain corresponding to the caller of the class to be loaded. This is much faster than the performance of the stack. In other words, replace 3 by 2 shown in Figure 8 to improve class loading performance.
  • the computer device Based on the initial class loader of the class to be loaded, the computer device determines the class loader currently performing the loading operation in the at least one class loader according to the parent delegation mechanism, and searches the full SO file for the class loader to be loaded The full information of the class to be loaded corresponding to the class name.
  • the parent delegation mechanism in traditional technology includes:
  • the class loading request is triggered. And determine whether the class to be loaded has been loaded, if it has been loaded (that is, the class information of the class to be loaded is stored in the memory), return directly.
  • the class loading request is first delegated to the parent class loader of the initial class loader for execution. If the parent class loader still has its parent class loader, it will be further delegated. Recursively, the class loading request will eventually reach the top-level startup class loader. If the parent class loader can complete the class loading task, it will return successfully. If the parent class loader cannot complete the loading task, the child loader will try to execute it by itself Load task" determines the class loader currently performing the load operation.
  • determining the class loader currently performing the loading operation in the at least one class loader may include: triggering a class loading request when the class to be loaded needs to be recorded, and according to the above 2 ) To determine the class loader currently performing the loading operation in the at least one class loader. Based on this, S304 can be used as a variant (or evolved or new) parent delegation mechanism.
  • S305 The computer device runs the application program according to the found full information of the class to be loaded.
  • loading a class based on a class loader is essentially to find the class to be loaded from all SO files managed by the class loader.
  • the computer device can perform the following steps based on the class loader corresponding to the SO file, as shown in Figure 9, to find the full information of the class to be loaded:
  • S401 According to the correspondence between multiple hash values and M buckets, search for a target hash value from the multiple hash values, and obtain a bucket corresponding to the target hash value. For example, according to the correspondence between multiple hash values and the numbers of M buckets, the target hash value is searched from the multiple hash values, and the number of the bucket corresponding to the target hash value is obtained.
  • the bucket corresponding to the target hash value is the H+1th bucket among the M buckets.
  • S402 Find the first address and the last address of the bucket corresponding to the target hash value from the first address and the last address of the M buckets.
  • the target hash value H is used as the offset to obtain the first address of the bucket corresponding to the target hash value. address.
  • the target hash value H is used as the offset to obtain the tail address of the bucket corresponding to the target hash value.
  • S403 Read the class address included in the bucket corresponding to the target hash value from the storage space defined by the first address to the last address of the bucket corresponding to the target hash value, and use the read class address as the target hash The class address corresponding to the value.
  • the class address included in the bucket corresponding to the target hash value can be determined. Assuming that the bucket corresponding to the target hash value H is bucket 1, according to 8 and 6 shown in Figure 4, the class address included in the bucket corresponding to the target hash value can be determined.
  • S404 Search for the class name of the class to be loaded in the storage space indicated by the class address corresponding to the target hash value.
  • the class name of the class to be loaded is part of the total information of the class to be loaded.
  • the storage space indicated by the class address corresponding to the target hash value can be determined. And judge whether the class name stored in the storage space matches the class name of the class to be loaded, if they are the same, it is considered a match (that is, it has been found); otherwise, it is considered not to match (that is, it is not found).
  • the class information of the class to be loaded is not stored in the SO file, and then the full information of the class to be loaded is searched in the next SO file corresponding to the class loader. If after traversing all SO files corresponding to the class loader, the full information of the class to be loaded is still not found, the next class loader will continue to look up according to the parent delegation mechanism until the full information of the class to be loaded is found. If after traversing all the class loaders of the application, the full information of the class to be loaded is still not found, the computer device outputs exception handling information.
  • the main difference between the technical solution provided by the embodiment of this application and the technology based on the Art operation mode is that the corresponding relationship between the class name and the full amount of information of the class is established in the static execution stage in the embodiment of this application, while the operation based on Art
  • the pattern technology establishes the correspondence between the class name and the class definition. Based on this, it can be seen that during class loading, the embodiment of the present application can directly find the full amount of information corresponding to the class name according to the class name, while the technology based on the Art operation mode can only find the class corresponding to the class name according to the class name.
  • the application when the application is started, all the SO files required to run the application are loaded into the memory. In this way, when the application is running, the class loading is essentially in the memory. Perform class search, so that you can further improve the class loading rate. Especially when the class information is loaded for the first time under the technology based on the Art operation mode, the technical solution provided in this application will try to make the system and the application run faster.
  • the technical solution provided by the embodiments of the present application fills in the gap of class loading after converting Dex files into SO files using static compilation technology in the Android operating system, and realizes a set of class loading mechanisms compatible with the normal operation of the Android operating system.
  • the embodiment of the present application may divide the class loading device into functional modules according to the foregoing method examples.
  • each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software functional modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division, and there may be other division methods in actual implementation.
  • FIG. 10 it is a schematic structural diagram of a class loading device 90 provided by an embodiment of this application.
  • the device 90 can be used to execute the method shown in FIG. 6, FIG. 8 or FIG.
  • the apparatus 90 may be the above computer equipment.
  • the device 90 may include a target binary file, and the target binary file includes a correspondence between the class names of multiple classes and the full information of the multiple classes, and the class names correspond to the full information of the classes one-to-one.
  • the device 90 includes: a determining unit 901, a searching unit 902, and an operating unit 903. Wherein, the determining unit 901 is used to determine the class name of the class to be loaded when running the application in the device 90.
  • the searching unit 902 is configured to search for the class name of the class to be loaded among the class names of the plurality of classes according to the correspondence between the class names of the plurality of classes and the full information of the plurality of classes, and obtain the class to be loaded
  • the running unit 903 is configured to run the application program according to the full amount of information corresponding to the class name of the class to be loaded.
  • the determining unit 901 may be specifically used to perform S301
  • the searching unit 902 may be specifically used to perform S302 to S304
  • the running unit 903 may be used to perform S305.
  • the target binary file further includes: the class addresses of the multiple classes, and the correspondence between the class addresses of the multiple classes and the hash values of the class names of the multiple classes;
  • the indicated storage space is used to store all the information of a class.
  • the searching unit 902 is further configured to search for the hash values of the class names of the multiple classes according to the correspondence between the class addresses of the multiple classes and the hash values of the class names of the multiple classes.
  • the target hash value, and the class address corresponding to the target hash value is obtained; the target hash value is the hash value of the class name of the class to be loaded.
  • the search unit 902 is specifically configured to: search for the class name of the class to be loaded in the storage space indicated by the class address corresponding to the target hash value, where the class name of the class to be loaded is the full amount of the class to be loaded Part of the information; the full amount of information in the storage space indicated by the class address corresponding to the target hash value is used as the full amount of information of the class to be loaded.
  • the searching unit 902 may be specifically configured to execute S403 to S405.
  • one hash value corresponds to one bucket, and one bucket includes zero, one or more class addresses; the correspondence between the class addresses of the multiple classes and the hash values of the class names of the multiple classes
  • the searching unit 902 is specifically configured to: according to the multiple buckets and the multiple classes The corresponding relationship between the hash values of the class names of the class names, the target hash value is searched in the hash values of the class names of the multiple classes, and the bucket corresponding to the target hash value is obtained, and the target hash value corresponds to The class address included in the bucket serves as the class address corresponding to the target hash value.
  • the searching unit 902 may be specifically configured to perform S403.
  • a bucket has a head address and a tail address
  • the multiple buckets include the first bucket
  • the storage space defined by the head address and the tail address of the first bucket is used to store the class addresses included in the first bucket.
  • the searching unit 902 is also used to: from the first and last addresses of the multiple buckets, find the first and last addresses of the bucket corresponding to the target hash value; from the first address to the last address of the bucket corresponding to the target hash value In the storage space limited by the tail address, read the class address included in the bucket corresponding to the target hash value.
  • the searching unit 902 may be specifically used to execute S401 to S402.
  • the device 90 further includes: a loading unit 904, configured to load the full amount of binary files required to run the above-mentioned application program from the external memory of the device 90 into the internal memory of the device 90; the full amount of binary files includes the target binary file .
  • a loading unit 904 configured to load the full amount of binary files required to run the above-mentioned application program from the external memory of the device 90 into the internal memory of the device 90; the full amount of binary files includes the target binary file .
  • the device 90 further includes: a creating unit 905, configured to create at least two class loaders of the above-mentioned application program, and establish a correspondence relationship between the at least two class loaders and the full binary file;
  • the two class loaders include a first class loader, and the first class loader is used to search for full information of the class to be loaded in the binary file corresponding to the first class loader.
  • the creation unit 905 may be used to execute S202 and S203.
  • the determining unit 901 is further configured to determine the class loader currently performing the search operation among the at least two class loaders according to the parental delegation mechanism, so as to pass the determined class loader currently performing the search operation, Find the full amount of information of the class to be loaded in the full amount of binary files required to run the above application.
  • the determining unit 901 may be used to execute S303.
  • the searching unit 902 is further configured to, according to the at least two class loaders and the full binary file
  • the loader is the initial class loader used in the parent delegation mechanism; the target stack frame is the stack frame that calls the computer device to be loaded, and the computer device to be loaded belongs to the to-be-loaded class.
  • the determining unit 901 may be used to execute S303.
  • the creating unit 905 is further configured to establish the correspondence between the at least two class loaders and the classes in the full binary file; wherein, the binary file corresponding to the first type loader and the first type loader There is a correspondence between the included classes; the determining unit 901 is also used to use the class loader corresponding to the class currently calling the class to be loaded as the initial class loader used in the parent delegation mechanism.
  • the foregoing binary file includes an SO file.
  • Any device 90 described above can be used to perform the corresponding steps in the above method embodiments. Therefore, for the explanation of the related content and beneficial effects, please refer to the corresponding description in the above method embodiments, which will not be repeated here. .
  • the above embodiments it may be implemented in whole or in part by software, hardware, firmware or any combination thereof.
  • a software program it may be implemented in the form of a computer program product in whole or in part.
  • the computer program product includes one or more computer instructions.
  • the computer-executed instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application are generated in whole or in part.
  • the computer can be a general-purpose computer, a dedicated computer, a computer network, or other programmable devices.
  • Computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • computer instructions may be transmitted from a website, computer, server, or data center through a cable (such as Coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL) or wireless (such as infrared, wireless, microwave, etc.) transmission to another website site, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or may include one or more data storage devices such as a server or a data center that can be integrated with the medium.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Abstract

本申请公开了类加载方法和装置,涉及计算机技术领域,有助于更快地进行类加载,从而缩短类加载所需的时长。该方法应用于计算机设备,该计算机设备包括目标二进制文件,目标二进制文件包括多个类的类名与该多个类的全量信息之间的对应关系,类名与类的全量信息一一对应;该方法包括:确定运行计算机设备中的应用程序时所需的待加载类的类名;根据该多个类的类名与该多个类的全量信息之间的对应关系,在该多个类的类名中查找所述待加载类的类名,并获取待加载类的类名对应的全量信息;其中,该多个类包括第一类,第一类的全量信息是指运行第一类所需的全部信息;根据待加载类的类名对应的全量信息,运行该应用程序。

Description

类加载方法和装置
本申请要求于2019年03月25日提交国家知识产权局、申请号为201910229643.6、申请名称为“类加载方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,尤其涉及类加载方法和装置。
背景技术
在java虚拟机(java virtual machine,JVM)框架下,java虚拟机将磁盘中描述类数据的字节码.class文件加载到内存,并对这些数据进行校正、转换解析和初始化,最终形成可以被java虚拟机直接使用的java类型,这就是标准JVM的类加载机制。
从安卓5.0(Android5.0)开始谷歌(Google)开放了Art运行模式。基于Art运行模式,系统服务(system server)进程和每个应用都运行在独立的Art实例上。在系统服务进程或应用运行时,如果需要加载某个类(class)的类信息(class info),则首先根据该类的类名查找到类定义(class definition),然后动态分配内存,加载类数据,通过动态链接填充类的属性、方法等信息。其中,类数据是用于描述类的信息,如类所包含的方法的数量等。类信息包括:类的属性、方法等。
上述技术方案,通常先根据待加载类的类名查找待加载类的类定义,再动态加载待加载类的数据和其他信息。这样,会导致类加载所需要的时间较长。
发明内容
本申请实施例提供了类加载方法和装置,有助于更快地进行类加载,从而缩短类加载所需的时长。
第一方面,本申请实施例提供了一种类加载方法,应用于计算机设备,计算机设备包括目标二进制文件,目标二进制文件包括多个类的类名与该多个类的全量信息之间的对应关系,类名与类的全量信息一一对应。目标二进制文件例如可以是Dex文件、Oat文件或共享动态库(shared object,SO)文件等。该方法包括:首先,确定运行计算机设备中的应用程序时所需的待加载类的类名;该应用程序例如可以是计算机设备中安装的系统服务进程或任意一个应用。待加载类可以是运行该应用程序所需的任意一个方法所属的类。运行一个应用程序时,例如可以是该应用程序的启动阶段的某一时刻,或者是该应用程序的运行阶段的某一时刻。然后,根据该多个类的类名与该多个类的全量信息之间的对应关系,在该多个类的类名中查找待加载类的类名,并获取待加载类的类名对应的全量信息;其中,该多个类包括第一类,第一类可以是该多个类中的任意一个类。第一类的全量信息是指运行第一类所需的全部信息,例如,该全部信息可以包括第一类的类名、类定义、类的属性、方法等。后续,可以根据待加载类的类名对应的全量信息,运行该应用程序。
可见,本申请实施例提供的技术方案中加载类的过程实质上是查找类名,从而获 取该类名对应的全量信息的过程。相比现有技术“先根据类名查找类定义,再动态加载类的数据和其他信息”的技术方案,本申请实施例提供的技术方案中,可以直接根据类名查找到类的全量信息,因此,有助于更快地进行类加载,从而缩短类加载所需的时长。
在一种可能的设计中,目标二进制文件还包括:该多个类的类地址,以及该多个类的类地址与该多个类的类名的哈希值之间的对应关系;一个类的类地址所指示的存储空间用于存储该类的全量信息。其中,类地址可以是在静态编译阶段生成的。例如,当目标二进制文件是SO文件时,类地址可以是在静态编译阶段中,且由Dex文件生成SO文件的过程中所生成的。相应的,该方法还包括:根据该多个类的类地址与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的类地址;其中,目标哈希值是待加载类的类名的哈希值。基于此,根据该多个类的类名与该多个类的全量信息之间的对应关系,在该多个类的类名中查找待加载类的类名,并获取所述待加载类的类名对应的全量信息,可以包括:在目标哈希值对应的类地址所指示的存储空间中,查找待加载类的类名,其中,待加载类的类名是待加载类的全量信息的一部分;将目标哈希值对应的类地址所指示的存储空间中的全量信息,作为待加载类的全量信息。
可见,本申请实施例支持通过寻址的方式查找待加载类的类名,这样,有助于快速从多个类的类名中查找到待加载类的类名。
在一种可能的设计中,一个哈希值对应一个桶(即哈希桶),一个桶包括零个、一个或多个类地址。相应的,根据该多个类的类地址与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的类地址,可以包括:根据多个桶与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的桶,将目标哈希值对应的桶所包括的类地址作为目标哈希值对应的类地址。可见,本申请实施例支持使用哈希桶的方式,这样有助于减少冲突率。
具体实现的过程中,在一种实现方式中,在静态编译阶段,确定桶的数量;可选的,在静态编译阶段确定每个桶所包括的类地址(即桶与类地址之间的对应关系)。换言之,本申请实施例支持静态确定桶的数量和每个桶所包括的类地址。在另一种实现方式中,在应用程序开启阶段或运行阶段,确定桶的数量;可选的,在应用程序开启阶段或运行阶段,确定每个桶所包括的类地址。换言之,本申请实施例支持动态确定桶的数量和每个桶所包括的类地址。
在一种可能的设计中,一个桶具有一个首地址和一个尾地址,该多个桶包括第一桶,第一桶可以是该多个桶中的任意一个桶。第一桶的首地址和尾地址所限定的存储空间用于存储第一桶包括的类地址。相应的,在将目标哈希值对应的桶所包括的类地址作为目标哈希值对应的类地址之前,该方法还可以包括:从该多个桶的首地址和尾地址中,查找目标哈希值对应的桶的首地址和尾地址;从目标哈希值对应的桶的首地址至尾地址所限定的存储空间中,读取目标哈希值对应的桶所包括的类地址。该可能的设计提供了一种确定类地址的实现方式。当然具体实现时不限于此。
在一种可能的设计中,在确定运行计算机设备中的应用程序时所需的待加载类的 类名之前,该方法还包括:将运行该应用程序所需的全量二进制文件(即全部二进制文件)从计算机设备的外存中加载到计算机设备的内存中;其中,计算机设备的外存例如可以是硬盘、磁盘等。计算机设备的外存可以用于存储静态编译阶段所生成的二进制文件。该全量二进制文件包括目标二进制文件。例如,当目标二进制文件是SO文件时,这里的运行该应用程序所需的全量二进制文件可以是运行该应用程序所需的全部的SO文件。又如,当目标二进制文件是Dex文件时,这里的运行该应用程序所需的全量二进制文件可以是运行该应用程序所需的全部的Dex文件。可选的,该过程可以发生在应用程序启动阶段。基于该可能的设计,在类加载时,计算机设备(具体是计算机设备的CPU)可以从内存中的全量二进制文件中,查找待加载类的全量信息,这样可以更快地进行类加载,从而缩短类加载所需的时长。
在一种可能的设计中,该方法还包括:创建该应用程序的至少两个类加载器;建立该至少两个类加载器与该全量二进制文件之间的对应关系;例如,一个类加载器可以与一个或多个二进制文件之间对应,该至少两个类加载器包括第一类加载器,第一类加载器可以是该至少两个类加载器中的任意一个类加载器。第一类加载器用于在与第一类加载器对应的二进制文件中查找待加载类的全量信息。可选的,该过程可以发生在应用程序启动阶段或应用程序运行阶段。基于该可能的设计,在类加载时,计算机设备可以基于类加载器,在相应的二进制文件中查找待加载类的全量信息。
在一种可能的设计中,该方法还包括:根据双亲委派机制,在该至少两个类加载器中确定当前执行查找操作的类加载器,以通过所确定的当前执行查找操作的类加载器,在该全量二进制文件中查找所述待加载类的全量信息。
在一种可能的设计中,类加载器与二进制文件存在对应关系,包括:该类加载器与该二进制文件的路径存在对应关系,其中,二进制文件的路径可以认为是二进制文件的标识信息的一种具体实现。相应的,该方法还包括:根据该至少两个类加载器与该全量二进制文件的路径之间的对应关系,在该全量二进制文件的路径中查找目标栈帧所在的二进制文件的路径,并获取目标栈帧所在的二进制文件的路径对应的类加载器,将所确定的类加载器作为双亲委派机制中所采用的初始类加载器;目标栈帧是调用待加载方法的栈帧,待加载方法所属待加载类。可见,本申请实施例支持调用待加载方法的目标栈帧所在的二进制文件的路径对应的类加载器,确定双亲委派机制中所采用的初始类加载器的技术方案。
在一种可能的设计中,该方法还包括:建立该至少两个类加载器与该全量二进制文件中的类之间的对应关系;其中,第一类加载器与第一类加载器对应的二进制文件所包含的类之间存在对应关系;将当前调用待加载类的类所对应的类加载器,作为双亲委派机制中所采用的初始类加载器。这样,有助于提升类加载性能。
第二方面,本申请实施例提供了一种类加载装置,该装置包括用于执行第一方面或第一方面任一种可能的设计中的类加载方法的各个模块。该装置例如可以是计算机设备或芯片。
第三方面,本申请实施例提供了一种类加载装置,该装置包括存储器和处理器,存储器用于用于存储计算机执行指令,该装置运行时,该处理器执行该存储器中的计算机执行指令以利用该装置中的硬件资源执行第一方面或第一方面任一种可能的设计 中的方法的操作步骤。该装置例如可以是计算机设备或芯片。
第四方面,本申请实施例提供了一种计算机可读存储介质,其上储存有计算机程序,当该计算机程序在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一种可能的设计中任一种可能的方法的操作步骤。
第五方面,本申请实施例提供了一种计算机程序产品,当其在计算机上运行时,使得上述第一方面或第一方面的任一种可能的设计中任一种可能的方法的操作步骤被执行。
可以理解的是,上述提供的任一种类加载装置或计算机可读存储介质或计算机程序产品等均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考对应的方法中的有益效果,此处不再赘述。
附图说明
图1为可适用于本申请实施例的一种计算机设备的硬件结构示意图;
图2为可适用于本申请实施例的一种另一种计算机设备的硬件结构示意图;
图3为本申请实施例提供的一种建立哈希表的方法的示意图;
图4为本申请实施例提供的一种基于类名生成的哈希表的示意图;
图5为本申请实施例提供的一种应用程序启动阶段计算机设备所执行的步骤的示意图;
图6为本申请实施例提供的一种应用程序运行阶段计算机设备所执行的步骤的示意图;
图7为本申请实施例提供的一种类加载器、SO文件和类加载器域之间的对应关系的示意图;
图8为本申请实施例提供的一种确定双亲委托机制所采用的初始类加载器的对比示意图;
图9为本申请实施例提供的一种类加载方法的流程示意图;
图10为本申请实施例提供的一种类加载装置的结构示意图。
具体实施方式
首先,对本申请实施例中所涉及的术语进行简单介绍,以方便读者理解:
类:是一种抽象的数据类型,它是对所具有相同特征实体的抽象。本申请实施例中所描述类通常是指java类。在一个示例中,可以认为一个类是多个属性和方法的集合。
类信息:一个类的类信息可以包括该类的类名、类定义、类的属性、方法等。
类的全量信息:是指执行该类所需的全部信息。例如,类的全量信息包括该类的所有类信息如类名、类定义、类的属性、方法以及属性和方法的对外可见性等。
作为一个示例,类的全量信息可以包括如表1所示的各种信息:
表1
类的全量信息 说明
shadow 用于指示类本身的类型java/lang/Class
clindex 用于指示所对应的类加载器域
sizeinfo 用于指示类及其对象(Object)的内存占用大小
itab 用于指示类的接口(Interface)方法相关信息
vtab 用于指示类的虚拟(Virtual)方法相关信息
classname 用于指示类的名称。
fields 用于指示所有的成员变量信息,包括静态变量和实例变量
methods 用于指示所有的成员方法信息
superclasses 用于指示所有的Super Class信息,包含所实现的接口信息
initstate 用于指示此类是否已经初始化
应当理解的是,表1所示的各种信息仅为类的全量信息的一个示例,实际实现时,一个类的全量信息可以包括比表1所示的信息更多或更少的信息。
类加载器(classloader),是加载java类到虚拟机中的逻辑单元。
二进制文件:广义的二进制文件是指文件,由文件在外部设备的存放形式为二进制而得名。狭义的二进制文件是除文本文件以外的文件。Dex文件、Oat文件或SO文件都属于二进制文件。如果不加说明,下文中的二进制文件均是以SO文件为例进行说明的。其中,Dex文件是Android虚拟机下的一种目标文件,包含应用程序的所有操作指令和运行时所需的数据。Oat文件是Dex文件经过静态(ahead of time,AOT)编译优化后的一种可执行文件。Oat文件可以基于AOT编译器的静态引导得到。SO文件是一种可执行格式(executable and linking format,ELF)文件,也称为动态库文件或共享库文件。
桶(bucket):也称为哈希桶,是哈希表内元素的虚拟子群组,同一个桶内的元素所对应的哈希值相同,不同桶内的元素所对应的哈希值不同。在本申请的一些实施例中,桶内的元素可以是类地址。
本申请实施例中的术语“至少一个(种)”包括一个(种)或多个(种)。“多个(种)”是指两个(种)或两个(种)以上。例如,A、B和C中的至少一种,包括:单独存在A、单独存在B、同时存在A和B、同时存在A和C、同时存在B和C,以及同时存在A、B和C。在本申请的描述中,除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。“多个”是指两个或多于两个。另外,为了便于清楚描述本申请实施例的技术方案,在本申请的实施例中,采用了“第一”、“第二”等字样对功能和作用基本相同的相同项或相似项进行区分。本领域技术人员可以理解“第一”、“第二”等字样并不对数量和执行次序进行限定,并且“第一”、“第二”等字样也并不限定一定不同。
如图1所示,为可适用于本申请实施例的一种计算机设备100的硬件结构示意图。图1所示的计算机设备100包括:至少一个处理器101、通信线路102、存储器103以及至少一个通信接口104。其中:
处理器101可以是一个通用中央处理器(central processing unit,CPU),微处理器,特定应用集成电路(application-specific integrated circuit,ASIC),或一个或多个用于控制本申请方案程序执行的集成电路。
通信线路102可以包括一通路,在上述组件之间传送信息。
通信接口104可以是任何收发器一类的装置,用于与其他设备或通信网络通信,如以太网,无线接入网(radio access network,RAN),无线局域网(wireless local area networks,WLAN)等。
存储器103可以是只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)或者可存储信息和指令的其他类型的动态存储设备,也可以是电可擦可编程只读存储器(electrically erasable programmable read-only memory,EEPROM)、只读光盘(compact disc read-only memory,CD-ROM)或其他光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质或者其他磁存储设备、或者能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。
存储器103可以是独立存在,通过通信线路102与处理器101相连接。或者,存储器103可以和处理器101集成在一起。本申请实施例提供的存储器103通常可以具有非易失性。其中,存储器103用于存储执行本申请方案的计算机指令,并由处理器101来控制执行。处理器101用于执行存储器103中存储的计算机指令,从而实现本申请实施例提供的方法。
本申请实施例不限定计算机设备100的类型,例如,计算机设备100可以是包含图1所示的硬件结构的通用的设备,也可以是包含图1所示的硬件结构的专用设备。
可选的,本申请实施例中的计算机指令也可以称之为应用程序代码,本申请实施例对此不作具体限定。
在具体实现中,作为一种实施例,计算机设备100可以包括多个处理器。这些处理器中的每一个可以是一个单核(single-CPU)处理器,也可以是一个多核(multi-CPU)处理器。这里的处理器可以指一个或多个设备、电路、和/或用于处理数据(例如计算机程序指令)的处理核。
在具体实现中,作为一种实施例,计算机设备100还可以包括输出设备105和输入设备106。输出设备105和处理器101通信,可以以多种方式来显示信息。例如,输出设备105可以是液晶显示器(liquid crystal display,LCD),发光二级管(light emitting diode,LED)显示设备,阴极射线管(cathode ray tube,CRT)显示设备,或投影仪(projector)等。输入设备106和处理器101通信,可以以多种方式接收用户的输入。例如,输入设备106可以是鼠标、键盘、触摸屏设备或传感设备等。
在具体实现中,作为一种实施例,如图2所示,存储器103可以包括主存储器1031和辅存储器1032。处理器101可以包括主处理器1011和辅处理器1012。其中:
主存储器1031可以是内存(memory)。
辅存储器1032可以是外存,也可以称为外存设备,例如可以是硬盘、光驱、软盘、磁盘等。辅存储器1032可以存储静态编译阶段编译得到的二进制文件(如SO文件等)等。
主处理器1011可以是CPU。主处理器1011不能直接访问辅存储器1032(如外存),只能访问主存储器1031(如内存)。
辅处理器1012可以是直接内存存取(direct memory access,DMA)处理器等可以 从辅存储器1032(如外存)中读取数据至主存储器1031(如内存)中的处理器。
以主处理器1011是CPU、辅处理器1012是DMA处理器、主存储器1031是内存、且辅存储器1032是外存为例,数据由外存到内存再到CPU的过程可以包括:内存向CPU发出读取外设指令,CPU将系统总线控制权限交给DMA处理器;DMA处理器将数据从外存读入内存;CPU从DMA处理器接管总线控制权;CPU向内存发出读取数据命令;CPU对数据进行运算处理,同时和内存进行必要的数据交换;处理结束后,如果有外存读取操作,CPU可以将结果数据发送到外存。
在一个示例中,计算机设备100运行应用程序(包括系统服务进程或应用等)的过程可以理解为是CPU调用方法的过程。所调用的方法属于一个类。在一个示例中,调用方法,可以理解为是调用函数。因此,可以由DMA处理器先将外存中存储的待加载方法所属的类的类信息加载到内存中,并由CPU读取内存中的数据,以执行该待加载方法。
以下,结合附图,说明本申请实施例提供的技术方案进行说明。为了清楚说明本申请实施例提供的技术方案,以下通过静态编译阶段、应用程序启动阶段和应用程序运行阶段进行说明。其中,本申请提供的类加载方法可以包含在应用程序运行阶段和/或应用程序启动阶段,因此,下文不再对类加载方法进行单独说明。
静态编译阶段
在静态编译阶段,静态编译器工具链编译动态库,即将Dex文件编译成SO文件。其中,本申请实施例对将Dex文件编译成SO文件的具体实现方式不进行限定,例如可以参考现有技术。需要说明的是,应用于本申请实施例时,在将Dex文件编译成SO文件的过程中,静态编译器工具链可以基于该Dex文件中的类的类名生成哈希表,该哈希表是SO文件的一部分。
具体的:对于任意一个待编译Dex文件来说,静态编译器工具链可以对待编译Dex文件中的所有类的类名分别进行哈希运算,得到每个类名的哈希值,并建立哈希表。
其中,本申请实施例对执行哈希运算时所采用的哈希算法不进行限定,例如可以是BKDR哈希算法等,其中,BKDR哈希算法来自于Kernighan and Dennis Ritchie合著的C语言编程一书,是2个人名合起来的简写。采用BKDR哈希算法进行哈希运算的一个示例如下:
Figure PCTCN2020081220-appb-000001
可选的,如图3所示,建立哈希表的过程可以包括以下步骤:
S101:静态编译器工具链生成待编译Dex文件中每个类的类地址。每个类的类地址所指示的存储空间中用于存放该类的全量信息。其中,一个Dex文件可以包括一个或多个类。
在本申请的一些实施例中,每个类对应一个类地址。类地址可以是虚拟地址(即 逻辑地址)或物理地址。本申请实施例对此不进行具体限定。
S102:静态编译器工具链建立待编译Dex文件中每个类的类地址与该类的类名的哈希值之间的对应关系。基于此,后续可以通过寻址的方式,查找待加载类的全量信息。
可选的,S102可以包括以下步骤S102-1~S102-3:
S102-1:静态编译器工具链通过哈希值将待编译Dex文件中所有类的类地址分布到不同的桶中。每个桶包括具有相同哈希值的类地址,不同桶包括具有不同哈希值的类地址。一个类地址具有的哈希值,是指该类地址表示的存储空间中存放的类信息包括的类名的哈希值。
也就是说,静态编译器工具链通过建立类地址与该类地址所属的桶之间的对应关系,和桶与哈希值之间的对应关系,来建立每个类的类地址与该类的类名的哈希值之间的对应关系。
作为一个示例,静态编译器工具链可以采用固定数量的桶,并根据桶所对应的哈希值大小从低到高连续存放所有桶。为了便于描述,下文中均以此为例进行说明。
作为一个示例,对于多个桶来说,静态编译器工具链可以按照桶所对应的哈希值大小从低到高对桶进行编号。为了便于描述,下文中均以此为例进行说明。
S102-2:静态编译器工具链为每个桶分配一个首地址和一个尾地址,其中,每个桶所包括的类地址存放在该桶的首地址和尾地址所限定的存储空间中。
例如,假设对从0开始各桶分别进行连续编号,那么对于桶m(即编号为m的桶)来说:如果m=0,则桶0的首地址是各桶的首地址,桶0的尾地址是基于桶0所包含的类地址的数量确定的;如果m>0,则桶m的首地址是基于桶m-1的尾地址确定的,桶m的尾地址是基于桶m所包含的类地址的数量确定的。0≤m≤M-1,M是桶的数量,m和M均是整数。
为了方便描述,本申请实施例中,是以每个桶中连续存放其所包含的类地址为例进行说明的。也就是说,如果一个桶中包括A个类地址,则该桶的尾地址与首地址之差为A,A是大于或等于0的整数。当然本申请实施例不限于此。
S102-3:静态编译器工具链创建对待编译Dex文件进行编译后得到的SO文件的第一字段(section)和第二字段。其中,第一字段用于存放该SO文件包括的所有桶的首地址。第二字段用于存放该SO文件包括的所有桶的尾地址。
作为一个示例,第一字段中所存放的首地址所属的桶的编号由低到高连续排列,第二字段中所存放的尾地址所属的桶的编号由低到高连续排列。
每个SO文件本质上都是一个Elf文件,包含Elf头(header)和多个字段,其中每个SO文件中包含一个哈希表,例如,如图4所示的哈希表。
如图4所示,为本申请实施例提供的一种基于类名生成的哈希表的示意图。图4所示的哈希表是一个SO文件中的哈希表。其中,①表示SO文件的第一字段。②表示SO文件的第二字段。③表示桶0,④表示桶1;且桶m对应哈希值m。若桶0包括11个类地址,桶1包括10个类地址,则桶0的首地址“__class_hashtab_bucket_0_start__”可以是地址0,尾地址“__class_hashtab_bucket_0_end__”可以是地址10;相应的,桶1首地址“__class_hashtab_bucket_1_start__”可以是地址11,尾地址 “__class_hashtab_bucket_1_end__”可以是地址21。⑤表示桶0中的第一个类地址所指示的存储空间中存储的类的全量信息,具体包括:类名(如“__classinfo__Ljava_2Flang_2FString_24CaseInsensitiveComparator_3B”)和其他信息。结合图4,可以认为:本申请实施例所描述的哈希表包含一个SO文件中的每个类和该类的组织关系。
需要说明的是,在一些实施例中,在静态编译阶段,确定桶的数量,如根据SO中所包含的类的数量确定桶的数量。在另一些实施例中,在应用程序启动阶段或应用程序运行阶段,确定桶的数量、桶与类地址之间的对应关系等。例如,所包含的类的数量较多的SO文件,所对应的桶的数量相对较多。这样,对于所包含的类数量较大的SO文件,有助于减少冲突率。其中,同一桶中所包含的类的数量越多,则冲突率越高。
可以理解的是,静态编译阶段所编译获得的SO文件通常会存储在计算机设备的外存中。
应用程序启动阶段
作为一个示例,如图5所示,在应用程序启动阶段,计算机设备可以执行如下步骤:
S201:在计算机设备中安装的应用程序启动时,将外存中的运行该应用程序所需的全量SO文件(即全部的SO文件)加载到内存中。例如,结合图2,计算机设备中的DMA处理器通过一次或多次加载,将外存中存储的运行该应用程序所需的全量SO文件加载到内存中。
其中,应用程序可以包括系统服务进程或应用(application,APP)等。
S202:计算机设备创建该应用程序的至少一个类加载器,例如通常建立多个类加载器。
作为一个示例,结合图2,S202的执行主体具体可以是计算机设备中的CPU。
其中,针对一个应用程序创建类加载器的具体实现方式可以参考现有技术(如现有基于Art运行模式的技术等)。可选的,如果针对该应用程序创建了多个类加载器,则计算机设备还可以创建该多个类加载器之间的父子关系,其具体实现过程可以参考现有技术(如现有基于Art运行模式的技术等)。
S203:计算机设备建立该至少一个类加载器与该全量SO文件之间的对应关系。其中,一个类加载器与一个或多个SO文件存在对应关系,一个SO文件仅与一个类加载器存在对应关系;一个类加载器用于在与自身存在对应关系的SO文件中查找待加载类的类信息。
计算机设备建立的该应用程序的至少一个类加载器与运行该应用程序所需的全量SO文件之间的对应关系的具体实现方式,可以参考现有技术(如现有基于Art运行模式的技术等)中的建立该应用程序的至少一个类加载器与运行该应用程序所需的全量Dex文件之间的对应关系。具体的,如果该至少一个类加载器中的类加载器i与该全量Dex文件中的Dex文件j之间对应,则类加载器i与SO文件j之间对应。其中,SO文件j是在静态编译期对Dex文件j进行编译得到SO文件。1≤i≤I,1≤j≤J,I是计算机设备所创建的该应用程序的类加载器的数量,J是计算机设备运行该应用程序所需的全量SO文件(或Dex文件)的数量。I、J、i和j均是整数,I<J。
S204:对于该至少一个类加载器中的任意一个类加载器来说,计算机设备通过系统调用方法打开与该类加载器对应的所有SO文件,并获得每个SO文件的第一字段(如图4中的__class_hashtab_start__)和第二字段(如图4中的__class_hashtabend_start__),并初始化每个SO文件中的所有类的类加载器域。该步骤是为该应用程序运行时执行类加载做准备。
在一个示例中,如图7所示,计算机设备所创建的每个类加载器的序号可以保存在类加载器列表①中,序号从0开始,类加载器之间可能存在父子关系,如图示中④中表示类加载器0的父亲是类加载器1。图7中是以类加载器0对应3个SO文件,如图中②表示的SO文件1、SO文件2和SO文件3为例进行说明的。每个SO文件可以包含Elf头和哈希表,其中,图7中的“.class_hashtab”表示哈希表。
每个类的类信息还可以包括类加载器域,如图7中的③所示。一个类的类加载器域中的信息可以用于表示该类所属的类加载器在类加载器列表①中的序号,如图7中SO文件2中的所有类的类加载器域中均被设置成CLIndex=0(即类加载器的索引或编号为0)。其中,一个类所属的类加载器是该类所属的SO文件所对应的类加载器。
上述S201~S204可以认为是执行类加载方法的准备阶段,基于此,后续所执行的类加载方法,具体为在内存中查询类的方法。这样,可以提高查找(或类加载)效率,从而缩短查找(或类加载)时间。需要说明的是,类加载方法可以在应用程序启动阶段和/或运行阶段执行,下文中均是以在应用程序运行阶段为例进行说明的。
应用程序运行阶段
作为一个示例,如图6所示,在应用程序运行阶段,计算机设备可以执行如下步骤:
S301:计算机设备确定当前需要调用的方法(即待加载方法),并将该方法所属的类作为待加载类。
S302:计算机设备根据哈希算法,对待加载类的类名进行哈希运算,得到目标哈希值。
其中,S302中所采用的哈希算法与上述静态编译阶段所采用的哈希算法相同。
S303:计算机设备在该应用程序的至少一个类加载器中确定待加载类的初始类加载器。
在一些实施例中,初始类加载器可以是显式指示的,如由用户指示给计算机设备的。
在另一些实施例中,在没有显式指示初始类加载器的情况下,本申请实施例提供了以下实现方式:
方式1:计算机设备根据该至少一个类加载器与该全量SO文件之间的对应关系,确定待加载方法的调用栈的目标栈帧所在的SO文件所对应的类加载器,并将所确定的类加载器作为待加载类的初始类加载器。其目标栈帧是调用(如直接或间接调用)待加载方法的栈帧。
例如,如果运行应用程序的过程中,需要调用方法A;在执行方法A的过程中,需要调用方法B;在调用方法B的过程中,需要调用方法C。那么,“方法A→方法B→方法C”即为一个调用栈,调用栈中的每个方法为该调用栈的一个栈帧。若待加载方法 是方法C,那么,目标栈帧可以是直接调用方法C的栈帧即方法B,或者是间接调用方法C的栈帧即方法A。
可以理解的是,在上述S203中已经建立了应用程序的至少一个类加载器与运行该应用程序所需的全量SO文件之间的对应关系。具体实现时,SO文件的路径可以作为SO文件的标识信息,因此,在一种实现方式中,一个类加载器与一个SO文件之间的对应关系,可以包括:该类加载器与该SO文件的路径之间的对应关系。基于此,方式1可以描述为:计算机设备根据该至少一个类加载器与该全量SO文件的路径之间的对应关系,确定目标栈帧所在的SO文件的路径所对应的类加载器,并将所确定的类加载器作为初始类加载器。
方式2:计算机设备将待加载类的调用者所对应的类加载器,作为待加载类的初始类加载器。待加载类的调用者是指当前调用待加载类的类。
在上述S204中已经初始化了每个SO文件中的所有类的类加载器域,也就是说,已经建立了该至少一个类加载器与该全量SO文件中的类之间的对应关系;其中,一个类加载器与该加载器对应的SO文件所包含的类之间存在对应关系。方式2提供的技术方案中,可以使用待加载类的调用者对应的类加载器域所指示的类加载器,作为待加载类的初始类加载器。
需要说明的是,基于Art运行模式的技术中,通常通过回栈(back stack)获取初始类加载,其中,回栈是获得当前待加载方法的调用栈中的某一栈。然而,回栈存在一定的时间开销,因此,本申请实施例中,直接使用待加载类的调用者所对应的类加载器作为初始类加载器,可以避免应用程序在运行时触发回栈所带来的时间开销。如果回栈触发频率越高,则使用方式2可以节省更多的CPU运行时间。
以Class.forName()为例,假设需要在类A中通过Class.forName()方法来加载Test类(如图8所示的①),且没有指定初始类加载器,则:基于Art运行模式的技术中,是在应用程序运行时通过VMStack.getCallingClassLoader()来获得初始类加载器(如图8所示的②)。的这个方法是通过回栈来实现的。本申请实施例中,在静态编译阶段就定义了每个类(包括类A)的类加载器域,如图8中所示的③中A.getClassLoader(),并且,在执行类加载之前,初始化了每个类的类加载域,因此,可以在没有指定初始类加载器时,直接调用A.getClassLoader(),即直接将特定类加载器域的初始值所指示的类加载器作为初始类加载器,该特定类加载器域是待加载类的调用者所对应的类加载器域。这比回栈的性能快很多。也就是说,通过图8中所示的②替换③,从而提升类加载性能。
S304:计算机设备基于待加载类的初始类加载器,并根据双亲委派机制,在该至少一个类加载器中确定当前执行加载操作的类加载器,并在该全量SO文件中查找待加载类的类名对应的待加载类的全量信息。
以应用于Art运行模式为例,传统技术中的双亲委派机制包括:
1)、当需要记载待加载类时,触发类加载请求。并确定是否加载过待加载类,如果加载过(即内存中存储有待加载类的类信息),则直接返回。
2)、如果没有加载过,则根据如下规则“优先把类加载请求委托给初始类加载器的父类加载器去执行,如果父类加载器还存在其父类加载器,则进一步向上委托,依 次递归,类加载请求最终将到达顶层的启动类加载器,如果父类加载器可以完成类加载任务,就成功返回。如果父类加载器无法完成加载任务,子加载器才会尝试自己去执行加载任务”确定当前执行加载操作的类加载器。
基于上述S201可知,在本申请的一些实施例中,在应用程序启动时,会将运行该应用程序所需的全量SO文件均加载到内存中。基于此,上述S304中,根据双亲委派机制,在该至少一个类加载器中确定当前执行加载操作的类加载器,可以包括:当需要记载待加载类时,触发类加载请求,并根据上述2)中的规则,在该至少一个类加载器中确定当前执行加载操作的类加载器。基于此,可以将S304作为变种的(或演进的或新的)双亲委派机制。
S305:计算机设备根据所查找到的待加载类的全量信息,运行应用程序。
具体实现时,基于类加载器加载类,本质就是从该类加载器所管理的所有SO文件中查找待加载类。其中,对于任意一个SO文件来说,计算机设备可以基于该SO文件所对应的类加载器,执行以下步骤,如图9所示,以查找待加载类的全量信息:
S401:根据多个哈希值与M个桶之间的对应关系,从该多个哈希值中查找目标哈希值,并获取目标哈希值对应的桶。例如,根据多个哈希值与M个桶的编号之间的对应关系,从该多个哈希值中查找目标哈希值,并获取目标哈希值对应的桶的编号。
例如,假设目标哈希值是H,则目标哈希值对应的桶是M个桶中的第H+1个桶。
S402:从M个桶的首地址和尾地址中,查找目标哈希值对应的桶的首地址和尾地址。
基于S401中的示例,从该SO文件的第一字段的第一个地址(即桶0的首地址)开始,将目标哈希值H作为偏移量,得到目标哈希值对应的桶的首地址。同理,从该SO文件的第二字段的第一个地址(即桶0的尾地址)开始,将目标哈希值H作为偏移量,得到目标哈希值对应的桶的尾地址。
S403:从目标哈希值对应的桶的首地址至尾地址所限定的存储空间中,读取目标哈希值对应的桶所包括的类地址,并将所读取的类地址作为目标哈希值对应的类地址。
基于S402中的示例,假设目标哈希值H对应的桶是桶0,则根据图4中所示的⑨和⑦,即可确定目标哈希值对应的桶所包括的类地址。假设目标哈希值H对应的桶是桶1,则根据图4中所示的⑧和⑥,即可确定目标哈希值对应的桶所包括的类地址。
S404:在目标哈希值对应的类地址所指示的存储空间中,查找待加载类的类名。其中,待加载类的类名是待加载类的全量信息中的一部分。
基于S403中的示例,假设目标哈希值H对应的桶是桶0,则根据图4中所示的⑩,可以确定目标哈希值对应的类地址所指示的存储空间。并判断该存储空间中存储的类名与待加载类的类名是否匹配,如果相同则认为匹配(即已查找到);否则,认为不匹配(即没有查找到)。
S405:如果查找到,则将目标哈希值对应的类地址所指示的存储空间中存储的类的全量信息,作为待加载类的全量信息。
可以理解的是,如果查找不到,说明该SO文件中没有存储待加载类的类信息,则在该类加载器所对应的下一个SO文件中查找待加载类的全量信息。如果遍历完该类加载器对应的所有SO文件之后,仍然查找不到待加载类的全量信息,则根据双亲 委派机制继续由下一个类加载器负责查找,直到查找到待加载类的全量信息。如果遍历完该应用程序的所有类加载器之后,仍然查找不到待加载类的全量信息,则计算机设备输出异常处理信息。
本申请实施例提供的技术方案,与基于Art运行模式的技术的主要区别在于,本申请实施例中在静态执行阶段建立的是类名与类的全量信息之间的对应关系,而基于Art运行模式的技术中建立的是类名与类定义之间的对应关系。基于此,可知,在进行类加载时,本申请实施例可以直接根据类名查找到该类名对应的全量信息,而基于Art运行模式的技术根据类名仅能查找到该类名对应的类定义,后续可以基于动态分配内存加载类数据,并通过动态链接填充类的属性、方法等信息,因此,相比基于Art运行模式的技术,本申请实施例提供的技术方案能够更快地进行类加载。
另外,在本申请的一些实施例中,在应用程序启动时,将运行该应用程序所需的全量SO文件均加载到内存中,这样,在应用程序运行时,类加载实质上为在内存中进行类查找,这样,可以进一步提高类加载速率。尤其是相对基于Art运行模式的技术下首次加载类信息时,本申请试试提供的技术方案,能够使系统和应用运行更快。
另外,本申请实施例提供的技术方案填补了安卓操作系统中运用静态编译技术将Dex文件转成SO文件后进行类加载的空白,实现了一套兼容安卓操作系统正常运行的类加载机制。
上述主要从方法的角度对本申请实施例提供的方案进行了介绍。为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
本申请实施例可以根据上述方法示例对类加载装置进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
如图10所示,为本申请实施例提供的一种类加载装置90的结构示意图。该装置90可以用于执行图6、图8或图9所示的方法。示例的,该装置90可以是上文中的计算机设备。
该装置90可以包括目标二进制文件,目标二进制文件包括多个类的类名与所述多个类的全量信息之间的对应关系,类名与类的全量信息一一对应。该装置90包括:确定单元901、查找单元902和运行单元903。其中,确定单元901,用于确定运行该装置90中的应用程序时所需的待加载类的类名。查找单元902,用于根据该多个类的类名与该多个类的全量信息之间的对应关系,在该多个类的类名中查找待加载类的类名,并获取待加载类的类名对应的全量信息;该多个类包括第一类,第一类的全量信息是指运行第一类所需的全部信息。运行单元903,用于根据待加载类的类名对应的全量 信息,运行该应用程序。例如,结合图6,确定单元901具体可以用于执行S301,查找单元902具体可以用于执行S302~S304,运行单元903可以用于执行S305。
可选的,目标二进制文件还包括:该多个类的类地址,以及该多个类的类地址与该多个类的类名的哈希值之间的对应关系;一个类的类地址所指示的存储空间用于存储一个类的全量信息。相应的,查找单元902还用于,根据该多个类的类地址与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的类地址;其中,目标哈希值是待加载类的类名的哈希值。在根据该多个类的类名与该多个类的全量信息之间的对应关系,在该多个类的类名中查找待加载类的类名,并获取待加载类的类名对应的全量信息的方面,查找单元902具体用于:在目标哈希值对应的类地址所指示的存储空间中,查找待加载类的类名,其中,待加载类的类名是待加载类的全量信息的一部分;将目标哈希值对应的类地址所指示的存储空间中的全量信息,作为待加载类的全量信息。例如,结合图9,查找单元902具体可以用于执行S403~S405。
可选的,一个哈希值对应一个桶,一个桶包括零个、一个或多个类地址;在根据该多个类的类地址与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的类地址的方面,查找单元902具体用于:根据多个桶与该多个类的类名的哈希值之间的对应关系,在该多个类的类名的哈希值中查找目标哈希值,并获取目标哈希值对应的桶,并将目标哈希值对应的桶所包括的类地址作为目标哈希值对应的类地址。例如,结合图9,查找单元902具体可以用于执行S403。
可选的,一个桶具有一个首地址和一个尾地址,该多个桶包括第一桶,第一桶的首地址和尾地址所限定的存储空间用于存储第一桶包括的类地址。相应的,查找单元902还用于:从该多个桶的首地址和尾地址中,查找目标哈希值对应的桶的首地址和尾地址;从目标哈希值对应的桶的首地址至尾地址所限定的存储空间中,读取目标哈希值对应的桶所包括的类地址。例如,结合图9,查找单元902具体可以用于执行S401~S402。
可选的,该装置90还包括:加载单元904,用于将运行上述应用程序所需的全量二进制文件从该装置90的外存加载到该装置90的内存中;全量二进制文件包括目标二进制文件。
可选的,该装置90还包括:创建单元905,用于创建上述应用程序的至少两个类加载器,并建立该至少两个类加载器与该全量二进制文件之间的对应关系;该至少两个类加载器包括第一类加载器,第一类加载器用于在与第一类加载器对应的二进制文件中查找待加载类的全量信息。例如,结合图5,创建单元905可以用于执行S202和S203。
可选的,确定单元901还用于,根据双亲委派机制,在该至少两个类加载器中确定当前执行查找操作的类加载器,以通过所确定的当前执行查找操作的类加载器,在运行上述应用程序所需的全量二进制文件中查找待加载类的全量信息。例如,结合图6,确定单元901可以用于执行S303。
可选的,类加载器与二进制文件存在对应关系,包括:类加载器与二进制文件的 路径存在对应关系;相应的,查找单元902还用于,根据该至少两个类加载器与该全量二进制文件的路径之间的对应关系,在该全量二进制文件的路径中查找目标栈帧所在的二进制文件的路径,并获取目标栈帧所在的二进制文件的路径对应的类加载器,将所确定的类加载器作为双亲委派机制中所采用的初始类加载器;目标栈帧是调用待加载计算机设备的栈帧,待加载计算机设备所属所述待加载类。例如,结合图6,确定单元901可以用于执行S303。
可选的,创建单元905还用于,建立该至少两个类加载器与该全量二进制文件中的类之间的对应关系;其中,第一类加载器与第一类加载器对应的二进制文件所包含的类之间存在对应关系;确定单元901还用于,将当前调用待加载类的类所对应的类加载器,作为双亲委派机制中所采用的初始类加载器。
可选的,上述二进制文件包括SO文件。
上述所描述的任意一种装置90均可以用于执行上述方法实施例中的相应步骤,因此,其相关内容的解释及有益效果均可以参考上述方法实施例中的相应描述,此处不再赘述。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件程序实现时,可以全部或部分地以计算机程序产品的形式来实现。该计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机执行指令时,全部或部分地产生按照本申请实施例的流程或功能。计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,计算机指令可以从一个网站站点、计算机、服务器或者数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可以用介质集成的服务器、数据中心等数据存储设备。可用介质可以是磁性介质(例如,软盘、硬盘、磁带),光介质(例如,DVD)、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。
以上所述,仅为本申请的具体实施方式。熟悉本技术领域的技术人员根据本申请提供的具体实施方式,可想到变化或替换,都应涵盖在本申请的保护范围之内。

Claims (21)

  1. 一种类加载方法,其特征在于,应用于计算机设备,所述计算机设备包括目标二进制文件,所述目标二进制文件包括多个类的类名与所述多个类的全量信息之间的对应关系,类名与类的全量信息一一对应;所述方法包括:
    确定运行所述计算机设备中的应用程序时所需的待加载类的类名;
    根据所述多个类的类名与所述多个类的全量信息之间的对应关系,在所述多个类的类名中查找所述待加载类的类名,并获取所述待加载类的类名对应的全量信息;其中,所述多个类包括第一类,所述第一类的全量信息是指运行所述第一类所需的全部信息;
    根据所述待加载类的类名对应的全量信息,运行所述应用程序。
  2. 根据权利要求1所述的方法,其特征在于,所述目标二进制文件还包括:所述多个类的类地址,以及所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系;一个类的类地址所指示的存储空间用于存储一个类的全量信息;所述方法还包括:
    根据所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找目标哈希值,并获取所述目标哈希值对应的类地址;其中,所述目标哈希值是所述待加载类的类名的哈希值;
    所述根据所述多个类的类名与所述多个类的全量信息之间的对应关系,在所述多个类的类名中查找所述待加载类的类名,并获取所述待加载类的类名对应的全量信息,包括:
    在所述目标哈希值对应的类地址所指示的存储空间中,查找所述待加载类的类名,其中,所述待加载类的类名是所述待加载类的全量信息的一部分;将所述目标哈希值对应的类地址所指示的存储空间中的全量信息,作为所述待加载类的全量信息。
  3. 根据权利要求2所述的方法,其特征在于,一个哈希值对应一个桶,一个桶包括零个、一个或多个类地址;所述根据所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找所述目标哈希值,并获取所述目标哈希值对应的类地址,包括:
    根据多个桶与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找所述目标哈希值,并获取所述目标哈希值对应的桶,并将所述目标哈希值对应的桶所包括的类地址作为所述目标哈希值对应的类地址。
  4. 根据权利要求3所述的方法,其特征在于,一个桶具有一个首地址和一个尾地址,所述多个桶包括第一桶,所述第一桶的首地址和尾地址所限定的存储空间用于存储所述第一桶包括的类地址;在所述将所述目标哈希值对应的桶所包括的类地址作为所述目标哈希值对应的类地址之前,所述方法还包括:
    从所述多个桶的首地址和尾地址中,查找所述目标哈希值对应的桶的首地址和尾地址;
    从所述目标哈希值对应的桶的首地址至尾地址所限定的存储空间中,读取所述目标哈希值对应的桶所包括的类地址。
  5. 根据权利要求1至4任一项所述的方法,其特征在于,在所述确定运行所述计 算机设备中的应用程序时所需的待加载类的类名之前,所述方法还包括:
    将运行所述应用程序所需的全量二进制文件从所述计算机设备的外存中加载到所述计算机设备的内存中;所述全量二进制文件包括所述目标二进制文件。
  6. 根据权利要求5所述的方法,其特征在于,所述方法还包括:
    创建所述应用程序的至少两个类加载器;
    建立所述至少两个类加载器与所述全量二进制文件之间的对应关系;其中,所述至少两个类加载器包括第一类加载器,所述第一类加载器用于在与所述第一类加载器对应的二进制文件中查找所述待加载类的全量信息。
  7. 根据权利要求6所述的方法,其特征在于,所述方法还包括:
    根据双亲委派机制,在所述至少两个类加载器中确定当前执行查找操作的类加载器,以通过所述确定的当前执行查找操作的类加载器,在所述全量二进制文件中查找所述待加载类的全量信息。
  8. 根据权利要求7所述的方法,其特征在于,类加载器与二进制文件存在对应关系,包括:类加载器与二进制文件的路径存在对应关系;所述方法还包括:
    根据所述至少两个类加载器与所述全量二进制文件的路径之间的对应关系,在所述全量二进制文件的路径中查找目标栈帧所在的二进制文件的路径,并获取所述目标栈帧所在的二进制文件的路径对应的类加载器,将所确定的类加载器作为所述双亲委派机制中所采用的初始类加载器;所述目标栈帧是调用待加载方法的栈帧,所述待加载方法所属所述待加载类。
  9. 根据权利要求7所述的方法,其特征在于,所述方法还包括:
    建立所述至少两个类加载器与所述全量二进制文件中的类之间的对应关系;其中,所述第一类加载器与所述第一类加载器对应的二进制文件所包含的类之间存在对应关系;
    将当前调用所述待加载类的类所对应的类加载器,作为所述双亲委派机制中所采用的初始类加载器。
  10. 根据权利要求1至9任一项所述的方法,其特征在于,所述二进制文件包括共享动态链接库SO文件。
  11. 一种计算机设备,其特征在于,所述计算机设备包括目标二进制文件,所述目标二进制文件包括多个类的类名与所述多个类的全量信息之间的对应关系,类名与类的全量信息一一对应;所述计算机设备包括:
    确定单元,用于确定运行所述计算机设备中的应用程序时所需的待加载类的类名;
    查找单元,用于根据所述多个类的类名与所述多个类的全量信息之间的对应关系,在所述多个类的类名中查找所述待加载类的类名,并获取所述待加载类的类名对应的全量信息;其中,所述多个类包括第一类,所述第一类的全量信息是指运行所述第一类所需的全部信息;
    运行单元,用于根据所述待加载类的类名对应的全量信息,运行所述应用程序。
  12. 根据权利要求11所述的计算机设备,其特征在于,所述目标二进制文件还包括:所述多个类的类地址,以及所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系;一个类的类地址所指示的存储空间用于存储一个类的全量信息;
    所述查找单元还用于,根据所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找目标哈希值,并获取所述目标哈希值对应的类地址;其中,所述目标哈希值是所述待加载类的类名的哈希值;
    在所述根据所述多个类的类名与所述多个类的全量信息之间的对应关系,在所述多个类的类名中查找所述待加载类的类名,并获取所述待加载类的类名对应的全量信息的方面,所述查找单元具体用于:在所述目标哈希值对应的类地址所指示的存储空间中,查找所述待加载类的类名,其中,所述待加载类的类名是所述待加载类的全量信息的一部分;将所述目标哈希值对应的类地址所指示的存储空间中的全量信息,作为所述待加载类的全量信息。
  13. 根据权利要求12所述的计算机设备,其特征在于,一个哈希值对应一个桶,一个桶包括零个、一个或多个类地址;在所述根据所述多个类的类地址与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找所述目标哈希值,并获取所述目标哈希值对应的类地址的方面,所述查找单元具体用于:
    根据多个桶与所述多个类的类名的哈希值之间的对应关系,在所述多个类的类名的哈希值中查找所述目标哈希值,并获取所述目标哈希值对应的桶,并将所述目标哈希值对应的桶所包括的类地址作为所述目标哈希值对应的类地址。
  14. 根据权利要求13所述的计算机设备,其特征在于,一个桶具有一个首地址和一个尾地址,所述多个桶包括第一桶,所述第一桶的首地址和尾地址所限定的存储空间用于存储所述第一桶包括的类地址;所述查找单元还用于:
    从所述多个桶的首地址和尾地址中,查找所述目标哈希值对应的桶的首地址和尾地址;
    从所述目标哈希值对应的桶的首地址至尾地址所限定的存储空间中,读取所述目标哈希值对应的桶所包括的类地址。
  15. 根据权利要求11至14任一项所述的计算机设备,其特征在于,所述计算机设备还包括:
    加载单元,用于将运行所述应用程序所需的全量二进制文件从所述计算机设备的外存加载到所述计算机设备的内存中;所述全量二进制文件包括所述目标二进制文件。
  16. 根据权利要求15所述的计算机设备,其特征在于,所述计算机设备还包括:
    创建单元,用于创建所述应用程序的至少两个类加载器,并建立所述至少两个类加载器与所述全量二进制文件之间的对应关系;所述至少两个类加载器包括第一类加载器,所述第一类加载器用于在与所述第一类加载器对应的二进制文件中查找所述待加载类的全量信息。
  17. 根据权利要求16所述的计算机设备,其特征在于,
    所述确定单元还用于,根据双亲委派机制,在所述至少两个类加载器中确定当前执行查找操作的类加载器,以通过所述确定的当前执行查找操作的类加载器,在所述全量二进制文件中查找所述待加载类的全量信息。
  18. 根据权利要求17所述的计算机设备,其特征在于,类加载器与二进制文件存在对应关系,包括:类加载器与二进制文件的路径存在对应关系;
    所述查找单元还用于,根据所述至少两个类加载器与所述全量二进制文件的路径 之间的对应关系,在所述全量二进制文件的路径中查找目标栈帧所在的二进制文件的路径,并获取所述目标栈帧所在的二进制文件的路径对应的类加载器,将所确定的类加载器作为所述双亲委派机制中所采用的初始类加载器;所述目标栈帧是调用待加载计算机设备的栈帧,所述待加载计算机设备所属所述待加载类。
  19. 根据权利要求17所述的计算机设备,其特征在于,
    所述创建单元还用于,建立所述至少两个类加载器与所述全量二进制文件中的类之间的对应关系;其中,所述第一类加载器与所述第一类加载器对应的二进制文件所包含的类之间存在对应关系;
    所述确定单元还用于,将当前调用所述待加载类的类所对应的类加载器,作为所述双亲委派机制中所采用的初始类加载器。
  20. 根据权利要求11至19任一项所述的计算机设备,其特征在于,所述二进制文件包括共享动态链接库SO文件。
  21. 一种类加载装置,其特征在于,包括:存储器和处理器;所述存储器用于存储计算机指令,所述处理器用于调用所述计算机指令,以执行权利要求1至10任一项所述的类加载方法中的操作步骤。
PCT/CN2020/081220 2019-03-25 2020-03-25 类加载方法和装置 WO2020192705A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US17/484,137 US11755341B2 (en) 2019-03-25 2021-09-24 Class loading method and apparatus

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910229643.6A CN111736913B (zh) 2019-03-25 2019-03-25 类加载方法和装置
CN201910229643.6 2019-03-25

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/484,137 Continuation US11755341B2 (en) 2019-03-25 2021-09-24 Class loading method and apparatus

Publications (1)

Publication Number Publication Date
WO2020192705A1 true WO2020192705A1 (zh) 2020-10-01

Family

ID=72609608

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/081220 WO2020192705A1 (zh) 2019-03-25 2020-03-25 类加载方法和装置

Country Status (3)

Country Link
US (1) US11755341B2 (zh)
CN (2) CN114153521A (zh)
WO (1) WO2020192705A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113873044A (zh) * 2021-10-15 2021-12-31 阿里巴巴(中国)有限公司 数据传输方法、系统、设备及存储介质
CN114924809A (zh) * 2022-05-19 2022-08-19 西安理工大学 一种基于dex文件类的流式微服务加载验证方法

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463303B (zh) * 2020-12-01 2023-11-24 中国工商银行股份有限公司 Java虚拟机类加载方法及系统
CN116974653B (zh) * 2023-09-21 2024-01-09 阿里云计算有限公司 类加载方法及系统

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040143826A1 (en) * 2003-01-16 2004-07-22 International Business Machines Corporation Externalized classloader information for application servers
US20070113234A1 (en) * 2005-11-17 2007-05-17 Bea Systems, Inc. Resource adapter classloading
CN101763257A (zh) * 2009-09-22 2010-06-30 浙江数芳科技有限公司 java类预处理通信系统及java类预处理方法
CN103647636A (zh) * 2013-12-31 2014-03-19 厦门市美亚柏科信息股份有限公司 安全访问数据的方法及装置
CN108279940A (zh) * 2016-12-30 2018-07-13 华为软件技术有限公司 一种web容器中的模块加载方法和装置

Family Cites Families (29)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6158045A (en) * 1995-11-13 2000-12-05 Object Technology Licensing Corporation Portable debugging services utilizing a client debugger object and a server debugger object with flexible addressing support
US6973646B1 (en) * 2000-07-21 2005-12-06 International Business Machines Corporation Method for compiling program components in a mixed static and dynamic environment
US6851111B2 (en) * 2000-12-15 2005-02-01 International Business Machines Corporation System and method for class loader constraint checking
KR100518584B1 (ko) * 2003-07-12 2005-10-04 삼성전자주식회사 공유 라이브러리 시스템 및 상기 시스템 구축 방법
US20070011723A1 (en) * 2005-07-07 2007-01-11 Ching-Yun Chao Method for maintaining application compatibility within an application isolation policy
US20090172648A1 (en) * 2007-12-28 2009-07-02 Gerginov Georgi A Byte code analysis library
US20110063304A1 (en) * 2009-09-16 2011-03-17 Nvidia Corporation Co-processing synchronizing techniques on heterogeneous graphics processing units
CN101968795B (zh) * 2010-09-03 2012-05-09 清华大学 一种数据块长度可变的文件系统缓存方法
CN102402427B (zh) * 2010-09-09 2015-09-02 阿里巴巴集团控股有限公司 一种Java应用程序的更新方法及装置
CN102567033B (zh) * 2010-12-14 2015-09-16 北京大学 基于嵌入式实时Java虚拟机的预先类加载方法及装置
EP2615544A1 (en) * 2011-01-26 2013-07-17 Job and Esther Technologies Ltd. A method for implementation of a software platform
CN103123593B (zh) * 2011-11-18 2016-08-31 腾讯科技(深圳)有限公司 Java应用服务器及处理Web业务的方法
CN103246525B (zh) * 2012-02-06 2017-03-08 腾讯科技(深圳)有限公司 一种实现应用运行的方法及客户端
US9325768B2 (en) * 2012-04-27 2016-04-26 Oracle International Corporation System and method for clustered transactional interoperability of multiple messaging providers using a single connector mechanism
CN103473096A (zh) * 2013-09-10 2013-12-25 浙江大学城市学院 一种在android系统的虚拟机上加载java类的方法及系统
CN104657258B (zh) * 2013-11-21 2018-10-30 腾讯科技(深圳)有限公司 一种向目标进程内注入Java字节码的方法及装置
US9785456B2 (en) * 2014-04-22 2017-10-10 Oracle International Corporation Metadata-driven dynamic specialization
CN103984548B (zh) * 2014-05-14 2018-03-06 陕西上讯信息技术有限公司 一种web应用前端框架及其构建方法、系统
CN104268159B (zh) * 2014-09-03 2017-06-20 河海大学 一种基于动态镜像的实时数据仓库数据预存取方法
US20160070557A1 (en) * 2014-09-09 2016-03-10 Tsuyoshi Yamada Information processing apparatus, information processing method, and information processing system
CN104199955B (zh) * 2014-09-15 2018-02-16 中国银行股份有限公司 信息管理系统及方法
CN105760407B (zh) * 2014-12-19 2019-08-06 乐视网信息技术(北京)股份有限公司 一种广告加载方法、装置和设备
US10268476B2 (en) * 2015-03-20 2019-04-23 ZeroTurnaround AS System and method for fast restarting of user apps
CN104764464B (zh) * 2015-03-30 2018-08-07 北京航天自动控制研究所 一种利用全量信息进行飞行器冗余诊断的方法
CN105630870B (zh) * 2015-12-16 2017-06-30 广州神马移动信息科技有限公司 搜索请求处理方法及系统
CN105608219B (zh) * 2016-01-07 2019-06-18 上海通创信息技术有限公司 一种基于聚类的流式推荐引擎、推荐系统以及推荐方法
CN105955765B (zh) * 2016-04-22 2020-03-03 北京小米移动软件有限公司 应用预加载方法及装置
CN106528255B (zh) * 2016-12-19 2019-07-12 北京小米移动软件有限公司 类加载方法及装置
CN107291480B (zh) * 2017-08-15 2020-12-15 中国农业银行股份有限公司 一种函数调用方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040143826A1 (en) * 2003-01-16 2004-07-22 International Business Machines Corporation Externalized classloader information for application servers
US20070113234A1 (en) * 2005-11-17 2007-05-17 Bea Systems, Inc. Resource adapter classloading
CN101763257A (zh) * 2009-09-22 2010-06-30 浙江数芳科技有限公司 java类预处理通信系统及java类预处理方法
CN103647636A (zh) * 2013-12-31 2014-03-19 厦门市美亚柏科信息股份有限公司 安全访问数据的方法及装置
CN108279940A (zh) * 2016-12-30 2018-07-13 华为软件技术有限公司 一种web容器中的模块加载方法和装置

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113873044A (zh) * 2021-10-15 2021-12-31 阿里巴巴(中国)有限公司 数据传输方法、系统、设备及存储介质
CN113873044B (zh) * 2021-10-15 2024-01-02 阿里巴巴(中国)有限公司 数据传输方法、系统、设备及存储介质
CN114924809A (zh) * 2022-05-19 2022-08-19 西安理工大学 一种基于dex文件类的流式微服务加载验证方法
CN114924809B (zh) * 2022-05-19 2024-03-29 西安理工大学 一种基于dex文件类的流式微服务加载验证方法

Also Published As

Publication number Publication date
US11755341B2 (en) 2023-09-12
US20220012067A1 (en) 2022-01-13
CN111736913A (zh) 2020-10-02
CN111736913B (zh) 2021-11-19
CN114153521A (zh) 2022-03-08

Similar Documents

Publication Publication Date Title
WO2020192705A1 (zh) 类加载方法和装置
US10261764B2 (en) Handling value types
US11341061B2 (en) Address translation method, apparatus, and system
JP5139987B2 (ja) 拡張可能メタデータ
US9176713B2 (en) Method, apparatus and program storage device that provides a user mode device interface
JP5147728B2 (ja) 質的に注釈を付けられた注釈付きコード
US11556348B2 (en) Bootstrapping profile-guided compilation and verification
US8615743B2 (en) Adaptive compiled code
US8701095B2 (en) Add/remove memory pressure per object
US11556468B2 (en) Multi-ring shared, traversable, and dynamic advanced database
US8200938B2 (en) Computer system and method providing a memory buffer for use with native and platform-independent software code
US20140157291A1 (en) Method and system for binding objects in dynamic programming languages using caching techniques
JP2015519646A (ja) マルチテナント型アプリケーション・ドメイン及びメモリの管理を伴う修正されたjvm
US20240126567A1 (en) Data processing system, method, and apparatus
US8341606B2 (en) Method of invoking inlined method and java virtual machine using the method
WO2023016485A1 (zh) 用于获取函数调用信息的方法、装置、电子设备和介质
US10296363B2 (en) Tuning a virtual machine startup parameter
US20240111555A1 (en) Unknown object sub-class identification
CN115145727A (zh) 优化内存管理方法、装置、电子设备以及存储介质
CN115827140A (zh) 可视化大屏的生成方法、装置、设备及存储介质
CN110633155A (zh) 一种插件化框架的通信方法、装置、介质及电子设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20778092

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20778092

Country of ref document: EP

Kind code of ref document: A1