An interface method table generation method, function pointer query method and device
By dynamically adjusting the hash table size according to the number of interface functions of Java class and selecting a suitable hash algorithm, the problem of waste of storage space and low query efficiency caused by fixed hash table size in the existing technology is solved, and more efficient storage space utilization and query performance is achieved.
Patent Information
- Application Number
- CN201910156548.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-03-01
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2039-03-01
AI Technical Summary
In the prior art, in the interface method table (Itab) generated for different Java classes, the size of the hash table is fixed, resulting in too large a hash table for some Java classes and wasting storage space, and too small a hash table for other Java classes, resulting in a decrease in the efficiency of function pointer query.
The size of the hash table is determined by multiplying the number of interface functions that can be implemented by the target Java class and the preset coefficients, and flexibly selecting a suitable hash algorithm to reduce hash collisions.
It solves the problems of wasted storage space and low efficiency of function pointer query caused by inappropriate hash table size, and improves storage space utilization and query efficiency.
Smart Images

Figure CN111638925B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and particularly to a method for generating an interface method table, a method for querying function pointers, and an apparatus therefor. Background Art
[0002] Java classes support the interface mechanism of multiple inheritances. That is to say, a Java class can often implement multiple interface functions. In this case, in order to facilitate a Java class to query the function pointers of interface functions, it is usually necessary to create a corresponding interface method table (Itab) for the Java class.
[0003] Among them, the Itab of each Java class includes a hash table and a collision resolution table. In the process of creating an Itab for a Java class, first, determine each interface function that the Java class can implement, and determine the size of the hash table and the hash algorithm; then, calculate the hash values of the respective interface functions through the determined hash algorithm and the function signatures of the respective interface functions; among them, if the hash value of a certain interface function does not have a hash collision with the hash values of other interface functions, then determine the index of the interface function in the hash table according to the hash value of the interface function, and store the function pointer of the interface function at the position indicated by the index to obtain the hash table of the Java class; in addition, if the hash value of a certain interface function has a hash collision with the hash values of other interface functions, then store the function signature and the function pointer of the interface function in the collision resolution table, so as to obtain the collision resolution table of the Java class, and further obtain the Itab composed of the hash table and the collision resolution table.
[0004] After generating the Itab of a Java class, when querying the function pointer of an interface function that the Java class can implement, first calculate the hash value through the function signature and the hash algorithm of the interface function, determine the index of the hash table according to the hash value, and when the position indicated by the index in the hash table stores a function pointer, then determine that the function pointer stored in the hash table is the function pointer of the interface function. In addition, when the position indicated by the index in the hash table does not store a function pointer, then query the collision resolution table according to the function signature of the interface function to obtain the function pointer stored in the collision resolution table.
[0005] However, during the research process of this application, the inventor found that in the prior art, when creating Itabs for different Java classes, the size of the hash table set is a same fixed value, that is, the size of the hash table for each Java class is the same. However, the types and quantities of interface functions that different Java classes can implement are usually different. Therefore, the Itabs generated according to the prior art often have the problem of being too large for some Java classes and too small for others. In this case, when the hash table of a Java class is large, it will cause waste of storage space, while when the hash table of a Java class is small, it will lead to a smaller number of function pointers stored in the hash table and a larger number of function pointers stored in the corresponding conflict resolution table. During the query process of function pointers, it is often necessary to query the conflict resolution table to query the required function pointer, which further reduces the query efficiency of function pointers. Summary of the Invention
[0006] When generating the interface method table Itab for different Java classes through the prior art, the size of the hash table set is a same fixed value, that is, the size of the hash table for each Java class is the same. However, the types and quantities of interface functions that different Java classes can implement are usually different. Therefore, the Itabs generated according to the prior art often have the problem of being too large for some Java classes and too small for others. When the hash table of a certain Java class is large, it will cause waste of storage space, while when the hash table of a Java class is small, it will lead to a smaller number of function pointers stored in the hash table and a larger number of function pointers stored in the corresponding conflict resolution table, further reducing the query efficiency of function pointers. To solve this problem, this application discloses a method for generating an interface method table Itab, a method for querying function pointers, and a device.
[0007] In a first aspect, an embodiment of this application discloses a method for generating an interface method table, including:
[0008] Generating a hash table for the target Java class based on the quantities of all interface functions that the target Java class can implement, where the size of the hash table is the product of the quantity of the interface functions and a preset coefficient;
[0009] Determining the hash algorithm of the target Java class;
[0010] Determining the hash values of all the interface functions based on the hash algorithm of the target Java class and the function signatures of all the interface functions;
[0011] Determine the index of the function pointer of the first interface function in the hash table based on the hash value of the first interface function and the size of the hash table, and store the function pointer of the first interface function at the position indicated by the index, where the first interface function is an interface function that does not have a hash conflict with other interface functions;
[0012] Store the function signature and function pointer of the second interface function in the conflict resolution table, where the second interface function is an interface function that has a hash conflict with other interface functions.
[0013] The solution disclosed in the embodiments of the present application solves the problem of waste of storage space caused by an overly large hash table in the prior art, thereby saving storage space, and solves the problem of decreased query efficiency of function pointers caused by an overly small hash table in the prior art, thereby improving the query efficiency of function pointers.
[0014] In an alternative design, it further includes:
[0015] Store the size of the hash table in the metadata information of the target Java class.
[0016] In the embodiments of the present application, the size of the hash table is stored in the metadata information of the target Java class, so as to determine the size of the hash table of the target Java class through this metadata information.
[0017] In an alternative design, the determining the index of the function pointer of the first interface function in the hash table based on the hash value of the first interface function and the size of the hash table includes:
[0018] Perform a modulo operation on the hash value of the first interface function and the size of the hash table;
[0019] Determine that the remainder obtained through the modulo operation is the index of the function pointer of the first interface function in the hash table.
[0020] In an alternative design, the determining the hash algorithm of the target Java class includes:
[0021] Calculate the hash values of the respective interface functions through various hash algorithms and the function signatures of the respective interface functions;
[0022] Compare the number of hash conflicts existing between the hash values obtained through the various hash algorithms;
[0023] Determine that the hash algorithm applied when the number of hash conflicts is the smallest is the hash algorithm of the target Java class.
[0024] The solution disclosed in the embodiments of the present application can flexibly select the hash algorithm of the target Java class. In this case, calculating the hash value through the hash algorithm of the target Java class can reduce hash collisions. Correspondingly, the query efficiency of function pointers can be improved. Moreover, it can also reduce the function signatures and function pointers stored in the conflict elimination table, further reducing the storage space occupied by the interface method table.
[0025] In an alternative design, it further includes:
[0026] Storing the algorithm index of the hash algorithm of the target Java class into the metadata information of the target Java class.
[0027] In the embodiments of the present application, storing the algorithm index of the hash algorithm of the target Java class into the metadata information of the target Java class, so as to determine the hash algorithm used by the target Java class through this metadata information.
[0028] In a second aspect, the embodiments of the present application disclose a function pointer query method, including:
[0029] Based on the metadata information of the target Java class, obtaining the size of the hash table of the target Java class;
[0030] Based on the function signature of the interface function to be implemented by the target Java class, calculating the hash value of the interface function;
[0031] Based on the size of the hash table and the hash value of the interface function, determining the index of the function pointer corresponding to the interface function in the hash table;
[0032] When a function pointer is stored at the position indicated by the index, determining the function pointer stored at the position indicated by the index as the function pointer of the interface function;
[0033] When no function pointer is stored at the position indicated by the index, querying the conflict elimination table based on the function signature of the interface function, and determining the function pointer of the interface function through the query result.
[0034] When querying the function pointer through the solution of the embodiments of the present application, the size of the hash table applied is set according to the number of each interface function that the target Java class can implement, avoiding the problems of the hash table being too large or too small, thus solving the problem in the prior art that the query efficiency of function pointers decreases due to the too small hash table, and improving the query efficiency of function pointers.
[0035] In an alternative design, the calculating the hash value of the interface function based on the function signature of the interface function to be implemented by the target Java class includes:
[0036] Query the algorithm index included in the metadata information of the target Java class;
[0037] Based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class, calculate the hash value of the interface function.
[0038] In an alternative design, the determining the index of the function pointer of the interface function corresponding to the hash table based on the size of the hash table and the hash value of the interface function includes:
[0039] Perform a modulo operation on the hash value of the interface function and the size of the hash table;
[0040] Determine that the remainder obtained through the modulo operation is the index of the function pointer of the interface function corresponding to the hash table.
[0041] In a third aspect, an embodiment of the present application discloses a terminal device, including:
[0042] A processor;
[0043] The processor is configured to generate a hash table for the target Java class based on the number of interface functions that the target Java class can implement. The size of the hash table is the product of the number of interface functions and a preset coefficient, determine the hash algorithm of the target Java class, determine the hash values of the respective interface functions based on the hash algorithm of the target Java class and the function signatures of the respective interface functions, determine the index of the function pointer of the first interface function in the hash table based on the hash value of the first interface function and the size of the hash table, and store the function pointer of the first interface function at the position indicated by the index. The first interface function is an interface function that does not have a hash conflict with other interface functions, and store the function signature and function pointer of the second interface function in a conflict resolution table. The second interface function is an interface function that has a hash conflict with other interface functions.
[0044] In an alternative design, the processor is further configured to store the size of the hash table in the metadata information of the target Java class.
[0045] In an alternative design, the processor is specifically configured to perform a modulo operation on the hash value of the first interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index of the function pointer of the first interface function in the hash table.
[0046] In an alternative design, the processor is specifically configured to calculate the hash values of the respective interface functions by using various hash algorithms and the function signatures of the respective interface functions, compare the number of hash conflicts existing between the hash values obtained by using the various hash algorithms, and determine that the hash algorithm applied when the number of hash conflicts is the smallest is the hash algorithm of the target Java class.
[0047] In an alternative design, the processor is further configured to store the algorithm index of the hash algorithm of the target Java class into the metadata information of the target Java class.
[0048] In a fourth aspect, an embodiment of the present application discloses a terminal device, including:
[0049] a processor;
[0050] The processor is configured to obtain the size of the hash table of the target Java class based on the metadata information of the target Java class, calculate the hash value of the interface function based on the function signature of the interface function to be implemented by the target Java class, determine the index in the hash table corresponding to the function pointer of the interface function based on the size of the hash table and the hash value of the interface function, and when a function pointer is stored at the position indicated by the index, determine that the function pointer stored at the position indicated by the index is the function pointer of the interface function, and when no function pointer is stored at the position indicated by the index, query a conflict resolution table based on the function signature of the interface function, and determine the function pointer of the interface function through the query result.
[0051] In an alternative design, the processor is specifically configured to query the algorithm index included in the metadata information of the target Java class, and calculate the hash value of the interface function based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class.
[0052] In an alternative design, the processor is specifically configured to perform a modulo operation on the hash value of the interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index in the hash table corresponding to the function pointer of the interface function.
[0053] In a fifth aspect, an embodiment of the present application discloses a terminal device, including:
[0054] a processor and a memory,
[0055] The memory is configured to store program instructions;
[0056] The processor is configured to call and execute the program instructions stored in the memory, so that the processor executes the interface method table generation method described in the first aspect of this application and various optional designs of the first aspect.
[0057] In a sixth aspect, an embodiment of this application discloses a terminal device, including:
[0058] a processor and a memory,
[0059] The memory is configured to store program instructions;
[0060] The processor is configured to call and execute the program instructions stored in the memory, so that the processor executes the function pointer query method described in the second aspect of this application and various optional designs of the second aspect.
[0061] In a seventh aspect, an embodiment of this application discloses a computer-readable storage medium, in which instructions are stored, and when the instructions run on a computer, the computer is caused to execute the interface method table generation method described in the first aspect of this application and various optional designs of the first aspect.
[0062] In an eighth aspect, an embodiment of this application discloses a computer-readable storage medium, in which instructions are stored, and when the instructions run on a computer, the computer is caused to execute the function pointer query method described in the second aspect of this application and various optional designs of the second aspect.
[0063] Through the solution of the embodiment of this application, a hash table and a conflict elimination table of a target Java class can be obtained, and correspondingly, an interface method table of the target Java class can be obtained. Moreover, when generating the hash table, the size of the hash table is determined by the product of the number of each interface function that the target Java class can implement and a preset coefficient, avoiding the problem of the hash table being too large or too small. Therefore, the problem of waste of storage space caused by the hash table being too large in the prior art is solved, so that the storage space can be saved. And the problem of the decline in the query efficiency of function pointers caused by the hash table being too small in the prior art is solved, thereby improving the query efficiency of function pointers.
[0064] Furthermore, the storage space occupied by the function signature of an interface function is usually much larger than that occupied by the function pointer of the interface function. Therefore, the more the number of the second interface functions of the target Java class, the more function signatures and function pointers need to be stored in the conflict elimination table, and correspondingly, the larger the storage space occupied by the interface method table. It can be seen therefrom that when generating the interface method table by the prior art, when the hash table is too small, the storage space occupied by the interface method table is relatively large. However, the solution disclosed in the embodiments of the present application can avoid the problem of too small hash table. Therefore, compared with the prior art, it can reduce the number of the second interface functions, correspondingly reduce the function signatures and function pointers that need to be stored in the conflict elimination table, and further reduce the storage space occupied by the interface method table. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the technical solutions of the present application, the drawings required for the embodiments will be briefly introduced below. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0066] Figure 1 FIG. 9 is a schematic flowchart of a method for generating an interface method table applied in an embodiment of the present application;
[0067] FIG. 2(a) is a schematic diagram of a hash table disclosed in an embodiment of the present application;
[0068] FIG. 2(b) is a schematic diagram of a conflict elimination table disclosed in an embodiment of the present application;
[0069] Figure 3 FIG. 19 is a schematic flowchart of a method for determining a hash algorithm of a target Java class in a method for generating an interface method table applied in an embodiment of the present application;
[0070] Figure 4 FIG. 23 is a schematic flowchart of a method for querying a function pointer applied in an embodiment of the present application;
[0071] Figure 5 FIG. 27 is a schematic structural diagram of a terminal device applied in an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0072] When generating the interface method table Itab for different Java classes through the prior art, the size of the set hash table is a same fixed value, that is, the size of the hash table for each Java class is the same. However, the categories and quantities of interface functions that different Java classes can implement are usually different. Therefore, the Itab generated according to the prior art often has the problem of being too large for some Java classes and too small for others. When the hash table of a certain Java class is large, it will cause waste of storage space, while when the hash table of a Java class is small, it will lead to a smaller number of function pointers stored in the hash table and a larger number of function pointers stored in the corresponding conflict elimination table, further resulting in a decline in the query efficiency of function pointers. To solve this problem, this application discloses an interface method table Itab generation method, a function pointer query method and a device through the following various embodiments.
[0073] See Figure 1 Referring to the schematic diagram of the workflow shown, an embodiment of this application discloses an interface method table generation method, and this method includes the following steps:
[0074] Step S11, generate a hash table for the target Java class based on the quantities of various interface functions that the target Java class can implement, and the size of the hash table is the product of the quantity of the interface functions and a preset coefficient.
[0075] The interface mechanism of a Java class is a multiple inheritance mechanism, that is, a Java class can often implement multiple interface functions, and moreover, the types and quantities of interface functions that different Java classes can implement are often different. Therefore, this application needs to determine the quantities of various interface functions that the target Java class can implement through step S11.
[0076] In addition, in the embodiment of this application, the target Java class refers to the Java class for which an interface method table needs to be generated. The size of the hash table refers to the quantity of function pointers that can be stored in the hash table. For example, when a certain hash table can store 40 function pointers, it is considered that the size of this hash table is 40.
[0077] In the above steps, the preset coefficient is a positive number greater than 1. Set the preset coefficient as N, then through step S11, the size of the hash table of the target Java class can be made N times the quantity of various interface functions that the target Java class can implement.
[0078] Step S12, determine the hash algorithm of the target Java class.
[0079] Hash algorithms often include multiple ones. For example, hash algorithms include various ones such as DJBHash algorithm, BKDRHash algorithm, RSHash algorithm, and SDBMHash algorithm. In the embodiments of the present application, through step S12, the hash algorithm of the target Java class is determined.
[0080] Step S13: Based on the hash algorithm of the target Java class and the function signatures of the respective interface functions, determine the hash values of the respective interface functions.
[0081] Among them, through the hash algorithm of the target Java class, performing a hash calculation on the function signatures of the respective interface functions, the obtained result is the hash value of the respective interface functions.
[0082] In addition, the function signature of an interface function usually includes relevant information of the interface function for differentiating different interface functions. For example, the function signature may include the function name, parameter types, and the number of parameters of the interface function, etc., and the embodiments of the present application do not make limitations in this regard.
[0083] Step S14: Based on the hash value of the first interface function and the size of the hash table, determine the index of the function pointer of the first interface function in the hash table, and store the function pointer of the first interface function at the position indicated by the index, where the first interface function is an interface function that does not have a hash conflict with other interface functions.
[0084] In the embodiments of the present application, according to the hash value of the interface function and the size of the hash table, the index of the function pointer of the interface function in the hash table is determined. In this case, if the indexes of the function pointers of two interface functions in the hash table are the same, it is considered that these two interface functions have a hash conflict; if the indexes of the function pointers of two interface functions in the hash table are different, it is considered that these two interface functions do not have a hash conflict.
[0085] In addition, in the embodiments of the present application, through whether each interface function has a hash conflict with other interface functions, each interface function is divided into two categories, namely the first interface function and the second interface function. Among them, the first interface function is an interface function that does not have a hash conflict with other interface functions, and the second interface function is an interface function that has a hash conflict with other interface functions.
[0086] Since the first interface function does not have a hash conflict with other interface functions, that is to say, the index of the function pointer of the first interface function in the hash table is different from that of other interface functions. Therefore, the function pointer of the first interface function can be stored at the position indicated by the index. In this case, the hash table storing the function pointers of each first interface function is the hash table in the interface method table of the target Java class.
[0087] Step S15: Store the function signature and function pointer of the second interface function into the conflict resolution table, where the second interface function is an interface function that has a hash conflict with other interface functions.
[0088] Since the second interface function has a hash conflict with other interface functions, if the function pointer of the second interface function is also stored in the hash table, at least two function pointers need to be stored at the same position in the hash table, resulting in the inability to accurately query the required function pointer through the hash table when querying function pointers later. Therefore, it is necessary to store the function signature and function pointer of the second interface function into the conflict resolution table. In this case, the conflict resolution table storing the function signatures and function pointers of each second interface function is the conflict resolution table in the interface method table of the target Java class.
[0089] For example, assume that the first target Java class can implement three interface functions. Among them, the first interface function has no hash conflict with the second interface function and the third interface function, so the function pointer of the first interface function is stored in the hash table of the first target Java class. However, there is a hash conflict between the second interface function and the third interface function, so the function signatures and function pointers of the second interface function and the third interface function are respectively stored in the conflict resolution table.
[0090] The hash table obtained through step S14 and the conflict resolution table obtained through step S15 constitute the interface method table of the target Java class.
[0091] In addition, when querying the function pointer, query the conflict resolution table through the function signature of the second interface function, and the function pointer of the second interface function can be found.
[0092] The types and quantities of interface functions that different Java classes can implement are often different. For example, the first Java class can implement 10 interface functions, and the second Java class can implement 24 interface functions. However, in the prior art, when generating an interface method table for each Java class, the size of the hash table in the interface method table is a same fixed value, that is, in the prior art, the sizes of the hash tables of each Java class are the same. For example, the prior art sets the sizes of the hash tables of the first Java class and the second Java class to be both 40. In this case, if the interface method table is generated by the prior art, for some Java classes, the hash table in the interface method table is larger, while for some Java classes, the hash table in the interface method table is smaller.
[0093] Among them, when the hash table of a certain Java class is large, it will cause waste of storage space. When the hash table of a certain Java class is small, the number of function pointers that the hash table can store is small. Correspondingly, more function pointers need to be stored in the conflict resolution table. When querying the function pointer of a certain interface function, first query the hash table. When the function pointer of the interface function is not stored in the hash table, then query the conflict resolution table. Therefore, when the number of function pointers stored in the hash table is small and the number of function pointers stored in the conflict resolution table is large, it is often necessary to query the conflict resolution table to query the required function pointer, resulting in a decrease in the query efficiency of the function pointer.
[0094] Through the solution of the embodiments of the present application, the hash table and the conflict resolution table of the target Java class can be obtained. Correspondingly, the interface method table of the target Java class can be obtained. Moreover, when generating the hash table, the size of the hash table is determined by the product of the number of each interface function that the target Java class can implement and a preset coefficient, avoiding the problem of the hash table being too large or too small. Therefore, the problem of waste of storage space caused by the hash table being too large in the prior art is solved, thus saving storage space. And the problem of the decrease in the query efficiency of the function pointer caused by the hash table being too small in the prior art is solved, thereby improving the query efficiency of the function pointer.
[0095] Furthermore, the storage space occupied by the function signature of an interface function is usually much larger than the storage space occupied by the function pointer of the interface function. Therefore, the more the number of the second interface functions of the target Java class, the more function signatures and function pointers need to be stored in the conflict resolution table. Correspondingly, the larger the storage space occupied by the interface method table. It can be seen from this that when generating the interface method table by the prior art, when the hash table is too small, the storage space occupied by the interface method table is large. However, the solution disclosed in the embodiments of the present application can avoid the problem of the hash table being too small. Therefore, compared with the prior art, it can reduce the number of the second interface functions, correspondingly reduce the function signatures and function pointers that need to be stored in the conflict resolution table, and further reduce the storage space occupied by the interface method table.
[0096] In addition, in the embodiments of the present application, the preset coefficient N is a positive number greater than 1. In a feasible implementation manner, the preset coefficient N can be set to 2. In this case, the size of the hash table of the target Java class is twice the number of each interface function that the target Java class can implement. For example, when the first Java class can implement 10 interface functions, the size of the hash table of the first Java class is 20, that is, the hash table can store 20 function pointers.
[0097] Further, in the embodiments of the present application, a method for generating an interface method table is disclosed through steps S11 to S15. In the actual application process of this method, the operation processes of steps S14 to S15 do not have a strict time sequence. For example, the operation of step S15 can also be executed first, and then the operation of step S14, or the operations of steps S14 and S15 can be executed simultaneously. The embodiments of the present application do not make any limitations in this regard.
[0098] To clarify the form of the interface method table generated by the embodiments of the present application, FIGS. 2(a) and 2(b) are also disclosed below. Among them, FIG. 2(a) is a hash table in the interface method table, and FIG. 2(b) is a conflict resolution table in the interface method table.
[0099] In the solution of the embodiments of the present application, the interface functions that the target Java class can implement are divided into first interface functions and second interface functions according to whether there is a hash conflict between the interface functions. Among them, there is no hash conflict between the first interface functions and other interface functions, and there is a hash conflict between the second interface functions and other interface functions. In the hash table shown in FIG. 2(a), the function pointers of the first interface functions are stored. In the conflict resolution table shown in FIG. 2(b), the function signatures and function pointers of the second interface functions are stored.
[0100] In addition, when a certain position in the hash table does not store a function pointer, that is, the indexes of the function pointers of each first interface function in the hash table are not the index of this position, this position remains the initial value of the hash table, where this initial value is usually 0.
[0101] Further, in the solution disclosed in the embodiments of the present application, the following steps are further included:
[0102] Store the size of the hash table into the metadata information of the target Java class.
[0103] The metadata information of the target Java class is used to store the attributes of the target Java class. In the prior art, since the sizes of the hash tables of different Java classes are the same, it is not necessary to store the size of the hash table of the Java class in the metadata information of the Java class. However, in the method of the embodiments of the present application, the size of the hash table is flexibly adjusted according to the number of interface functions that the target Java class can implement, that is, for different target Java classes, the size of the hash table is variable. Therefore, in the embodiments of the present application, the size of the hash table can also be stored into the metadata information of the target Java class, so as to determine the size of the hash table of the target Java class through this metadata information.
[0104] In the solution disclosed in the embodiments of the present application, an operation of determining the index of the function pointer of the first interface function in the hash table based on the hash value of the first interface function and the size of the hash table is included. This operation includes the following steps:
[0105] Perform a modulo operation on the hash value of the first interface function and the size of the hash table;
[0106] Determine that the remainder obtained through the modulo operation is the index of the function pointer of the first interface function in the hash table.
[0107] Wherein, during the modulo operation, the hash value of the first interface function is the dividend, and the size of the hash table is the divisor.
[0108] In this case, when the hash value of the first interface function is not greater than the size of the hash table, the remainder obtained through the modulo operation is the hash value of the first interface function. That is to say, the index of the function pointer of the first interface function in the hash table is the hash value of the first interface function.
[0109] For example, the size of the hash table is 20, that is, the hash table can store 20 function pointers. When the hash value of the first interface function is 10, the index of the function pointer of the first interface function in the hash table is 10, and the function pointer of the first interface function needs to be stored at the position with index 10 in the hash table; in addition, when the hash value of the first interface function is 23, through the modulo operation, the obtained remainder is 3, then the index of the function pointer of the first interface function in the hash table is 3, and the function pointer of the first interface function needs to be stored at the position with index 3 in the hash table.
[0110] In addition, in the embodiments of the present application, if the indices of the function pointers of two interface functions in the hash table are the same, it is considered that there is a hash conflict between these two interface functions; if the indices of the function pointers of two interface functions in the hash table are different, it is considered that there is no hash conflict between these two interface functions. And according to the above steps, it can be known that the index of the function pointer of the interface function in the hash table can be obtained by performing a modulo operation on the hash value of the first interface function and the size of the hash table. In this case, when the remainders obtained after performing the modulo operation on the hash values of two interface functions and the size of the hash table are the same, it is considered that there is a hash conflict between these two interface functions.
[0111] For example, when the size of the hash table is 20, if the hash value of interface function a is 3 and the hash value of interface function b is 23, then after performing the modulo operation on interface function a and interface function b, the obtained remainders are the same. In this case, it can be determined that there is a hash conflict between interface function a and interface function b.
[0112] In addition, in the above steps, the operation of publicly determining the hash algorithm of the target Java class can be implemented in various ways.
[0113] In one implementation, the pre-set hash algorithm is used as the hash algorithm of the target Java class. That is to say, in this solution, a corresponding hash algorithm is pre-set for the target Java class.
[0114] In another implementation, referring to Figure 3 the schematic diagram of the workflow shown, this operation includes the following steps:
[0115] Step S121: Calculate the hash values of the respective interface functions through various hash algorithms and the function signatures of the respective interface functions.
[0116] There are often multiple hash algorithms. For example, the hash algorithms include DJBHash algorithm, BKDRHash algorithm, RSHash algorithm, and SDBMHash algorithm, etc. In step S121, the hash values of the respective interface functions are calculated through various hash algorithms and the function signatures of the respective interface functions.
[0117] Step S122: Compare the number of hash conflicts existing between the hash values obtained through the various hash algorithms.
[0118] Step S123: Determine that the hash algorithm applied when the number of hash conflicts is the smallest is the hash algorithm of the target Java class.
[0119] For example, when applying the DJBHash hash algorithm, the number of hash conflicts is the smallest, then DJBHash is determined as the hash algorithm of the target Java class.
[0120] In the prior art, when calculating the hash values of interface functions for different Java classes, the same hash algorithm is used. However, the types and quantities of interface functions that different Java classes can implement often vary. In this case, using the same hash algorithm for different Java classes is not conducive to reducing hash conflicts. That is to say, the same hash algorithm is adopted for various Java classes, and this hash algorithm may not be applicable to some Java classes, resulting in more hash conflicts for some Java classes. The more hash conflicts there are, the more function signatures and function pointers are stored in the conflict resolution table, which is not conducive to the query of function pointers, thus reducing the query efficiency of function pointers. Moreover, the more function signatures and function pointers are stored in the conflict resolution table, the larger the storage space occupied by the interface method table of this Java class.
[0121] To solve this problem, the embodiments of the present application disclose the solutions of steps S121 to S123. In this solution, the hash values of each interface function are calculated through various hash algorithms respectively, and then when the number of hash conflicts is the smallest, the hash algorithm applied is the hash algorithm of the target Java class. Compared with the prior art, the solution disclosed in the embodiments of the present application can flexibly select the hash algorithm of the target Java class. In this case, calculating the hash value through the hash algorithm of the target Java class can reduce hash conflicts. Correspondingly, the query efficiency of function pointers can be improved. Moreover, it can also reduce the function signatures and function pointers stored in the conflict elimination table, further reducing the storage space occupied by the interface method table.
[0122] Further, in the solution disclosed in the embodiments of the present application, the following steps are further included:
[0123] Store the algorithm index of the hash algorithm of the target Java class into the metadata information of the target Java class.
[0124] The metadata information of the target Java class is used to store the attributes of the target Java class. In the prior art, since the hash algorithms applied by different Java classes are the same, there is no need to store the algorithm index of the hash algorithm of the Java class in the metadata information of the Java class. However, in the method of the embodiments of the present application, the hash algorithm that minimizes the number of hash conflicts is determined from various hash algorithms as the hash algorithm of the target Java class, so that the hash algorithm can be flexibly selected, that is, for different target Java classes, the hash algorithm adopted is variable. Therefore, in the embodiments of the present application, the algorithm index of the hash algorithm of the target Java class can also be stored into the metadata information of the target Java class, so as to determine the hash algorithm used by the target Java class through this metadata information.
[0125] Among them, the algorithm index of the hash algorithm is used to distinguish different hash algorithms, and the algorithm indexes of different hash algorithms are different. Specifically, the algorithm index of the hash algorithm can be characters such as numbers or letters, that is, each hash algorithm corresponds to a character respectively, and different hash algorithms correspond to different characters, so that the hash algorithm of the target Java class can be determined according to the algorithm index stored in the metadata information. Of course, the algorithm index of the hash algorithm can also be in other forms, and the embodiments of the present application do not limit this.
[0126] Further, in the embodiments of the present application, the hash algorithm applied may be a first-level hash algorithm or a multi-level hash algorithm. Among them, the first-level hash algorithm means that only one hash calculation is performed when calculating the hash value; while the multi-level hash algorithm means that multiple hash calculations are performed when calculating the hash value, and when performing multiple hash calculations, the first hash calculation is to calculate the function signature of the interface function, and each subsequent hash calculation is to calculate the result obtained from the previous hash calculation again. In addition, when performing the multi-level hash algorithm, the hash algorithms used at each level may be the same or different, and the embodiments of the present application do not limit this.
[0127] For example, in the embodiments of the present application, a second-level hash algorithm may be adopted for the target Java class. The first-level hash algorithm in the second-level hash algorithm is the DJBHash algorithm, and the second-level hash algorithm is the BKDRHash algorithm. In this case, first, the DJBHash algorithm is used to calculate the function signatures of each interface function to obtain the corresponding hash values, and then, the BKDRHash algorithm is used to calculate the hash values obtained through the DJBHash algorithm, and the result obtained is the hash value of each interface function.
[0128] Through multi-level hash calculation, the number of hash conflicts can be reduced, thereby reducing the function signatures and function pointers stored in the conflict elimination table, reducing the storage space occupied by the interface method table, and improving the query efficiency of function pointers.
[0129] In addition, when the hash algorithm adopted for the target Java class in the embodiments of the present application is a multi-level hash algorithm, the algorithm indexes of the hash algorithm of the target Java class also include multiple. For example, when a second-level hash algorithm is adopted for the target Java class, the first-level hash algorithm in the second-level hash algorithm is the DJBHash algorithm, and the second-level hash algorithm is the BKDRHash algorithm, then the algorithm indexes of the hash algorithm of the target Java class include the algorithm indexes of the two hash algorithms, namely the DJBHash algorithm and the BKDRHash algorithm.
[0130] To demonstrate the advantages of the solution disclosed in the embodiments of the present application, a specific example is disclosed below.
[0131] In this example, it is assumed that there are a first target Java class and a second target Java class. Among them, the first target Java class can implement the following 10 interface functions:
[0132] 1. "apply|()"
[0133] 2. "putString|(Ljava / lang / String;Ljava / lang / String;)"
[0134] 3. "putInt|(Ljava / lang / String;I)"
[0135] 4. "clear|()"
[0136] 5. "remove|(Ljava / lang / String;)"
[0137] 6. "putStringSet|(Ljava / lang / String;Ljava / util / Set;)"
[0138] 7. "putLong|(Ljava / lang / String;J)"
[0139] 8. "commit|()"
[0140] 9. "putFloat|(Ljava / lang / String;F)"
[0141] 10. "putBoolean|(Ljava / lang / String;Z)"
[0142] In addition, the second target Java class can implement the following 24 interface functions:
[0143] 1. "comparingLong|(Ljava / util / function / ToLongFunction;)"
[0144] 2. "thenComparing|(Ljava / util / function / Function;Ljava / util / Comparator;)"
[0145] 3. "reversed|()"
[0146] 4. "lambda$comparingDouble$8dcf42ea$1|(Ljava / util / function / ToDoubleFunction;Ljava / lang /
[0147] Object;Ljava / lang / Object;)"
[0148] 5. "thenComparing|(Ljava / util / function / Function;)"
[0149] 6. "lambda$comparing$ea9a8b3a$1|(Ljava / util / Comparator;Ljava / util / function / Function;Ljava / lang / Object;Ljava / lang / Object;)"
[0150] 7. "comparingInt|(Ljava / util / function / ToIntFunction;)"
[0151] 8. "compare|(Ljava / lang / Object;Ljava / lang / Object;)"
[0152] 9. lambda$thenComparing$36697e65$1|(Ljava / util / Comparator;Ljava / util / Comparator;Ljava /
[0153] 10. "naturalOrder|()"
[0154] 11. "thenComparing|(Ljava / util / Comparator;)"
[0155] 12. lambda$comparing$77a9974f$1|(Ljava / util / function / Function;Ljava / lang / Object;Ljava / lang / Object;)"
[0156] 13. "comparing|(Ljava / util / function / Function;)"
[0157] 14. "reverseOrder|()"
[0158] 15. "lambda$comparingInt$7b0bb60$1|(Ljava / util / function / ToIntFunction;Ljava / lang / Object;
[0159] 16. "lambda$comparing$77a9974f$1|(Ljava / util / function / Function;Ljava / lang / Object;Ljava / lang / Object;)"
[0160] Ljava / lang / Object;)"
[0161] 16. "thenComparingInt|(Ljava / util / function / ToIntFunction;)"
[0162] 17. "comparing|(Ljava / util / function / Function;Ljava / util / Comparator;)"
[0163] 18. "comparingDouble|(Ljava / util / function / ToDoubleFunction;)"
[0164] 19. "nullsFirst|(Ljava / util / Comparator;)"
[0165] 20. "nullsLast|(Ljava / util / Comparator;)"
[0166] 21. "equals|(Ljava / lang / Object;)"
[0167] 22. "thenComparingDouble|(Ljava / util / function / ToDoubleFunction;)"
[0168] 23. "thenComparingLong|(Ljava / util / function / ToLongFunction;)"
[0169] 24. "lambda$comparingLong$6043328a$1|(Ljava / util / function / ToLongFunction;Ljava / lang /
[0170] Object;Ljava / lang / Object;)"
[0171] When generating the interface method table through the prior art, the sizes of the hash tables of the first target Java class and the second target Java class are the same, usually 40, that is, the hash tables of the first target Java class and the second target Java class can both store 40 function pointers, and moreover, the hash algorithms adopted by the first target Java class and the second target Java class are the same, both being the DJBHash algorithm.
[0172] In this case, after performing hash calculation through the DJBHash algorithm, it is found that among the 10 interface functions of the first target Java class, the hash values of 6 interface functions do not conflict, and the hash values of 4 interface functions have hash conflicts. That is, the function signatures and function pointers of 4 interface functions need to be stored in the conflict resolution table of the first target Java class. If each function pointer is 8 Bytes, and each function signature is 8 Bytes, since the hash table of the first target Java class can store 40 function pointers, the storage space occupied by the hash table is 40 * 8 = 320 Bytes. Additionally, since the function signatures and function pointers of 4 interface functions are stored in the conflict resolution table, the storage space occupied by the conflict resolution table is 4 * 2 * 8 = 64 Bytes. Moreover, in the prior art, there is no need to store the size of the hash table and the algorithm index of the hash algorithm in the metadata information of the first target Java class, so the increased value of the metadata information is 0 Bytes.
[0173] Furthermore, after performing hash calculation through DJBHash, it is found that among the 24 interface functions of the second target Java class, the hash values of 4 interface functions do not conflict, and the hash values of 20 interface functions have hash conflicts. That is, the function signatures and function pointers of 20 interface functions need to be stored in the conflict resolution table of the second target Java class. If each function pointer is 8 Bytes, and each function signature is 8 Bytes, since the hash table of the second target Java class can store 40 function pointers, the storage space occupied by the hash table is 40 * 8 = 320 Bytes. Additionally, since the function signatures and function pointers of 20 interface functions are stored in the conflict resolution table of the second target Java class, the storage space occupied by the conflict resolution table is 20 * 2 * 8 = 320 Bytes. Moreover, in the prior art, there is no need to store the size of the hash table and the algorithm index of the hash algorithm in the metadata information of the second target Java class, so the increased value of the metadata information is 0 Bytes.
[0174] Based on this, it can be determined that in the prior art, the total storage space occupied by the interface method tables of the first target Java class and the second target Java class is 320 + 64 + 320 + 320 = 1024 Bytes, and there are a total of 24 interface functions whose hash values have hash conflicts.
[0175] When generating an interface method table for a first target Java class and a second target Java class through the solution disclosed in the embodiments of the present application, the size of the hash table is the product of the number of interface functions and a preset coefficient N. Here, N can be 2. Then, the sizes of the hash tables of the first target Java class and the second target Java class are respectively twice the number of interface functions that the first target Java class and the second target Java class can implement. That is, the size of the hash algorithm of the first target Java class is 20, and the size of the hash table of the second target Java class is 48. Additionally, through various hash algorithms, such as the DJBHash algorithm, BKDRHash algorithm, RSHash algorithm, and SDBMHash algorithm, etc., the hash values of each interface function that the first target Java class and the second target Java class can implement are calculated respectively. When the number of hash conflicts is the smallest, the applied hash algorithms are respectively the hash algorithms of the first target Java class and the second target Java class.
[0176] In this case, when the number of hash conflicts of the first target Java class is the smallest, the applied hash algorithm is used as the optimal algorithm of the first target Java class. Then, through the hash calculation of the optimal algorithm of the first target Java class, it is determined that among the 10 interface functions of the first target Java class, the hash values of 8 interface functions do not conflict, and the hash values of 2 interface functions have hash conflicts. That is, the function signatures and function pointers of 2 interface functions need to be stored in the conflict resolution table of the first target Java class. If each function pointer is 8 Bytes, and each function signature is 8 Bytes, since the hash table of the first target Java class is twice the number of interface functions that the first target Java class can implement, the storage space occupied by the hash table is 10 * 2 * 8 = 160 Bytes. Additionally, since the function signatures and function pointers of 2 interface functions are stored in the conflict resolution table, the size of the conflict resolution table is 2 * 2 * 8 = 32 Bytes. Moreover, the present application also needs to store the size of the hash table and the algorithm index of the hash algorithm in the metadata information of the first target Java class, so the metadata information needs to increase by 4 Bytes. These 4 Bytes are the storage space occupied by the size of the hash table and the algorithm index of the hash algorithm in the metadata information.
[0177] When the number of hash conflicts of the second target Java class is minimized, the applied hash algorithm is used as the optimal algorithm for the second target Java class. Then, through the hash calculation of the optimal algorithm of the second target Java class, it is determined that among the 24 interface functions of the second target Java class, the hash values of 18 interface functions do not conflict, and the hash values of 6 interface functions have hash conflicts. That is, the function signatures and function pointers of 2 interface functions need to be stored in the conflict elimination table of the second target Java class. If each function pointer is 8 Bytes, and each function signature is 8 Bytes, since the hash table of the second target Java class is twice the number of interface functions that the second target Java class can implement, the storage space occupied by the hash table of the second target Java class is 24 * 2 * 8 = 384 Bytes. Additionally, since the function signatures and function pointers of 6 interface functions are stored in the conflict elimination table, the size of the conflict elimination table is 6 * 2 * 8 = 96 Bytes. Moreover, this application also needs to store the size of the hash table and the algorithm index of the hash algorithm in the metadata information of the second target Java class, so the metadata information needs to increase by 4 Bytes. These 4 Bytes are the storage space occupied by the size of the hash table and the algorithm index of the hash algorithm in the metadata information.
[0178] Based on this, it can be determined that through the solution disclosed in the embodiments of this application, the total storage space occupied by the interface method tables of the first target Java class and the second target Java class is 260 + 324 + 4 + 384 + 96 + 4 = 680 Bytes, and there are a total of 8 interface functions whose hash values have hash conflicts.
[0179] Based on this, the following table regarding the storage space occupied by the prior art and the solution of this application can be obtained:
[0180]
[0181] According to the above description and the above table, it can be determined that when comparing the solution of this application with the prior art solution, the storage space saved by the solution of this application is 1024 - 680 = 344 Bytes, which greatly reduces the storage space occupied by the interface method table.
[0182] In addition, in the prior art, there are a total of 24 hash conflicts between the first target Java class and the second target Java class. In the solution of this application, there are a total of 8 hash conflicts between the first target Java class and the second target Java class. Assuming that the access frequencies of the first target Java class and the second target Java class to each interface function are the same, the solution of this embodiment reduces the query operations caused by 67% (i.e., (24 - 8) / 24) of the hash conflicts, greatly improving the query efficiency of the function pointer.
[0183] Correspondingly, corresponding to the method for generating the interface method table disclosed in the foregoing embodiments, an embodiment of the present application further discloses a function pointer query method to implement querying for a function pointer in the interface method table generated in the foregoing embodiments.
[0184] Referring to Figure 4 the schematic diagram of the workflow shown, the function pointer query method disclosed in the embodiment of the present application includes the following steps:
[0185] Step S21: Based on the metadata information of the target Java class, obtain the size of the hash table of the target Java class.
[0186] In the embodiment of the present application, the size of the hash table in the interface method table can be flexibly adjusted, that is, the sizes of the hash tables of different target Java classes may be different, and the size of the hash table of the target Java class is stored in the metadata information of the target Java class. In this case, by querying the metadata information of the target Java class, the size of the hash table of the target Java class stored in the metadata information can be obtained.
[0187] Step S22: Based on the function signature of the interface function to be implemented by the target Java class, calculate the hash value of the interface function.
[0188] Specifically, in this step, first determine the hash algorithm used by the target Java class when calculating the hash value, and then calculate the hash value of the interface function through this hash algorithm and the function signature of the interface function.
[0189] In addition, since Java classes support multiple inheritance mechanisms, that is to say, a Java class can often implement multiple interface functions. Among them, the interface function to be implemented by the target Java class refers to the interface function that the current target Java class needs to implement, and this interface function is one or more of the multiple interface functions that the target Java class can implement.
[0190] Step S23: Based on the size of the hash table and the hash value of the interface function, determine the index in the hash table corresponding to the function pointer of the interface function.
[0191] Step S24: When a function pointer is stored at the position indicated by the index, determine that the function pointer stored at the position indicated by the index is the function pointer of the interface function.
[0192] During the generation process of the interface method table, when a certain interface function does not have a hash conflict with other interface functions, the function pointer of this interface function will be stored in the hash table. In this case, at the position indicated by this index, a function pointer will be stored, and this function pointer is the function pointer of the interface function.
[0193] Step S25: When the position indicated by the index does not store a function pointer, query the conflict resolution table based on the function signature of the interface function, and determine the function pointer of the interface function through the query result.
[0194] During the generation of the interface method table, when a certain interface function has a hash conflict with other interface functions, the function pointer of the interface function will be stored in the conflict resolution table. In this case, the position indicated by the index in the hash table does not store a function pointer, so it is necessary to query the conflict resolution table.
[0195] In addition, in the conflict resolution table, the function signature and function pointer of the interface function are stored respectively. Therefore, through the function signature of the interface function, the function pointer of this interface function can be queried.
[0196] Through the operations of steps S21 to S25, the function pointer in the interface method table can be queried.
[0197] In the prior art, the size of the hash table in the interface method table of each Java class is a same fixed value. That is to say, in the prior art, the sizes of the hash tables of each Java class are the same. Therefore, for different Java classes, the hash tables generated by the prior art have problems of being too large or too small. Among them, when the hash table of a certain Java class is large, it will cause waste of storage space. When the hash table of a certain Java class is small, the number of function pointers that the hash table can store is small. Correspondingly, more function pointers need to be stored in the conflict resolution table. When querying the function pointer of a certain interface function, first query the hash table. When the function pointer of this interface function is not stored in the hash table, then query the conflict resolution table. Therefore, when the number of function pointers stored in the hash table is small and the number of function pointers stored in the conflict resolution table is large, it is often necessary to query the conflict resolution table to query the required function pointer, resulting in a decrease in the query efficiency of the function pointer.
[0198] When querying the function pointer through the solution of the embodiment of the present application, the size of the applied hash table is set according to the number of interface functions that the target Java class can implement, avoiding the problems of being too large or too small of the hash table, thus solving the problem of the decrease in the query efficiency of the function pointer caused by the too small hash table in the prior art and improving the query efficiency of the function pointer.
[0199] In step S22, the operation of calculating the hash value of the interface function based on the function signature of the interface function to be implemented by the target Java class is disclosed. In this step, the applied hash algorithm can be a hash algorithm preset for the target Java class. In addition, the hash algorithm applied by the target Java class can also be determined by querying the metadata information of the target Java class.
[0200] In this case, in the embodiments of the present application, calculating the hash value of the interface function based on the function signature of the interface function to be implemented by the target Java class includes the following steps:
[0201] Query the algorithm index included in the metadata information of the target Java class;
[0202] Calculate the hash value of the interface function based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class.
[0203] Different target Java classes may adopt different hash algorithms, and the algorithm index of the hash algorithm adopted by each target Java class is stored in the metadata information of the target Java class. In this case, by querying the metadata information, the hash algorithm of the target Java class can be obtained, and then the hash value of the interface function can be calculated through the hash algorithm of the target Java class.
[0204] In step S23, an operation of determining the index of the function pointer of the interface function corresponding to the hash table based on the size of the hash table and the hash value of the interface function is disclosed. This operation generally includes the following steps:
[0205] Perform a modulo operation on the hash value of the interface function and the size of the hash table;
[0206] Determine that the remainder obtained through the modulo operation is the index of the function pointer of the interface function corresponding to the hash table.
[0207] Wherein, in the process of performing the modulo operation on the hash value of the interface function and the size of the hash table, the hash value of the interface function is the dividend and the size of the hash table is the divisor.
[0208] Through the above operations, the index of the function pointer of the interface function corresponding to the hash table can be determined based on the size of the hash table and the hash value of the interface function.
[0209] The following are the embodiments of the apparatus of the present application, which can be used to execute the method embodiments of the present application. For the details not disclosed in the embodiments of the apparatus of the present application, please refer to the method embodiments of the present application.
[0210] In the embodiments of the present application, a terminal device is disclosed, and the terminal includes a processor.
[0211] Among them, the processor is used to generate a hash table of the target Java class based on the number of interface functions that the target Java class can implement. The size of the hash table is the product of the number of interface functions and a preset coefficient. Determine the hash algorithm of the target Java class, and based on the hash algorithm of the target Java class and the function signatures of the respective interface functions, determine the hash values of the respective interface functions. Based on the hash value of the first interface function and the size of the hash table, determine the index of the function pointer of the first interface function in the hash table, and store the function pointer of the first interface function at the position indicated by the index. The first interface function is an interface function that does not have a hash conflict with other interface functions. Store the function signature and function pointer of the second interface function in the conflict resolution table. The second interface function is an interface function that has a hash conflict with other interface functions.
[0212] Through the terminal device of the embodiments of the present application, a hash table and a conflict resolution table of the target Java class can be obtained. Correspondingly, an interface method table of the target Java class can be obtained. Moreover, when generating the hash table, the terminal device determines the size of the hash table by multiplying the number of interface functions that the target Java class can implement by a preset coefficient, avoiding the problem of the hash table being too large or too small. Therefore, the problem of waste of storage space caused by an overly large hash table in the prior art is solved, thereby saving storage space. And the problem of the decrease in the query efficiency of function pointers caused by an overly small hash table in the prior art is solved, thereby improving the query efficiency of function pointers.
[0213] Furthermore, the storage space occupied by the function signature of an interface function is usually much larger than the storage space occupied by the function pointer of the interface function. Therefore, the more the number of second interface functions of the target Java class, the more function signatures and function pointers need to be stored in the conflict resolution table. Correspondingly, the larger the storage space occupied by the interface method table. It can be seen from this that when generating the interface method table by the prior art, when the hash table is too small, the storage space occupied by the interface method table is relatively large. However, the terminal device disclosed in the embodiments of the present application can avoid the problem of an overly small hash table. Therefore, compared with the prior art, it can reduce the number of second interface functions, correspondingly reduce the function signatures and function pointers that need to be stored in the conflict resolution table, and further reduce the storage space occupied by the interface method table.
[0214] Furthermore, the processor is also used to store the size of the hash table in the metadata information of the target Java class.
[0215] Further, the processor is specifically configured to perform a modulo operation on the hash value of the first interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index of the function pointer of the first interface function in the hash table.
[0216] Wherein, during the modulo operation, the hash value of the first interface function is the dividend, and the size of the hash table is the divisor.
[0217] In this case, when the hash value of the first interface function is not greater than the size of the hash table, the remainder obtained through the modulo operation is the hash value of the first interface function. That is to say, the index of the function pointer of the first interface function in the hash table is the hash value of the first interface function.
[0218] Further, the processor is specifically configured to calculate the hash values of the respective interface functions through various hash algorithms and the function signatures of the respective interface functions, compare the number of hash conflicts existing between the hash values obtained through the various hash algorithms, and determine that when the number of hash conflicts is the smallest, the hash algorithm applied is the hash algorithm of the target Java class.
[0219] The terminal device disclosed in the embodiment of the present application calculates the hash values of the respective interface functions through various hash algorithms, and then determines that when the number of hash conflicts is the smallest, the hash algorithm applied is the hash algorithm of the target Java class. Compared with the prior art, the terminal device disclosed in the embodiment of the present application can flexibly select the hash algorithm of the target Java class. In this case, calculating the hash value through the hash algorithm of the target Java class can reduce hash conflicts. Correspondingly, the query efficiency of the function pointer can be improved, and further, the function signatures and function pointers stored in the conflict elimination table can be reduced, and the storage space occupied by the interface method table can be further reduced.
[0220] Further, the processor is further configured to store the algorithm index of the hash algorithm of the target Java class into the metadata information of the target Java class. In this case, through this metadata information, the hash algorithm used by the target Java class can be determined.
[0221] Correspondingly, in another embodiment of the present application, a terminal device is disclosed, and this terminal device is used to query the function pointer in the interface method table generated in the above embodiment.
[0222] The terminal device disclosed in the embodiment of the present application includes: a processor.
[0223] The processor is configured to obtain the size of the hash table of the target Java class based on the metadata information of the target Java class, calculate the hash value of the interface function to be implemented by the target Java class based on the function signature of the interface function, determine the index of the hash table corresponding to the function pointer of the interface function based on the size of the hash table and the hash value of the interface function, when a function pointer is stored at the position indicated by the index, determine that the function pointer stored at the position indicated by the index is the function pointer of the interface function, and when no function pointer is stored at the position indicated by the index, query a conflict resolution table based on the function signature of the interface function, and determine the function pointer of the interface function through the query result.
[0224] When querying the function pointer, the size of the hash table applied by the terminal device disclosed in the embodiment of the present application is set according to the number of interface functions that the target Java class can implement, avoiding the problem of the hash table being too large or too small, thereby solving the problem in the prior art that the query efficiency of the function pointer is reduced due to the too small hash table, and improving the query efficiency of the function pointer.
[0225] Further, the processor is specifically configured to query the algorithm index included in the metadata information of the target Java class, and calculate the hash value of the interface function based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class.
[0226] Different target Java classes can adopt different hash algorithms, and the algorithm indexes of the hash algorithms adopted by each target Java class are stored in the metadata information of the target Java class. In this case, by querying the metadata information, the hash algorithm of the target Java class can be obtained, and then the hash value of the interface function can be calculated through the hash algorithm of the target Java class.
[0227] Further, the processor is specifically configured to perform a modulo operation on the hash value of the interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index of the hash table corresponding to the function pointer of the interface function.
[0228] Wherein, in the process of performing the modulo operation on the hash value of the interface function and the size of the hash table, the hash value of the interface function is the dividend and the size of the hash table is the divisor. In this case, the index of the hash table corresponding to the function pointer of the interface function can be determined through the size of the hash table and the hash value of the interface function.
[0229] Correspondingly, in another embodiment of the present application, a terminal device is further disclosed. Refer to Figure 5 the structural schematic diagram shown, the terminal device includes:
[0230] a processor 1101 and a memory,
[0231] the memory is used to store program instructions;
[0232] the processor is used to call and execute the program instructions stored in the memory, so that the processor executes Figure 1 and Figure 3 all or part of the steps in the corresponding embodiments.
[0233] Further, the terminal device may further include: a transceiver 1102 and a bus 1103, and the memory includes a random access memory 1104 and a read-only memory 1105.
[0234] Wherein, the processor is respectively coupled to the transceiver, the random access memory and the read-only memory through the bus. When the terminal device needs to run, it is started by the basic input / output system solidified in the read-only memory or the bootloader in the embedded system to guide the terminal device into the normal running state. After the terminal device enters the normal running state, application programs and operating systems are run in the random access memory, so that the terminal device executes Figure 1 and Figure 3 all or part of the steps in the corresponding embodiments.
[0235] The terminal device according to the embodiment of the present invention may correspond to the terminal device in the above Figure 1 and Figure 3 corresponding embodiments, and the processor in the terminal device can implement Figure 1 and Figure 3 the functions and / or various steps and methods implemented by the terminal device in the corresponding embodiments. For the sake of brevity, details are not described herein again.
[0236] The processor in the embodiment of the present application can be implemented in a variety of ways. Exemplarily, the processor may be a processing unit, or may also be other modules with processing functions.
[0237] It should be noted that this embodiment can also be based on a general physical server combined with a terminal device implemented by network function virtualization (NFV) technology, and the terminal device is a virtual terminal device (such as a virtual host, a virtual router or a virtual switch). The virtual terminal device can be a virtual machine (VM) running a program for generating an interface method table, and the virtual machine is deployed on a hardware device (for example, a physical server). A virtual machine refers to a complete computer system with complete hardware system functions simulated by software and running in a completely isolated environment. Those skilled in the art can virtualize multiple communication devices with the above functions on a general physical server by reading this application. It will not be repeated here.
[0238] Correspondingly, in another embodiment of the present application, a terminal device is also disclosed, the terminal device comprising:
[0239] processor and memory,
[0240] The memory is used to store program instructions;
[0241] The processor is used to call and execute the program instructions stored in the memory so that the processor executes Figure 4 All or part of the steps in the corresponding embodiments.
[0242] Furthermore, the terminal device may also include: a transceiver and a bus, and the memory includes a random access memory and a read-only memory.
[0243] The processor is coupled to the transceiver, random access memory and read-only memory through the bus. When the terminal device needs to be operated, the basic input and output system solidified in the read-only memory or the bootloader boot system in the embedded system is used to start the terminal device and guide the terminal device into a normal operating state. After the terminal device enters the normal operating state, the application program and the operating system are run in the random access memory, so that the terminal device executes Figure 4 All or part of the steps in the corresponding embodiments.
[0244] The terminal device of the embodiment of the present invention may correspond to the above Figure 4 The terminal device in the corresponding embodiment, and the processor in the terminal device can implement Figure 4 For the sake of brevity, the functions of the terminal device in the corresponding embodiment and / or the various steps and methods implemented are not described in detail here.
[0245] The processor in the embodiments of the present application can be implemented in various ways. Exemplarily, the processor can be a processing unit, or can also be other modules with processing functions.
[0246] It should be noted that this embodiment can also be an end device implemented based on a general physical server combined with Network Function Virtualization (NFV) technology, and the end device is a virtual end device (such as a virtual host, a virtual router, or a virtual switch). The virtual end device can be a virtual machine (VM) running a program for querying function pointers, and the virtual machine is deployed on a hardware device (for example, a physical server). A virtual machine refers to a complete computer system with complete hardware system functions simulated by software and running in a completely isolated environment. Those skilled in the art can virtualize multiple communication devices with the above functions on a general physical server by reading this application. Details are not described herein again.
[0247] In specific implementation, the embodiments of the present application further provide a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions run on a computer, the computer can be caused to implement including Figure 1 and Figure 3 all or part of the steps in the corresponding embodiments. The computer-readable storage medium is disposed in any device, and the any device can be a random-access memory (RAM), and the memory can also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); the memory can also include a combination of the above types of memories, etc.
[0248] In specific implementation, the embodiments of the present application further provide a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions run on a computer, the computer can be caused to implement including Figure 4All or part of the steps in the corresponding embodiments. The computer-readable storage medium is disposed in any device, and the any device may be a random-access memory (RAM), and the memory may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD) or solid-state drive (SSD); the memory may also include a combination of the above types of memories, etc.
[0249] Those skilled in the art can also understand that the various illustrative logical blocks and steps listed in the embodiments of the present application can be implemented by electronic hardware, computer software, or a combination of both. Whether such a function is implemented by hardware or software depends on the specific application and the design requirements of the entire system. Those skilled in the art can use various methods to implement the described function for each specific application, but such implementation should not be construed as exceeding the scope of protection of the embodiments of the present application.
[0250] The various illustrative logic units and circuits described in the embodiments of the present application can be implemented or operated by a general-purpose processor, a digital signal processor, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of the above designs. The general-purpose processor may be a microprocessor, and optionally, the general-purpose processor may also be any conventional processor, controller, microcontroller or state machine. The processor can also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, multiple microprocessors, one or more microprocessors combined with a digital signal processor core, or any other similar configuration.
[0251] The steps of the methods or algorithms described in the embodiments of this application may be directly embedded in hardware, software units executed by a processor, or a combination of both. The software units may be stored in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium in the art. Exemplarily, the storage medium may be connected to the processor so that the processor can read information from the storage medium and write information to the storage medium. Optionally, the storage medium may also be integrated into the processor. The processor and the storage medium may be provided in an ASIC, and the ASIC may be provided in a UE. Optionally, the processor and the storage medium may also be provided in different components of the UE.
[0252] It should be understood that in various embodiments of this application, the sequence numbers of the various processes do not imply the order of execution, and the order of execution of the various processes should be determined by their functions and internal logics, and should not constitute any limitation to the implementation process of the embodiments of this application.
[0253] In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of this application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)).
[0254] Each part of this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method embodiment section.
[0255] Although the preferred embodiments of the present application have been described, those skilled in the art can make additional changes and modifications to these embodiments once they know the basic creative concept. Therefore, the appended claims are intended to be construed as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.
[0256] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions in the embodiments of the present invention, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments of the present invention.
[0257] For the same or similar parts among the embodiments in this specification, reference can be made to each other. In particular, for the... embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method embodiments.
[0258] The above-described embodiments of the present invention do not constitute a limitation to the protection scope of the present invention.
Claims
1. An interface method table generation method, characterized in that, it includes: Generating a hash table of the target Java class based on the number of interface functions that the target Java class can implement, where the size of the hash table is the product of the number of interface functions and a preset coefficient; Determining the hash algorithm of the target Java class; Based on the hash algorithm of the target Java class and the function signatures of the respective interface functions, determining the hash values of the respective interface functions, where the hash algorithm is a first-level hash algorithm or a multi-level hash algorithm. In the case where the hash algorithm is the multi-level hash algorithm, performing multiple hash calculations on the function signature. The first hash calculation is performed on the function signature, and each subsequent hash calculation is performed on the result obtained from the previous hash calculation; Based on the hash value of the first interface function and the size of the hash table, determining the index of the function pointer of the first interface function in the hash table, and storing the function pointer of the first interface function at the position indicated by the index, where the first interface function is an interface function that does not have a hash conflict with other interface functions; Storing the function signature and function pointer of the second interface function in a conflict resolution table, where the second interface function is an interface function that has a hash conflict with other interface functions, and the interface method table includes the hash table and the conflict resolution table.
2. The method according to claim 1, characterized in that, it further includes: Storing the size of the hash table in the metadata information of the target Java class.
3. The method according to claim 1, characterized in that, The determining the index of the function pointer of the first interface function in the hash table based on the hash value of the first interface function and the size of the hash table includes: Performing a remainder operation on the hash value of the first interface function and the size of the hash table; Determining that the remainder obtained through the remainder operation is the index of the function pointer of the first interface function in the hash table.
4. The method according to any one of claims 1 to 3, characterized in that, The determining the hash algorithm of the target Java class includes: Calculating the hash values of the respective interface functions respectively through various hash algorithms and the function signatures of the respective interface functions; Comparing the number of hash conflicts existing between the hash values obtained through the various hash algorithms; Determining that the hash algorithm applied when the number of hash conflicts is the smallest is the hash algorithm of the target Java class.
5. The method according to claim 4, characterized in that, it further includes: Storing the algorithm index of the hash algorithm of the target Java class in the metadata information of the target Java class.
6. A function pointer query method, characterized in that, it includes: Based on the metadata information of the target Java class, obtaining the size of the hash table of the target Java class; Based on the function signature of the interface function to be implemented by the target Java class, calculate the hash value of the interface function through a hash algorithm, where the hash algorithm is a first-level hash algorithm or a multi-level hash algorithm. In the case where the hash algorithm is the multi-level hash algorithm, perform multiple hash calculations on the function signature. The first hash calculation is performed on the function signature, and each subsequent hash calculation is performed on the result obtained from the previous hash calculation; Based on the size of the hash table and the hash value of the interface function, determine the index of the hash table corresponding to the function pointer of the interface function; When a function pointer is stored at the position indicated by the index, determine that the function pointer stored at the position indicated by the index is the function pointer of the interface function; When a function pointer is not stored at the position indicated by the index, query the conflict resolution table based on the function signature of the interface function, and determine the function pointer of the interface function through the query result.
7. The method according to claim 6, wherein, the calculating the hash value of the interface function through a hash algorithm based on the function signature of the interface function to be implemented by the target Java class includes: query the algorithm index included in the metadata information of the target Java class; calculate the hash value of the interface function based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class.
8. The method according to claim 6 or 7, wherein, the determining the index of the hash table corresponding to the function pointer of the interface function based on the size of the hash table and the hash value of the interface function includes: perform a remainder operation on the hash value of the interface function and the size of the hash table; determine that the remainder obtained through the remainder operation is the index of the hash table corresponding to the function pointer of the interface function.
9. A terminal device, wherein, comprising: a processor; The processor is configured to generate a hash table for the target Java class based on the number of interface functions that the target Java class can implement. The size of the hash table is the product of the number of interface functions and a preset coefficient. Determine the hash algorithm for the target Java class. Based on the hash algorithm of the target Java class and the function signatures of the respective interface functions, determine the hash values of the respective interface functions. The hash algorithm is a first-level hash algorithm or a multi-level hash algorithm. In the case where the hash algorithm is the multi-level hash algorithm, perform multiple hash calculations on the function signature. The first hash calculation is performed on the function signature, and each subsequent hash calculation is performed on the result obtained from the previous hash calculation. Based on the hash value of the first interface function and the size of the hash table, determine the index of the function pointer of the first interface function in the hash table, and store the function pointer of the first interface function at the position indicated by the index. The first interface function is an interface function that does not have a hash conflict with other interface functions. Store the function signature and function pointer of the second interface function in a conflict resolution table. The second interface function is an interface function that has a hash conflict with other interface functions. The interface method table includes the hash table and the conflict resolution table.
10. The terminal device according to claim 9, wherein, the processor is further configured to store the size of the hash table in the metadata information of the target Java class.
11. The terminal device according to claim 9, wherein, the processor is specifically configured to perform a modulo operation on the hash value of the first interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index of the function pointer of the first interface function in the hash table.
12. The terminal device according to any one of claims 10 to 11, wherein, the processor is specifically configured to calculate the hash values of the respective interface functions respectively through various hash algorithms and the function signatures of the respective interface functions, compare the number of hash conflicts existing between the hash values obtained through the various hash algorithms, and determine that the hash algorithm applied when the number of hash conflicts is the smallest is the hash algorithm for the target Java class.
13. The terminal device according to claim 12, wherein, the processor is further configured to store the algorithm index of the hash algorithm of the target Java class in the metadata information of the target Java class.
14. A terminal device, wherein, comprising: a processor; The processor is configured to obtain the size of the hash table of the target Java class based on the metadata information of the target Java class, calculate the hash value of the interface function based on the function signature of the interface function to be implemented by the target Java class, where the hash algorithm is a first-level hash algorithm or a multi-level hash algorithm. In the case where the hash algorithm is the multi-level hash algorithm, perform multiple hash calculations on the function signature. The first hash calculation is performed on the function signature, and each subsequent hash calculation is performed on the result obtained from the previous hash calculation. Based on the size of the hash table and the hash value of the interface function, determine the index in the hash table corresponding to the function pointer of the interface function. When a function pointer is stored at the position indicated by the index, determine that the function pointer stored at the position indicated by the index is the function pointer of the interface function. When no function pointer is stored at the position indicated by the index, query the conflict resolution table based on the function signature of the interface function, and determine the function pointer of the interface function through the query result.
15. The terminal device according to claim 14, wherein, the processor is specifically configured to query the algorithm index included in the metadata information of the target Java class, and calculate the hash value of the interface function based on the hash algorithm corresponding to the algorithm index and the function signature of the interface function to be implemented by the target Java class.
16. The terminal device according to claim 14 or 15, wherein, the processor is specifically configured to perform a modulo operation on the hash value of the interface function and the size of the hash table, and determine that the remainder obtained through the modulo operation is the index in the hash table corresponding to the function pointer of the interface function.
17. A terminal device, wherein, comprises: a processor and a memory, the memory is configured to store program instructions; the processor is configured to call and execute the program instructions stored in the memory, so that the processor executes the interface method table generation method according to any one of claims 1-5.
18. A terminal device, wherein, comprises: a processor and a memory, the memory is configured to store program instructions; the processor is configured to call and execute the program instructions stored in the memory, so that the processor executes the function pointer query method according to any one of claims 6-8.
19. A computer-readable storage medium, wherein, the computer-readable storage medium stores instructions, and when the instructions run on a computer, the computer is caused to execute the interface method table generation method according to any one of claims 1-5.
20. A computer-readable storage medium, wherein, the computer-readable storage medium stores instructions, and when the instructions run on a computer, the computer is caused to execute the function pointer query method according to any one of claims 6-8.
Citation Information
Patent Citations
Data retrieval apparatus, data storage method and data retrieval method
CN103914506A