Automatic incremental compiling method and system for Java development
By performing hash checksum dependency analysis on Java source code, a relationship dependency graph is generated and a topological sorting algorithm is used to generate a compilation task queue, the problem of large compilation scope and incomplete dependency processing in the existing incremental compilation technology is solved, and the problem of incomplete compilation relationship processing is realized. Efficient incremental compilation.
Patent Information
- Application Number
- CN202411976814.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-12-31
AI Technical Summary
The existing incremental compilation technology has a combination of too large compilation scope and the inability to effectively handle static and dynamic dependencies, resulting in low compilation efficiency.
By hash verification of the Java source code, the static dependency information and dynamic call relationships in the change event information are extracted, the relationship dependency graph is generated, and the topological sorting algorithm is used to generate a compilation task queue, and finally the Java source code is compiled.
Accurately locate code change information, reduce the initial scope of incremental compilation, fully represent the dependencies between code units, and improve the accuracy and efficiency of compilation.
Smart Images

Figure CN119396406A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software engineering, and in particular to an automatic incremental compilation method and system for Java development. Background Art
[0002] Currently, code compilation is an essential step in Java development. The traditional compilation method is usually full compilation, that is, after each code change, regardless of the scope of the change, the entire project needs to be recompiled. Although full compilation ensures the consistency and correctness of the code, it has the following problems when the project is large in scale and has complex dependencies: Long compilation time: As the project size grows, the number of code files and the complexity of dependencies grow exponentially. Full compilation requires re-parsing and processing of all code files, resulting in a significant increase in compilation time.
[0003] Serious waste of resources: During the full compilation process, many unchanged code files are also compiled repeatedly, consuming a large amount of computing resources and storage space, reducing development efficiency.
[0004] Extension of development feedback cycle: In the development mode of continuous integration and rapid iteration, developers need to modify the code frequently. The inefficiency of full compilation directly leads to the extension of feedback cycle, which seriously affects development efficiency.
[0005] In recent years, incremental compilation technology has gradually attracted attention as a solution. Incremental compilation identifies the scope of code changes and only compiles the affected part of the code, avoiding the waste of resources and time caused by full compilation. However, the existing incremental compilation technology also has the following shortcomings: Too large a compilation scope: By relying solely on static analysis, the compiler may need to compile a large number of code units that are not related to the change, thus reducing the efficiency of incremental compilation.
[0006] Incomplete dependency relationships: Dynamic call relationships cannot be accurately captured, which may lead to the omission of key dependency information, thus affecting the correctness and consistency of the generated code.
[0007] In summary, existing incremental compilation technologies have the disadvantages of a large compilation scope and the inability to effectively handle the combination of static and dynamic dependencies, which results in low compilation efficiency. Summary of the invention
[0008] In order to solve the problem that the existing incremental compilation technology has a large compilation scope and cannot effectively handle the combination of static and dynamic dependencies, resulting in low compilation efficiency, the present invention proposes an automatic incremental compilation method for Java development, comprising: Performing hash value verification on the acquired Java source code to obtain change event information in the Java source code; Extracting static dependency information and dynamic call relationships corresponding to the change event information from the change event information respectively, and generating a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship; Based on the relationship dependency graph, a compilation task queue is generated using a topological sorting algorithm; The change event information in the Java source code is compiled according to the compilation task queue to obtain a machine code corresponding to the change event information.
[0009] Optionally, performing hash value verification on the acquired Java source code to obtain change event information in the Java source code includes: Divide the obtained Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block; By performing hash comparison on the hash value of each logic block, a changed code block in the Java source code is obtained; Performing a syntax consistency check on the changed code block using a syntax tree to obtain change event information in the Java source code; The code elements include one or more of the following: class definition, method definition and comment segment.
[0010] Optionally, generating a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship includes: Representing the static dependency information in a graph to obtain a corresponding static directed graph; Representing the dynamic call relationship in a graph to obtain a corresponding dynamic directed graph; Using a graph isomorphism algorithm, nodes of the static directed graph and the dynamic directed graph are merged to obtain a merged node directed graph; Using a graph clustering algorithm, the merged node directed graph is divided into communities to construct a relationship dependency graph.
[0011] Optionally, generating a compilation task queue based on the relationship dependency graph using a topological sorting algorithm includes: Performing connected component analysis according to the relationship dependency graph to extract acyclic key subgraphs in the relationship dependency graph; According to the acyclic critical subgraph, using a topological sorting algorithm, obtaining the task execution order in the change event information; A compilation task queue is generated according to the task execution order.
[0012] Optionally, compiling the change event information in the Java source code according to the compilation task queue to obtain a machine code corresponding to the change event information includes: Based on the preset task dependency, the compilation task queue is divided into multiple batches to obtain compilation task queues in different batches; Prioritize the compilation task queues under the different batches and generate a visual task scheduling table; According to the visual task scheduling table, the change event information in the Java source code is hierarchically compiled through a hierarchical compilation strategy to obtain a machine code corresponding to the change event information.
[0013] Optionally, the step of performing hierarchical compilation on the change event information in the Java source code by using a hierarchical compilation strategy to obtain a machine code corresponding to the change event information includes: Utilizing the thread pool, the compilation tasks in the visualization task scheduling table are executed in layers to obtain the bytecode files and cache data of each layer; The bytecode files and cache data of each layer are integrated to generate machine codes corresponding to the change event information.
[0014] Optionally, the change event information includes one or more of the following: a changed file path, a change type, and a timestamp.
[0015] Based on the same inventive concept, the present invention also provides an automatic incremental compilation system for Java development, comprising: A hash verification module is used to perform hash value verification on the acquired Java source code to obtain change event information in the Java source code; A dependency graph construction module, used to extract static dependency information and dynamic call relationships corresponding to the change event information from the change event information, and generate a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship; A task sorting module, used to generate a compilation task queue based on the relationship dependency graph using a topological sorting algorithm; The automatic compilation module is used to compile the change event information in the Java source code according to the compilation task queue to obtain the machine code corresponding to the change event information.
[0016] Optionally, the hash verification module includes: A hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate a hash value for each logical block; A hash comparison module, used for obtaining a changed code block in the Java source code by performing a hash comparison on a hash value of each logic block; A consistency check module, used to perform a syntax consistency check on the changed code block using a syntax tree to obtain change event information in the Java source code; The code elements include one or more of the following: class definition, method definition and comment segment.
[0017] Optionally, the dependency graph construction module includes: A static graph construction submodule is used to perform a graph representation on the static dependency information to obtain a corresponding static directed graph; A dynamic graph construction submodule is used to represent the dynamic call relationship in a graph to obtain a corresponding dynamic directed graph; A node merging submodule, used to merge nodes of the static directed graph and the dynamic directed graph using a graph isomorphism algorithm to obtain a merged node directed graph; The community division submodule is used to use a graph clustering algorithm to perform community division on the merged node directed graph and construct a relationship dependency graph.
[0018] Optionally, the task sorting module includes: A connectivity analysis submodule, used to perform connectivity component analysis based on the relationship dependency graph and extract acyclic key subgraphs in the relationship dependency graph; A topological sorting submodule, used to obtain the task execution order in the change event information according to the acyclic key subgraph using a topological sorting algorithm; The queue generation submodule is used to generate a compilation task queue according to the task execution order.
[0019] Optionally, the automatic compilation module includes: A queue division submodule, used to divide the compilation task queue into multiple batches based on preset task dependencies, to obtain compilation task queues under different batches; A priority sorting submodule is used to prioritize the compilation task queues under the different batches and generate a visual task scheduling table; The hierarchical compilation submodule is used to perform hierarchical compilation on the change event information in the Java source code according to the visual task scheduling table and through a hierarchical compilation strategy to obtain machine code corresponding to the change event information.
[0020] Optionally, the hierarchical compilation submodule includes: A task visualization unit is used to utilize a thread pool to execute the compilation tasks in the visualization task scheduling table in layers, and obtain bytecode files and cache data of each layer; The file integration unit is used to integrate the bytecode files and cache data of each layer to generate machine codes corresponding to the change event information.
[0021] Optionally, the change event information includes one or more of the following: a changed file path, a change type, and a timestamp.
[0022] In another aspect, the present invention further provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the automatic incremental compilation method for Java development as described above is implemented.
[0023] On the other hand, the present invention further provides a computer device readable storage medium having an execution program stored thereon, and when the execution program is executed, the automatic incremental compilation method for Java development as described above is implemented.
[0024] Compared with the prior art, the present invention has the following beneficial effects: The present invention provides an automatic incremental compilation method and system for Java development, comprising: performing hash value verification on an acquired Java source code to obtain change event information in the Java source code; extracting static dependency information and dynamic call relationships corresponding to the change event information from the change event information respectively, and generating a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationships; generating a compilation task queue based on the relationship dependency graph and using a topological sorting algorithm; compiling the change event information in the Java source code according to the compilation task queue to obtain machine code corresponding to the change event information; the present application accurately locates code change information through hash value verification, which is beneficial to reducing the initial scope of incremental compilation; by extracting static dependency information and dynamic call relationships from the change event information respectively, generating a relationship dependency graph, completely representing the dependency relationships between code units, solving the problem of missing dynamic call relationships, and improving the correctness and efficiency of compilation. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 A schematic diagram of a flow chart of an automatic incremental compilation method for Java development provided by the present invention; Figure 2 A schematic diagram of a framework flow chart for determining change event information in an automatic incremental compilation method for Java development provided by the present invention; Figure 3A schematic diagram of a process for constructing a relationship dependency graph in an automatic incremental compilation method for Java development provided by the present invention; Figure 4 A schematic diagram of the structure of an automatic incremental compilation system for Java development provided by the present invention; Figure 5 The present invention provides a schematic structural diagram of an electronic device. DETAILED DESCRIPTION
[0026] The present invention provides an automatic incremental compilation method, system, device and medium for Java development. The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0027] Embodiment 1: The present invention provides an automatic incremental compilation method for Java development, the flow chart is as follows Figure 1 As shown, including: Step 1: Perform hash value verification on the obtained Java source code to obtain change event information in the Java source code; Step 2: Extract static dependency information and dynamic call relationships corresponding to the change event information from the change event information, and generate a relationship dependency graph of the change event information based on the static dependency information and the dynamic call relationship; Step 3: Generate a compilation task queue based on the relationship dependency graph using a topological sorting algorithm; Step 4: Compile the change event information in the Java source code according to the compilation task queue to obtain the machine code corresponding to the change event information.
[0028] In modern software development, as the scale and complexity of projects continue to increase, the efficiency of source code compilation has become crucial. The traditional full compilation method requires the entire code base to be recompiled, regardless of the scope of the code modification. This not only wastes a lot of time and computing resources, but also significantly reduces the efficiency of development feedback. To solve this problem, incremental compilation technology came into being. By accurately identifying the changed parts of the code, only the affected code is compiled, thereby achieving dual optimization of resources and time. The first step of incremental compilation is to efficiently detect changes in the source code. By quickly identifying the changed areas of the code through intelligent methods, reliable basic data can be provided for subsequent dependency analysis and compilation task division. Specifically: In one implementation, Figure 2 As shown, the above process of performing hash value verification on the acquired Java source code to obtain change event information in the Java source code may include: Divide the obtained Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block; By performing hash comparison on the hash value of each logic block, the changed code block in the Java source code is obtained; Use the syntax tree to check the syntax consistency of the changed code block and obtain the change event information in the Java source code; For example, the above code elements may include one or more of the following: class definition, method definition and comment section; For example, the above-mentioned change event information may include one or more of the following: change file path, change type and timestamp; In this implementation, the processing capability of change event information can be further enhanced by introducing dependency tracking technology, so as to comprehensively analyze the impact of code changes on other parts, thereby optimizing the subsequent compilation process. For example, after performing hash value verification on the acquired Java source code and identifying the changed code blocks, static and dynamic dependency analysis is performed on each changed code block. Static dependency analysis is used to parse explicit dependencies such as classes, method calls, and variable references in the code, while dynamic dependency analysis captures implicit dependencies that may be involved at runtime, such as relationships introduced by reflection, dynamic proxies, or call paths generated at runtime. Combining the results of static and dynamic dependency analysis, a comprehensive dependency graph can be constructed to characterize the relationship between the changed code block and other code units. Using this dependency graph, the change event information can be extended to include the affected code range and the cross-module dependency chain, thereby providing basic support for subsequent task scheduling and compilation optimization. The introduction of this dependency tracking technology can significantly improve the accuracy and compilation efficiency of change detection, ensuring the correct compilation and consistency maintenance of the changed code and its associated code; this implementation method verifies the Java source code by hash value, divides the source code into logical blocks and calculates the hash value one by one, then accurately identifies the changed code block through hash comparison, combines the syntax tree for syntax consistency check, and finally generates change event information. This implementation method can effectively improve the accuracy and efficiency of change detection, check the change events of the file system through hash value verification, capture the addition, modification or deletion operations, and extract the file path, change type (addition, modification, deletion) and timestamp information for the changed source code file. This change capture method based on file system meta information can quickly and accurately lock the change scope of the code, thereby generating a change record table containing complete change details. Secondly, through intelligent code block division and change detection, the solution can intelligently identify the code parts that need to be recompiled according to the changes in the source code, avoiding unnecessary full compilation. This not only reduces the computational burden of compilation, but also significantly improves the compilation efficiency, especially in large projects, it can greatly shorten the development feedback cycle. In addition, by using dependency tracking technology, it can accurately identify and isolate changes in the source code to ensure that only the code related to the changed part is compiled. This dependency tracking capability ensures the accuracy of incremental compilation, avoids runtime errors that may be caused by missing dependencies, and further optimizes the execution efficiency of compilation tasks. Overall, this implementation method monitors changes in the code base in real time, automatically triggers the incremental compilation process, and does not require manual intervention. It maintains the consistency and integrity of the compilation, effectively improves the compilation efficiency, reduces the development feedback cycle, and provides technical support for the continuous integration and rapid iteration of complex projects.
[0029] In order to achieve efficient incremental compilation, it is necessary not only to accurately capture the change event information of the Java source code, but also to deeply analyze the correlation between the changed code block and other code units. The detection of the changed code block is only the first step. To ensure the integrity and accuracy of the compilation, it is crucial to further generate a relationship dependency graph of the change event information. By constructing a relationship dependency graph, the static dependency and dynamic call relationship between code units can be fully represented, providing a solid foundation for subsequent compilation task scheduling and dependency optimization. Specifically: In one implementation, Figure 3 As shown, the process of generating a relationship dependency graph of change event information based on static dependency information and dynamic call relationship may include: Represent the static dependency information in a graph to obtain the corresponding static directed graph; The dynamic call relationship is represented by a graph to obtain a corresponding dynamic directed graph; Using the graph isomorphism algorithm, the nodes of the static directed graph and the dynamic directed graph are merged to obtain a merged node directed graph; Using graph clustering algorithm, the community of the merged node directed graph is divided to construct a relationship dependency graph; In this implementation, the static dependency information and dynamic call relationship are constructed as a static directed graph and a dynamic directed graph respectively by using a graph representation. The nodes of the two are merged through a graph isomorphism algorithm to form a unified merged node directed graph. This step can accurately integrate the static and dynamic dependency relationships in the code and fully capture the correlation between the changed code block and other code units. For the files in the change record table, you can choose to use the JavaParser tool to parse the import statements and call relationships of the changed files to effectively extract static dependency information; for the runtime behavior of the changed files, you can choose to use the ASM tool to capture dynamic call relationships (such as runtime loading of classes and method calls). This combination of static and dynamic methods avoids dependency paths that may be missed by a single analysis method; secondly, the merged node directed graph is divided into communities through a graph clustering algorithm, and the complex dependency network is divided into multiple highly correlated subgraphs to construct a clear relationship dependency graph. This not only optimizes the structural expression of the dependency graph, but also marks all code units affected by the change, including direct and indirect dependencies, to ensure that the code within the scope of the change can be accurately identified and processed. Finally, by combining the results of static and dynamic dependencies, this implementation can dynamically update the initial dependency graph, form a complete dependency model for the latest changes, and mark all affected code units. This method ensures the accuracy of dependency tracking and compilation task division even in the case of high code complexity, laying the foundation for subsequent compilation optimization and task scheduling.
[0030] To ensure the efficiency of incremental compilation, it is not enough to just build a dependency graph to directly guide the compilation process. Although the dependency graph fully displays the static and dynamic dependencies between the changed code block and other code units, it needs to be further converted into an executable compilation task queue. By analyzing and processing the dependency graph, the key dependency paths and execution order can be extracted, thus providing clear guidance for the task division of incremental compilation. Specifically: In one implementation, the process of generating a compilation task queue based on the relationship dependency graph and using a topological sorting algorithm may include: Perform connected component analysis based on the relationship dependency graph and extract the acyclic key subgraph in the relationship dependency graph; According to the acyclic critical subgraph, the task execution order in the change event information is obtained by using the topological sorting algorithm; Generate a compilation task queue based on the task execution order; In this implementation, by analyzing the connected components of the dependency graph, the acyclic key subgraphs related to the change event information can be accurately extracted, focusing on the set of code units directly and indirectly affected, and avoiding redundant processing of irrelevant code units. For the set of affected code units, the connected components of the dependency graph are analyzed to ensure that only the dependency paths actually affected by the change are processed, thereby reducing the compilation scope and improving the compilation efficiency; secondly, the updated dependency graph is further processed using the topological sorting algorithm to clarify the dependency order between code units. The certainty of this dependency order ensures the correctness of the compilation task and avoids compilation errors caused by incorrect processing of dependencies. For the updated dependency graph, the order generated by the topological sorting algorithm can also optimize the task scheduling process, so that the compilation task can be efficiently executed in the dependency order; finally, by generating a compilation task queue, the compilation task is clearly divided into executable independent units, providing basic support for layered compilation or parallel compilation. The generation of this task queue not only ensures the integrity and consistency of the changed code, but also significantly shortens the compilation time and improves the overall efficiency of incremental compilation.
[0031] After generating the compilation task queue based on the relationship dependency graph, in order to further optimize the compilation efficiency, a dynamic cache mechanism is introduced into the compilation process. By comparing the timestamp of the code unit in the task schedule with the cache pool version information, the validity of the cache can be quickly determined. For code units with valid cache, the bytecode file in the cache is directly loaded to avoid redundant compilation operations, thereby saving computing resources and time. For code units with invalid cache, recompilation is triggered to generate new bytecode files and store them in the cache pool for reuse in subsequent compilation tasks. This dynamic cache mechanism can also save intermediate results during the compilation process. By reusing the compiled parts in subsequent tasks, the overhead of repeated calculations is greatly reduced. The overall strategy achieves a balance between resource utilization and performance improvement, providing a more efficient solution for large-scale incremental compilation.
[0032] On the basis of optimizing the compilation task execution by using the dynamic cache mechanism, in order to further improve the organizational efficiency and execution effect of compilation, the hierarchical compilation strategy can be combined to batch and prioritize the compilation tasks. This strategy can not only effectively coordinate the order of task execution, but also clearly display the task dependencies and execution process through a visual task schedule, providing strong support for accurate and efficient incremental compilation. Specifically: In one implementation, the process of compiling the change event information in the Java source code according to the compilation task queue to obtain the machine code corresponding to the change event information may include: Based on the preset task dependency, the compilation task queue is divided into multiple batches to obtain the compilation task queues under different batches; Prioritize the compilation task queues in different batches and generate a visual task schedule; According to the visual task scheduling table, the change event information in the Java source code is hierarchically compiled through the hierarchical compilation strategy to obtain the machine code corresponding to the change event information; In this implementation, by implementing batch division, priority sorting and hierarchical compilation strategy of compilation task queue, the compilation efficiency and flexibility of task management can be significantly improved. By dividing the compilation tasks into multiple batches based on task dependencies and sorting the execution priorities of tasks in each batch, a visual task schedule is generated, which not only optimizes the execution order of compilation tasks, but also provides clear guidance for task collaboration in complex projects. At the same time, combined with the hierarchical compilation strategy, compilation tasks can be efficiently scheduled and executed in different batches to ensure that the dependencies between tasks are correctly parsed and processed. In the actual execution process, for the uncached code units in the task schedule, the existing Java compiler (such as Javac) is called to compile them; for the cached code units, the bytecode files in the cache are directly reused. Finally, the newly generated bytecode files are integrated with the valid cache data to form a complete set of machine code files (i.e., .class file sets). This method makes full use of the existing tool chain support and supports integration with the existing Java compiler without major modifications to the development tools, thereby significantly improving the scalability and compatibility of the system.
[0033] In this implementation, the process of hierarchically compiling the change event information in the Java source code through the hierarchical compilation strategy to obtain the machine code corresponding to the change event information may include: Use the thread pool to execute the compilation tasks in the visual task schedule in layers to obtain the bytecode files and cache data of each layer; The bytecode files and cache data of each layer are integrated to generate machine code corresponding to the change event information; this implementation method effectively improves the execution efficiency of incremental compilation and the utilization rate of system resources through the layered compilation strategy; the thread pool is used to perform layered execution of the compilation tasks in the visual task scheduling table, which can significantly improve the parallelism of the compilation tasks and make full use of the multi-core processing capabilities. This layered execution method ensures that the dependencies of the compilation tasks are correctly parsed and processed, while making task scheduling more efficient and reducing task waiting and resource idleness. By integrating the bytecode files and cache data generated by each layer to form a complete machine code, the solution not only simplifies the code generation process, but also ensures the consistency and integrity of the compilation results. In addition, the combination of the layered compilation strategy and the cache mechanism enables the system to reuse the generated intermediate results in subsequent compilation tasks, further reducing the overhead of redundant calculations. This efficient compilation process is particularly suitable for large and complex projects, which can significantly shorten the compilation time and improve the development feedback speed.
[0034] After generating the complete machine code, in order to ensure its quality and the correctness of the dependencies, the generated bytecode files need to be further verified. Through the binary verification tool, the integrity and consistency of the generated machine code files can be checked to ensure that the compilation results meet expectations and no errors are introduced. Subsequently, in order to ensure that the dependency graph of subsequent tasks can correctly reflect the current code status, the latest dependencies are recalculated based on the initial dependency graph, and the dependency graph is updated accordingly (that is, the optimized dependency graph for the next incremental compilation) to keep it consistent with the current code status. This dual-security strategy not only improves the reliability of the machine code, but also provides accurate dependency information support for subsequent compilation and execution, thereby further improving the accuracy and efficiency of the entire compilation process.
[0035] In summary, the present invention aims at the existing incremental compilation method, which has a large compilation scope, relies only on static analysis, cannot effectively handle the combination of static and dynamic dependencies, and has a low cache reuse rate, resulting in low compilation efficiency; an automatic incremental compilation method for Java development is proposed, which significantly optimizes the incremental compilation process by accurately detecting and efficiently processing the change event information of the Java source code. First, the code changes are quickly identified by hash value verification, and a change record table is generated, which provides comprehensive and efficient basic data for subsequent dependency analysis. This intelligent recognition technology avoids the redundant calculations required for full compilation, ensures that only the changed part of the code is processed, thereby greatly improving the compilation efficiency. On the basis of change detection, combined with the analysis of static dependency information and dynamic call relationships, a relationship dependency graph is generated. Through dependency tracking technology, the relationship dependency graph fully captures the association between code units, and clarifies the sets of code units directly and indirectly affected. This static and dynamic combined analysis method optimizes the scope of incremental compilation, lays the foundation for efficient compilation management, and provides optimization support for the subsequent improvement of incremental compilation efficiency. Based on the relationship dependency graph, the topological sorting algorithm is used to generate the compilation task queue, and the dynamic cache mechanism is combined to optimize the task scheduling logic. The incremental compilation schedule not only ensures the efficiency of task scheduling by clarifying the task execution order and cache reuse strategy, but also reduces the overhead of repeated calculations and significantly shortens the compilation time. For the code units in the task schedule, the cache status is dynamically checked, and the valid cache is directly loaded to avoid repeated compilation; for the invalid cache part, the compilation is triggered to generate a new bytecode file, and finally integrated into a complete machine code file. This process ensures the correctness and consistency of the compilation results and meets the actual development needs. The overall solution accurately identifies the changed parts of the source code, and combines intelligent analysis and dependency optimization strategies to decompose the compilation task into controllable incremental execution units, realizing efficient support for continuous integration and rapid iteration of large projects. In addition, the solution supports seamless integration with existing Java compilers, improves the compatibility and scalability of the system, further optimizes resource utilization by dynamically caching intermediate results, and perfectly balances development efficiency and compilation performance. It is an ideal implementation of modern incremental compilation technology.
[0036] Embodiment 2: The present invention based on the same inventive concept also provides an automatic incremental compilation system for Java development, the structural composition diagram is as follows Figure 4 As shown, including: A hash verification module is used to verify the hash value of the acquired Java source code to obtain the change event information in the Java source code; A dependency graph building module is used to extract static dependency information and dynamic call relationships corresponding to the change event information from the change event information, and generate a relationship dependency graph of the change event information based on the static dependency information and the dynamic call relationship; The task sorting module is used to generate a compilation task queue based on the relationship dependency graph using a topological sorting algorithm; The automatic compilation module is used to compile the change event information in the Java source code according to the compilation task queue to obtain the machine code corresponding to the change event information.
[0037] In one implementation, the above-mentioned hash verification module may include: A hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate a hash value for each logical block; A hash comparison module is used to obtain the changed code block in the Java source code by performing a hash comparison on the hash value of each logic block; A consistency check module is used to perform syntax consistency check on the changed code block using the syntax tree to obtain the change event information in the Java source code; For example, the above code elements may include one or more of the following: class definition, method definition and comment section; For example, the above-mentioned change event information may include one or more of the following: a changed file path, a change type, and a timestamp.
[0038] In one implementation, the dependency graph building module may include: The static graph construction submodule is used to represent the static dependency information in a graph to obtain the corresponding static directed graph; The dynamic graph construction submodule is used to represent the dynamic call relationship in a graph to obtain the corresponding dynamic directed graph; The node merging submodule is used to merge nodes of a static directed graph and a dynamic directed graph using a graph isomorphism algorithm to obtain a merged node directed graph; The community division submodule is used to use the graph clustering algorithm to divide the community of the merged node directed graph and construct a relationship dependency graph.
[0039] In one implementation, the task sorting module may include: A connectivity analysis submodule is used to perform connectivity component analysis based on the relationship dependency graph and extract acyclic key subgraphs in the relationship dependency graph; The topological sorting submodule is used to obtain the task execution order in the change event information based on the acyclic key subgraph using the topological sorting algorithm; The queue generation submodule is used to generate a compilation task queue according to the task execution order.
[0040] In one implementation, the automatic compilation module may include: The queue division submodule is used to divide the compilation task queue into multiple batches based on the preset task dependency relationship to obtain the compilation task queues under different batches; The priority sorting submodule is used to prioritize the compilation task queues under different batches and generate a visual task scheduling table; The hierarchical compilation submodule is used to perform hierarchical compilation on the change event information in the Java source code according to the visual task scheduling table and the hierarchical compilation strategy to obtain the machine code corresponding to the change event information.
[0041] In this implementation, the above-mentioned hierarchical compilation submodule may include: The task visualization unit is used to use the thread pool to execute the compilation tasks in the visualization task scheduling table in layers, and obtain the bytecode files and cache data of each layer; The file integration unit is used to integrate the bytecode files and cache data of each layer to generate machine codes corresponding to the change event information.
[0042] Embodiment 3: like Figure 5 As shown, the present invention also provides an electronic device, which may be a computer device, a single-chip device, an intelligent mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, the processor, and the transceiver component are connected via a bus; the memory may be used to store an execution program, and an exemplary execution program may include instructions; the processor is used to execute the instructions stored in the memory. The memory may also be used to store data, which may be called and / or modified when the instructions are executed.
[0043] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in a storage medium to implement the corresponding method flow or corresponding functions, so as to implement the steps of an automatic incremental compilation method for Java development in the above-mentioned embodiment.
[0044] Embodiment 4: Based on the same inventive concept, the present invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory), which is a memory device in an electronic device for storing programs and data. It can be understood that the storage medium here can include both built-in storage media in the electronic device and, of course, extended storage media supported by the electronic device. The storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more execution programs (including program codes). It should be noted that the storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The processor loads and executes one or more instructions stored in the storage medium, which can implement the steps of an automatic incremental compilation method for Java development in the above embodiment.
[0045] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0046] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0047] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0048] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0049] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit its protection scope. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the field should understand that after reading the present invention, those skilled in the art can still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the protection scope of the claims to be approved.
Claims
1. An automatic incremental compilation method for Java development, characterized in that: include: Performing hash value verification on the acquired Java source code to obtain change event information in the Java source code; Extracting static dependency information and dynamic call relationships corresponding to the change event information from the change event information respectively, and generating a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship; Based on the relationship dependency graph, a compilation task queue is generated using a topological sorting algorithm; The change event information in the Java source code is compiled according to the compilation task queue to obtain a machine code corresponding to the change event information.
2. The method according to claim 1, characterized in that The step of performing hash value verification on the acquired Java source code to obtain change event information in the Java source code includes: Divide the obtained Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block; By performing hash comparison on the hash value of each logic block, a changed code block in the Java source code is obtained; Performing a syntax consistency check on the changed code block using a syntax tree to obtain change event information in the Java source code; The code elements include one or more of the following: class definition, method definition and comment segment.
3. The method according to claim 1, characterized in that The step of generating a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship includes: Representing the static dependency information in a graph to obtain a corresponding static directed graph; Representing the dynamic call relationship in a graph to obtain a corresponding dynamic directed graph; Using a graph isomorphism algorithm, nodes of the static directed graph and the dynamic directed graph are merged to obtain a merged node directed graph; Using a graph clustering algorithm, the merged node directed graph is divided into communities to construct a relationship dependency graph.
4. The method according to claim 1, characterized in that The generating of the compilation task queue based on the relationship dependency graph and using a topological sorting algorithm includes: Performing connected component analysis according to the relationship dependency graph to extract acyclic key subgraphs in the relationship dependency graph; According to the acyclic critical subgraph, using a topological sorting algorithm, obtaining the task execution order in the change event information; A compilation task queue is generated according to the task execution order.
5. The method according to claim 1, characterized in that The step of compiling the change event information in the Java source code according to the compilation task queue to obtain a machine code corresponding to the change event information includes: Based on the preset task dependency, the compilation task queue is divided into multiple batches to obtain compilation task queues in different batches; Prioritize the compilation task queues under the different batches and generate a visual task scheduling table; According to the visual task scheduling table, the change event information in the Java source code is hierarchically compiled through a hierarchical compilation strategy to obtain a machine code corresponding to the change event information.
6. The method according to claim 5, characterized in that The step of performing hierarchical compilation on the change event information in the Java source code through a hierarchical compilation strategy to obtain a machine code corresponding to the change event information includes: Utilizing the thread pool, the compilation tasks in the visualization task scheduling table are executed in layers to obtain the bytecode files and cache data of each layer; The bytecode files and cache data of each layer are integrated to generate machine codes corresponding to the change event information.
7. The method according to claim 1, characterized in that The change event information includes one or more of the following: a changed file path, a change type, and a timestamp.
8. An automatic incremental compilation system for Java development, characterized in that: include: A hash verification module is used to perform hash value verification on the acquired Java source code to obtain change event information in the Java source code; A dependency graph construction module, used to extract static dependency information and dynamic call relationships corresponding to the change event information from the change event information, and generate a relationship dependency graph of the change event information according to the static dependency information and the dynamic call relationship; A task sorting module, used to generate a compilation task queue based on the relationship dependency graph using a topological sorting algorithm; The automatic compilation module is used to compile the change event information in the Java source code according to the compilation task queue to obtain the machine code corresponding to the change event information.
9. The system according to claim 8, characterized in that The hash verification module comprises: A hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate a hash value for each logical block; A hash comparison module, used for obtaining a changed code block in the Java source code by performing a hash comparison on a hash value of each logic block; A consistency check module, used to perform a syntax consistency check on the changed code block using a syntax tree to obtain change event information in the Java source code; The code elements include one or more of the following: class definition, method definition and comment segment.
10. The system according to claim 8, characterized in that The dependency graph building module includes: A static graph construction submodule is used to perform a graph representation on the static dependency information to obtain a corresponding static directed graph; A dynamic graph construction submodule is used to represent the dynamic call relationship in a graph to obtain a corresponding dynamic directed graph; A node merging submodule, used to merge nodes of the static directed graph and the dynamic directed graph using a graph isomorphism algorithm to obtain a merged node directed graph; The community division submodule is used to use a graph clustering algorithm to perform community division on the merged node directed graph and construct a relationship dependency graph.
Citation Information
Patent Citations
File compiling method and device, equipment and storage medium
CN112783508A
Static detection method and detection system for incremental codes
CN114510722A
Display method and device of code increment coverage information and electronic equipment
CN117215932A
Accelerated construction method and device for front-end development, equipment and storage medium
CN119002926A
Compiling method and device and computer readable storage medium
CN119376738A
Cited By
Instruction scheduling optimization method and device based on directed acyclic graph and compiling method
CN119621072A
A directed acyclic graph-based instruction scheduling optimization method, device and compilation method
CN119621072B
Code reconstruction method and system, computing device, storage medium and program product
CN120315754A
Compilation optimization method and electronic equipment
CN120909601A
Compiling optimization method and electronic device
CN120909601B