CN106528255B - Kind loading method and device - Google Patents

Kind loading method and device Download PDF

Info

Publication number
CN106528255B
CN106528255B CN201611175849.8A CN201611175849A CN106528255B CN 106528255 B CN106528255 B CN 106528255B CN 201611175849 A CN201611175849 A CN 201611175849A CN 106528255 B CN106528255 B CN 106528255B
Authority
CN
China
Prior art keywords
class
address
loaded
file
mapped
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611175849.8A
Other languages
Chinese (zh)
Other versions
CN106528255A (en
Inventor
董俊杰
张昭
贾慧星
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xiaomi Mobile Software Co Ltd
Original Assignee
Beijing Xiaomi Mobile Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Xiaomi Mobile Software Co Ltd filed Critical Beijing Xiaomi Mobile Software Co Ltd
Priority to CN201611175849.8A priority Critical patent/CN106528255B/en
Publication of CN106528255A publication Critical patent/CN106528255A/en
Application granted granted Critical
Publication of CN106528255B publication Critical patent/CN106528255B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • G06F9/4451User profiles; Roaming

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The disclosure is directed to a kind of kind loading method and devices.This method comprises: establishing mapped file according to the entrance class in the APK file of application program, if the failure when mapping to mapped file with reference to fixing address, mapped file is then mapped to first address different from fixing address is referred to, according to the first deviant corresponding with the mark of class to be loaded in the mark of class to be loaded and mapping table and the first address, determine the first address of class to be loaded, the address that the class first address cited in it is stored in class to be loaded is determined according to the second deviant corresponding with the mark of class to be loaded in the first address of class to be loaded and mapping table, and the value stored in address is revised as the difference of the first address and reference fixing address plus the value after the value stored in address, initialize class to be loaded, it realizes and realizes that flexibly load is using journey in the case where not influencing operating system stability The class that sequence defines, thus, improve the starting speed and the speed of service of application program.

Description

Kind loading method and device
Technical field
This disclosure relates to computer technology more particularly to a kind of kind loading method and device.
Background technique
Android operation system is most popular system on current terminal device.Android operation system uses java language As main development language.Since 5.0 versions, Android system introduces an entitled ART (Android RunTime) Virtual machine.The program write with java, is compiled into the file of DEX format, and DEX file first can be compiled into terminal device by ART Central processing unit (Central Processing Unit;Referred to as: the CPU) machine instruction code that can directly run, then CPU executes the machine code after compiling again, can greatly speed up the speed of service of system.In order to further increase the operation speed of system Degree, how ART, which loads java class (class), becomes extremely important.
In the related technology, ART loads java class in the following manner: by what is enumerated in preload-classes file Class is first loaded into memory, and then this block later, is connected to these classes from being transported in the continuous memory of a block address in memory The address of the data of continuous memory and continuous memory is stored in boot.art file;When needing to load java class, ART At the address of boot.art File Mapping to contiguous memory, thereby realizing class can directly be used.
Summary of the invention
To overcome the problems in correlation technique, the disclosure provides a kind of kind loading method and device.
According to the first aspect of the embodiments of the present disclosure, a kind of kind loading method is provided, comprising:
Mapped file is established according to the entrance class in the APK file of application program;It wherein, include ginseng in the mapped file Fixing address, mapping table and the data according to each class in the set of the determining class of the entrance class are examined, are deposited in the mapping table Contain the storage location and the mapped file of the mark, the class of each class in the mapped file first position it Between the first deviant and the class store between the position of class first address and first position of the class cited in it The mapping relations of second deviant, it is described with reference to fixing address be the mapped file memory extremely to be mapped address;
If the failure when the mapped file is mapped to the reference fixing address, the mapped file is mapped to From first address different with reference to fixing address;
Partially according in the mark of class to be loaded and the mapping table corresponding with the mark of the class to be loaded first Shifting value and first address, determine the first address of the class to be loaded;
According to corresponding with the mark of the class to be loaded in the first address and the mapping table of the class to be loaded Second deviant determines the address that the class first address cited in it is stored in the class to be loaded, and will store in the address Value be revised as first address and the difference with reference to fixing address plus the value after the value stored in the address;
Initialize the class to be loaded.
With reference to first aspect, in the first possible implementation of the first aspect, the APK according to application program Entrance class in file establishes mapped file, comprising:
Entrance class is determined according to the APK file of application program, determines class cited in the entrance class, by the entrance class And set of the class as class cited in the entrance class;
All classes in the set of the class are loaded onto the memory of terminal device;
All classes in the memory are copied in continuous memory, selection refers to fixing address, and according to the ginseng Examine fixing address modify stored in each class its cited in class first address;
Cited in it is stored in storage location and each class in mapped file according to the mark of each class, each class The position of class first address, establishes mapping table;
The mapping is written into the data of each class in the set with reference to fixing address, the mapping table and the class In file.
With reference to first aspect or the first possible implementation of first aspect, second in first aspect are possible Implementation in, the initialization class to be loaded, comprising:
Call the initialization function of the class to be loaded.
The possible implementation of with reference to first aspect the first, in the third possible implementation of first aspect In, the APK file according to application program determines entrance class, comprising:
Read the global configuration file in the APK file;
The entrance class is obtained from the global configuration file.
According to the second aspect of an embodiment of the present disclosure, a type loading device is provided, comprising:
Module is established, the entrance class being configured as in the APK file according to application program establishes mapped file;Wherein, institute State includes referring to fixing address, mapping table and the number according to each class in the set of the determining class of the entrance class in mapped file According to being stored with the mark of each class, storage location of the class in the mapped file and the mapping in the mapping table The first deviant and the class between first position of file store the class first address cited in it position and the class First position between the second deviant mapping relations, it is described with reference to fixing address be the mapped file it is to be mapped extremely Memory address;
Mapping block is configured as when failing when the mapped file is mapped to the reference fixing address, will The mapped file maps to and first address different with reference to fixing address;
Determining module, be configured as according in the mark of class to be loaded and the mapping table with the class to be loaded Corresponding first deviant and first address are identified, determines the first address of the class to be loaded;
Modified module, be configured as in first address and the mapping table according to the class to be loaded with it is described to be loaded Corresponding second deviant of mark of class determine the address that the class first address cited in it is stored in the class to be loaded, and The value stored in the address is revised as first address and the difference with reference to fixing address plus in the address Value after the value of storage;
Initialization module is configured as initializing the class to be loaded.
In conjunction with second aspect, in the first possible implementation of the second aspect, the module of establishing includes:
It determines submodule, is configured as determining entrance class according to the APK file of application program, determine that the entrance class is drawn Class, using class cited in the entrance class and the entrance class as the set of class;
Submodule is loaded, is configured as all classes in the set of the class being loaded onto the memory of terminal device;
Submodule is replicated, is configured as all classes in the memory being copied in continuous memory, selection is with reference to solid Determine address, and according to it is described modified with reference to fixing address stored in each class its cited in class first address;
Setting up submodule is configured as storage location in mapped file of the mark according to each class, each class and every The position that the class first address cited in it is stored in a class, establishes mapping table;
Submodule is written, being configured as will be each in the set with reference to fixing address, the mapping table and the class The data of class are written in the mapped file.
In conjunction with the possible implementation of the first of second aspect or second aspect, second in second aspect may Implementation in, the initialization module includes:
Submodule is called, is configured as calling the initialization function of the class to be loaded.
In conjunction with the first possible implementation of second aspect, in the third possible implementation of second aspect In, the determining submodule includes:
Reading submodule is configured as reading the global configuration file in the APK file;
Acquisition submodule is configured as obtaining the entrance class from the global configuration file.
According to the third aspect of an embodiment of the present disclosure, a type loading device is provided, comprising:
Processor;
For storing the memory of the processor-executable instruction;
Wherein, the processor is configured to:
Mapped file is established according to the entrance class in the APK file of application program;It wherein, include ginseng in the mapped file Fixing address, mapping table and the data according to each class in the set of the determining class of the entrance class are examined, are deposited in the mapping table Contain the storage location and the mapped file of the mark, the class of each class in the mapped file first position it Between the first deviant and the class store between the position of class first address and first position of the class cited in it The mapping relations of second deviant, it is described with reference to fixing address be the mapped file memory extremely to be mapped address;
If the failure when the mapped file is mapped to the reference fixing address, the mapped file is mapped to From first address different with reference to fixing address;
Partially according in the mark of class to be loaded and the mapping table corresponding with the mark of the class to be loaded first Shifting value and first address, determine the first address of the class to be loaded;
According to corresponding with the mark of the class to be loaded in the first address and the mapping table of the class to be loaded Second deviant determines the address that the class first address cited in it is stored in the class to be loaded, and will store in the address Value be revised as first address and the difference with reference to fixing address plus the value after the value stored in the address;
Initialize the class to be loaded.
The technical scheme provided by this disclosed embodiment can include the following benefits:
In one embodiment, mapped file is established by the entrance class in the APK file according to application program, if will Mapped file maps to failure when with reference to fixing address, then mapped file is mapped to first ground different from fixing address is referred to Location, according to the first deviant corresponding with the mark of class to be loaded in the mark of class to be loaded and mapping table and the first ground Location determines the first address of class to be loaded, according to the mark in the first address and mapping table of class to be loaded with class to be loaded Corresponding second deviant determines the address that the class first address cited in it is stored in class to be loaded, and will store in address Value is revised as the difference of the first address and reference fixing address plus the value after the value stored in address, initializes to be loaded Class is realized that first, when that can not map to mapped file with reference to fixing address, mapped file is mapped to Other positions may be implemented easily compared to the mode that mapped file can only be mapped to fixing address in the related technology It is more flexible according to the practival operating condition loading classes of application program;The second, the class loaded in the embodiment of the present disclosure is using journey The class of definition in sequence, compared in the related technology can only the class that defines of load operating system, application is more extensive;Third, this public affairs The method for opening embodiment does not modify the source code of ART, may be implemented to load the class that independent application program defines, does not influence to grasp Make the stability of system.In conclusion the kind loading method that the embodiment of the present disclosure provides, realize not influence operating system steady The class that neatly loading application programs define is realized in qualitative situation, thus, improve the starting speed and fortune of application program Scanning frequency degree improves user experience in turn.
It should be understood that above general description and following detailed description be only it is exemplary and explanatory, not The disclosure can be limited.
Detailed description of the invention
The drawings herein are incorporated into the specification and forms part of this specification, and shows the implementation for meeting the disclosure Example, and together with specification for explaining the principles of this disclosure.
Fig. 1 is a kind of flow chart of kind loading method shown according to an exemplary embodiment;
Fig. 2 is the block diagram of type loading device shown according to an exemplary embodiment;
Fig. 3 is the block diagram of the type loading device shown according to another exemplary embodiment;
Fig. 4 is the block diagram of the type loading device shown according to a further exemplary embodiment;
Fig. 5 is the block diagram according to the type loading device shown in another exemplary embodiment;
Fig. 6 is the block diagram of the type loading device shown according to another exemplary embodiment;
Fig. 7 is the block diagram of type loading device shown according to an exemplary embodiment.
Through the above attached drawings, it has been shown that the specific embodiment of the disclosure will be hereinafter described in more detail.These attached drawings It is not intended to limit the scope of this disclosure concept by any means with verbal description, but is by referring to specific embodiments Those skilled in the art illustrate the concept of the disclosure.
Specific embodiment
Example embodiments are described in detail here, and the example is illustrated in the accompanying drawings.Following description is related to When attached drawing, unless otherwise indicated, the same numbers in different drawings indicate the same or similar elements.Following exemplary embodiment Described in embodiment do not represent all implementations consistent with this disclosure.On the contrary, they be only with it is such as appended The example of the consistent device and method of some aspects be described in detail in claims, the disclosure.
Fig. 1 is a kind of flow chart of kind loading method shown according to an exemplary embodiment.As shown in Figure 1, the disclosure Embodiment provide kind loading method the following steps are included:
In a step 101, mapped file is established according to the entrance class in the Android installation package file of application program.
It wherein, include with reference to fixing address, mapping table and according to every in the set of the determining class of entrance class in mapped file The data of a class are stored with the of the storage location and mapped file of the mark, class of each class in mapped file in mapping table The first deviant and class between one position store between the position of the class first address cited in it and first position of class The second deviant mapping relations, with reference to fixing address be mapped file memory extremely to be mapped address.
The kind loading method that the embodiment of the present disclosure provides can be executed by terminal device.Terminal device can be hand-held set Standby, mobile unit, calculates equipment and various forms of user equipmenies (User Equipment at wearable device;Referred to as: UE), mobile station (Mobile Station;Referred to as: MS) and terminal (terminal) etc..Illustratively, in the embodiment of the present disclosure Terminal device can be mobile phone.
The kind loading method that the embodiment of the present disclosure provides can be to be executed by the ART in Android operation system, by holding The class of the definition in loading application programs may be implemented in the kind loading method that the row embodiment of the present disclosure provides, and in turn, improves application The starting speed and the speed of service of program.Class involved in it can be java class.If ART is mentioned using the embodiment of the present disclosure Relevant class, then can be improved the starting speed of application program when what the kind loading method of confession loaded is application program launching;Such as The kind loading method load that fruit ART is provided using the embodiment of the present disclosure is relevant class when application program is run, then can mention The speed of service of high application program.
Android installation kit (the Android Package of application program in the embodiment of the present disclosure;Referred to as: APK) it can be The APK for the third party application installed on terminal device.Entrance class refers to realizing the class of the application program entry function.
When entrance class in the APK file according to application program establishes mapped file, it can be real as follows It is existing: entrance class being determined according to the APK file of application program, determines class cited in entrance class, entrance class and entrance class are drawn Set of the class used as class;All classes in the set of class are loaded onto the memory of terminal device;It will be all in memory Class is copied in continuous memory, and selection refers to fixing address, and modifies its stored in each class according to reference fixing address The first address of cited class;It is deposited in the storage location and each class in mapped file according to the mark of each class, each class The position for storing up the class first address cited in it, establishes mapping table;By class each in the set of reference fixing address, mapping table and class Data write-in mapped file in.
Terminal device can read the global configuration file (AndroidManifest.xml) in APK file, and from this Entrance class is determined in AndroidManifest.xml file.Entrance class is being determined and then is reading in APK Classes.dex file parses this document, can determine class cited in entrance class.It include institute in classes.dex file Have the definition of class and the reference information of class, therefore, after entrance class has been determined, it can according to entrance class and Classes.dex file determines class cited in entrance class.Using class cited in entrance class and entrance class as a class set.
The data of each class in class set may include: function, the packet that the title of class, the class member that includes, class include The address of the function contained, the access authority of class and adduction relationship of class etc..Adduction relationship may include the ground of class cited in class Location.Illustratively, the first address of the class cited in it is stored in the data of class.
After the set of class has been determined, all classes in the set are loaded onto the memory of terminal device.Here interior Deposit the memory that can be address dispersion.Class, which is loaded onto memory, indicates that the function of the content realization class by analysis classes is internal Deposit into row read or write.Later, all classes in these memories are copied in continuous memory.Continuous memory means this The address of a little memories is continuous.Reselection refers to fixing address, this is that mapped file needs map to reference to fixing address Memory address.It should be noted that can be identical as the address of continuous memory with reference to fixing address, it can also be different. And modified according to reference fixing address stored in each class its cited in class first address.
Modify stored in each class its cited in the first address of class be to guarantee that this class can be quoted correctly Class cited in it.For example, the first address of contiguous memory is the 0th position that 1000, class A is stored in contiguous memory It sets, then the first address of class A is the 100th position that 1000, class B is stored in contiguous memory, then the first ground of class B Location is 1100, class A reference class B, then the first address 1100 of class B is stored in class A, is generating mapping text When part, class A is stored in the 0th position of mapped file, and class B is stored in the 100th position of mapped file, have with Lower two kinds of situations: assuming that if reference fixing address at this time is 1000, then if mapped file being mapped to the address, The address of class A be the address of 1000, class B be stored in 1100, class A class B first address be 1100, Then from the memory that address is 1100 go out that class B can be read, reference is correct;Assuming that reference fixing address at this time is 2000, it is assumed that do not modify the adduction relationship in class A, then when mapped file being mapped to the address, class A mapping The address for the class B for mapping to 2100 to 2000, class B, but storing in class A is still 1100, but is from address Class B can't be read in 1100 memory, and misquotation occurs, so, after having determined with reference to fixing address, need Modified according to the difference of itself and the address of contiguous memory stored in each class its cited in class first address, after upper example In a kind of situation, contiguous memory and be 1000 with reference to the difference between fixing address, then the class B that will be stored in class A First address be revised as 1100+1000=2100, correct reference can be realized.
It should be noted that selection is copied to continuous memory with reference to the step of fixing address and by all classes in memory In step between there is no sequential relationship.If all classes in memory are being copied to company with reference to the step of fixing address by selection Before step in continuous memory, when the first address of the class of the reference stored in modifying each class, duplication and modification can be It carries out simultaneously.
After all classes in class set are copied in continuous memory, need to establish mapping table.It is stored in mapping table Be mark, first deviant of the class between the storage location in mapped file and first position of mapped file of class with And class stores between the second deviant between the position and such first position of the class first address cited in it one by one Corresponding relationship.It should be noted that the first address of class refers to after class is replicated in contiguous memory in the embodiment of the present invention The first address of class.The mark of class can be title of class etc. can be with such attribute of unique identification.Illustrated below first partially Shifting value and the second deviant, it is assumed that class A is stored in the 100th position of mapped file, then the first deviant is exactly 100, Assuming that is stored at the 8th byte of class A is the first address of class B cited in class A, then the second deviant is just It is 8.Optionally, what first position of mapped file indicated is the first character section of mapped file, first position table of class What is shown is the first character section of class.
Optionally, the process for establishing mapping table can be established by the way of Hash mapping, then the mapping table finally established For Hash Map.Hash Map, which can be improved, searches the first deviant corresponding with the mark of class and second in subsequent step The speed of deviant.
After establishing mapping table, the data of class each in the set of reference fixing address, mapping table and class are written In mapped file, that is, completes and establish mapped file.
In a step 102, if the failure when mapping to mapped file with reference to fixing address, mapped file is mapped to First address different from reference fixing address.
When needing loading classes, first mapped file is mapped to reference to fixing address.If referring to fixing address quilt at this time Other program occupies, and is not available, then can map failure, then mapped file is mapped to first different from fixing address is referred to Address.
In step 103, according in the mark of class to be loaded and mapping table corresponding with the mark of class to be loaded One deviant and the first address, determine the first address of class to be loaded.
According to the concrete operations of concrete condition and user in program operation process, class to be loaded is determined.
After class to be loaded has been determined, it is thus necessary to determine that the first address of class to be loaded.At this point, the first ground of mapped file Location is the first address, and the first deviant can be determined from mapping table, and the first address is to be loaded plus the first deviant The first address of class.
At step 104, according to corresponding with the mark of class to be loaded in the first address and mapping table of class to be loaded Second deviant determines the address that the class first address cited in it is stored in class to be loaded, and the value stored in address is modified The value after the value stored in address is added for the first address and with reference to the difference of fixing address.
After the first address that class to be loaded has been determined, need to modify cited in its of the storage in the class to be loaded Class first address.Need first to find the address for the class first address that the class to be loaded stores cited in it at this time.
It can determine in class to be loaded and deposit according to the first address of the class to be loaded determined in step 103 and mapping table The address of the class first address cited in it is stored up, the first address of class specially to be loaded adds the second deviant corresponding to it. Later, the value in the address that the class first address cited in it is stored in class to be loaded is revised as the first address and with reference to fixing The difference of address is plus the value stored originally in the address.
The implementation procedure of step 103 and step 104, which can be, establishes a new Classloader by ART to realize.
Illustrate the process of step 103 Yu step 104 with a specific example below: when generating mapped file, reference It is the address of 1000, class B is that class B is stored in 1100, class A that fixing address, which is the address of 1000, class A, First address be that the position of 1100 this value is stored in 1100, class A is the 8th position, class A is stored in mapped file The 0th position, class B is stored in the 100th position of mapped file, then in mapped file, the mark of corresponding class A Know, the first deviant is 0, and the second deviant is 8.Failure, choosing are mapped when mapping to the mapped file with reference to fixing address It selects and maps to mapped file at 2000, then the first address is 2000.In order to guarantee that subsequent class A reference is correct, need to repair Change the adduction relationship in class A.The first address for determining the class A after mapping first, with the first address plus the first offset Value is the first address that can determine class A, is 2000, and similarly, the first address of class B is 2100.In the head for determining class A After address, the first address of class A is the ground that the class first address cited in it is stored in class A plus the second deviant Location, the address are 2008.The value 1100 stored in the address is revised as 2000-1000+1100=2100, indicates class A The first address of the class of reference is 2100.It can be seen that class B is tangibly stored in 2100, it may therefore be assured that reference is just Really.
In step 105, class to be loaded is initialized.
It is realized by the initialization function for the class for calling this to be loaded and initializes the class to be loaded.Complete the load of class Journey.
The kind loading method that the embodiment of the present disclosure provides is established by the entrance class in the APK file according to application program Mapped file is mapped to if the failure when mapping to mapped file with reference to fixing address and refers to fixation by mapped file The first different address of address, according in the mark of class to be loaded and mapping table corresponding with the mark of class to be loaded first Deviant and the first address, determine the first address of class to be loaded, according in the first address and mapping table of class to be loaded with to Corresponding second deviant of mark of the class of load determines the address that the class first address cited in it is stored in class to be loaded, and By the value stored in address be revised as the first address and with reference to fixing address difference plus the value after the value stored in address, Class to be loaded is initialized, is realized that first, when that can not map to mapped file with reference to fixing address, it will Mapped file maps to other positions, compared to the mode that mapped file can only be mapped to fixing address in the related technology, The practival operating condition loading classes easily according to application program may be implemented, it is more flexible;The second, add in the embodiment of the present disclosure The class of load is the class of the definition in application program, compared in the related technology can only the class that defines of load operating system, using more Extensively;Third, the method for the embodiment of the present disclosure do not modify the source code of ART, and it is fixed to may be implemented to load independent application program The class of justice, does not influence the stability of operating system.In conclusion the kind loading method that the embodiment of the present disclosure provides, realizes It does not influence to realize the class that neatly loading application programs define in the case where operating system stability, thus, it improves using journey The starting speed and the speed of service of sequence improve user experience in turn.
Following is embodiment of the present disclosure, can be used for executing embodiments of the present disclosure.It is real for disclosure device Undisclosed details in example is applied, embodiments of the present disclosure is please referred to.
Fig. 2 is the block diagram of type loading device shown according to an exemplary embodiment.Such loading device can lead to Crossing being implemented in combination with for software, hardware or both becomes comprising some or all of of terminal device.As shown in Fig. 2, the disclosure The class loading device that embodiment provides includes following module:
Module 21 is established, the entrance class being configured as in the APK file according to application program establishes mapped file.
It wherein, include with reference to fixing address, mapping table and according to every in the set of the determining class of entrance class in mapped file The data of a class are stored with the of the storage location and mapped file of the mark, class of each class in mapped file in mapping table The first deviant and class between one position store between the position of the class first address cited in it and first position of class The second deviant mapping relations, with reference to fixing address be mapped file memory extremely to be mapped address.
Mapping block 22 is configured as when failing when mapping to mapped file with reference to fixing address, by mapping text Part maps to first address different from fixing address is referred to.
Determining module 23 is configured as the mark pair in mark and mapping table according to class to be loaded with class to be loaded The first deviant answered and the first address, determine the first address of class to be loaded.
Modified module 24 is configured as the mark in first address and mapping table according to class to be loaded with class to be loaded Corresponding second deviant determines the address that the class first address cited in it is stored in class to be loaded, and will store in address Value is revised as the difference of the first address and reference fixing address plus the value after the value stored in address.
Initialization module 25 is configured as initializing class to be loaded.
The class loading device that the embodiment of the present disclosure provides is established module by setting, is configured as according to application program Entrance class in APK file establishes mapped file, wherein includes with reference to fixing address, mapping table and according to entering in mapped file The data of each class in the set for the class that mouthful class determines, the mark for being stored with each class in mapping table, class are in mapped file The first deviant and class between storage location and first position of mapped file store the position of the class first address cited in it The mapping relations for setting the second deviant between first position of class are that mapped file is to be mapped extremely with reference to fixing address The address of memory, mapping block are configured as when failing when mapping to mapped file with reference to fixing address, by mapping text Part map to from reference to different the first address of fixing address, determining module, be configured as according to the mark of class to be loaded and First deviant corresponding with the mark of class to be loaded and the first address, determine the first address of class to be loaded in mapping table, Modified module is configured as corresponding with the mark of class to be loaded second in first address and mapping table according to class to be loaded Deviant determines the address that the class first address cited in it is stored in class to be loaded, and the value stored in address is revised as The difference of one address and reference fixing address is configured as initial plus the value after the value stored in address, initialization module Change class to be loaded, is realized that first, when that can not map to mapped file with reference to fixing address, will map File Mapping is to other positions, can be with compared to the mode that mapped file can only be mapped to fixing address in the related technology It realizes easily according to the practival operating condition loading classes of application program, it is more flexible;The second, it is loaded in the embodiment of the present disclosure Class is the class of the definition in application program, compared in the related technology can only the class that defines of load operating system, application is more extensive; Third, the embodiment of the present disclosure do not modify the source code of ART, may be implemented to load the class that independent application program defines, not shadow Ring the stability of operating system.To sum up, the class loading device that the embodiment of the present disclosure provides is realized not influence operating system steady The class that neatly loading application programs define is realized in qualitative situation, thus, improve the starting speed and fortune of application program Scanning frequency degree improves user experience in turn.
Fig. 3 is the block diagram of the type loading device shown according to another exemplary embodiment.The embodiment of the present disclosure is in Fig. 1 On the basis of illustrated embodiment, one is made to the concrete composition for establishing module 21 and is described in detail.As shown in figure 3, the embodiment of the present disclosure On the basis of embodiment shown in Fig. 2, establishing module 21 includes:
It determines submodule 211, is configured as determining entrance class according to the APK file of application program, determines that entrance class is drawn Class, using class cited in entrance class and entrance class as the set of class.
Submodule 212 is loaded, all classes being configured as in the set by class are loaded onto the memory of terminal device.
Submodule 213 is replicated, is configured as all classes in memory being copied in continuous memory, selection is with reference to fixation Address, and modified according to reference fixing address stored in each class its cited in class first address.
Setting up submodule 214, be configured as storage location in mapped file of the mark according to each class, each class and The position that the class first address cited in it is stored in each class, establishes mapping table.
Submodule 215 is written, is configured as writing the data of each class in the set with reference to fixing address, mapping table and class Enter in mapped file.
In the class loading device that the embodiment of the present disclosure provides, the process for establishing mapped file is realized simply, is improved class and is added The stability of load.
Fig. 4 is the block diagram of the type loading device shown according to a further exemplary embodiment.The embodiment of the present disclosure is to first The concrete composition of beginningization module 25 is made one and is described in detail.As shown in figure 4, the embodiment of the present disclosure is in Fig. 2 or embodiment illustrated in fig. 3 On the basis of, initialization module 25 includes:
Submodule 251 is called, is configured as calling the initialization function of class to be loaded.
In the class loading device that the embodiment of the present disclosure provides, realizes that the process for initializing class to be loaded is simple, improve The stability and speed of class load.
Fig. 5 is the block diagram according to the type loading device shown in another exemplary embodiment.The embodiment of the present disclosure is in Fig. 3 On the basis of illustrated embodiment, the concrete composition work one for determining submodule 211 is described in detail.As shown in figure 5, the disclosure is implemented In the class loading device that example provides, determine that submodule 211 includes:
Reading submodule 2111 is configured as reading the global configuration file in APK file.
Acquisition submodule 2112 is configured as obtaining entrance class from global configuration file.
The class loading device that the embodiment of the present disclosure provides is configured as reading in APK file by the way that reading submodule is arranged Global configuration file, acquisition submodule, be configured as from global configuration file obtain entrance class, realize and quickly determine Entrance class improves the speed of class load.
The foregoing describe the built-in function of class loading device and structure, Fig. 6 is shown according to another exemplary embodiment The block diagram of one type loading device.As shown in fig. 6, such loading device can be realized are as follows:
Processor 61;
Memory 62 for 61 executable instruction of storage processor;
Wherein, processor 61 is configured as:
Mapped file is established according to the entrance class in the APK file of application program;It wherein, include with reference to solid in mapped file Determine address, mapping table and the data according to each class in the set of the determining class of entrance class, is stored with each class in mapping table Mark, first deviant and class of the class between the storage location in mapped file and first position of mapped file store it The mapping relations of the second deviant between the position of cited class first address and first position of class, with reference to fixing address For the address of mapped file memory extremely to be mapped;
If the failure when mapping to mapped file with reference to fixing address, mapped file being mapped to and is referred to fixedly The first different address of location;
According to the first deviant corresponding with the mark of class to be loaded in the mark of class to be loaded and mapping table and One address determines the first address of class to be loaded;
It is true according to the second deviant corresponding with the mark of class to be loaded in the first address and mapping table of class to be loaded Store the address of the class first address cited in it in fixed class to be loaded, and by the value stored in address be revised as the first address with With reference to fixing address difference plus the value after the value stored in address;
Initialize class to be loaded.
Fig. 7 is the block diagram of type loading device shown according to an exemplary embodiment.For example, class loading device 800 It can be mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, Medical Devices, Body-building equipment, personal digital assistant etc..
Referring to Fig. 7, device 800 may include following one or more components: processing component 802, memory 804, power supply Component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor module 814, Yi Jitong Believe component 816.
The integrated operation of the usual control device 800 of processing component 802, such as with display, telephone call, data communication, phase Machine operation and record operate associated operation.Processing component 802 may include that one or more processors 820 refer to execute It enables, to perform all or part of the steps of the methods described above.In addition, processing component 802 may include one or more modules, just Interaction between processing component 802 and other assemblies.For example, processing component 802 may include multi-media module, it is more to facilitate Interaction between media component 808 and processing component 802.
Memory 804 is configured as storing various types of data to support the operation in device 800.These data are shown Example includes the instruction of any application or method for operating on device 800, contact data, and telephone book data disappears Breath, picture, video etc..Memory 804 can be by any kind of volatibility or non-volatile memory device or their group It closes and realizes, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM) is erasable to compile Journey read-only memory (EPROM), programmable read only memory (PROM), read-only memory (ROM), magnetic memory, flash Device, disk or CD.
Power supply module 806 provides electric power for the various assemblies of device 800.Power supply module 806 may include power management system System, one or more power supplys and other with for device 800 generate, manage, and distribute the associated component of electric power.
Multimedia component 808 includes the screen of one output interface of offer between device 800 and user.In some realities It applies in example, screen may include liquid crystal display (LCD) and touch panel (TP).If screen includes touch panel, screen can To be implemented as touch screen, to receive input signal from the user.Touch panel include one or more touch sensors with Sense the gesture on touch, slide, and touch panel.Touch sensor can not only sense the boundary of a touch or slide action, and And also detect duration and pressure relevant to touch or slide.In some embodiments, multimedia component 808 includes One front camera and/or rear camera.It is such as in a shooting mode or a video mode, preceding when device 800 is in operation mode It sets camera and/or rear camera can receive external multi-medium data.Each front camera and rear camera can Be a fixed optical lens system or have focusing and optical zoom capabilities.
Audio component 810 is configured as output and/or input audio signal.For example, audio component 810 includes a Mike Wind (MIC), when device 800 is in operation mode, when such as call mode, recording mode, and voice recognition mode, microphone is matched It is set to reception external audio signal.The received audio signal can be further stored in memory 804 or via communication set Part 816 is sent.In some embodiments, audio component 810 further includes a loudspeaker, is used for output audio signal.
I/O interface 812 provides interface between processing component 802 and peripheral interface module, and above-mentioned peripheral interface module can To be keyboard, click wheel, button etc..These buttons may include, but are not limited to: home button, volume button, start button and lock Determine button.
Sensor module 814 includes one or more sensors, and the state for providing various aspects for device 800 is commented Estimate.For example, sensor module 814 can detecte the state that opens/closes of device 800, and the relative positioning of component, for example, it is described Component is the display and keypad of device 800, and sensor module 814 can be with 800 1 components of detection device 800 or device Position change, the existence or non-existence that user contacts with device 800,800 orientation of device or acceleration/deceleration and device 800 Temperature change.Sensor module 814 may include proximity sensor, be configured to detect without any physical contact Presence of nearby objects.Sensor module 814 can also include optical sensor, such as CMOS or ccd image sensor, at As being used in application.In some embodiments, which can also include acceleration transducer, gyro sensors Device, Magnetic Sensor, pressure sensor or temperature sensor.
Communication component 816 is configured to facilitate the communication of wired or wireless way between device 800 and other equipment.Device 800 can access the wireless network based on communication standard, such as WiFi, 2G or 3G or their combination.In an exemplary implementation In example, communication component 816 receives broadcast singal or broadcast related information from external broadcasting management system via broadcast channel. In one exemplary embodiment, the communication component 816 further includes near-field communication (NFC) module, to promote short range communication.Example Such as, NFC module can be based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra wide band (UWB) technology, Bluetooth (BT) technology and other technologies are realized.
In the exemplary embodiment, device 800 can be believed by one or more application specific integrated circuit (ASIC), number Number processor (DSP), digital signal processing appts (DSPD), programmable logic device (PLD), field programmable gate array (FPGA), controller, microcontroller, microprocessor or other electronic components are realized, for executing the above method.
In the exemplary embodiment, a kind of non-transitorycomputer readable storage medium including instruction, example are additionally provided It such as include the memory 804 of instruction, above-metioned instruction can be executed by the processor 820 of device 800 to complete the above method.For example, The non-transitorycomputer readable storage medium can be ROM, random access memory (RAM), CD-ROM, tape, floppy disk With optical data storage devices etc..
A kind of non-transitorycomputer readable storage medium, when the instruction in the storage medium is by the processing of class loading device When device executes, so that class loading device is able to carry out above-mentioned kind loading method.
Those skilled in the art after considering the specification and implementing the invention disclosed here, will readily occur to its of the disclosure Its embodiment.This application is intended to cover any variations, uses, or adaptations of the disclosure, these modifications, purposes or Person's adaptive change follows the general principles of this disclosure and including the undocumented common knowledge in the art of the disclosure Or conventional techniques.The description and examples are only to be considered as illustrative, and the true scope and spirit of the disclosure are by following Claims are pointed out.
It should be understood that the present disclosure is not limited to the precise structures that have been described above and shown in the drawings, and And various modifications and changes may be made without departing from the scope thereof.The scope of the present disclosure is only limited by appended claims System.

Claims (9)

1. a kind of kind loading method characterized by comprising
Mapped file is established according to the entrance class in the Android installation kit APK file of application program;Wherein, in the mapped file Including reference fixing address, mapping table and according to the entrance class determine class set in each class data, the mapping The storage location and the mapped file of the mark of each class, each class in set in the mapped file are stored in table First position between the first deviant and set in each class store position and the collection of the class first address cited in it The mapping relations of the second deviant between first position of each class in conjunction, the reference fixing address is the mapping The address of file memory extremely to be mapped;
If by the mapped file map to it is described with reference to fixing address when failure, the mapped file is mapped to and institute State first address different with reference to fixing address;
According to the first deviant corresponding with the mark of the class to be loaded in the mark of class to be loaded and the mapping table And first address, determine the first address of the class to be loaded;
According to the mark corresponding second in the first address and the mapping table of the class to be loaded with the class to be loaded Deviant determines the address that the class first address cited in it is stored in the class to be loaded, and the value that will be stored in the address First address and the difference with reference to fixing address are revised as plus the value after the value stored in the address;
Initialize the class to be loaded.
2. the method according to claim 1, wherein the entrance class in the APK file according to application program Establish mapped file, comprising:
Entrance class is determined according to the APK file of application program, determines class cited in the entrance class, by the entrance class and institute State set of the class cited in entrance class as class;
All classes in the set of the class are loaded onto the memory of terminal device;
All classes in the memory are copied in continuous memory, selection refers to fixing address, and according to described with reference to solid Determine address modify stored in each class its cited in class first address;
According to the mark of each class, each class it is stored in the storage location and each class in mapped file cited in class it is first The position of address, establishes mapping table;
The mapped file is written into the data of each class in the set with reference to fixing address, the mapping table and the class In.
3. method according to claim 1 or 2, which is characterized in that the initialization class to be loaded, comprising:
Call the initialization function of the class to be loaded.
4. according to the method described in claim 2, it is characterized in that, the APK file according to application program determines entrance class, Include:
Read the global configuration file in the APK file;
The entrance class is obtained from the global configuration file.
5. a type loading device characterized by comprising
Module is established, the entrance class being configured as in the Android installation kit APK file according to application program establishes mapped file;Its In, it include with reference to fixing address, mapping table and according to each in the set of the determining class of the entrance class in the mapped file The data of class are stored with the storage of the mark of each class, each class in set in the mapped file in the mapping table Each class in the first deviant and set between position and first position of the mapped file stores cited in it The mapping relations of the second deviant between first position of each class in the position and set of class first address, the reference Fixing address is the address of the mapped file memory extremely to be mapped;
Mapping block is configured as when failing when the mapped file is mapped to the reference fixing address, will be described Mapped file maps to and first address different with reference to fixing address;
Determining module is configured as according to the mark in the mark of class to be loaded and the mapping table with the class to be loaded Corresponding first deviant and first address, determine the first address of the class to be loaded;
Modified module is configured as in first address and the mapping table according to the class to be loaded and the class to be loaded Corresponding second deviant of mark determine the address that the class first address cited in it is stored in the class to be loaded, and by institute It states the value stored in address and is revised as first address and the difference with reference to fixing address plus storing in the address Value after value;
Initialization module is configured as initializing the class to be loaded.
6. device according to claim 5, which is characterized in that the module of establishing includes:
It determines submodule, is configured as determining entrance class according to the APK file of application program, determine cited in the entrance class Class, using class cited in the entrance class and the entrance class as the set of class;
Submodule is loaded, is configured as all classes in the set of the class being loaded onto the memory of terminal device;
Submodule is replicated, is configured as all classes in the memory being copied in continuous memory, selection is with reference to fixedly Location, and according to it is described modified with reference to fixing address stored in each class its cited in class first address;
Setting up submodule is configured as the storage location and each class of the mark according to each class, each class in mapped file It is middle storage its cited in class first address position, establish mapping table;
Submodule is written, is configured as each class in the set with reference to fixing address, the mapping table and the class Data are written in the mapped file.
7. device according to claim 5 or 6, which is characterized in that the initialization module includes:
Submodule is called, is configured as calling the initialization function of the class to be loaded.
8. device according to claim 6, which is characterized in that the determining submodule includes:
Reading submodule is configured as reading the global configuration file in the APK file;
Acquisition submodule is configured as obtaining the entrance class from the global configuration file.
9. a type loading device characterized by comprising
Processor;
For storing the memory of the processor-executable instruction;
Wherein, the processor is configured to:
Mapped file is established according to the entrance class in the Android installation kit APK file of application program;Wherein, in the mapped file Including reference fixing address, mapping table and according to the entrance class determine class set in each class data, the mapping The storage location and the mapped file of the mark of each class, each class in set in the mapped file are stored in table First position between the first deviant and set in each class store position and the collection of the class first address cited in it The mapping relations of the second deviant between first position of each class in conjunction, the reference fixing address is the mapping The address of file memory extremely to be mapped;
If by the mapped file map to it is described with reference to fixing address when failure, the mapped file is mapped to and institute State first address different with reference to fixing address;
According to the first deviant corresponding with the mark of the class to be loaded in the mark of class to be loaded and the mapping table And first address, determine the first address of the class to be loaded;
According to the mark corresponding second in the first address and the mapping table of the class to be loaded with the class to be loaded Deviant determines the address that the class first address cited in it is stored in the class to be loaded, and the value that will be stored in the address First address and the difference with reference to fixing address are revised as plus the value after the value stored in the address;
Initialize the class to be loaded.
CN201611175849.8A 2016-12-19 2016-12-19 Kind loading method and device Active CN106528255B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611175849.8A CN106528255B (en) 2016-12-19 2016-12-19 Kind loading method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611175849.8A CN106528255B (en) 2016-12-19 2016-12-19 Kind loading method and device

Publications (2)

Publication Number Publication Date
CN106528255A CN106528255A (en) 2017-03-22
CN106528255B true CN106528255B (en) 2019-07-12

Family

ID=58340768

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611175849.8A Active CN106528255B (en) 2016-12-19 2016-12-19 Kind loading method and device

Country Status (1)

Country Link
CN (1) CN106528255B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107423093B (en) * 2017-07-21 2020-09-15 珠海市魅族科技有限公司 Control method and apparatus, computer apparatus, and computer-readable storage medium
CN107562499A (en) * 2017-08-23 2018-01-09 青岛海信移动通信技术股份有限公司 Using the method, apparatus and computer-readable recording medium of loading
CN108021445B (en) * 2017-11-22 2021-12-28 广州品唯软件有限公司 Memory optimization method, device and system and computer readable storage medium
CN111736913B (en) 2019-03-25 2021-11-19 华为技术有限公司 Class loading method and device
CN115292721B (en) * 2022-10-09 2023-01-24 北京麟卓信息科技有限公司 Starting method for adapting to multiple Linux kernels in android compatible environment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103473096A (en) * 2013-09-10 2013-12-25 浙江大学城市学院 Method and system for loading java class on virtual machine of android system
CN103970563A (en) * 2014-04-15 2014-08-06 四川长虹电器股份有限公司 Dynamic Android class loading method
CN104318155A (en) * 2014-11-18 2015-01-28 刘鹏 Dynamic loading method capable of guarding against reverse APK file
CN105278989A (en) * 2015-10-12 2016-01-27 邱寅峰 Fast loading method of APK file

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103473096A (en) * 2013-09-10 2013-12-25 浙江大学城市学院 Method and system for loading java class on virtual machine of android system
CN103970563A (en) * 2014-04-15 2014-08-06 四川长虹电器股份有限公司 Dynamic Android class loading method
CN104318155A (en) * 2014-11-18 2015-01-28 刘鹏 Dynamic loading method capable of guarding against reverse APK file
CN105278989A (en) * 2015-10-12 2016-01-27 邱寅峰 Fast loading method of APK file

Also Published As

Publication number Publication date
CN106528255A (en) 2017-03-22

Similar Documents

Publication Publication Date Title
CN106528255B (en) Kind loading method and device
CN104484200B (en) The method and device upgraded to firmware
CN105204894B (en) The method and apparatus for installing the plug-in unit of smart machine
CN105847430B (en) Mix application page data access method and device
CN104951335B (en) The processing method and processing device of application program installation kit
CN105094931B (en) Method for upgrading software and device
CN105553963B (en) The control method and device of positioning service
CN106126685B (en) Page loading method and device
CN106020634B (en) Screenshotss method and device
CN105468410B (en) Method for upgrading system and device
CN105630546B (en) Method for updating system and device
CN104317647B (en) Application function implementation method, device and terminal
CN110569329B (en) Data processing method and device, electronic equipment and storage medium
CN106201610A (en) Web application accesses the method and device of the primary function of terminal
CN102646037A (en) Menu display processing method and terminal device
KR20170038178A (en) Method, apparatus, and mobile terminal for identificating fingerprint
CN106537288B (en) The method and device of self-starting is applied in control
CN105871913A (en) Identity authentication method and system
CN105183571A (en) Function calling method and device
CN109683954A (en) The library lib integrated approach, device and storage medium
CN105094830A (en) Method and device for executing target functions
CN105407160B (en) Interface display method and device
CN104063424B (en) Web page picture shows method and demonstration device
CN109388423A (en) Method for upgrading software and device
CN104951337B (en) File increment update method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant