Class loading method and device, storage medium and electronic device
Patent Information
- Application Number
- CN202510962134.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-11-07
AI Technical Summary
现有技术多采用这样的整体替换思路,会导致动态化性能难以达到令人满意的效果,更新范围无法动态控制,难以实现面向对象的动态化更新
[0039]The class loading method, device, storage medium and electronic device provided by the embodiment of the application, according to the service triggering operation of the user, read the corresponding target class dynamic file, create a target class structure model according to the target class dynamic file, and perform target field assignment on the target class structure model according to the target class dynamic file, which includes assigning the associated class field of the target class structure model to an associated class instance, so as to realize direct calling of the loaded associated class instance in the target class instance, complete the dynamic loading of the target class, solve the problems of poor dynamic performance of application program updating and lack of object-oriented dynamic updating method in the prior art, realize object-oriented application program dynamic updating, shorten the updating cycle, make the online quality maintenance system of the application program more perfect, and improve the user experience.
Smart Images

Figure CN120909670A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the computer field, in particular to a class loading method and device, a storage medium and an electronic device. BACKGROUND
[0002] Under the background of rapid development of the software industry, the use needs of users and the operation needs of software developers are driving software products to be updated and iterated at an increasingly fast speed. The core performance of the software development framework focuses on whether it can provide an updating mechanism with high efficiency, stability and low memory occupation. However, from the existing technology, the updating mechanism of the mainstream development framework still has optimization space. Taking Flutter cross-terminal technology as an example, Flutter application itself does not have dynamic hot updating capability. The existing updating scheme mainly replaces the compiled products in the application installation directory by downloading the updated Flutter compiled products on the application side to realize dynamic updating. The existing technology adopts such a whole replacement idea, which causes the dynamic performance to be difficult to achieve satisfactory results, the updating range to be unable to be dynamically controlled, and object-oriented dynamic updating to be difficult to be realized. SUMMARY
[0003] Embodiments of the present application provide a class loading method, device, storage medium and electronic device, aiming to realize object-oriented application dynamic updating, shorten the updating cycle, make the online quality maintenance system of the application more perfect, and improve user experience.
[0004] According to an aspect of an embodiment of the present application, a class loading method is provided, comprising:
[0005] reading a target class dynamic file according to a business triggering operation of a user;
[0006] creating a target class structure model according to the target class dynamic file;
[0007] performing target field assignment on the target class structure model according to the target class dynamic file to obtain a target class instance;
[0008] The target field assignment comprises assigning an associated class field of the target class structure model to an associated class instance.
[0009] In an optional implementation, the performing target field assignment on the target class structure model according to the target class dynamic file comprises:
[0010] determining a target associated class according to associated class calling data in the target class dynamic file, and performing loading state query on the target associated class;
[0011] assign the association class field of the target class structure model to the association class instance of the target association class.
[0012] In an optional implementation, after the target association class is determined according to the association class calling data in the target class dynamic file, and the loading state of the target association class is queried, the method further includes:
[0013] In a case where it is queried that the target association class is in a to-be-loaded state, an association class dynamic file is obtained.
[0014] An association class structure model is created according to the association class dynamic file.
[0015] The target field of the association class structure model is assigned according to the association class dynamic file, so as to obtain the association class instance of the target association class.
[0016] The association class field of the target class structure model is assigned to the association class instance of the target association class.
[0017] In an optional implementation, the target association class is determined according to the association class calling data in the target class dynamic file, and the loading state of the target association class is queried, including:
[0018] The class name of each target association class is obtained in the association class calling data.
[0019] In a class instance storage table, a class instance corresponding to the class name is queried.
[0020] In a case where it is queried that the class instance exists, it is determined that the target association class corresponding to the class name is in a loaded state.
[0021] In an optional implementation, after the target class instance is obtained by assigning the target field of the target class structure model to the target class dynamic file, the method further includes:
[0022] The target class class name in the target class instance is obtained.
[0023] The target class class name and the target class instance are stored correspondingly in the class instance storage table.
[0024] In an optional implementation, the target class dynamic file is read according to the business trigger operation of the user, including:
[0025] According to the business trigger operation, a target file identifier is obtained in an entry file.
[0026] In the preset mapping table, a dynamic file name having a mapping relationship with the target file identifier is acquired;
[0027] In a case where it is determined that the corresponding dynamic file exists, the corresponding dynamic file is determined as the target class dynamic file, and the target class dynamic file is read.
[0028] In an optional implementation, the creating of the target class structure model according to the target class dynamic file comprises:
[0029] Target class declaration data in the target class dynamic file is acquired.
[0030] In a case where the target class declaration data is determined as internal class data, an internal class structure model is created.
[0031] In a case where the target class declaration data is determined as external class data, an external class structure model is created.
[0032] According to another aspect of the embodiments of the present application, a class loading device is provided, comprising:
[0033] A file reading module is configured to read a target class dynamic file according to a business triggering operation of a user.
[0034] A model creating module is configured to create a target class structure model according to the target class dynamic file.
[0035] A field assigning module is configured to assign a target field of the target class structure model according to the target class dynamic file, to obtain a target class instance.
[0036] The target field assignment comprises assigning an associated class field of the target class structure model to an associated class instance.
[0037] According to another aspect of the embodiments of the present application, a computer readable storage medium is provided, which comprises a stored program, wherein the program is executed to perform the class loading method provided in any of the embodiments of the present application.
[0038] According to another aspect of the embodiments of the present application, an electronic device is provided, comprising a memory and a processor, the memory storing a computer program, and the processor being configured to execute the class loading method provided in any of the embodiments of the present application through the computer program.
[0039] The class loading method, device, storage medium and electronic device provided by the embodiment of the application, according to the service triggering operation of the user, read the corresponding target class dynamic file, create a target class structure model according to the target class dynamic file, and perform target field assignment on the target class structure model according to the target class dynamic file, which includes assigning the associated class field of the target class structure model to an associated class instance, so as to realize direct calling of the loaded associated class instance in the target class instance, complete the dynamic loading of the target class, solve the problems of poor dynamic performance of application program updating and lack of object-oriented dynamic updating method in the prior art, realize object-oriented application program dynamic updating, shorten the updating cycle, make the online quality maintenance system of the application program more perfect, and improve the user experience. BRIEF DESCRIPTION OF DRAWINGS
[0040] The accompanying drawings, which are incorporated herein and constitute part of the specification, illustrate embodiments consistent with the application and, together with the description, serve to explain the principles of the application.
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the accompanying drawings required by the embodiments or the prior art description will be briefly introduced below. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.
[0042] Figure 1 Fig. 1 is a hardware environment schematic diagram of a class loading method according to an embodiment of the application;
[0043] Figure 2 Fig. 2 is a flowchart of a class loading method according to an embodiment of the application;
[0044] Figure 3 Fig. 3 is a structure schematic diagram of a meta-class system in a runtime according to an embodiment of the application;
[0045] Figure 4 Fig. 4 is a storage structure schematic diagram of a class instance storage table according to an embodiment of the application;
[0046] Figure 5 Fig. 5 is a flowchart of a class loading method according to an embodiment of the application;
[0047] Figure 6 Fig. 6 is a structure schematic diagram of a class loading device according to an embodiment of the application;
[0048] Figure 7 Fig. 7 is a structure schematic diagram of an electronic device according to an embodiment of the application. DETAILED DESCRIPTION
[0049] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application, so that those skilled in the art can better understand the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of the present application.
[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0051] According to an aspect of the embodiments of the present application, a class loading method is provided. The class loading method is widely used in smart home, smart home, smart home device ecology, intelligence house ecology and other whole-house intelligent digital control application scenarios. Optionally, in the present embodiment, the class loading method can be applied to the hardware environment composed of terminal device 102 and server 104 as shown in Figure 1 As shown in Figure 1 The server 104 is connected with the terminal device 102 through the network, which can be used to provide services (such as application services, etc.) for the terminal or the client installed on the terminal, a database can be set on the server or independently of the server, which is used to provide data storage services for the server 104, cloud computing and / or edge computing services can be configured on the server or independently of the server, which is used to provide data operation services for the server 104.
[0052] The network can include, but is not limited to, at least one of the following: a wired network, a wireless network. The wired network can include, but is not limited to, at least one of the following: a wide area network, a metropolitan area network, a local area network. The wireless network can include, but is not limited to, at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 can include, but is not limited to, at least one of the following: a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart oven, a smart refrigerator, a smart oven, a smart oven, a smart washing machine, a smart water heater, a smart washing device, a smart dishwasher, a smart projection device, a smart television, a smart clothesline, a smart curtain, a smart audio and video, a smart socket, a smart sound, a smart sound box, a smart fresh air device, a smart kitchen and bathroom device, a smart bathroom device, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification device, a smart steamer, a smart microwave oven, a smart kitchen, a smart purifier, a smart water dispenser, a smart door lock, etc.
[0053] In this embodiment, a class loading method is provided, which is applied to a terminal device, preferably, a runtime of the terminal device, Figure 2 A flowchart of the class loading method provided in the embodiment of the present application is provided, which includes the following steps:
[0054] In step 210, the target class dynamic file is read according to the user's service trigger operation.
[0055] The user's service trigger operation can be a specific operation performed by the user on the terminal device to initiate the dynamic update service of the application. The target class dynamic file can be a readable file for storing the program code of the class required to be loaded by the dynamic update service.
[0056] When the user needs to obtain the dynamic update of the application, the user can perform a service trigger operation on the terminal device used by the user, for example, the user can click the dynamic update service on the interface provided on the terminal device after starting the application. The dynamic update service initiated by the user through the service trigger operation can include dynamic loading of at least one class. Therefore, the class that needs to be dynamically loaded can be determined according to the user's service trigger operation, and the corresponding target class dynamic file is further determined and read.
[0057] The target class dynamic file can be compiled and converted from the source code file and written in a readable language of the runtime of the terminal device. The runtime can read the target class dynamic file and dynamically parse the class loading related code written therein, so as to execute the subsequent class loading step.
[0058] In an optional implementation, the application can be an application developed based on the Flutter cross-end technology. In the Flutter cross-end technology, based on the syntax characteristics of the Dart language and the declarative programming characteristics thereof, a Dart language template code can be converted into a DSL (Domain Specific Language) JSON (JavaScript Object Notation) file, so that a runtime can dynamically parse the JSON file to load a class declaration node therein.
[0059] In an optional implementation, reading the target class dynamic file according to the business trigger operation of the user can include: obtaining a target file identifier in an entry file according to the business trigger operation; obtaining a dynamic file name having a mapping relationship with the target file identifier in a preset mapping table; in a case where a corresponding dynamic file of the dynamic file name exists, determining the corresponding dynamic file as the target class dynamic file, and reading the target class dynamic file.
[0060] The entry file can be a preset file used to store identifiers of all dynamic files. The target file identifier can be a unique identifier of a dynamic file corresponding to a class required to be loaded in a dynamic business initiated by the business trigger operation. The preset mapping table can be a preset query table used to store a mapping relationship between identifiers of dynamic files and file names. The dynamic file name can be a file name of each dynamic file. The dynamic file can be a readable file used to store program codes of any class that can be dynamically loaded. The corresponding dynamic file of the dynamic file name can be a dynamic file having the dynamic file name as a file name.
[0061] The entry file can be preset, and identifiers of dynamic files, for example, IDs (Identifiers) of the dynamic files, are stored in the entry file. When the user performs the business trigger operation, the target file identifier corresponding to the business trigger operation can be obtained by reading the entry file. Each target file identifier corresponds to a dynamic file and a dynamic file name of the dynamic file. A mapping relationship between a unique identifier of each dynamic file and the dynamic file name of the dynamic file is stored in a preset mapping table, so that the dynamic file name having a mapping relationship with the target file identifier can be obtained in the preset mapping table. For the sake of logical robustness, it can be further determined whether the corresponding dynamic file of the dynamic file name exists. If the corresponding dynamic file does not exist, it can be determined that an exception occurs. In general, each dynamic file name has a unique corresponding dynamic file, and the corresponding dynamic file can be determined as the target class dynamic file.
[0062] In an optional implementation, the above files can be stored in the form of a resource package, i.e., a dynamic resource package is preset. In the dynamic resource package, all dynamic files are included. Optionally, in the update of the Flutter application, the dynamic files can be obtained by converting source code files written in the Dart language into JSON language. In the dynamic resource package, a configuration file can also be set to store a preset mapping table. Optionally, the configuration file of the dynamic resource package can also be stored, for example, the name of the dynamic resource package can be included. The entry file can be set as the main file of the dynamic resource package.
[0063] Step 220: creating a target class structure model according to the target class dynamic file.
[0064] The target class structure model can be a preset storage structure of the class that needs to be dynamically loaded.
[0065] The code in the target class dynamic file can obtain information of the class that needs to be dynamically loaded, and the target class structure model can be created according to the information. The target class structure model can be created according to the preset class storage structure in the terminal device. The storage structure can include preset fields, and the storage structure and fields of different classes can be different, which can be preset according to the characteristics and / or attributes of the class. The characteristics and / or attributes of the class that needs to be loaded can be determined according to the program code in the target class dynamic file, so as to obtain the corresponding preset storage structure and create the target class structure model.
[0066] In an optional implementation, creating a target class structure model according to the target class dynamic file and obtaining field assignment data of the target class structure model can include: obtaining target class declaration data in the target class dynamic file; in a case where it is determined that the target class declaration data is internal class data, creating an internal class structure model; and in a case where it is determined that the target class declaration data is external class data, creating an external class structure model.
[0067] The target class declaration data can be program code in the target class dynamic file for indicating the class that needs to be loaded. The internal class data can be program code for indicating any internal class that needs to be loaded, and the internal class can be a class defined in the runtime of the terminal device. The internal class structure model can be a preset storage structure of the internal class. The external class data can be program code for indicating any external class that needs to be loaded, and the external class can be a class customized by a code operator. The external class structure model can be a preset storage structure of the external class.
[0068] The target class declaration data can be obtained by reading the target class dynamic file. If the target class declaration data is internal class data, it can be determined that the class to be loaded is an internal class, and an internal class structure model can be created according to a preset storage structure. If the target class declaration data is external class data, it can be determined that the class to be loaded is an external class, and an external class structure model can be created according to a preset storage structure. Optionally, the identification information of the class to be loaded in the target class declaration data can be obtained, and it can be determined whether the identification information exists in a file for storing internal class identification information, so as to determine whether the class to be loaded is an internal class or an external class.
[0069] In an optional embodiment, the target class structure model can be stored in the runtime meta-class system in advance. In a typical example, Figure 3 A structure diagram of a meta-class system in runtime provided by an embodiment of the present application is shown in FIG. 1. As shown in the figure, in an optional embodiment, a storage structure of an internal class can be set, and optionally, an internal class structure model can be determined. Optionally, the storage structure of the internal class in runtime can be represented by InstanceClass, and the fields thereof can include: a name field for storing the class name; a super field for pointing to the parent class; an objectMethods field for storing the methods of the object, such as toString(), hashCode, etc.; a mixins field for pointing to the mixin class; an implements field for pointing to the interface class; a constructors field for storing the constructor; a methods field for storing the methods, including the instance method and the static method; a staticFields field for storing the static attribute; and a fields field for storing the instance attribute. Figure 3
[0070] In an optional embodiment, the storage structure of the object after the internal class is instantiated can be preset. Optionally, the object after the internal class is instantiated can be represented by InstanceOop, and the fields thereof can include: a metaClass field for pointing to the class to which it belongs; a parentInstance field for pointing to the InstanceOop of the parent class; and a fields field for storing the values of the attributes.
[0071] In an optional implementation, a storage structure of the external class can be set, and optionally, a structure model of the external class can be determined. Optionally, a storage structure of the external class in a runtime can be set as the ProxyMirrorClass, and fields of the ProxyMirrorClass can include: a name field for storing a class name; a classMirror field for pointing to a static object thereof; and an invokeMethod field for storing an invocation interface of the static object.
[0072] In an optional implementation, a storage structure of an object of the external class after instantiation can be preset. Optionally, the object of the external class after instantiation can be represented as the ProxyMirrorOop, and fields of the ProxyMirrorOop can include: a metaClass field for pointing to a class to which the object belongs; an instanceMirror field for pointing to an instance object of the external class; and an invokeMethod field for storing an invocation interface of the instance object.
[0073] In an optional implementation, the target class dynamic file can be a DSL JSON file, and target class declaration data in the target class dynamic file can be a program code of a class declaration node in the DSL JSON file, for example, a ClassDeclaration node. Further optionally, it can be determined that the class to be loaded is an internal class by judging that the class declaration node is an internal symbol in a dynamic resource package in which the DSL JSON file is located, and it can be determined that the class to be loaded is an external class by judging that the class declaration node is not an internal symbol in the dynamic resource package.
[0074] The above implementations provide two methods of creating a class structure model and obtaining field information of a class for the internal class and the external class to be loaded, can automatically distinguish the internal class and the external class, and implement more accurate class creation, and increase the application range and reliability of the method.
[0075] Step 230, target field assignment is performed on the target class structure model according to the target class dynamic file, and a target class instance is obtained.
[0076] The target field assignment includes assigning an associated class field of the target class structure model as an associated class instance.
[0077] The target field assignment can be an operation of assigning each field of the target class structure model. The target class instance can be an instance obtained after class loading of a class currently to be loaded is completed. The associated class field can be a field for pointing to a class having an association relationship with the class currently to be loaded, for example, a parent class, a mixed class, and an interface class of the class currently to be loaded. The associated class instance can be an instance obtained after class loading of the class having the association relationship with the class currently to be loaded is completed.
[0078] According to the program code in the target class dynamic file, the attribute of the class to be loaded can be determined, so as to assign values to each field in the target class structure model, and obtain the target class instance after dynamic loading. In the program code in the target class structure model, the declaration of the class associated with the class to be loaded can be included. In the case that the class in the declaration has completed loading, the associated class instance loaded therefrom can be directly obtained, so that the associated class field of the target class structure model can be assigned to the associated class instance, so as to directly call the associated class instance that has been loaded in the obtained target class instance.
[0079] In an optional embodiment, the target class dynamic file can include the class name of the class to be loaded, the class name of the associated parent class, the list of associated interface class names, the list of associated mixin class names, the constructor list, the method list, and the attribute table.
[0080] In an optional embodiment, the target field assignment of the target class structure model according to the field assignment data can include: determining a target associated class according to the associated class calling data in the target class dynamic file, and querying the loading state of the target associated class; in the case that the target associated class is in the loaded state, assigning the associated class field of the target class structure model to the associated class instance of the target associated class.
[0081] The associated class calling data can be the program code of the declaration of the class associated with the class to be loaded. The target associated class can be the class associated with the class to be loaded. The loading state query can be an operation of obtaining the loading state of the class at runtime. The loaded state can be a state in which the corresponding class is loaded at runtime.
[0082] By analyzing the associated class calling data, the target associated class associated with the class to be loaded can be determined, and the loading state of each target associated class can be queried. At this time, the runtime can have completed the loading of the target associated class, and the target associated class is in the loaded state, and the associated class instance corresponding thereto has been generated, so that the associated class field of the target class structure model can be directly assigned to the associated class instance of the target associated class.
[0083] In an optional embodiment, after determining the target associated class according to the associated class calling data in the target class dynamic file and querying the loading state of the target associated class, the method can further include: in the case that the target associated class is in the to-be-loaded state, obtaining an associated class dynamic file; creating an associated class structure model according to the associated class dynamic file; assigning target fields of the associated class structure model according to the associated class dynamic file to obtain the associated class instance of the target associated class; and assigning the associated class field of the target class structure model to the associated class instance of the target associated class.
[0084] The to-be-loaded state can be a state in which the corresponding class is not loaded at runtime. The associated class dynamic file can be a readable file used to store the program code of the target associated class. The associated class structure model can be a preset storage structure of the target associated class.
[0085] By querying the loading state of each target associated class, the runtime can also not have loaded the target associated class at this time, and the target associated class is in a to-be-loaded state, which can be loaded. Specifically, the corresponding associated class dynamic file of the target associated class can be obtained, and the associated class structure model can be created according to the associated class dynamic file and target field assignment is performed to obtain the associated class instance. It should be noted that in the process of performing target field assignment on the associated class structure model, for a class having an association relationship with the target associated class, if the runtime has loaded the class, the instance of the class can be directly assigned to the corresponding field of the target associated class; if the runtime has not loaded the class, the operation on the target associated class in the unloaded state is repeated until all the associated classes are loaded, and the instances of the loaded classes are assigned to the corresponding fields, so that the loading of the target associated class of the class to be loaded is completed, and the corresponding associated class instance is obtained. Finally, the obtained associated class instance is assigned to the associated class field of the target class structure model, so that the target associated class instance dynamically loaded is called in the obtained target class instance.
[0086] In an optional embodiment, determining the target associated class according to the associated class calling data in the target class dynamic file, and querying the loading state of the target associated class can include: obtaining the class name of each target associated class in the associated class calling data; querying the class instance corresponding to the class name in the class instance storage table; and in the case where the class instance is queried to exist, determining that the target associated class corresponding to the class name is in a loaded state.
[0087] The class instance storage table can be a preset query table used to store the correspondence between the class instance obtained after the class is loaded and the class name.
[0088] According to the declaration of the target associated class according to the associated class calling data, the class name of each target associated class can be obtained. Correspondingly, the class instance of each loaded class and the class name are stored in the preset class instance storage table, and the class name of the target associated class can be queried in the class instance storage table. If the class instance corresponding to the class name can be queried in the class instance storage table, it can be indicated that the target associated class is in a loaded state; otherwise, if the class instance corresponding to the class name cannot be queried in the class instance storage table, it can be indicated that the target associated class is in a to-be-loaded state.
[0089] In an optional implementation, after the target class instance is obtained by performing target field assignment on the target class structure model according to the target class dynamic file, the method can further include: obtaining the target class name in the target class instance; and storing the target class name and the target class instance in the class instance storage table correspondingly.
[0090] The target class name can be the class name of the class currently to be loaded.
[0091] Optionally, the target class name in the target class instance can be obtained by parsing the target class name in the target class dynamic file during the target field assignment, or the target class name in the target class instance can be obtained after the target field assignment is completed. The target class name and the target class instance are stored in the class instance storage table correspondingly, so that the target class instance can be queried according to the target class name in the class instance query table. When the class currently loaded is a target associated class of other classes to be loaded, the loading state of the class can be queried by querying the class instance query table, and it is determined that the class is in a loaded state, so that the class instance can be directly assigned to the corresponding field to call the class without loading the class again.
[0092] In an optional implementation, the class instance storage table can be stored in the structure of a hash table, the key can be the class name, and the value can be the class instance. Optionally, the class name can be a general ClassName, which represents the file URI (Uniform Resource Identifier, Uniform Resource Identifier) in which the class declaration code is located in the target class dynamic file. The result of concatenating the class name by a special symbol "#" is, for example, my_package / lib / util.dart#Utils. The file URI in which the class declaration code is located is usually generated in the compilation stage of the target class dynamic file and stored in the URI field of the ClassDeclaration node in the JSON format target class dynamic file. The value stores the corresponding InstanceClass instance.
[0093] In a typical example, Figure 4 A storage structure diagram of a class instance storage table provided for an embodiment of the application is shown in FIG. 1. Figure 4 As shown in FIG. 1, the class instance storage table ClassTable is stored in the structure of a hash table, the key in the ClassTable is the ClassName, and the value is the InstanceClass instance. Figure 4 As shown in FIG. 1, five pairs of class name and class instance key-value pairs are stored in the ClassTable.
[0094] In the above embodiment, using a hash table as the storage structure of the class instance storage table can optimize the time complexity of the loading state query, thereby greatly improving the efficiency of class loading. In the target class loading process, it is first determined whether the associated class to be loaded exists in the class instance storage table. If the associated class has been loaded, the corresponding associated class instance is directly returned. Otherwise, the associated class loading process is executed. In the above example, if ClassA has been loaded and stored in ClassTable, the class name ClassA and the instance InstanceClassA will be mapped in ClassTable. In the subsequent class loading, if there is a reference to ClassA, the corresponding InstanceClassA is directly returned. In this way, each class is loaded only once, the class loading efficiency is improved, and repeated loading of the class is avoided.
[0095] In an optional embodiment, the target field assignment to the target class structure model according to the target class dynamic file can include: parsing a class declaration node in the target class dynamic file to obtain a class name; and assigning the class name to a class name field of the target class structure model.
[0096] In an optional embodiment, the target field assignment to the target class structure model according to the target class dynamic file can include: traversing a constructor list in the target class dynamic file, and parsing a constructor node therein to obtain at least one constructor; and adding each constructor to a constructor list in the target class structure model.
[0097] In an optional embodiment, the target field assignment to the target class structure model according to the target class dynamic file can include: traversing a method list in the target class dynamic file, and parsing a method node therein to obtain at least one method; and adding each method to a method list in the target class structure model, which can include adding a static method to a static method list or adding an instance method to an instance method list.
[0098] In an optional embodiment, the target field assignment to the target class structure model according to the target class dynamic file can include: traversing an attribute list in the target class dynamic file, and parsing an attribute node therein to obtain at least one attribute; and adding each attribute to an attribute table in the target class structure model, which can include adding an attribute value of a static attribute to a static attribute table or adding an instance attribute to an instance attribute table. In a case where it is determined that the parsed attribute is a static attribute, an initializer of the static attribute is executed to obtain an initialized attribute value of the static attribute.
[0099] In an optional implementation, the target field assignment to the target class structure model according to the target class dynamic file can include: parsing the parent class declaration in the target class dynamic file to obtain a parent class name; querying the class instance storage table for a class instance corresponding to the parent class name, and in the case of querying the corresponding class instance, assigning the parent class name to a parent class field of the target class structure model; in the case of not querying the corresponding class instance, performing dynamic loading of the parent class as the target class to obtain a class name and a class instance corresponding to the class instance stored in the class instance storage table after the loading is completed, and assigning the class instance to the parent class field of the target class structure model to call the parent class instance.
[0100] In an optional implementation, the target field assignment to the target class structure model according to the target class dynamic file can include: parsing the interface class list in the target class dynamic file to obtain interface class names in sequence, querying the class instance storage table for a class instance corresponding to the interface class name, and in the case of querying the corresponding class instance, adding the interface class name to the interface class list of the target class structure model; in the case of not querying the corresponding class instance, performing dynamic loading of the interface class as the target class to obtain a class name and a class instance corresponding to the class instance stored in the class instance storage table after the loading is completed, and adding the class instance to the interface class list of the target class structure model to call the interface class instance, until the interface class list in the target class dynamic file is traversed.
[0101] In an optional implementation, the target field assignment to the target class structure model according to the target class dynamic file can include: parsing the interface class list in the target class dynamic file to obtain interface class names in sequence, querying the class instance storage table for a class instance corresponding to the interface class name, and in the case of querying the corresponding class instance, adding the interface class name to the interface class list of the target class structure model; in the case of not querying the corresponding class instance, performing dynamic loading of the interface class as the target class to obtain a class name and a class instance corresponding to the class instance stored in the class instance storage table after the loading is completed, and adding the class instance to the interface class list of the target class structure model to call the interface class instance, until the interface class list in the target class dynamic file is traversed.
[0102] In a typical example, Figure 5 A flowchart of a class loading method provided by an embodiment of the application is shown in FIG. 1. Figure 5As shown, after the Flutter application is started, according to the dynamic business clicked by the user, the runtime can obtain the target class dynamic file DSL JSON file name through the target file identification pageID in the entry file. It is judged whether the DSL JSON file exists, and in the case where it is determined that the DSL JSON file exists, the DSL JSON file is loaded and the ClassDeclaration class declaration node is parsed. It is judged whether the parsed ClassDeclaration class declaration node is an internal symbol of the dynamic resource package where the DSL JSON file is located, and if so, the target class InstanceClass with an internal class storage structure can be constructed, the class name and parent class class name of the name field are obtained by parsing the DSL JSON file, and the parent class InstanceClass instance corresponding to the parent class class name is searched in the class instance storage table ClassTable. If the parent class InstanceClass instance can be found, the parent class InstanceClass instance is assigned to the super field of the target class InstanceClass instance; if the parent class InstanceClass instance cannot be found, the corresponding DSL JSON file name is obtained through the parent class class name and subsequent steps are executed until completion to load the parent class. If the ClassDeclaration class declaration node is not an internal symbol of the dynamic resource package where the DSL JSON file is located, the target class ProxyMirrorClass with an external class storage structure can be created, and the parent class InstanceClass instance is assigned to the super field of the target class ProxyMirrorClass instance by parsing the DSL JSON file. The interface class implements list in the DSL JSON file is traversed, the InstanceClass instance is searched in the ClassTable through the class name in the list, it is judged whether the interface class InstanceClass instance can be found, in the case where it is determined that the interface class InstanceClass instance can be found, the interface class InstanceClass instance is added to the implements list of the target class instance; in the case where the interface class InstanceClass instance corresponding to the interface class class name cannot be found, the corresponding DSL JSON file name is obtained through the interface class class name and subsequent steps are executed until completion to load the interface class. The mixed class with / mixin list in the DSL JSON file is traversed, the InstanceClass instance is searched in the ClassTable through the class name in the list, it is judged whether the mixed class InstanceClass instance can be found, in the case where it is determined that the mixed class InstanceClass instance can be found, the mixed class InstanceClass instance is added to the / mixin list of the target class instance; in the case where the mixed class InstanceClass instance corresponding to the mixed class class name cannot be found, the corresponding DSL JSON file name is obtained through the mixed class class name and subsequent steps are executed until completion to load the mixed class.The process iterates through and parses the constructors in the DSLJSON file, adding them to the `constructors` list of the target class instance. It then iterates through the method list in the DSLJSON file, parsing each method to determine if it is static. If a method is static, it is added to the static method list of the target class instance; otherwise, it is added to the instance method list. Next, iterates through the property list in the DSLJSON file, parsing each property to determine if it is static. If a property is static, its initializer is executed to obtain the initial value `DataCell`, which is then stored in the `staticFields` table of the target class instance; otherwise, it is added to the `field` table of the target class instance. Finally, the resulting `InstanceClass` instance is stored in the `ClassTable`, completing the dynamic loading process of the target class.
[0103] This application provides a class loading method, apparatus, storage medium, and electronic device. Based on a user's business-triggered operation, it reads the corresponding target class dynamic file, creates a target class structure model based on the target class dynamic file, and assigns target fields to the target class structure model according to the target class dynamic file. This includes assigning associated class fields of the target class structure model to associated class instances, enabling direct invocation of the loaded associated class instances within the target class instances. This completes the dynamic loading of the target class, solving the problems of poor dynamic performance and lack of object-oriented dynamic update methods in existing technologies. It realizes object-oriented dynamic updates of applications, shortens the update cycle, makes the online quality maintenance system of applications more robust, and improves user experience.
[0104] According to another aspect of the embodiments of the present invention, Figure 6 This is a schematic diagram of a class loading device provided in an embodiment of the present invention, as shown below. Figure 6 As shown, the device includes a file reading module 610, a model creation module 620, and a field assignment module 630, wherein:
[0105] The file reading module 610 is used to read target type dynamic files based on user business trigger operations;
[0106] The model creation module 620 is used to create a target class structure model based on the target class dynamic file;
[0107] The field assignment module 630 is used to assign target field values to the target class structure model according to the target class dynamic file to obtain a target class instance;
[0108] The target field assignment includes assigning the associated class field of the target class structure model to an associated class instance.
[0109] In an optional implementation, the field assignment module 630 can include a state query unit configured to determine a target associated class according to the associated class call data in the target class dynamic file, and perform a loaded state query on the target associated class; and a first assignment unit configured to, in a case where the target associated class is determined to be in a loaded state, assign the associated class field of the target class structure model to an associated class instance of the target associated class.
[0110] In an optional implementation, the field assignment module 630 can further include a second assignment unit configured to, in a case where the target associated class is determined to be in a to-be-loaded state, obtain an associated class dynamic file; create an associated class structure model according to the associated class dynamic file; perform target field assignment on the associated class structure model according to the associated class dynamic file to obtain an associated class instance of the target associated class; and assign the associated class field of the target class structure model to the associated class instance of the target associated class.
[0111] In an optional implementation, the state query unit can include an associated class obtaining subunit configured to obtain the class name of each target associated class in the associated class call data; an instance query subunit configured to query the class instance corresponding to the class name in the class instance storage table; and a state determination subunit configured to, in a case where the class instance is determined to exist, determine that the target associated class corresponding to the class name is in a loaded state.
[0112] In an optional implementation, the class loading apparatus can further include an instance storage model configured to obtain the target class class name in the target class instance; and store the target class class name and the target class instance correspondingly in the class instance storage table.
[0113] In an optional implementation, the file reading module 610 can include an identifier obtaining unit configured to obtain a target file identifier in the entry file according to a business triggering operation; a file name obtaining unit configured to obtain a dynamic file name having a mapping relationship with the target file identifier in a preset mapping table; and a file obtaining unit configured to, in a case where the corresponding dynamic file of the dynamic file name is determined to exist, determine the corresponding dynamic file as the target class dynamic file, and read the target class dynamic file.
[0114] In an optional implementation, the model creation module 620 can include a class declaration obtaining unit configured to obtain target class declaration data in the target class dynamic file; an inner class creation unit configured to, in a case where the target class declaration data is determined to be inner class data, create an inner class structure model; and an outer class creation unit configured to, in a case where the target class declaration data is determined to be outer class data, create an outer class structure model.
[0115] According to another aspect of the embodiments of the present application, Figure 7 A structural schematic diagram of an electronic device provided by the embodiments of the present application is shown in Figure 7 The electronic device includes a processor 710, a memory 720, an input device 730 and an output device 740; the number of processors 710 in the electronic device can be one or more, Figure 7 The processor 710 in the electronic device, the memory 720, the input device 730 and the output device 740 can be connected through a bus or other means, Figure 7 The connection through the bus is taken as an example.
[0116] The memory 720 is a kind of computer readable storage medium, which can be used to store software programs, computer executable programs and modules, such as program instructions / modules (for example, the file reading module 610, the model creating module 620 and the field assignment module 630 in the class loading device) corresponding to the class loading method in the embodiments of the present application. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 720, that is, realizes the class loading method described above.
[0117] The memory 720 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application program required by a function; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory 720 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some examples, the memory 720 can further include a memory remotely arranged with respect to the processor 710, which can be connected to the electronic device through a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0118] The input device 730 can be used to receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device, and can also be a camera for acquiring images and a pickup device for acquiring audio data. The output device 740 can include a display device such as a display screen, and can include an audio device such as a loudspeaker. It should be noted that the specific composition of the input device 730 and the output device 740 can be set according to the actual situation. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 720.
[0119] According to another aspect of the embodiments of the present application, the embodiments of the present application further provide a computer readable storage medium, which comprises a stored program, wherein the program performs the class loading method when running.
[0120] reading the target class dynamic file according to the service triggering operation of the user;
[0121] creating a target class structure model according to the target class dynamic file;
[0122] performing target field assignment on the target class structure model according to the target class dynamic file to obtain a target class instance;
[0123] The target field assignment comprises assigning an associated class field of the target class structure model to an associated class instance.
[0124] Of course, the storage medium provided by the embodiments of the present application comprises computer executable instructions, which are not limited to the method operations described above, but can also perform the related operations in the class loading method provided by any of the embodiments of the present application.
[0125] From the above description of the embodiments, those skilled in the art can clearly understand that the present application can be realized by means of software and necessary universal hardware, and of course can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a floppy disk, a read-only memory (ROM), a random access memory (RAM), a FLASH memory, a hard disk or an optical disk, and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in various embodiments of the present application.
[0126] It should be noted that in the above embodiments of the class loading device, each unit and module included is only divided according to functional logic, but is not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy distinction, and do not limit the protection scope of the present application.
[0127] The above description is only the preferred embodiments of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should also be considered as the protection scope of the present application.
Claims
1. A class loading method, characterized by, The method comprises the following steps: reading a target class dynamic file according to a business trigger operation of a user; creating a target class structure model according to the target class dynamic file; performing target field assignment on the target class structure model according to the target class dynamic file to obtain a target class instance; wherein the target field assignment comprises assigning an associated class field of the target class structure model to an associated class instance.
2. The method of claim 1, wherein, The target field assignment on the target class structure model according to the target class dynamic file comprises: determining a target associated class according to associated class call data in the target class dynamic file, and performing loading state query on the target associated class; in a case where it is queried that the target associated class is in a loaded state, assigning the associated class field of the target class structure model to the associated class instance of the target associated class.
3. The method of claim 2, wherein, After the step of determining the target associated class according to the associated class call data in the target class dynamic file and performing loading state query on the target associated class, the method further comprises: in a case where it is queried that the target associated class is in a to-be-loaded state, obtaining an associated class dynamic file; creating an associated class structure model according to the associated class dynamic file; performing the target field assignment on the associated class structure model according to the associated class dynamic file to obtain the associated class instance of the target associated class; assigning the associated class field of the target class structure model to the associated class instance of the target associated class.
4. The method of claim 2, wherein, The step of determining the target associated class according to the associated class call data in the target class dynamic file and performing loading state query on the target associated class comprises: obtaining the class name of each target associated class in the associated class call data; querying the class instance corresponding to the class name in a class instance storage table; in a case where it is queried that the class instance exists, determining that the target associated class corresponding to the class name is in a loaded state.
5. The method of claim 4, wherein, After the step of performing target field assignment on the target class structure model according to the target class dynamic file to obtain a target class instance, the method further comprises: obtaining the target class class name in the target class instance; storing the target class class name and the target class instance corresponding thereto in the class instance storage table.
6. The method of claim 1, wherein, The step of reading a target class dynamic file according to a business trigger operation of a user comprises: obtaining a target file identifier in an entry file according to the business trigger operation; obtaining a dynamic file name having a mapping relationship with the target file identifier in a preset mapping table; in a case where it is determined that the corresponding dynamic file of the dynamic file name exists, determining the corresponding dynamic file as the target class dynamic file and reading the target class dynamic file.
7. The method of claim 1, wherein, The step of creating a target class structure model according to the target class dynamic file comprises: obtaining target class declaration data in the target class dynamic file; in a case where it is determined that the target class declaration data is internal class data, creating an internal class structure model; in a case where it is determined that the target class declaration data is external class data, creating an external class structure model.
8. A class loading apparatus, characterized by comprising: The method comprises the following steps: a file reading module, configured to read a target class dynamic file according to a business trigger operation of a user; A model creating module is configured to create a target class structure model according to the target class dynamic file; A field assigning module is configured to assign target fields of the target class structure model according to the target class dynamic file, and obtain a target class instance. The target field assignment includes assigning an associated class field of the target class structure model to an associated class instance.
9. A computer readable storage medium, characterized in that, The computer readable storage medium includes a stored program, and the program is configured to execute the class loading method in any one of claims 1 to 7. 10.An electronic device comprising a memory and a processor, the electronic device characterized by, The memory stores a computer program, and the processor is configured to execute the class loading method in any one of claims 1 to 7 through the computer program.
Citation Information
Patent Citations
Object instantiation method and device, storage medium and electronic device
CN115576544A
Model generation method, device and equipment based on Java language and readable storage medium
CN115686459A
Class instance construction method and device, equipment, storage medium and program product
CN118012391A