A method and system for installing application packages for resource-constrained devices

By designing specialized instruction set access classes and static fields in resource-constrained devices, constant pool indexing is avoided and static field initialization is simplified, thus solving the problem of slow application package installation speed in resource-constrained devices and achieving a faster installation process and smaller file size.

CN115437654BActive Publication Date: 2026-06-30BEIJING WATCH DATA SYSTEM CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING WATCH DATA SYSTEM CO LTD
Filing Date
2022-08-09
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing technologies for application in resource-constrained devices involve cumbersome installation processes, resulting in slow installation speeds and failing to meet the demand for rapid installation.

Method used

By designing a dedicated instruction set to access classes, static fields, static methods, instance fields, and virtual methods, the use of constant pool indexes is avoided. Instead, class segment offsets, method segment offsets, and static field mirror offsets are used for referencing, generating a linker file, and simplifying the initialization of static fields through static field initialization methods.

Benefits of technology

The installation package file size has been reduced, the installation speed has been improved, and the installation process has been simplified.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437654B_ABST
    Figure CN115437654B_ABST
Patent Text Reader

Abstract

This invention relates to an application package installation method and system for resource-constrained devices. The invention proposes a technique for implementing an object-oriented virtual machine on resource-constrained devices. Instructions for accessing classes, static fields, static methods, instance fields, and virtual methods in the instruction set are specifically designed for resource-constrained hardware environments. This eliminates the need for complex parsing processes during class installation, which relies on a constant pool index. A static field initialization method is designed to replace existing static field component technologies, simplifying the initialization operation of static fields. Through these optimization steps, the file size of the installation package is reduced, and the installation speed is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer technology, specifically relating to an application package installation method and system for resource-constrained devices. Background Technology

[0002] A virtual machine is an abstract computer created by a software application or instruction sequence executed by a processor. Platform independence means that applications written in high-level object-oriented programming languages ​​such as Python, Java, and Kotlin can be executed through virtual machines on various computer platforms. The instruction sequence of a virtual machine is a stream of one or more bytecode codes encoded for a platform-independent manner. High-level language virtual machines execute high-level programming languages ​​and are used for 32-bit or 64-bit architectures. Resource-constrained devices such as security elements (smart cards, smart SEs, security MCUs) cannot easily support virtual machines that implement 32-bit operating instructions.

[0003] Traditional object-oriented virtual machines implemented on resource-constrained devices such as Secure Elements can independently execute applications written in high-level languages. These applications are compiled, converted into installable file formats, and installed into the Secure Elements runtime environment for execution. Traditional virtual machine instruction sets import packages and the classes, static fields, instance fields, static methods, and virtual methods defined within these packages via constant pool references. To install applications across hardware platforms on resource-constrained devices, optimization techniques are needed to simplify the class loading process. For example, token-based linking technology replaces fixed-length tokens with symbolic names in the constant pool, significantly reducing its size. Reference location components simplify the parsing of constant pool indexes in bytecode. However, even with these optimization techniques, the application package installation process remains cumbersome, resulting in slow installation and failing to meet the requirements of applications demanding rapid installation. Summary of the Invention

[0004] To address the shortcomings of existing technologies, the present invention aims to provide an application package installation method and system for resource-constrained devices. This method and system specifically design instructions for accessing classes, static fields, static methods, instance fields, and virtual methods within the instruction set for resource-constrained hardware environments. This avoids the complex parsing and processing required during class installation caused by the use of constant pool indexes in existing instructions. Furthermore, the present application's method designs a static field initialization method to replace existing static field component technology, simplifying the initialization operation of static fields. Through these optimization steps, the file size of the installation package is reduced, and the installation speed is improved.

[0005] To achieve the above objectives, the technical solution adopted by this invention is: an application package installation method for resource-constrained devices, comprising the following steps: referencing classes, static methods, and static fields defined in the package through offsets; referencing classes defined in the package through class segment offsets, referencing static methods defined in the package through method segment offsets, and referencing static fields defined in the package through static field mirror offsets. Each class in the class segment contains a field for security checks, the field representing the index of the first package-visible or private instance field declared by the class; if the class does not declare any package-visible or private instance fields, the value is 0xFF; and referencing the first instance field of the imported package through the exported item identifier. The system uses a first instruction to access externally visible classes, externally visible static fields, and externally visible static methods of the imported package; it also uses an index to access a second instruction defined in the imported package or the current package, which includes instructions to access instance fields and virtual methods defined in the imported package or the current package; it uses an interface method index to access interface methods; it generates a corresponding link file based on the exported item identifier, the index, and the interface method index; it allocates static field mirror space and initializes the static fields using a preset static field initialization method; and it generates an installation file corresponding to the application package using the link file of the imported package and the class file of the application package to install the application package.

[0006] Furthermore, referencing the first instruction to access the imported package via the export item identifier includes: sorting the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtaining the export item indices corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively; combining the export item indices corresponding to the externally visible classes, externally visible static fields, and externally visible static methods with the export item tag and the package identifier of the imported package to obtain the export item identifier.

[0007] Furthermore, referencing the second instruction defined in the imported package or the current package through an index includes: referencing the instruction to access the instance field through an instance field index; and referencing the instruction to access the virtual method through a virtual method index.

[0008] Furthermore, the static field initialization method includes creating a basic type array and performing initialization instructions on the array, as well as static field assignment instructions.

[0009] Furthermore, the step of generating an installation file corresponding to the application package using the link file of the imported package and the class file of the application package to install the application package includes: converting the class file in the application package using the link file of the imported package to convert the symbol names of exported items in the constant pool into corresponding index types; converting the class file of the application package to generate an installation file corresponding to the application package; and executing the installation file to install the application package.

[0010] An application package installation system for resource-constrained devices includes the following devices: a first referencing device, used to reference classes, static methods, and static fields defined in the package via offsets; to reference classes defined in the package via class segment offsets, to reference static methods defined in the package via method segment offsets, and to reference static fields defined in the package via static field mirror offsets, wherein each class in the class segment contains a field for security checks, the field representing the index of the first package-visible or private instance field declared by the class, and if the class does not declare any package-visible or private instance fields, the value is 0xFF; a second referencing device, used to reference a first instruction for accessing the imported package via an export item identifier, the first instruction including accessing externally visible classes, externally visible classes, and externally visible classes of the imported package. The system includes: a third referencing device for accessing static fields and externally visible static methods; a fourth referencing device for referencing interface methods via interface method indexes; a linker file generation device for generating corresponding linkers based on the exported item identifier, the index, and the interface method index; an initialization device for allocating static field mirror space and initializing static fields using a preset static field initialization method; and an application package installation device for generating an installation file corresponding to the application package using the linker file of the imported package and the class file of the application package to install the application package.

[0011] Furthermore, the second referencing device includes: a sorting unit, used to sort the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtain the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively; and a combining unit, used to combine the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively with the export item marker and the package identifier of the imported package to obtain the export item identifier.

[0012] Furthermore, the third referencing device includes units: a first instance field referencing unit, used to reference instructions for accessing the instance field through an instance field index; and a first virtual method referencing unit, used to reference instructions for accessing the virtual method through a virtual method index.

[0013] Furthermore, the static field initialization method includes creating a basic type array and performing initialization instructions on the array, as well as static field assignment instructions.

[0014] Furthermore, the application package installation device includes the following units: a conversion unit, used to convert the class files in the application package through the link file of the imported package, so as to convert the symbol names of the exported items in the constant pool into the corresponding index types, and replace the corresponding constant pool index in the instruction with the corresponding index type; a generation unit, used to convert the class files of the application package to generate an installation file corresponding to the application package, the installation file including a file header, class segment, method segment, imported package segment, exported item segment, and indirect package identifier location segment; and an installation unit, used to execute the installation file to install the application package.

[0015] The advantages of this invention are as follows: By employing the method described in this invention, and by specifically designing the instructions for accessing classes, static fields, static methods, instance fields, and virtual methods (including interface methods) in the instruction set for resource-constrained hardware environments, the problem of complex parsing and processing during class installation caused by using constant pool indexes in existing instructions can be avoided; in the technical method of this application, a static field initialization method is designed to replace the existing static field component technology, simplifying the initialization operation of static fields; through the above optimization steps, the file size of the installation package is reduced, and the installation speed of the installation package is improved. Attached Figure Description

[0016] Figure 1 This is a flowchart of the method described in this invention;

[0017] Figure 2 This is a schematic diagram of a sub-process of the method described in this invention;

[0018] Figure 3 This is a schematic diagram of another sub-process of the method described in this invention;

[0019] Figure 4 This is a schematic diagram of another sub-process of the method described in this invention;

[0020] Figure 5 This is a structural diagram of the system described in this invention;

[0021] Figure 6 This is a structural diagram of the device in the system described in this invention;

[0022] Figure 7This is a structural diagram of another device in the system described in this invention;

[0023] Figure 8 This is a structural diagram of another device in the system described in this invention. Detailed Implementation

[0024] The present invention will now be further described with reference to the accompanying drawings and specific embodiments.

[0025] like Figure 1 As shown, an application package installation method for a resource-constrained device is disclosed. This method is applied to the resource-constrained device and is executed by application software installed on the resource-constrained device. The resource-constrained device can be a security element such as a smart SE or a security MCU. The method includes the following steps:

[0026] S110. References to classes, static methods, and static fields defined in this package via offsets.

[0027] For classes, static methods, and static fields defined in this package, the class segment offset is used to reference the classes defined in this package, the method segment offset is used to reference the static methods defined in this package, and the static field mirror offset is used to reference the static fields defined in this package. Each class in the class segment contains a field for security checks. The field represents the index of the first package-visible or private instance field declared by the class. If the class does not declare any package-visible or private instance fields, the value is 0xFF.

[0028] S120. The first instruction for accessing the imported package is referenced by the exported item identifier, the first instruction including instructions for accessing the externally visible classes, static fields and static methods of the imported package.

[0029] For external imported packages that are not defined in this package, instructions to access externally visible classes, static fields, and static methods of the imported package need to use the export identifier.

[0030] In one embodiment, such as Figure 2 As shown, step S120 includes sub-steps S121 and S122.

[0031] S121. Sort the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtain the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively.

[0032] S122. Combine the export item indexes corresponding to the externally visible class, the externally visible static field, and the externally visible static method with the export item tag and the package identifier of the imported package to obtain the export item identifier.

[0033] The externally visible classes (including interfaces), static fields, and static methods of a package are sorted, and the sorting number is called the export item index. Instructions reference the outer package export item through the export item identifier.

[0034] For example, in a specific embodiment, the length of the derived item identifier can be set to 16 bits. 15 b 14 ...b1b0). The derived item identifier of the generated externally visible class consists of the following parts: derived item tag (b 15 )+Package identifier(b 14 b 13 ...b9b8)+Class Derived Item Index(b7b6...b1b0); The derived item identifier of the generated static field consists of the following parts: Derived Item Tag (b 15 )+Package identifier(b 14 b 13 ...b9b8)+static field derivation index(b7b6...b1b0); the generated static method's derivation identifier consists of the following parts: derivation tag (b 15 )+Package identifier(b 14 b 13 ...b9b8)+static method exported item index(b7b6...b1b0).

[0035] Specifically, based on the type of package identifier, exported item identifiers can be divided into direct exported item identifiers and indirect exported item identifiers.

[0036] Package identification has two methods: direct package identification and indirect package identification. The method used is specified when generating the installation file. Direct package identification depends on the installed applications and libraries of the virtual machine platform being installed, while indirect package identification does not depend on the installed applications and libraries of the virtual machine platform being installed, but its installation or execution efficiency is lower than that of direct package identification. Direct package identification: Direct package identification can be specified when converting the package's class files. Direct package identification is unique system-wide. The referenced package must be installed before the referencing package, and the linked file of the referenced package must include its direct package identification. The system can optionally provide a command to query the direct package identification of currently installed packages. Indirect package identification: This is specified through an index in the import package table. The entries in the import package table include the AID of the imported package and the package version number.

[0037] There are three methods for resolving exported item identifiers: The first method requires the installation file to provide an import package table segment. During application installation, the AID in the import package table needs to be replaced with the package's direct package identifier, and the indirect package identifier is obtained by querying the import package table. The second method requires the installation file to provide two optional segments: an import package table segment and an indirect package identifier location segment. During application installation, the indirect package identifier in the bytecode is obtained through the indirect package identifier location segment. The package's AID is obtained from the import package table using the indirect package identifier, and the package's direct package identifier is obtained from the package's AID. Finally, the indirect package identifier in the bytecode replaces the direct package identifier. The third method requires the installation file to provide two optional segments: an import package table segment and an indirect package identifier location segment. During application installation, the indirect package identifier in the bytecode is obtained through the indirect package identifier location segment. The package's AID is obtained from the import package table using the indirect package identifier, and the package's direct package identifier is obtained from the package's AID. Finally, the indirect package identifier and exported item index in the bytecode replace the reference identifier for the implementation dependency.

[0038] S130. Reference a second instruction defined in the imported package or the current package through an index, the second instruction including instructions for accessing instance fields or virtual methods defined in the imported package or the current package.

[0039] In one embodiment, such as Figure 3 As shown, step S130 includes sub-steps S131 and S132.

[0040] S131. Reference the instruction to access the instance domain through the instance domain index.

[0041] In a specific embodiment of this application, instructions for accessing instance fields require the use of instance field indexes. Specifically, each instance field declared by a class is identified by an instance field index, and instance field instructions specify the instance field to be accessed through instance field references (see the instance field reference section). All instance fields declared by a class are uniformly numbered: boolean, byte, and short types occupy one index number, while int type instance fields require two index numbers. The indexes of a root class instance field start from 0 and are numbered consecutively, while the indexes of all instance fields in a subclass start from the maximum index number of the direct parent class instance field plus 1 and are numbered consecutively. To facilitate garbage collection, static fields of reference types in each class can be numbered consecutively. If the subclass and parent class are defined in different packages, the maximum index number of the parent class's instance fields can be obtained through the parent class's linker file.

[0042] S132. Reference the instruction to access the virtual method through the virtual method index.

[0043] In a specific embodiment of this application, instructions accessing externally visible or package-visible virtual methods require the use of virtual method indexes. Specifically, virtual methods defined in this package and imported into the package are referenced using virtual method indexes; virtual methods are dynamically resolved instance methods, including all public, protected, and package-visible instance methods. Private instance methods and all constructors are not virtual methods and are statically resolved at compile time. Externally visible (public or protected) virtual methods of a class are assigned externally visible virtual method indices, and package-visible virtual methods of a class are assigned package-visible virtual method indices. The two types of indices can be distinguished by the highest bit of a byte, and the virtual method index value ranges from 0 to 127 (inclusive of boundary values).

[0044] In the index of externally visible virtual methods, the indices of externally visible virtual methods of the parent class `Object` for all classes are numbered consecutively starting from 0. The indices of externally visible virtual methods of subclasses are numbered consecutively starting from the maximum index of externally visible virtual methods of the direct parent class plus 1. If an externally visible virtual method of a subclass overrides an externally visible virtual method implemented in the parent class, then the virtual method is assigned the same index value as the parent class virtual method. In the index of package-visible virtual methods, the indices of package-visible virtual methods of the parent class `Object` for all classes are numbered consecutively starting from 0. The indices of package-visible virtual methods of subclasses are numbered consecutively starting from the maximum index of package-visible virtual methods of the direct parent class plus 1. If a package-visible virtual method of a subclass overrides a package-visible virtual method of a parent class (the subclass and parent class must be declared in the same package), the package-visible virtual method of the subclass uses the same index as the package-visible virtual method of the parent class.

[0045] For application package installation using the above method, the requirements for the generated linker file are as follows: the linker file needs to provide the maximum index number of the instance fields of the exported classes; the linker file needs to provide the maximum index value of the package-visible virtual methods of the exported classes.

[0046] In one embodiment, step S130 may further include the following steps: referencing instructions for accessing the instance field through class reference and instance field index; and referencing instructions for accessing the virtual method through class reference and virtual method index.

[0047] In another specific embodiment of this application, instructions for accessing instance fields require the use of class references and instance field indexes. Specifically, the instance field indexes are numbered consecutively starting from 0 for all instance fields declared by the class. Boolean, byte, and short types occupy one index number, while int type instance fields require two index numbers. Priority is given to the numbering of externally visible instance fields. To facilitate garbage collection, all reference type static fields of each class can be numbered consecutively.

[0048] In another specific embodiment of this application, instructions for accessing externally visible or package-visible virtual methods require the use of class references and virtual method indexes. Specifically, regarding virtual method indexes, virtual methods are dynamically resolved instance methods, including all public, protected, and package-visible instance methods. Private instance methods and all constructors are not virtual methods and are statically resolved at compile time. Externally visible (public or protected) virtual methods of a class are assigned externally visible virtual method indices, and package-visible virtual methods of a class are assigned package-visible virtual method indices. The two types of indices can be distinguished by the highest bit of a byte, and the virtual method index value ranges from 0 to 127 (inclusive).

[0049] In the index of externally visible virtual methods, the indexes of externally visible virtual methods of the parent class Object of all classes are numbered consecutively starting from 0. The indexes of externally visible virtual methods of subclasses start from the maximum index of the externally visible virtual methods of the direct parent class plus 1. If an externally visible virtual method of a subclass overrides an externally visible virtual method implemented in the parent class, then the virtual method is assigned the same index value as the virtual method of the parent class.

[0050] In the package-visible virtual method index, if the subclass and superclass are not declared in the same package, the subclass's package-visible virtual method index is numbered consecutively starting from 0. If the subclass's package-visible virtual method overrides the superclass's package-visible virtual method (the subclass and superclass must be declared in the same package), the subclass's package-visible virtual method uses the same index as the superclass's package-visible virtual method.

[0051] For application package installation using the above method, the requirements for the generated linker file are as follows: the linker file does not need to provide the maximum index number of the instance fields of exported classes; the linker file does not need to provide the maximum index value of the package-visible virtual methods of exported classes. However, it is necessary to provide an instance field and package-visible virtual method reference segment, and an instance field and package-visible virtual method reference location segment. The instance field and virtual method reference segment includes the following: an instance field and virtual method reference table, including the instance fields and package-visible virtual methods referenced by methods of each class declared in the package; the format of the reference table is as follows: instance field or virtual method flag (1 byte), class reference (2 bytes), instance field or package-visible virtual method index (1 byte); the class reference can be a method segment offset or a class export identifier; instance field access instructions and virtual method call instructions specify the instance field and package-visible virtual method to be accessed through the index of the instance field and virtual method reference table. Virtual method references can use a 16-bit reference identifier, in the following format: virtual method type flag (1 bit), externally visible virtual method index (15 bits), or instance and virtual method reference table index (15 bits); the instance field and package visible virtual method reference location field provides the location of instance fields and package visible virtual method table indexes used in the bytecode, which the package installer needs to parse.

[0052] S140. Reference the interface method through the interface method index.

[0053] Interface method references are made using interface method indexes. Each class in the class segment defines a virtual method index table for each method in each interface it implements, with the index of the table corresponding to the interface method.

[0054] S150. Generate the corresponding link file based on the exported item identifier, the instance domain index, the virtual method index, and the interface method index.

[0055] The corresponding linker file is generated based on the exported item identifier, instance field index, virtual method index, and interface method index. The offset includes offset information referencing classes, static methods, and static fields defined in this package; the exported item identifier includes identifier information referencing the first instruction to access the imported package, where the first instruction includes instructions to access externally visible classes, static fields, and static methods of the imported package; the index includes index information referencing the second instruction to access the imported package or defined in this package; and the interface method index is the index information referencing interface methods.

[0056] S160. Allocate static domain mirror space and initialize static domains using a preset static domain initialization method.

[0057] Specifically, this application's embodiments employ a special method, pClInit, constructed using a conversion tool, to replace the functionality of existing static field components. Static fields are accessed through offsets of their mirror images; therefore, all static fields need to be sorted to determine their offsets. To facilitate garbage collection, all reference type static fields are placed contiguously. The required space allocation for all static fields is calculated. A static field initialization method is constructed to implement the static field initialization function. When installing the application package, the installer allocates space according to the size of the static field mirror image; the pClInit method is executed to perform static field initialization. The pClInit method is executed only once, and the code can be discarded after completion.

[0058] The static field initialization method includes the following two instructions: (1) an instruction to create a primitive type array and initialize the array; and (2) a static field assignment instruction. The instruction to create a primitive type array and initialize the array is `newArrayAndFillData`, where the operands include: `offset` (the offset of the array type static field in the static field mirror), `type` (the type of the array to be created), `count` (the size of the initial data), and `values` (the initial data). The static field assignment instruction is `putStatic`, where the operands include: `offset` (the offset of the first non-default primitive type in the static field mirror), `count` (the size of the initial data), and `values` (the initial data). All static field initialization instructions for all classes in the application package are placed in a method `pClInit`; the method is defined as `statc public pClInit()`.

[0059] S170. An installation file corresponding to the application package is generated using the link file of the imported package and the class file of the application package to install the application package.

[0060] An installation file corresponding to the application package can be generated through the linker file. The header of the installation file provides the size of the static field image that needs to be allocated for each Java package. The method pClInit is placed at the end of the method component, and the header of the installation file provides the location information of pClInit. If the method in steps S131 and S132 is used to reference instance fields and virtual methods, then the following steps are used to install the application package; if the method in steps S1301 and S1302 is used to reference instance fields and virtual methods, then in addition to the following steps, the method also needs to provide a utility instance and a package-visible virtual method reference segment, and a utility instance and a package-visible virtual method reference location segment.

[0061] In one embodiment, such as Figure 4 As shown, step S170 includes sub-steps S171, S172 and S173.

[0062] S171. The class files in the application package are converted through the link file of the imported package to convert the symbol names of the exported items in the constant pool into the corresponding index types, and the corresponding constant pool index in the instruction is replaced with the corresponding index type; S172. The class files of the application package are converted to generate an installation file corresponding to the application package.

[0063] When converting class files within a package, a linker file for the imported packages is required to convert the symbolic names of imported items in the constant pool to their corresponding index types. The linker file includes a header and a list of externally visible items. The header includes the application package's AID, version number, package size, the maximum instance field index for each public class, and the maximum index value for package-visible virtual methods of each public class. The list of externally visible items includes an ordered list of all externally visible classes (including interfaces), static fields, and static methods in the package; specifically, an ordered list of all public classes, all public / protected static fields, and all public / protected static methods (including constructors). The index of each externally visible item in the list is used to construct the exported item identifier.

[0064] For example, the direct package identifier of tgomos.base is 0, and the list of externally visible components is shown in Table 1.

[0065] Table 1

[0066] index name 0 Object 1 Throwable 2 ObjectNullException 3 ……

[0067] For example, the direct export of tgomos.base.Object is identified as 0x8001, and the list of externally visible static methods is shown in Table 2.

[0068] Table 2

[0069] index name Method descriptor 0 ArrayBoundsException() ()V 1 ArrayNegativeSizeException() ()V 2 ArrayStoreTypeException() ()V 3 …… ……

[0070] For example, the direct export of the method ArrayStoreTypeException is identified as 0x8002.

[0071] The generated installation file includes a file header, import package section, class section, method section, import section, and indirect package identifier location section.

[0072] The file header includes the file format version number, the unique identifier of the package, the offset and size of each segment in the file, the application's AID and the location of the application installation method, and the location of the static field initialization method.

[0073] The imported package segment includes the AID of all imported packages of the application package and the package version number; during application installation, the AID in the imported package table needs to be replaced with the direct package identifier of the package, and the indirect package identifier is obtained by querying the imported package table to obtain the direct package identifier.

[0074] The class segment describes information about all interfaces and classes defined within the package. Class information includes references to virtual methods defined in the class. If a virtual method is defined in an imported package, these references are not defined in this class segment but are obtained by looking up the virtual method in the parent class. The class segment includes a virtual method table and an interface implementation method table. The virtual method table includes the virtual methods provided by each class definition, including a public / protected virtual method table, the index of the smallest public virtual method declared in this class, a package-visible virtual method table, and the index of the smallest package-visible virtual method declared in this class. If a virtual method table entry corresponds to a virtual method declared in this class, the offset of that virtual method in the method segment is recorded; otherwise, it is set to a special value indicating that the virtual method is defined in the parent class. The interface implementation method table provides a table of interface methods that implement the interface for each class definition. The index of each interface method in the interface method table is the index of that interface method. Providing the interface method table allows for the mapping from the interface method index to the corresponding public virtual method index.

[0075] Each class record in the class segment provides a field representing the index of the first package-visible or private instance field declared by that class. If the class does not declare any package-visible or private instance fields, this value is 0xFF. This field is used for security checks when the virtual machine executes instance field access instructions. When the index of the instance field is not within the scope of instance fields declared by the class containing the object, the superclass of the class is traversed through the index to determine the defining class of the instance field. If the defining class of the instance field and the class containing the method that accesses the instance field are not in the same package, and the index is the index of a package-visible or private instance field (i.e., greater than or equal to the value of the field), a security exception is thrown.

[0076] The method segment includes execution information for all methods defined in the package, excluding... <clinit>Method declarations for methods and interfaces, each including information for exception handling and the method's bytecode. Methods from all classes in the package are placed in the following priority order: 1) Private methods, including private static methods, private constructors, and private instance methods; 2) Package-visible virtual methods; 3) Externally visible virtual methods.

[0077] The exported items section includes the physical location information of all classes, static methods, and externally visible items of static fields within the package. The order of the visible items follows that of the package's linker file. The package's exported items section is used to construct the runtime environment's reference table. The specific contents of the exported items are shown in Table 3.

[0078] Table 3

[0079] Exported items Exported content kind Offset of class in class segment static domain Offset of static domain in static domain mirror static methods Offset of static methods in the method block

[0080] The position of the relative package identifier in the bytecode of the specified method. Depending on how the package installer generates the reference table, it may choose to replace the relative package identifier or the entire exported item identifier in the bytecode.

[0081] S173. Execute the installation file to install the application package.

[0082] The runtime environment needs to maintain three reference tables for each installation package: classes, static fields, and static methods. These tables record the location information of all exported items for each package within the system. The package installer adds the exported item list to the reference tables in its original order and modifies the segment offset relative address to the physical address. The virtual machine accesses the corresponding reference table when executing instructions. The reference tables use a two-level structure: the first level is the package identifier table, and the second level is the export item table. The runtime environment can optionally maintain an import table for each installation package to map indirect package identifiers to direct package identifiers.

[0083] Due to the special design of virtual machine instructions, for statically bound items, the package definition uses the offset of the relevant segment, and exported items use the exported item identifier. For dynamically bound items, the index of instance fields and virtual methods defined in the class inheritance structure is used. Therefore, there is no constant pool index as in existing methods. Removing the constant pool component can reduce the size of the installation file and simplify the linking process during package installation, thereby improving the installation speed. Package identifiers can use direct package identifiers and indirect package identifiers, and exported item identifiers have multiple resolution methods during installation to adapt to different application scenarios. The conversion tool constructs a static initialization method, which the installer executes, replacing the existing static field component technology.

[0084] In this embodiment, classes, static methods, and static fields defined in the package are referenced through offsets; first instructions for accessing imported packages are referenced through exported item identifiers; second instructions for accessing imported packages or defined in the package are referenced through indexes; and interface methods are referenced through interface method indexes. Based on these reference relationships, a linker file is generated, static fields are initialized, and the application package is installed through the linker file. By specifically designing the instructions for accessing classes, static fields, static methods, instance fields, and virtual methods in the instruction set for resource-constrained hardware environments, this approach avoids the complex parsing and processing required during class installation caused by using constant pool indexes in existing instructions. Furthermore, the static field initialization method in this application simplifies the initialization operation of static fields by replacing existing static field component technology. These optimization steps reduce the file size of the installation package and improve its installation speed.

[0085] like Figure 5 As shown, an application package installation system for a resource-constrained device is provided. The system can be configured in a resource-constrained device and is used to execute any of the aforementioned application package installation methods for resource-constrained devices. The system includes the following devices: a first referencing device 110, a second referencing device 120, a third referencing device 130, a fourth referencing device 140, a link file generation device 150, an initialization device 160, and an application package installation device 170.

[0086] The first referencing device 110 is used to reference classes, static methods, and static fields defined in the package by offset; to reference classes defined in the package by class segment offset; to reference static methods defined in the package by method segment offset; and to reference static fields defined in the package by static field mirror offset. Each class in the class segment contains a field for security checks, which represents the index of the first package-visible or private instance field declared by the class. If the class does not declare any package-visible or private instance fields, the value is 0xFF.

[0087] The second referencing device 120 is used to reference a first instruction for accessing an imported package via an exported item identifier. The first instruction includes instructions for accessing externally visible classes, externally visible static fields, and externally visible static methods of the imported package.

[0088] In one specific embodiment, such as Figure 6 As shown, the second referencing device 120 includes the following units: a sorting unit 121, used to sort the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtain the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively; and a combining unit 122, used to combine the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively with the export item marker and the package identifier of the imported package to obtain the export item identifier.

[0089] The third referencing device 130 is used to reference a second instruction defined in the imported package or the current package by means of an index, the second instruction including instructions for accessing instance fields and virtual methods defined in the imported package or the current package.

[0090] In one specific embodiment, such as Figure 7 As shown, the third referencing device 130 includes the following units: a first instance field referencing unit 131, used to reference instructions for accessing the instance field through an instance field index; and a first virtual method referencing unit 132, used to reference instructions for accessing the virtual method through a virtual method index.

[0091] In one specific embodiment, the static field initialization method includes creating a basic type array and performing initialization instructions on the array, as well as static field assignment instructions.

[0092] The fourth referencing device 140 is used to reference an interface method via an interface method index.

[0093] Link file generation device 150 is used to generate corresponding link files based on the exported item identifier, the index, and the interface method index.

[0094] The initialization device 160 is used to allocate static domain mirror space and initialize static domains using a preset static domain initialization method.

[0095] The application package installation device 170 is used to generate an installation file corresponding to the application package by using the link file of the imported package and the class file of the application package to install the application package.

[0096] In one specific embodiment, such as Figure 8 As shown, the application package installation device 170 includes the following units: a conversion unit 171, used to convert the class files in the application package through the link file of the imported package, so as to convert the symbol names of the exported items in the constant pool into the corresponding index types; a generation unit 172, used to convert the class files of the application package to generate an installation file corresponding to the application package; and an installation unit 173, used to execute the installation file to install the application package.

[0097] In this embodiment, classes, static methods, and static fields defined in the package are referenced through offsets; first instructions for accessing imported packages are referenced through exported item identifiers; second instructions for accessing imported packages or defined in the package are referenced through indexes; and interface methods are referenced through interface method indexes. Based on these reference relationships, a linker file is generated, static fields are initialized, and the application package is installed through the linker file. By specifically designing the instructions for accessing classes, static fields, static methods, instance fields, and virtual methods in the instruction set for resource-constrained hardware environments, this approach avoids the complex parsing and processing required during class installation caused by using constant pool indexes in existing instructions. Furthermore, the static field initialization method in this application simplifies the initialization operation of static fields by replacing existing static field component technology. These optimization steps reduce the file size of the installation package and improve its installation speed.

[0098] Those skilled in the art should understand that the methods and systems described and implemented in this invention are not limited to the embodiments described in the specific implementation details. The above detailed description is merely for illustrative purposes and is not intended to limit the invention. Other implementation methods derived by those skilled in the art based on the technical solutions of this invention also fall within the scope of the technical innovation of this invention. The scope of protection of this invention is defined by the claims and their equivalents.< / clinit>

Claims

1. A method for installing an application package on a resource-constrained device, characterized in that, The method is applied to a resource-constrained device, and the method includes the following steps: Classes, static methods, and static fields defined in this package are referenced by offsets; classes defined in this package are referenced by class segment offsets, static methods defined in this package are referenced by method segment offsets, and static fields defined in this package are referenced by static field mirror offsets. Each class in the class segment contains a field for security checks, which represents the index of the first package-visible or private instance field declared by the class. If the class does not declare any package-visible or private instance fields, the value is 0xFF. The first instruction to access the imported package is referenced by the exported item identifier. The first instruction includes instructions to access the externally visible classes, externally visible static fields, and externally visible static methods of the imported package. The index references a second instruction defined in the imported package or the current package, the second instruction including instructions to access instance fields or virtual methods defined in the imported package or the current package; Interface methods are referenced via their method indexes; Generate the corresponding link file based on the exported item identifier, the instance domain index, the virtual method index, and the interface method index; The static domain mirror space is allocated and the static domain is initialized using the preset static domain initialization method; The application package is installed by generating an installation file corresponding to the application package using the link file of the imported package and the class file of the application package. The reference to the first instruction for accessing the imported package via the exported item identifier includes: Sort the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtain the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively; The exported item identifier is obtained by combining the exported item index corresponding to the externally visible class, the externally visible static field, and the externally visible static method with the exported item tag and the package identifier of the imported package.

2. The application package installation method for resource-constrained devices as described in claim 1, characterized in that, The reference to the second instruction defined in the imported package or the current package via an index includes: Instructions for accessing the instance domain are referenced through the instance domain index; The virtual method index references the instructions that access the virtual method.

3. The application package installation method for resource-constrained devices as described in claim 1, characterized in that, The static field initialization method includes creating a basic type array and performing array initialization instructions as well as static field assignment instructions.

4. The application package installation method for resource-constrained devices as described in claim 1, characterized in that, The step of generating an installation file corresponding to the application package using the link file of the imported package and the class file of the application package to install the application package includes: The class files in the application package are converted by the link file of the imported package, so as to convert the symbol names of the exported items in the constant pool into the corresponding index types; The class files of the application package are converted to generate an installation file corresponding to the application package. The installation file includes a file header, class section, method section, import package section, export item section, and indirect package identifier location section. Execute the installation file to install the application package.

5. An application package installation system for resource-constrained devices, characterized in that, Includes the following devices: The first referencing device is used to reference classes, static methods, and static fields defined in this package by offset; to reference classes defined in this package by class segment offset, to reference static methods defined in this package by method segment offset, and to reference static fields defined in this package by static field mirror offset. Each class in the class segment contains a field for security checks, which represents the index of the first package-visible or private instance field declared by the class. If the class does not declare any package-visible or private instance fields, the value is 0xFF. The second referencing device is used to reference a first instruction for accessing an imported package by means of an exported item identifier, the first instruction including instructions for accessing externally visible classes, externally visible static fields and externally visible static methods of the imported package; A third referencing device is used to reference a second instruction defined in the imported package or the current package via an index, the second instruction including instructions to access instance fields or virtual methods defined in the imported package or the current package; The fourth referencing device is used to reference an interface method via an interface method index; A link file generation device is used to generate a corresponding link file based on the exported item identifier, the instance field index, the virtual method index, and the interface method index. An initialization device is used to allocate static domain mirror space and initialize static domains using a preset static domain initialization method. An application package installation device is used to generate an installation file corresponding to the application package using the link file of the imported package and the class file of the application package. The installation file includes a file header, class segment, method segment, imported package segment, exported item segment, and indirect package identifier location segment, and to install the application package installation file. The second referencing device includes a unit: The sorting unit is used to sort the externally visible classes, externally visible static fields, and externally visible static methods of the imported package respectively, and obtain the export item indexes corresponding to the externally visible classes, externally visible static fields, and externally visible static methods respectively; The combination unit is used to combine the export item indexes corresponding to the externally visible class, the externally visible static field, and the externally visible static method with the export item tag and the package identifier of the imported package to obtain the export item identifier.

6. The application package installation system for resource-constrained devices as described in claim 5, characterized in that, The third referencing device includes a unit: An instance field reference unit is used to reference instructions for accessing the instance field through an instance field index; A virtual method reference unit is used to reference instructions that access the virtual method through a virtual method index.

7. The application package installation system for resource-constrained devices as described in claim 5, characterized in that, The static field initialization method includes creating a basic type array and performing array initialization instructions as well as static field assignment instructions.

8. The application package installation system for resource-constrained devices as described in claim 5, characterized in that, The application package installation device includes a unit: The conversion unit is used to convert the class files in the application package through the link file of the imported package, so as to convert the symbol names of the exported items in the constant pool into the corresponding index types, and replace the corresponding constant pool index in the instruction with the corresponding index type. The generation unit is used to convert the class files of the application package to generate an installation file corresponding to the application package. The installation file includes a file header, class segment, method segment, import package segment, export item segment, and indirect package identifier location segment. The installation unit is used to execute the installation file to install the application package.