Runtime recompilation optimization method and system for dynamic hotspot code
Patent Information
- Application Number
- CN202610404430.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-30
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2046-03-30
AI Technical Summary
这种孤立分析的方式,导致编译器无法区分同一段代码在不同业务上下文中的具体行为模式
[0015]本方法能够显著提升医院信息系统在复杂多变的医疗业务场景下的运行时性能。通过实时监控程序执行过程,精准捕获包含执行频率、调用关系和数据访问特征的代码块,基于医疗业务调用上下文构建多层调用依赖图,有效揭示了不同业务流程间潜在的代码复用模式。通过量化分析共享代码路径在不同业务场景下的参数分布差异和执行路径分歧,能够可靠地识别出那些行为稳定、具备优化潜力的多态稳定热点。
Smart Images

Figure CN122450582B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of performance optimization technology for medical information systems, and in particular to a method and system for runtime recompiling and optimizing dynamic hotspot code. Background Technology
[0002] In the field of healthcare informatics, hospital information systems typically employ dynamic compilation techniques to optimize runtime performance. Existing technologies generally monitor program execution to identify and collect frequently executed code blocks as hotspots. These hotspots are then submitted to a just-in-time (JIT) compiler for recompilation, generating highly optimized machine code to improve the execution efficiency of critical business paths. Conventional practices focus on analyzing the execution frequency of code blocks, call stack information, and local data access patterns, using this as a basis for standardized compilation optimizations, such as method inlining and loop unrolling.
[0003] However, existing conventional optimization methods have significant drawbacks. Hospital information systems handle diverse and complex business processes such as registration, diagnosis, billing, and pharmacy management, resulting in the same underlying code being called by multiple different upper-level business modules. Current technologies treat each frequently called code path as an independent hotspot for optimization, ignoring the semantic relationships and behavioral differences behind these cross-business process calls. This isolated analysis approach prevents the compiler from distinguishing the specific behavioral patterns of the same code in different business contexts. When generating a single optimized version for such shared code, it may only be highly effective for a specific calling scenario. In other business scenarios, due to differences in parameter type distribution, data flow characteristics, or execution paths, the optimized code may cause frequent type check failures or branch prediction errors, forcing the runtime system to repeatedly revert to the unoptimized original code path, severely compromising the stability of the optimization effect and the overall system performance balance. Summary of the Invention
[0004] This invention provides a runtime recompiling optimization method and system for dynamic hotspot code, which can solve the problems in the prior art.
[0005] A first aspect of the present invention provides a runtime recompilation optimization method for dynamic hotspot code, comprising: Obtain code blocks during the execution of a target program in a hospital information system. These code blocks include code block identifiers, execution counts, call chains, and data access modes. A multi-layered call dependency graph is constructed for the code block according to the medical business call context, and shared code paths across business processes are identified. The parameter distribution difference degree and execution path divergence entropy of the shared code path under different business processes are calculated. When the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold, the shared code path is marked as a polymorphic stable hot spot. The type constraint intersection and data flow invariant of the polymorphic stable hot spot under each business process are extracted, a set of type specialization versions is generated, and a precondition guard expression is constructed and bound to form a condition optimization unit. The condition optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights. Selective inlining and loop unrolling are performed to generate dual-path code including fast path branches and slow path branches. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the intersection of the type constraints is updated.
[0006] A multi-layered call dependency graph is constructed for the code block according to the medical business call context, and shared code paths across business processes are identified. For the shared code paths, the parameter distribution difference and execution path divergence entropy under different business processes are calculated, including: A business process call tree is constructed based on the business process identifier in the call chain of the code block. The call depth of each node and the data dependency relationship passed by the parent node are marked in the business process call tree. Code blocks with the same call depth and receiving the same parent node data dependency relationship are identified. The code blocks are aggregated into the same-level call node group. The data flow overlap and control flow coupling degree between the same-level call node groups are calculated. Traverse each level of the call node group in the business process call tree, extract the code block identifiers that appear frequently in the target, align and match the call paths of the code block identifiers in different business process call trees, and determine the shared code path across business processes based on the edit distance of the path nodes. For the code blocks in the shared code path, the set of parameter types and the range of parameter values received are statistically analyzed under each business process, a parameter feature matrix is constructed, principal component analysis is performed on the parameter feature matrix to extract feature vectors, and the Euclidean distance of the feature vectors under different business processes is calculated as the parameter distribution difference; the conditional branch execution trajectory of the shared code path under each business process is extracted, a branch state transition graph is constructed, and the trace norm difference of the state transition probability matrix of the branch state transition graph is calculated as the execution path divergence entropy.
[0007] Extract the execution trajectory of the conditional branches of the shared code path under each business process, construct a branch state transition graph, and calculate the trace norm difference of the state transition probability matrix of the branch state transition graph as the execution path branch entropy, including: For the conditional branch instructions in the shared code path, the set of variables involved in the branch judgment conditions and the branch execution results are collected under each business process. The values of each variable in the set of variables are encoded and mapped to construct a variable value encoding vector. The combination of the variable value encoding vector and the branch execution results is used as a composite status identifier. Extract the transition path of the composite state identifier in the execution time sequence, construct a directed state transition graph, mark the number of transitions for each transition edge in the directed state transition graph, calculate the total number of outgoing edge transitions for each state node, divide the number of transitions for each outgoing edge by the total number of outgoing edge transitions to obtain the transition probability, and fill the state transition probability matrix based on the transition probability. Calculate the graph Laplacian matrix of the state transition probability matrix, extract the eigenvalue spectrum of the graph Laplacian matrix, and calculate the spectral distance between the eigenvalue spectra under different business processes; Perform a matrix logarithm operation on the state transition probability matrix to calculate the trace of the matrix logarithm, calculate the trace variance under different business processes, and use the normalized linear combination of the spectral distance and the trace variance as the execution path divergence entropy.
[0008] Extract the intersection of type constraints and data flow invariants of the polymorphic stable hotspots under each business process, generate a set of type-specialized versions, construct a precondition guard expression, and bind it to form a condition optimization unit, including: For the execution records of the polymorphic stable hotspots under each business process, the type signature and type compatibility matrix of the input parameters are extracted, matrix decomposition is performed on the type compatibility matrix, orthogonal basis vectors are extracted, and the type combination corresponding to the orthogonal basis vectors is taken as the type constraint intersection. Slice analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimal dependent variables that affect the output variables and perform abstract interpretation. An abstract domain lattice of variables is constructed, and the supremum and infimum in the abstract domain lattice are used as data flow invariants. Based on the type combinations in the intersection of the type constraints, template instantiation is performed on the polymorphic stable hotspots, generating specific code after template instantiation for each type combination. Escape analysis and scalar replacement are performed on the specific code to generate a set of type-specialized versions. The upper bound and lower bound in the data flow invariant are encoded into a Bloom filter structure. A hash function combination is performed on the Bloom filter structure to construct it. The detection logic constructed by the hash function combination is serialized into a precondition guard expression. The precondition guard expression is used as the entry point of the dispatch function and the set of type specialization versions is used as the dispatch target to form a condition optimization unit.
[0009] Slice analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimal dependent variables affecting the output variables and perform abstract interpretation. An abstract range lattice of variables is constructed, and the supremum and infimum in the abstract range lattice are used as data flow invariants, including: Extract the code block sequence contained in the polymorphic stable hot spot, connect the code block sequence in execution order to form a path code segment, perform control flow analysis and data flow analysis on the path code segment, construct a path-level control flow graph and a path-level data flow graph, construct a set of control dependency edges based on the dominance relationship in the path-level control flow graph, construct a set of data dependency edges based on the cross-code block variable definition-use relationship in the path-level data flow graph, and jointly form a program dependency graph; The backward slicing algorithm is executed on the program dependency graph to construct a reachability tree starting from the output variable. Branches that have no dependency relationship with the output variable are pruned in the reachability tree, and the variables corresponding to the leaf nodes of the reachability tree are extracted as the minimum dependency variable set. For each variable in the set of minimum dependent variables, the value propagation path of the variable is traced in the program dependency graph, abstract semantic computation is performed on the operation nodes on the value propagation path, and the computation results are used to construct a partial order relation in the abstract domain to form the abstract value domain lattice. The upper bound is obtained by performing a minimum upper bound operation on the abstract value range lattice, and the lower bound is obtained by performing a maximum lower bound operation. The upper bound and the lower bound are encoded into an interval representation as the data stream invariant.
[0010] The conditional optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights, selective inlining and loop unrolling are performed, and dual-path code including fast path branches and slow path branches is generated, including: A control flow graph is constructed for the type-specialized version of the conditional optimization unit. A dominance tree is constructed for the control flow graph. The execution frequency of each edge is calculated based on the dominance tree and converted into a branch weight. A minimum static single assignment transformation is performed on the type-specialized version. A variable merging function is inserted at the dominance boundary position and the branch weight is added to construct the static single assignment intermediate representation with branch weight. For the static single-assignment intermediate representation with branch weights, a call graph is constructed and bottom-up traversal is performed. The weighted call depth of each function call node is calculated. When the weighted call depth is less than the depth limit and the function body size is less than the size limit, inline replacement of the function body is performed, and selective inlining is performed. For the loop structure, data dependency analysis is performed. When there is no loop carrying dependency, a copy of the loop body is generated according to the expansion factor and the inductive variable is updated, and loop unrolling is performed. The precondition guard expression is compiled into a conditional jump instruction, and a fast path branch is constructed when the guard condition is met and a slow path branch is constructed when the guard condition is not met, thus generating the dual-path code; In the fast path branch, algebraic simplification and strength reduction are performed, value range analysis is performed on memory access instructions, and security check instructions are removed when the access index value range is completely covered by the data flow invariant. In the slow path branch, complete type verification and boundary verification logic is inserted.
[0011] In the fast path branch, algebraic simplification and strength reduction are performed, value range analysis is performed on memory access instructions, and safety check instructions are removed when the access index value range is completely covered by the data flow invariant. In the slow path branch, complete type validation and boundary validation logic is inserted, including: In the fast path branch, the static single assignment intermediate representation is rewritten by performing expression rewriting, decomposing the multiplication constant into the sum of powers of two, replacing the multiplication operation with a combination sequence of shift and addition, extracting the reciprocal of the divisor for the division operation and converting it into multiplication form, and performing algebraic simplification and intensity reduction. For the memory access instructions of the fast path branch, extract the base address register and offset expression, construct a symbolic value graph from the offset expression, perform abstract interpretation propagation on the symbolic value graph, calculate the upper and lower bounds of the symbolic values to form the access index value domain, and perform value domain analysis. Extract the legal access interval from the data stream invariant, construct the inclusion relationship determination between the access index value field and the legal access interval, and delete the corresponding boundary check instruction and null value check instruction when the access index value field is a proper subset of the legal access interval, and remove the security check instruction. Insert a null pointer trap instruction before each object dereference point in the slow path branch, insert a runtime type tag comparison instruction before each type conversion point, insert upper and lower bound range verification instructions before each array index access point, and insert complete type verification and boundary verification logic.
[0012] A second aspect of this invention provides a runtime recompilation optimization system for dynamic hotspot code, comprising: The code block acquisition unit is used to acquire code blocks during the execution of the target program of the hospital information system. The code block includes a code block identifier, execution count, call chain, and data access mode. The dependency graph construction unit is used to construct a multi-level call dependency graph for the code block according to the medical business call context, identify shared code paths across business processes, and calculate the parameter distribution difference degree and execution path divergence entropy for the shared code paths under different business processes. The hotspot marking unit is used to mark the shared code path as a polymorphic stable hotspot when the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold. It extracts the type constraint intersection and data flow invariant of the polymorphic stable hotspot under each business process, generates a set of type specialization versions, constructs a precondition guard expression, and binds it to form a condition optimization unit. An optimization unit is used to recompile the conditional optimization unit, construct a static single-assignment intermediate representation with branch weights, perform selective inlining and loop unrolling, and generate dual-path code including fast path branches and slow path branches. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the intersection of the type constraints is updated.
[0013] A third aspect of the present invention provides an electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0014] A fourth aspect of the present invention provides a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0015] This method significantly improves the runtime performance of hospital information systems in complex and ever-changing medical business scenarios. By monitoring the program execution process in real time, it accurately captures code blocks containing execution frequency, call relationships, and data access characteristics. Based on the medical business call context, it constructs a multi-layered call dependency graph, effectively revealing potential code reuse patterns between different business processes. By quantitatively analyzing the differences in parameter distribution and execution path divergence of shared code paths in different business scenarios, it can reliably identify those stable, polymorphic hotspots with optimization potential.
[0016] For identified polymorphic stable hotspots, this method can automatically derive their common type constraints and invariant data flow properties across various business variants. Based on these common characteristics, the system can generate a set of type-specialized optimized versions, each equipped with precise precondition guards. This approach of binding optimization code to runtime conditions ensures the safety and specificity of the optimization, avoiding performance degradation or logical errors caused by misjudgment of scenarios.
[0017] During the recompilation phase, a static single-assignment form with branch weights is used for intermediate representation, providing richer information for compiler optimization. Aggressive yet controlled optimization techniques such as selective inlining and loop unrolling are employed, combined with the generated dual-path code structure. The fast path specifically handles common cases satisfying specific type constraints, while the slow path serves as a general backup, ensuring program correctness. The system continuously monitors the hit rate of the fast path; when optimization prerequisites are no longer met, it automatically rolls back to the original code and updates the optimization conditions, achieving an adaptive and self-maintaining optimization loop that keeps system performance at a high level over the long term. Attached Figure Description
[0018] Figure 1 This is a flowchart illustrating the runtime recompilation optimization method for dynamic hotspot code according to an embodiment of the present invention. Figure 2 This is a flowchart illustrating the process of constructing a multi-level call dependency graph and identifying shared code paths in an embodiment of the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] The technical solution of the present invention will be described in detail below with reference to specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0021] Figure 1 This is a flowchart illustrating the runtime recompilation optimization method for dynamic hotspot code according to an embodiment of the present invention, as shown below. Figure 1 As shown, the method includes: Obtain code blocks during the execution of a target program in a hospital information system. These code blocks include code block identifiers, execution counts, call chains, and data access modes. A multi-layered call dependency graph is constructed for the code block according to the medical business call context, and shared code paths across business processes are identified. The parameter distribution difference degree and execution path divergence entropy of the shared code path under different business processes are calculated. When the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold, the shared code path is marked as a polymorphic stable hot spot. The type constraint intersection and data flow invariant of the polymorphic stable hot spot under each business process are extracted, a set of type specialization versions is generated, and a precondition guard expression is constructed and bound to form a condition optimization unit. The condition optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights. Selective inlining and loop unrolling are performed to generate dual-path code including fast path branches and slow path branches. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the intersection of the type constraints is updated.
[0022] Figure 2 This is a flowchart illustrating the method for constructing a multi-layered call dependency graph and identifying shared code paths according to an embodiment of the present invention. The method involves constructing a multi-layered call dependency graph for the code block based on the medical business call context, identifying shared code paths across business processes, and calculating the parameter distribution difference and execution path divergence entropy for the shared code paths under different business processes, including: A business process call tree is constructed based on the business process identifier in the call chain of the code block. The call depth of each node and the data dependency relationship passed by the parent node are marked in the business process call tree. Code blocks with the same call depth and receiving the same parent node data dependency relationship are identified. The code blocks are aggregated into the same-level call node group. The data flow overlap and control flow coupling degree between the same-level call node groups are calculated. Traverse each level of the call node group in the business process call tree, extract the code block identifiers that appear frequently in the target, align and match the call paths of the code block identifiers in different business process call trees, and determine the shared code path across business processes based on the edit distance of the path nodes. For the code blocks in the shared code path, the set of parameter types and the range of parameter values received are statistically analyzed under each business process, a parameter feature matrix is constructed, principal component analysis is performed on the parameter feature matrix to extract feature vectors, and the Euclidean distance of feature vectors under different business processes is calculated as the parameter distribution difference. Extract the execution trajectory of the conditional branches of the shared code path under each business process, construct a branch state transition graph, and calculate the trace norm difference of the state transition probability matrix of the branch state transition graph as the execution path divergence entropy.
[0023] After obtaining the code blocks from the target program of the hospital information system during its execution, a deep-level call relationship analysis is needed. This involves parsing the call chain of the code blocks to extract the business process identifiers contained within them. These business process identifiers are used to mark the specific medical business scenario to which the code block belongs, such as different business processes like outpatient registration, inpatient registration, and medication dispensing. Using the business process identifiers in the call chain as the root node, a business process call tree is constructed according to the order of method calls. Each node in the tree represents a code block, and edges represent call relationships.
[0024] In the constructed business process call tree, each node is labeled with its call depth value within the tree. The call depth value starts from 0 at the root node and increases incrementally. The depth of a child node is the depth of its parent node plus 1. Simultaneously, the data dependencies passed from the parent node to the child node are recorded, including passed parameter objects, shared variables, and database connection handles. The entire call tree is traversed, and all nodes with the same call depth are selected. The data dependencies received by these nodes from their parent nodes are further examined. When multiple nodes have the same call depth and receive data dependencies of the same type, quantity, and transmission method, these code blocks are aggregated into a group of call nodes at the same level.
[0025] Data flow analysis is performed on the same-level call node group. The set of variables read and written by each code block in the group is counted, and the degree of overlap of data flow between different code blocks is calculated. The degree of overlap of data flow is determined by calculating the ratio of the number of commonly accessed variables to the total number of accessed variables. At the same time, the control flow coupling degree is analyzed to identify whether there are conditional dependencies or circular nesting relationships between code blocks. The coupling degree is quantified by the proportion of the number of control dependency edges to the total call relationship.
[0026] The algorithm iterates through all node groups at each level of the business process call tree, counting the frequency of each code block identifier in different business processes. A frequency threshold is set at 60% of all business processes. Code block identifiers with frequencies exceeding this threshold are extracted, and the complete call paths of these high-frequency code blocks in different business process call trees are extracted. Path alignment is then performed. Path alignment uses a sequence matching algorithm to calculate the edit distance between two path node sequences, i.e., the minimum number of operations required to convert one path into another through insertion, deletion, and replacement. When the edit distance is less than 30% of the path length, it is considered a shared code path across business processes.
[0027] For the identified shared code paths, parameter information received by the code blocks under each business process is collected. The parameter type set includes type labels such as integer, string, and object reference. The parameter value range records the minimum, maximum, and distribution range of numerical parameters. A parameter feature matrix is constructed, with rows representing different business processes and columns representing parameter feature dimensions. Principal component analysis is performed on this matrix to extract the eigenvectors corresponding to the first three principal components. The Euclidean distance between the eigenvectors of different business processes is calculated as the parameter distribution difference.
[0028] Extract the execution records of conditional branches of the shared code path under each business process, including the selection of if-else statements and switch-case branches. Convert the branch selection sequence into a state transition graph, where nodes represent branch states and edges represent state transitions and their probabilities. Construct a state transition probability matrix and calculate the trace norm difference of this matrix under different business processes. The trace norm is the sum of the diagonal elements of the matrix, and the difference reflects the degree of divergence of the execution path; this value is used as the execution path divergence entropy.
[0029] Extract the execution trajectory of the conditional branches of the shared code path under each business process, construct a branch state transition graph, and calculate the trace norm difference of the state transition probability matrix of the branch state transition graph as the execution path branch entropy, including: For the conditional branch instructions in the shared code path, the set of variables involved in the branch judgment conditions and the branch execution results are collected under each business process. The values of each variable in the set of variables are encoded and mapped to construct a variable value encoding vector. The combination of the variable value encoding vector and the branch execution results is used as a composite status identifier. Extract the transition path of the composite state identifier in the execution time sequence, construct a directed state transition graph, mark the number of transitions for each transition edge in the directed state transition graph, calculate the total number of outgoing edge transitions for each state node, divide the number of transitions for each outgoing edge by the total number of outgoing edge transitions to obtain the transition probability, and fill the state transition probability matrix based on the transition probability. Calculate the graph Laplacian matrix of the state transition probability matrix, extract the eigenvalue spectrum of the graph Laplacian matrix, and calculate the spectral distance between the eigenvalue spectra under different business processes; Perform a matrix logarithm operation on the state transition probability matrix to calculate the trace of the matrix logarithm, calculate the trace variance under different business processes, and use the normalized linear combination of the spectral distance and the trace variance as the execution path divergence entropy.
[0030] In practical implementation, to measure the differences in the execution behavior of shared code paths under different business processes, a spectral analysis method using composite state modeling and state transition probability matrices is adopted. The specific process is as follows: When a shared code path is frequently called in both outpatient registration and inpatient settlement business processes, all conditional branch instructions in that code path are marked. For each conditional branch instruction, such as "if(patient.age>60 &&service.type==emergency)", the set of variables involved in the branch's judgment condition is collected, in this case, {patient.age, service.type}. During the execution of the outpatient registration process, the actual values of these variables are recorded. For example, if patient.age is 45 and service.type is ordinary, the corresponding branch execution result is recorded as false. In the inpatient settlement process, another set of values is recorded, such as patient.age being 68 and service.type being emergency, the branch execution result is true.
[0031] When encoding and mapping variable values, the continuous variable patient.age is divided into encoded values according to the range, for example, 0-18 years old is encoded as 0, 19-60 years old is encoded as 1, and over 60 years old is encoded as 2; the enumerated variable service.type is mapped according to type, ordinary is encoded as 0, and emergency is encoded as 1. A variable value encoding vector is constructed, such as [1, 0] representing an age range of 19-60 years old and a service type of ordinary. This encoding vector is combined with the branch execution result false to form a composite status identifier "[1, 0]: false".
[0032] The changes in composite state identifiers are tracked during execution. For example, in the outpatient registration process, the state transition sequence is observed to be "[1,0]:false → [2,1]:true → [1,0]:false", and in the inpatient settlement process, it is observed to be "[2,1]:true → [2,1]:true → [1,1]:false". A directed state transition graph is constructed, where nodes are composite state identifiers and edges represent state transitions. After executing the outpatient registration process 1000 times, the number of transitions from "[1,0]:false" to "[2,1]:true" is 320, and the number of transitions from "[1,0]:false" to "[1,0]:false" is 180. The total number of outgoing edge transitions for the state "[1,0]:false" is calculated to be 320 + 180 = 500, resulting in transition probabilities of 0.64 and 0.36, respectively. The same calculation is performed on the outgoing edges of all state nodes, and the state transition probability matrix P is filled, where the element Pij This represents the probability of transitioning from state i to state j.
[0033] Calculate the graph Laplacian matrix L=DP from the obtained state transition probability matrix P, where D is the degree matrix. Perform eigenvalue decomposition on the graph Laplacian matrix to extract the eigenvalue spectrum. The eigenvalue spectra of the outpatient registration process and the inpatient settlement process are calculated separately, and denoted as follows: and Euclidean distance is used to calculate spectral distance. .
[0034] Performing matrix logarithm operation on the state transition probability matrix yields Calculate its trace value Calculate the trace values for the outpatient registration process and the inpatient settlement process, denoted as t1 and t2 respectively, and calculate the variance of the trace values. After normalizing the spectral distance and trace variance, a weighted linear combination is used. As the final measure of execution path divergence entropy, when this measure is lower than the preset convergence threshold of 0.15, it indicates that the execution behavior of the shared code path under different business processes has a high degree of consistency.
[0035] Extract the intersection of type constraints and data flow invariants of the polymorphic stable hotspots under each business process, generate a set of type-specialized versions, construct a precondition guard expression, and bind it to form a condition optimization unit, including: For the execution records of the polymorphic stable hotspots under each business process, the type signature and type compatibility matrix of the input parameters are extracted, matrix decomposition is performed on the type compatibility matrix, orthogonal basis vectors are extracted, and the type combination corresponding to the orthogonal basis vectors is taken as the type constraint intersection. Slice analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimal dependent variables that affect the output variables and perform abstract interpretation. An abstract domain lattice of variables is constructed, and the supremum and infimum in the abstract domain lattice are used as data flow invariants. Based on the type combinations in the intersection of the type constraints, template instantiation is performed on the polymorphic stable hotspots, generating specific code after template instantiation for each type combination. Escape analysis and scalar replacement are performed on the specific code to generate a set of type-specialized versions. The upper bound and lower bound in the data flow invariant are encoded into a Bloom filter structure. A hash function combination is performed on the Bloom filter structure to construct it. The detection logic constructed by the hash function combination is serialized into a precondition guard expression. The precondition guard expression is used as the entry point of the dispatch function and the set of type specialization versions is used as the dispatch target to form a condition optimization unit.
[0036] For polymorphic stable hotspots, execution records under different business processes are collected to gather the actual type information of input parameters during runtime. For patient data processing hotspots in hospital information systems, the specific types of parameters called during outpatient, inpatient, and laboratory business process calls are recorded. This type information is constructed into a type compatibility matrix, where rows represent different calling scenarios, columns represent parameter positions, and element values represent the type code of the parameter at that position. Singular value decomposition is performed on this matrix to obtain orthogonal basis vectors by calculating eigenvectors. The top k orthogonal basis vectors with a cumulative contribution rate reaching 95% are selected, and the type combinations corresponding to these basis vectors are used as the type constraint intersection. For example, when the patient ID parameter is consistently represented as a long integer and the name field is always a fixed-length string in all business processes, these consistent type characteristics constitute the constraint intersection.
[0037] Backward slicing analysis is performed on the program dependency graph of polymorphic stable hotspots, tracing data and control dependencies backward from the output variables and marking all reachable nodes. Code branches and variables that do not affect the output are pruned to obtain the minimal set of dependent variables. Abstract interpretation is performed on the variables in this set, mapping specific values to abstract domains. An abstract domain lattice for the variables is constructed, with elements sorted by precision. The supremum represents the widest range of variable values, and the infimum represents the strictest constraint that the variable must satisfy. For example, for the age field, by analyzing all execution paths, its infimum is determined to be 0, and its supremum to be 150. These boundaries serve as data flow invariants.
[0038] Based on type combinations within the intersection of type constraints, template instantiation is performed on polymorphic stable hotspots. This replaces generic parameters in the original code with concrete types, generating code copies of the concrete types to ensure each type combination has a corresponding implementation version. For each generated concrete type code, escape analysis is performed to identify the object's memory allocation strategy. Escape analysis constructs an object reference graph, tracks the object's propagation path, and determines whether the object will exceed the current method's lifecycle. For example, in the drug inventory management hotspot method, if a temporarily created drug object is only used within the method and not passed to other threads or returned to the caller, it is marked as a non-escape object. For non-escape objects, scalar replacement optimization is performed, decomposing the object into independent basic type variables. For example, a PatientInfo object is decomposed into independent scalar variables such as patientId (integer), patientName (string), and birthDate (date). This reduces heap memory allocation and garbage collection overhead, significantly improving processing speed. After scalar replacement, a highly optimized code version is generated for each type combination; these versions collectively constitute a set of type-specialized versions.
[0039] An efficient distribution mechanism is constructed based on the data flow invariants. The boundary values of the data flow invariants obtained from the previous analysis are encoded into a Bloom filter. In the specific implementation, three independent hash functions, such as MurmurHash, FNVHash, and JenkinsHash, are selected for each invariant. These hash functions are applied to the boundary values of the invariants, and the results are mapped to specific positions on the bitmap and marked as 1. For example, the upper and lower bounds of the age range [0, 120] are calculated respectively, and marked at the corresponding positions in the bitmap. At runtime, these three hash functions are also applied to the input parameters to check whether the corresponding positions in the bitmap are all 1. If so, it indicates that the parameter value satisfies the invariant condition.
[0040] The hash calculation and bitmap detection logic is converted into efficient bytecode instruction sequences to form guard expressions. For example, in the hotspot method for prescription drug review, the invariant detection of parameters such as drug type and dosage can be converted into an expression of the form "(drugTypeHash & MASK_A) == VALUE_A && (dosageHash & MASK_B) == VALUE_B". The generated guard expression is inserted at the entry point of the hotspot function as a dispatch condition. When the runtime parameters meet the guard condition, execution jumps directly to the corresponding specialized version; otherwise, it falls back to the original general implementation to ensure program correctness. A binding relationship is established between guard expressions and specialized versions, and a function pointer array is created. The array index corresponds to different type combination scenarios, and the array elements store the entry address of the corresponding specialized version. Based on the evaluation result of the guard expression, the index value is calculated, and the function pointer of the corresponding specialized version is retrieved from the array to achieve efficient jump.
[0041] Slice analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimal dependent variables affecting the output variables and perform abstract interpretation. An abstract range lattice of variables is constructed, and the supremum and infimum in the abstract range lattice are used as data flow invariants, including: Extract the code block sequence contained in the polymorphic stable hot spot, connect the code block sequence in execution order to form a path code segment, perform control flow analysis and data flow analysis on the path code segment, construct a path-level control flow graph and a path-level data flow graph, construct a set of control dependency edges based on the dominance relationship in the path-level control flow graph, construct a set of data dependency edges based on the cross-code block variable definition-use relationship in the path-level data flow graph, and jointly form a program dependency graph; The backward slicing algorithm is executed on the program dependency graph to construct a reachability tree starting from the output variable. Branches that have no dependency relationship with the output variable are pruned in the reachability tree, and the variables corresponding to the leaf nodes of the reachability tree are extracted as the minimum dependency variable set. For each variable in the set of minimum dependent variables, the value propagation path of the variable is traced in the program dependency graph, abstract semantic computation is performed on the operation nodes on the value propagation path, and the computation results are used to construct a partial order relation in the abstract domain to form the abstract value domain lattice. The upper bound is obtained by performing a minimum upper bound operation on the abstract value range lattice, and the lower bound is obtained by performing a maximum lower bound operation. The upper bound and the lower bound are encoded into an interval representation as the data stream invariant.
[0042] In the outpatient registration process, inpatient settlement process, and drug delivery process of the hospital information system, there are shared code paths for patient identity verification and cost calculation. After the system identifies this path as a polymorphic stable hot spot, it performs program dependency graph slice analysis to extract data flow invariants.
[0043] This polymorphic stable hotspot comprises three sequentially executed code blocks: a patient information query code block, a fee rule matching code block, and a fee calculation code block. These three code blocks are connected in execution order to form a path code segment, approximately 150 lines in length. Control flow analysis is performed on this path code segment to identify conditional branch nodes, loop nodes, and basic blocks, constructing a path-level control flow graph. Simultaneously, data flow analysis is performed to trace the cross-code block definition-use relationships of the variable `patientID` (defined in the patient information query code block and used in the fee rule matching code block) and the variable `feeAmount` (defined in the fee rule matching code block and used in the fee calculation code block), constructing a path-level data flow graph.
[0044] In the path-level control flow graph, basic block B1 dominates basic block B3, indicating that B1 must be executed before B3 is executed. Based on this, a control dependency edge B3→B1 is constructed. In the path-level data flow graph, the variable totalFee is defined in line 45 of the amount calculation code block and used in line 78. A data dependency edge def(totalFee, 45)→use(totalFee, 78) is constructed. The control dependency edge set and the data dependency edge set are combined to form a program dependency graph containing 87 nodes and 134 edges.
[0045] Starting with the output variable `finalAmount`, a backward slicing algorithm is executed. Traversing backward along the data dependency edges from the `finalAmount` node, we reach the `totalFee`, `discountRate`, and `basePrice` nodes. Continuing the traversal, we reach the `patientType` and `feeCategory` nodes, constructing a reachability tree containing these five nodes. The program dependency graph also contains the variables `logTimestamp` and `operatorID`, but these two variables have no dependency path with `finalAmount` and are pruned in the reachability tree. The variables `patientType` and `feeCategory` corresponding to the leaf nodes of the reachability tree are extracted, along with the intermediate variables `totalFee`, `discountRate`, and `basePrice`, forming a minimal set of dependent variables containing five variables.
[0046] For the variable `discountRate`, its value propagation path is traced in the program dependency graph. In the patient type determination branch, this variable takes values of 0.8, 0.9, or 1.0 based on `patientType`. At the cost calculation node, it is multiplied by `basePrice` to obtain `totalFee`. Abstract semantic computation is performed on the multiplication node, establishing a partial order relation in the abstract domain [0, +∞). When the abstract value of `basePrice` is [100, 500] and the abstract value of `discountRate` is [0.8, 1.0], the abstract value of `totalFee` is calculated to be [80, 500]. These three values form an abstract value domain. A minimum upper bound operation is performed on this abstract value domain, traversing all value combinations, resulting in an upper bound of `totalFee` of 500. A maximum lower bound operation is performed, resulting in an infimum of 80. The upper and lower bounds are encoded as an interval representation [80, 500], serving as a data flow invariant for the variable `totalFee`. This invariant indicates that regardless of the patient type, the final cost totalFee will always fall within the range of 80 to 500. Subsequent recompilation can be based on this constraint for loop boundary optimization and overflow check elimination.
[0047] The conditional optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights, selective inlining and loop unrolling are performed, and dual-path code including fast path branches and slow path branches is generated, including: A control flow graph is constructed for the type-specialized version of the conditional optimization unit. A dominance tree is constructed for the control flow graph. The execution frequency of each edge is calculated based on the dominance tree and converted into a branch weight. A minimum static single assignment transformation is performed on the type-specialized version. A variable merging function is inserted at the dominance boundary position and the branch weight is added to construct the static single assignment intermediate representation with branch weight. For the static single-assignment intermediate representation with branch weights, construct a call graph and perform bottom-up traversal. Calculate the weighted call depth of each function call node. When the weighted call depth is less than the depth limit and the function body size is less than the size limit, perform inline replacement within the function body and perform selective inlining. Perform data dependency analysis on the loop structure. When there is no loop carrying dependency, generate a copy of the loop body according to the expansion factor and update the inductive variable, and then perform the loop expansion. The precondition guard expression is compiled into a conditional jump instruction, and a fast path branch is constructed when the guard condition is met and a slow path branch is constructed when the guard condition is not met, thus generating the dual-path code. In the fast path branch, algebraic simplification and strength reduction are performed, value range analysis is performed on memory access instructions, and security check instructions are removed when the access index value range is completely covered by the data flow invariant. In the slow path branch, complete type verification and boundary verification logic is inserted.
[0048] During the recompilation phase of dynamic hotspot code, deep transformation is performed on identified conditional optimization units. Type-specialized versions contained within these units are extracted, and control flow analysis is conducted on the generated type-specialized versions. The source code or intermediate representation is then converted into a control flow graph. This graph consists of basic block nodes and control transfer edges. Each basic block contains a sequentially executed sequence of instructions without internal branches. In the hospital information system's drug management module, the control flow graph for the drug dispensing process includes basic block nodes for drug information verification, dosage calculation, and incompatibility checks.
[0049] The algorithm for constructing a dominance tree based on the control flow graph is used. The dominance tree reflects the essential node relationships during program execution. Node A dominates node B, meaning that execution to B must first pass through A. In the drug dispensing process, the patient information verification node dominates all subsequent processing nodes. The dominance tree construction employs iterative data flow analysis, starting from the entry node and progressively calculating the set of dominators for each node until the set stabilizes. The dominance tree provides a structural basis for branch frequency estimation. Combined with execution probability data collected during runtime, the execution frequency of each edge in the control flow graph is calculated. During peak outpatient hours in hospitals, the execution frequency of routine drug processing paths is typically higher than that of special drug processing paths. Execution frequencies are labeled as branch weights, expressed as decimal execution probabilities or integer count values.
[0050] For type-specialized versions, a minimal static single-assignment transformation is performed. This static single-assignment form ensures that each variable is defined only once, simplifying data flow analysis. The transformation process requires inserting a φ function at the control flow junction to merge multiple versions of the variable. For example, in the drug inventory check logic, the assignments of different branch paths to the inventory status variable are merged at the control flow junction using a φ function. These variable merging functions are inserted at the dominance boundary, and the previously calculated branch weights are appended to the φ function to represent the execution probability of each source branch. After the transformation, a static single-assignment intermediate representation with branch weights is formed. This representation preserves the program's control flow and data flow characteristics while containing branch execution frequency information, providing a basis for subsequent optimization.
[0051] A function call graph is constructed using a static single-assignment intermediate with branch weights to capture the call relationships between functions. In the medical record processing module, the main processing function calls sub-functions such as patient information parsing, diagnostic code conversion, and medical insurance rule verification. The call graph is traversed from bottom to top, starting with leaf nodes that do not call external functions, and calculating the weighted call depth of each function node upwards. The weighted call depth considers both the call chain length and execution frequency, and the calculation formula combines the nesting level of calls and the weight of each call edge. When the weighted call depth of a function is less than a preset depth limit (typically five levels) and the function body size is less than a size limit (typically fifty instructions), the function body is inlined to the call point to eliminate function call overhead. For example, a frequently called patient age calculation function with a small code size is directly inlined into the main flow to avoid function call overhead. This selective inlining strategy balances code bloat and execution efficiency.
[0052] Data dependency analysis is performed on the loop structure in the code to identify variable dependencies in the loop. For each pair of variable definitions and uses, it is checked whether there is a loop-carried dependency, that is, the variable definition in the current iteration affects the calculation of the next iteration. In the batch processing loop of the patient list, if each patient is processed independently and there is no loop-carried dependency, the loop can be safely expanded. When there is no loop-carried dependency, the loop body is copied according to the preset expansion factor (usually four or eight), generating multiple loop body copies and executing them in series. At the same time, the growth step of the inductive variable is adjusted according to the expansion factor. For example, expanding the patient record processing loop from processing one record at a time to processing four records at a time can significantly reduce the loop control overhead. Loop expansion optimization is particularly suitable for batch data processing scenarios in hospital information systems, such as day-end settlement or batch report generation.
[0053] Building upon the previous optimizations, the extracted precondition guard expressions are compiled into efficient conditional jump instructions. Guard expressions typically include checks on the type and range of input parameters, such as "(patientType & MASK_A) ==TYPE_NORMAL && (age >= 0 && age <= 120)". These expressions are then converted into machine code-level comparison and conditional jump instruction sequences. A dual-path code structure is constructed, containing fast path branches when guard conditions are met and slow path branches when they are not. The fast path branch corresponds to the case where all guard conditions are met. This path assumes that type constraints have been confirmed and redundant checks can be omitted. The slow path branch corresponds to the degradation scenario where guard conditions are not met, retaining complete safety verification logic. In the fast path, algebraic simplification is performed, constant expressions are evaluated at compile time, and multiplication operations are replaced with a combination of shift and addition to reduce strength. Value range analysis is performed on memory access instructions to extract the value range of array indices or offsets. When the analyzed index value range is completely contained within the legal range of the data flow invariant constraints, the access is proven to be safe, and boundary check instructions are removed. In the slow path, complete type verification code is inserted to check whether the actual type of the object matches expectations. Array boundary verification and null pointer checks are also inserted to ensure execution safety. After the dual-path code is generated, it is dispatched through the guard jump instruction at the program entry point. At runtime, the corresponding execution path is selected based on the actual parameter type and value.
[0054] In the fast path branch, algebraic simplification and strength reduction are performed, value range analysis is performed on memory access instructions, and safety check instructions are removed when the access index value range is completely covered by the data flow invariant. In the slow path branch, complete type validation and boundary validation logic is inserted, including: In the fast path branch, the static single assignment intermediate representation is rewritten by performing expression rewriting, decomposing the multiplication constant into the sum of powers of two, replacing the multiplication operation with a combination sequence of shift and addition, extracting the reciprocal of the divisor for the division operation and converting it into multiplication form, and performing algebraic simplification and intensity reduction. For the memory access instructions of the fast path branch, extract the base address register and offset expression, construct a symbolic value graph from the offset expression, perform abstract interpretation propagation on the symbolic value graph, calculate the upper and lower bounds of the symbolic values to form the access index value domain, and perform value domain analysis. Extract the legal access interval from the data stream invariant, construct the inclusion relationship determination between the access index value field and the legal access interval, and delete the corresponding boundary check instruction and null value check instruction when the access index value field is a proper subset of the legal access interval, and remove the security check instruction. Insert a null pointer trap instruction before each object dereference point in the slow path branch, insert a runtime type tag comparison instruction before each type conversion point, insert upper and lower bound range verification instructions before each array index access point, and insert complete type verification and boundary verification logic.
[0055] After generating the dual-path code structure, differentiated optimization strategies must be adopted for the fast and slow paths to ensure that the hot-spot code of the hospital information system achieves optimal execution efficiency in common scenarios. For static single-assignment intermediates in the fast path branches, the expression is rewritten. In the drug dosage calculation module, when a constant operand of a multiplication instruction is detected, the constant is decomposed into a sum of powers of two. For example, when the unit dosage of a drug needs to be multiplied by 13 for batch dispensing calculation, the multiplication operation is rewritten as a combination of left shift by three bits, left shift by two bits, and left shift by zero bits, i.e., transformed into the form "(dosage << 3) + (dosage << 2) + dosage", avoiding the use of multiplication instructions.
[0056] The same intensity reduction strategy is adopted for division operations. In patient cost calculation, the operation of dividing by a constant is converted into multiplying by its reciprocal approximation. By pre-calculating the fixed-point representation of the reciprocal of the divisor, the high-overhead division instruction is replaced with a multiplication instruction. This technique is particularly effective in the billing module, significantly improving the efficiency of batch settlement processing.
[0057] A detailed value range analysis is performed on memory access instructions in the fast path to ensure the safety of the optimized code. Base address registers and offset expressions are extracted from each memory load or store instruction. For example, in accessing a patient record array, the base address is the starting address of the patient array, and the offset is the index value multiplied by the record size. A symbolic value graph is constructed for these offsets, where nodes represent intermediate values and edges represent data dependencies between variables. In the medical record retrieval module, the symbolic value graph clearly expresses the entire computation process of the retrieval index from user input to the final memory access point. An abstract interpretation algorithm is executed on the constructed symbolic value graph. An abstract domain is maintained for each intermediate variable, and the interval information of the input variables is initialized. Based on constraints in the precondition guard, such as the patient age range being 0 to 120 years, this interval information is propagated along the symbolic value graph using a fixed-point iteration method. Corresponding abstract transformation rules are applied to each operation node. For example, in addition, the lower bounds of two intervals are added to obtain the lower bound of the result, and the upper bounds are added to obtain the upper bound of the result; multiplication by a positive constant multiplies both the upper and lower bounds of the interval by the constant. After multiple iterations until the interval stabilizes, the precise range of values for the access index is finally calculated.
[0058] The calculated access index value range is compared with the valid access interval extracted from the data flow invariant. The valid access interval defines all safe array index ranges or object field offsets under a given type constraint. For example, the valid access interval for a prescription detail array is zero to the number of prescription items minus one. A value range inclusion relationship determination logic is constructed, comparing the upper and lower bounds of the access index value range with the boundaries of the valid interval to determine if a subset relationship is formed. When the determination result shows that the access index value range falls entirely within the valid access interval, the boundary check instruction for the corresponding access point can be safely removed. In the drug inventory management module, by confirming through value range analysis that the inventory query index is always within the valid range, removing the index check instruction improved the batch inventory query speed by 35%. Similarly, when the non-nullability of an object reference is guaranteed by an invariant, the null pointer check instruction can be removed, further reducing the number of instructions and improving execution efficiency.
[0059] For slow path branches, a conservative optimization strategy is adopted, preserving complete runtime verification logic. Null pointer checks are inserted before each object dereference, type label comparison logic is inserted at type conversion points, and boundary checks are added before array accesses. While these checks reduce execution speed, they ensure that the program can still execute safely even when precondition guard checks fail. In hospital information systems, this dual-path strategy significantly improves execution efficiency in common scenarios while maintaining system stability.
[0060] This invention also provides a runtime recompilation optimization system for dynamic hotspot code, including: The code block acquisition unit is used to acquire code blocks during the execution of the target program of the hospital information system. The code block includes a code block identifier, execution count, call chain, and data access mode. The dependency graph construction unit is used to construct a multi-level call dependency graph for the code block according to the medical business call context, identify shared code paths across business processes, and calculate the parameter distribution difference degree and execution path divergence entropy for the shared code paths under different business processes. The hotspot marking unit is used to mark the shared code path as a polymorphic stable hotspot when the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold. It extracts the type constraint intersection and data flow invariant of the polymorphic stable hotspot under each business process, generates a set of type specialization versions, constructs a precondition guard expression, and binds it to form a condition optimization unit. An optimization unit is used to recompile the conditional optimization unit, construct a static single-assignment intermediate representation with branch weights, perform selective inlining and loop unrolling, and generate dual-path code including fast path branches and slow path branches. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the intersection of the type constraints is updated.
[0061] A third aspect of the present invention provides an electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0062] A fourth aspect of the present invention provides a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0063] This invention can be a method, apparatus, system, and / or computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for performing various aspects of the invention.
[0064] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A runtime recompile optimization method for dynamic hotspot code, characterized in that, include: Obtain code blocks during the execution of a target program in a hospital information system. These code blocks include code block identifiers, execution counts, call chains, and data access modes. A multi-layered call dependency graph is constructed for the code block according to the medical business call context, and shared code paths across business processes are identified. For the shared code paths, the parameter distribution difference and execution path divergence entropy under different business processes are calculated, including: A business process call tree is constructed based on the business process identifier in the call chain of the code block. The call depth of each node and the data dependency relationship passed by the parent node are marked in the business process call tree. Code blocks with the same call depth and receiving the same parent node data dependency relationship are identified and aggregated into the same-level call node group. The data flow overlap and control flow coupling between the same-level call node groups are calculated. The set of variables read and written by each code block in the group is counted, and the degree of overlap of data flow between different code blocks is calculated. The data flow overlap is determined by calculating the ratio of the number of commonly accessed variables to the total number of accessed variables. At the same time, the control flow coupling is analyzed to identify whether there are conditional dependencies or circular nesting relationships between code blocks. The control flow coupling is quantified by the proportion of the number of control dependency edges to the total call relationship. Traverse each level of the call node group in the business process call tree, extract the code block identifiers that appear frequently in the target, align and match the call paths of the code block identifiers in different business process call trees, and determine the shared code path across business processes based on the edit distance of the path nodes. For the code blocks in the shared code path, the set of parameter types and the range of parameter values received are statistically analyzed under each business process, a parameter feature matrix is constructed, principal component analysis is performed on the parameter feature matrix to extract feature vectors, and the Euclidean distance of the feature vectors under different business processes is calculated as the parameter distribution difference; the conditional branch execution trajectory of the shared code path under each business process is extracted, a branch state transition diagram is constructed, and the trace norm difference of the state transition probability matrix of the branch state transition diagram is calculated as the execution path divergence entropy; When the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold, the shared code path is marked as a polymorphic stable hotspot. The type constraint intersection and data flow invariant of the polymorphic stable hotspot under each business process are extracted, a set of type-specialized versions is generated, and a precondition guard expression is constructed. This is then bound to form a condition optimization unit, including: For the execution records of the polymorphic stable hotspots under each business process, the type signature and type compatibility matrix of the input parameters are extracted, matrix decomposition is performed on the type compatibility matrix, orthogonal basis vectors are extracted, and the type combination corresponding to the orthogonal basis vectors is taken as the type constraint intersection. Slicing analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimum dependent variables that affect the output variable and perform abstract interpretation. This includes performing a backward slicing algorithm on the program dependency graph, constructing a reachability tree starting from the output variable, pruning branches in the reachability tree that have no dependency relationship with the output variable, extracting the variables corresponding to the leaf nodes of the reachability tree as the set of minimum dependent variables, constructing an abstract domain lattice for the variables, and using the supremum and infimum in the abstract domain lattice as data flow invariants. Based on the type combinations in the intersection of the type constraints, template instantiation is performed on the polymorphic stable hotspots, generating specific code after template instantiation for each type combination. Escape analysis and scalar replacement are performed on the specific code to generate a set of type-specialized versions. The upper bound and lower bound in the data flow invariant are encoded into a Bloom filter structure. A hash function combination is performed on the Bloom filter structure. The detection logic constructed by the hash function combination is serialized into a precondition guard expression. The precondition guard expression is used as the entry point of the dispatch function and the set of type specialization versions is used as the dispatch target to form a condition optimization unit. The conditional optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights. Selective inlining and loop unrolling are performed, and dual-path code including fast path branches and slow path branches is generated. This includes compiling the precondition guard expression into a conditional jump instruction, constructing a fast path branch when the guard condition is met and a slow path branch when it is not met, and generating the dual-path code. Algebraic simplification and strength reduction are performed in the fast path branch, and value range analysis is performed on memory access instructions. When the access index value range is completely covered by the data flow invariant, the security check instruction is removed. Complete type validation and boundary validation logic is inserted in the slow path branch. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the type constraint intersection is updated.
2. The method according to claim 1, characterized in that, Extract the execution trajectory of the conditional branches of the shared code path under each business process, construct a branch state transition graph, and calculate the trace norm difference of the state transition probability matrix of the branch state transition graph as the execution path branch entropy, including: For the conditional branch instructions in the shared code path, the set of variables involved in the branch judgment conditions and the branch execution results are collected under each business process. The values of each variable in the set of variables are encoded and mapped to construct a variable value encoding vector. The combination of the variable value encoding vector and the branch execution results is used as a composite status identifier. Extract the transition path of the composite state identifier in the execution time sequence, construct a directed state transition graph, mark the number of transitions for each transition edge in the directed state transition graph, calculate the total number of outgoing edge transitions for each state node, divide the number of transitions for each outgoing edge by the total number of outgoing edge transitions to obtain the transition probability, and fill the state transition probability matrix based on the transition probability. Calculate the graph Laplacian matrix of the state transition probability matrix, extract the eigenvalue spectrum of the graph Laplacian matrix, and calculate the spectral distance between the eigenvalue spectra under different business processes; Perform a matrix logarithm operation on the state transition probability matrix to calculate the trace of the matrix logarithm, calculate the trace variance under different business processes, and use the normalized linear combination of the spectral distance and the trace variance as the execution path divergence entropy.
3. The method according to claim 1, characterized in that, Slice analysis is performed on the program dependency graph of the polymorphic stable hotspot to extract the set of minimal dependent variables affecting the output variables and perform abstract interpretation. An abstract range lattice of variables is constructed, and the supremum and infimum in the abstract range lattice are used as data flow invariants, including: Extract the code block sequence contained in the polymorphic stable hot spot, connect the code block sequence in execution order to form a path code segment, perform control flow analysis and data flow analysis on the path code segment, construct a path-level control flow graph and a path-level data flow graph, construct a set of control dependency edges based on the dominance relationship in the path-level control flow graph, construct a set of data dependency edges based on the cross-code block variable definition-use relationship in the path-level data flow graph, and jointly form a program dependency graph; For each variable in the set of minimum dependent variables, the value propagation path of the variable is traced in the program dependency graph, abstract semantic computation is performed on the operation nodes on the value propagation path, and the computation results are used to construct a partial order relation in the abstract domain to form the abstract value domain lattice. The upper bound is obtained by performing a minimum upper bound operation on the abstract value range lattice, and the lower bound is obtained by performing a maximum lower bound operation. The upper bound and the lower bound are encoded into an interval representation as the data stream invariant.
4. The method according to claim 1, characterized in that, The conditional optimization unit is recompiled to construct a static single-assignment intermediate representation with branch weights, and selective inlining and loop unrolling are performed, including: A control flow graph is constructed for the type-specialized version of the conditional optimization unit. A dominance tree is constructed for the control flow graph. The execution frequency of each edge is calculated based on the dominance tree and converted into a branch weight. A minimum static single assignment transformation is performed on the type-specialized version. A variable merging function is inserted at the dominance boundary position and the branch weight is added to construct the static single assignment intermediate representation with branch weight. For the static single-assignment intermediate representation with branch weights, a call graph is constructed and a bottom-up traversal is performed. The weighted call depth of each function call node is calculated. When the weighted call depth is less than the depth limit and the function body size is less than the size limit, inline replacement of the function body is performed, and selective inlining is performed. For the loop structure, data dependency analysis is performed. When there is no loop carrying dependency, a copy of the loop body is generated according to the expansion factor and the inductive variable is updated, and loop unrolling is performed.
5. The method according to claim 1, characterized in that, In the fast path branch, algebraic simplification and strength reduction are performed, value range analysis is performed on memory access instructions, and safety check instructions are removed when the access index value range is completely covered by the data flow invariant. In the slow path branch, complete type validation and boundary validation logic is inserted, including: In the fast path branch, the static single assignment intermediate representation is rewritten by performing expression rewriting, decomposing the multiplication constant into the sum of powers of two, replacing the multiplication operation with a combination sequence of shift and addition, extracting the reciprocal of the divisor for the division operation and converting it into multiplication form, and performing algebraic simplification and intensity reduction. For the memory access instructions of the fast path branch, extract the base address register and offset expression, construct a symbolic value graph from the offset expression, perform abstract interpretation propagation on the symbolic value graph, calculate the upper and lower bounds of the symbolic values to form the access index value domain, and perform value domain analysis. Extract the legal access interval from the data stream invariant, construct the inclusion relationship determination between the access index value field and the legal access interval, and delete the corresponding boundary check instruction and null value check instruction when the access index value field is a proper subset of the legal access interval, and remove the security check instruction. Insert a null pointer trap instruction before each object dereference point in the slow path branch, insert a runtime type tag comparison instruction before each type conversion point, insert upper and lower bound range verification instructions before each array index access point, and insert complete type verification and boundary verification logic.
6. A runtime recompile optimization system for dynamic hotspot code, used to implement the method as described in any one of claims 1-5, characterized in that, include: The code block acquisition unit is used to acquire code blocks during the execution of the target program of the hospital information system. The code block includes a code block identifier, execution count, call chain, and data access mode. The dependency graph construction unit is used to construct a multi-level call dependency graph for the code block according to the medical business call context, identify shared code paths across business processes, and calculate the parameter distribution difference degree and execution path divergence entropy for the shared code paths under different business processes. The hotspot marking unit is used to mark the shared code path as a polymorphic stable hotspot when the parameter distribution difference is lower than the consistency threshold and the execution path divergence entropy is lower than the convergence threshold. It extracts the type constraint intersection and data flow invariant of the polymorphic stable hotspot under each business process, generates a set of type specialization versions, constructs a precondition guard expression, and binds it to form a condition optimization unit. An optimization unit is used to recompile the conditional optimization unit, construct a static single-assignment intermediate representation with branch weights, perform selective inlining and loop unrolling, and generate dual-path code including fast path branches and slow path branches. The dual-path code structure is deployed. When the fast path hit rate is lower than the validity threshold, the code is rolled back to the original code and the intersection of the type constraints is updated.
7. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Hotspot code determination method and device, server and storage medium
CN112947898A
Mass code program control flow and data flow dependency extraction method based on intermediate language
CN120561920A
