An automatic incremental compilation method and system for Java development

By performing hash value verification and dependency analysis on Java source code, a compilation task queue is generated. Combined with dynamic caching and tiered compilation strategies, the problems of large compilation scope and incomplete dependency handling in incremental compilation are solved, achieving an efficient and accurate compilation process.

CN119396406BActive Publication Date: 2025-11-11BAO DAFANG TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411976814.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-11-11
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

Existing incremental compilation techniques suffer from problems such as excessively large compilation scope and inability to effectively handle static and dynamic dependencies, resulting in low compilation efficiency.

Method used

By performing hash value verification on Java source code, generating change event information, extracting static dependency information and dynamic call relationships, constructing a dependency graph, generating a compilation task queue using a topological sorting algorithm, and combining dynamic caching mechanisms and tiered compilation strategies, the execution of compilation tasks is optimized.

Benefits of technology

It accurately identifies the scope of code changes, reduces the initial scope of compilation, improves compilation efficiency and correctness, shortens the development feedback cycle, and supports continuous integration and rapid iteration of large projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396406B_ABST
    Figure CN119396406B_ABST
Patent Text Reader

Abstract

This invention provides an automatic incremental compilation method and system 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 from the change event information, and generating a dependency graph based on the static dependency information and dynamic call relationships; generating a compilation task queue based on the dependency graph using a topological sorting algorithm; and 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. This application accurately locates code change information through hash value verification, which helps to reduce the initial scope of incremental compilation; by extracting static dependency information and dynamic call relationships from the change event information to generate a dependency graph, the dependency relationships between code units are fully represented, solving the problem of missing dynamic call relationships and improving the correctness and efficiency of compilation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software engineering technology, and more specifically to an automatic incremental compilation method and system for Java development. Background Technology

[0002] Currently, code compilation is an essential step in Java development. Traditional compilation methods typically involve full compilation, meaning that every time the code is changed, regardless of the scope of the change, the entire project needs to be recompiled. While full compilation ensures code consistency and correctness, it presents the following problems when dealing with large projects with complex dependencies:

[0003] Long compilation time: As the project grows, the number of code files and the complexity of dependencies increase exponentially. Full compilation requires re-parsing and processing all code files, resulting in a significant increase in compilation time.

[0004] Serious waste of resources: During the full compilation process, many unchanged code files are also compiled repeatedly, consuming a lot of computing resources and storage space, and reducing development efficiency.

[0005] Extended development feedback cycles: In continuous integration and rapid iteration development models, developers need to frequently modify code. The inefficiency of full compilation directly leads to extended feedback cycles, severely impacting development efficiency.

[0006] In recent years, incremental compilation technology has gradually gained attention as a solution. Incremental compilation identifies the scope of code changes and compiles only the affected portions, avoiding the resource waste and time consumption of full compilation. However, existing incremental compilation technologies also have the following shortcomings:

[0007] Excessive compilation scope: Because it relies solely on static analysis, the compiler may need to compile a large number of code units that are unrelated to the changes, thus reducing the efficiency of incremental compilation.

[0008] Incomplete dependencies: Dynamic call relationships cannot be accurately captured, which may lead to the omission of key dependency information, thereby affecting the correctness and consistency of the generated code.

[0009] In summary, existing incremental compilation techniques suffer from a large compilation scope and an inability to effectively handle the combination of static and dynamic dependencies, resulting in low compilation efficiency. Summary of the Invention

[0010] To address the problems of low compilation efficiency caused by the large compilation scope and inability to effectively handle the combination of static and dynamic dependencies in existing incremental compilation techniques, this invention proposes an automatic incremental compilation method for Java development, comprising:

[0011] The hash value of the obtained Java source code is verified to obtain the change event information in the Java source code;

[0012] Extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information respectively, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship;

[0013] Based on the aforementioned dependency graph, a compilation task queue is generated using a topological sorting algorithm;

[0014] Based on the compilation task queue, the change event information in the Java source code is compiled to obtain the machine code corresponding to the change event information.

[0015] Optionally, the step of performing hash value verification on the acquired Java source code to obtain change event information in the Java source code includes:

[0016] The obtained Java source code is divided into different logical blocks according to code elements, and a hash value is calculated for each logical block.

[0017] By performing a hash comparison on the hash value of each logical block, the modified code blocks in the Java source code are obtained;

[0018] The syntax tree is used to perform a syntax consistency check on the modified code block to obtain the change event information in the Java source code;

[0019] The code elements include one or more of the following: class definitions, method definitions, and comment sections.

[0020] Optionally, generating the relational dependency graph of the change event information based on the static dependency information and the dynamic calling relationship includes:

[0021] The static dependency information is represented by a graph to obtain the corresponding static directed graph;

[0022] The dynamic calling relationship is represented by a graph to obtain the corresponding dynamic directed graph;

[0023] Using a graph isomorphism algorithm, nodes are merged between the static directed graph and the dynamic directed graph to obtain a merged node directed graph;

[0024] Using a graph clustering algorithm, the directed graph of the merged nodes is divided into communities to construct a relational dependency graph.

[0025] Optionally, generating a compilation task queue based on the dependency graph using a topological sorting algorithm includes:

[0026] Based on the dependency graph, perform connected component analysis to extract the acyclic key subgraph from the dependency graph;

[0027] Based on the acyclic key subgraph, the task execution order in the change event information is obtained using a topological sorting algorithm;

[0028] A compilation task queue is generated based on the task execution order.

[0029] Optionally, the step 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 includes:

[0030] Based on the preset task dependencies, the compilation task queue is divided into multiple batches to obtain compilation task queues under different batches;

[0031] Prioritize the compilation task queues under different batches and generate a visual task scheduling table;

[0032] Based on the visualized task scheduling table, the change event information in the Java source code is compiled in layers using a layered compilation strategy to obtain the machine code corresponding to the change event information.

[0033] Optionally, the step of performing layered compilation on the change event information in the Java source code to obtain the machine code corresponding to the change event information includes:

[0034] Using a thread pool, the compilation tasks in the visualized task scheduler are executed in layers to obtain bytecode files and cached data for each layer.

[0035] The bytecode files and cached data of each layer are integrated to generate the machine code corresponding to the change event information.

[0036] Optionally, the change event information may include one or more of the following: changed file path, change type, and timestamp.

[0037] Based on the same inventive concept, this invention also provides an automatic incremental compilation system for Java development, comprising:

[0038] The 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;

[0039] The dependency graph construction module is used to extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship.

[0040] The task sorting module is used to generate a compilation task queue based on the relational dependency graph using a topological sorting algorithm;

[0041] An automatic compilation module is used to compile the change event information in the Java source code according to the compilation task queue, so as to obtain the machine code corresponding to the change event information.

[0042] Optionally, the hash verification module includes:

[0043] The hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block separately.

[0044] The hash comparison module is used to obtain the modified code blocks in the Java source code by performing hash comparison on the hash value of each logical block;

[0045] The consistency check module is 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.

[0046] The code elements include one or more of the following: class definitions, method definitions, and comment sections.

[0047] Optionally, the dependency graph construction module includes:

[0048] The static graph construction submodule is used to represent the static dependency information into a graph to obtain the corresponding static directed graph;

[0049] The dynamic graph construction submodule is used to represent the dynamic calling relationship in a graph to obtain the corresponding dynamic directed graph;

[0050] The node merging submodule is used to merge nodes in the static directed graph and the dynamic directed graph using a graph isomorphism algorithm to obtain a merged node directed graph.

[0051] The community partitioning submodule is used to partition the directed graph of the merged nodes into communities using a graph clustering algorithm, and construct a relational dependency graph.

[0052] Optionally, the task sorting module includes:

[0053] The connectivity analysis submodule is used to perform connectivity component analysis based on the relation dependency graph and extract acyclic key subgraphs from the relation dependency graph;

[0054] The topology sorting submodule is used to obtain the task execution order in the change event information based on the acyclic key subgraph using a topology sorting algorithm.

[0055] The queue generation submodule is used to generate a compilation task queue according to the task execution order.

[0056] Optionally, the automatic compilation module includes:

[0057] The queue partitioning submodule is used to divide the compilation task queue into multiple batches based on preset task dependencies, thereby obtaining compilation task queues under different batches.

[0058] The priority sorting submodule is used to sort the compilation task queues under different batches by priority and generate a visual task scheduling table.

[0059] The tiered compilation submodule is used to perform tiered compilation on the change event information in the Java source code according to the visualized task scheduling table and through a tiered compilation strategy, so as to obtain the machine code corresponding to the change event information.

[0060] Optionally, the layered compilation submodule includes:

[0061] The task visualization unit is used to execute the compilation tasks in the visualized task scheduling table in layers using a thread pool, and to obtain the bytecode file and cached data of each layer.

[0062] The file integration unit is used to integrate the bytecode files and cached data of each layer to generate the machine code corresponding to the change event information.

[0063] Optionally, the change event information may include one or more of the following: changed file path, change type, and timestamp.

[0064] In another aspect, the present invention also provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus;

[0065] The memory is used to store one or more programs;

[0066] When the one or more programs are executed by the at least one processor, an automatic incremental compilation method for Java development as described above is implemented.

[0067] In another aspect, the present invention also provides a computer device readable storage medium having an executable program stored thereon, wherein when the executable program is executed, it implements an automatic incremental compilation method for Java development as described above.

[0068] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0069] This invention provides an automatic incremental compilation method and system for Java development, comprising: performing hash value verification on 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, and generating a dependency graph of the change event information based on the static dependency information and dynamic call relationships; generating a compilation task queue based on the dependency graph using a topological sorting algorithm; and 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. This application uses hash value verification to accurately locate code change information, which helps reduce the initial scope of incremental compilation; by extracting static dependency information and dynamic call relationships from the change event information to generate a dependency graph, it fully represents the dependencies between code units, solving the problem of missing dynamic call relationships and improving the correctness and efficiency of compilation. Attached Figure Description

[0070] Figure 1 A flowchart illustrating an automatic incremental compilation method for Java development provided by this invention;

[0071] Figure 2 This invention provides a schematic diagram of the framework for determining change event information in an automatic incremental compilation method for Java development.

[0072] Figure 3 This invention provides a schematic diagram of the dependency graph construction process in an automatic incremental compilation method for Java development.

[0073] Figure 4 This invention provides a schematic diagram of the structural composition of an automatic incremental compilation system for Java development;

[0074] Figure 5 This is a schematic diagram of the structure of an electronic device provided by the present invention. Detailed Implementation

[0075] This invention proposes an automatic incremental compilation method, system, device, and medium for Java development. The specific embodiments of this invention will be further described in detail below with reference to the accompanying drawings.

[0076] Example 1:

[0077] This invention provides an automatic incremental compilation method for Java development, the flowchart of which is shown below. Figure 1 As shown, it includes:

[0078] Step 1: Perform hash value verification on the obtained Java source code to obtain change event information in the Java source code;

[0079] Step 2: Extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship;

[0080] Step 3: Based on the dependency graph, use the topological sorting algorithm to generate a compilation task queue;

[0081] 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.

[0082] In modern software development, as project scale and complexity continue to increase, source code compilation efficiency becomes crucial. Traditional full compilation methods require recompiling the entire codebase, regardless of the scope of code modifications. This not only wastes significant time and computing resources but also significantly reduces the efficiency of development feedback. To address this issue, incremental compilation technology has emerged. By accurately identifying changed parts of the code, it only compiles the affected code, thereby optimizing both resources and time. The first step in incremental compilation is efficient detection of changes in the source code. Intelligent methods quickly identify changed areas, providing reliable foundational data for subsequent dependency analysis and compilation task allocation. Specifically:

[0083] In one implementation, such as Figure 2 As shown, the process of performing hash value verification on the obtained Java source code to obtain change event information in the Java source code may include:

[0084] The obtained Java source code is divided into different logical blocks according to code elements, and a hash value is calculated for each logical block.

[0085] By comparing the hash values ​​of each logical block, the modified code blocks in the Java source code can be obtained.

[0086] The syntax tree is used to perform syntax consistency checks on the modified code blocks to obtain change event information in the Java source code;

[0087] For example, the code elements mentioned above may include one or more of the following: class definition, method definition, and comment section;

[0088] For example, the change event information mentioned above may include one or more of the following: changed file path, change type, and timestamp;

[0089] In this implementation, the ability to process 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 and optimize the subsequent compilation process. For example, after performing hash value verification and identifying changed code blocks on the obtained Java source code, static and dynamic dependency analysis is performed on each changed code block. Static dependency analysis is used to resolve 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 through reflection, dynamic proxies, or runtime-generated call paths. By combining the results of static and dynamic dependency analysis, a comprehensive dependency graph can be constructed to represent the associations between changed code blocks and other code units. Using this dependency graph, change event information can be expanded to include the affected code scope and cross-module dependency chains, thus providing foundational support for subsequent task scheduling and compilation optimization. The introduction of this dependency tracking technology significantly improves the accuracy of change detection and compilation efficiency, ensuring the correct compilation and consistency maintenance of changed code and its associated code. This implementation method performs hash value verification on Java source code, dividing the source code into logical blocks and calculating hash values ​​for each. Then, it accurately identifies changed code blocks through hash comparison, performs syntax consistency checks in conjunction with a syntax tree, and finally generates change event information. This implementation method effectively improves the accuracy and efficiency of change detection. By checking file system change events through hash value verification, it captures add, modify, or delete operations, and extracts file paths, change types (add, modify, delete), and timestamp information for changed source code files. This change capture method based on file system metadata can quickly and accurately pinpoint the scope of code changes, thereby generating a change log table containing complete change details. Secondly, this solution employs intelligent code block partitioning and change detection. Based on changes in the source code, it intelligently identifies the code sections requiring recompilation, avoiding unnecessary full compilations. This not only reduces the computational burden of compilation but also significantly improves compilation efficiency, particularly in large projects where it can drastically shorten the development feedback cycle. Furthermore, by utilizing dependency tracking technology, it accurately identifies and isolates source code changes, ensuring that only code related to the changed parts is compiled. This dependency tracking capability guarantees 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 monitors changes in the codebase in real time, automatically triggers the incremental compilation process without manual intervention, maintains compilation consistency and integrity, effectively improves compilation efficiency, reduces the development feedback cycle, and provides technical support for continuous integration and rapid iteration in complex projects.

[0090] To achieve efficient incremental compilation, it's not only necessary to accurately capture change events in Java source code, but also to deeply analyze the relationships between changed code blocks and other code units. Detecting changed code blocks is only the first step; to ensure the completeness and accuracy of compilation, generating a dependency graph of change event information is crucial. By constructing a dependency graph, static dependencies and dynamic calling relationships between code units can be comprehensively represented, providing a solid foundation for subsequent compilation task scheduling and dependency optimization. Specifically:

[0091] In one implementation, such as Figure 3 As shown, the process of generating a dependency graph of change event information based on static dependency information and dynamic calling relationships can include:

[0092] The static dependency information is represented as a graph to obtain the corresponding static directed graph;

[0093] The dynamic call relationships are represented by a graph, resulting in the corresponding dynamic directed graph;

[0094] Using the graph isomorphism algorithm, nodes are merged between static and dynamic directed graphs to obtain a merged directed graph.

[0095] Using graph clustering algorithms, communities are partitioned in the directed graph of merged nodes to construct a relational dependency graph;

[0096] In this implementation, a graph representation is used to construct static dependency information and dynamic call relationships as static directed graphs and dynamic directed graphs, respectively. A graph isomorphism algorithm is then used to merge nodes from both, forming a unified merged node directed graph. This step accurately integrates static and dynamic dependencies in the code, comprehensively capturing the relationships between changed code blocks and other code units. For files in the change log table, the JavaParser tool can be used to parse the import statements and call relationships of the changed files, effectively extracting static dependency information. For the runtime behavior of the changed files, the ASM tool can be used to capture dynamic call relationships (such as runtime class loading and method calls). This combination of static and dynamic approaches avoids dependency paths that might be missed by a single analysis method. Secondly, a graph clustering algorithm is used to perform community partitioning on the merged node directed graph, dividing the complex dependency network into multiple highly correlated subgraphs and constructing a clear relational dependency graph. This not only optimizes the structural expression of the dependency graph but also marks all code units affected by the change, including both direct and indirect dependencies, ensuring that 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 approach ensures the accuracy of dependency tracking and compilation task partitioning even under high code complexity, laying the foundation for subsequent compilation optimization and task scheduling.

[0097] To ensure the efficiency of incremental compilation, simply constructing a dependency graph is insufficient to directly guide the compilation process. While the dependency graph comprehensively 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. Through the analysis and processing of the dependency graph, key dependency paths and execution orders can be extracted, thus providing clear guidance for the task division of incremental compilation. Specifically:

[0098] In one implementation, the process of generating a compilation task queue based on a dependency graph and using a topological sorting algorithm may include:

[0099] Perform connected component analysis on the dependency graph to extract acyclic key subgraphs from the dependency graph;

[0100] Based on the acyclic critical subgraph, the task execution order in the change event information is obtained using the topological sorting algorithm;

[0101] Generate a compilation task queue based on the task execution order;

[0102] In this implementation, by performing connectivity component analysis on the dependency graph, acyclic key subgraphs related to change event information can be accurately extracted, focusing on the sets of code units directly and indirectly affected, avoiding unnecessary processing of irrelevant code units. Analyzing the connectivity components of the dependency graph for the affected code unit set ensures that only dependency paths actually affected by the change are processed, thereby reducing the compilation scope and improving compilation efficiency. Secondly, a topological sorting algorithm is used to further process the updated dependency graph, clarifying the order of dependencies between code units. This deterministic dependency order ensures the correctness of the compilation task, avoiding compilation errors caused by incorrect handling of dependencies. The order generated by the topological sorting algorithm for the updated dependency graph can also optimize the task scheduling process, enabling compilation tasks to be executed efficiently in the dependency order. Finally, by generating a compilation task queue, compilation tasks are clearly divided into executable independent units, providing basic support for layered or parallel compilation. This task queue generation not only ensures the integrity and consistency of the changed code but also significantly shortens compilation time and improves the overall efficiency of incremental compilation.

[0103] After generating a compilation task queue based on the dependency graph, a dynamic caching mechanism is introduced into the compilation process to further optimize compilation efficiency. By comparing the timestamps of code units in the task schedule with the version information in the cache pool, the validity of the cache can be quickly determined. For valid code units, the bytecode files in the cache are directly loaded, avoiding redundant compilation operations and saving computational resources and time. For invalid code units, recompilation is triggered to generate new bytecode files, which are then stored in the cache pool for reuse in subsequent compilation tasks. This dynamic caching mechanism can also save intermediate results during compilation. By reusing the compiled parts in subsequent tasks, the overhead of repeated computation is significantly reduced. The overall strategy achieves a balance between resource utilization and performance improvement, providing a more efficient solution for large-scale incremental compilation.

[0104] Building upon the optimization of compilation task execution using dynamic caching mechanisms, to further improve compilation organization efficiency and execution performance, a tiered compilation strategy can be combined to batch and prioritize compilation tasks. This strategy not only effectively coordinates the order of task execution but also clearly displays task dependencies and execution flows through a visual task scheduling table, providing strong support for achieving accurate and efficient incremental compilation. Specifically:

[0105] 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:

[0106] Based on the preset task dependencies, the compilation task queue is divided into multiple batches to obtain compilation task queues under different batches;

[0107] Prioritize the compilation task queues under different batches and generate a visual task scheduling table;

[0108] Based on the visualized task scheduling table, the change event information in the Java source code is compiled in layers using a layered compilation strategy to obtain the machine code corresponding to the change event information.

[0109] This implementation significantly improves compilation efficiency and task management flexibility by batching, prioritizing, and implementing a tiered compilation strategy for the compilation task queue. By dividing compilation tasks into multiple batches based on task dependencies and prioritizing tasks within each batch to generate a visual task scheduling table, it not only optimizes the execution order of compilation tasks but also provides clear guidance for task collaboration in complex projects. Furthermore, the tiered compilation strategy allows for efficient scheduling and execution of compilation tasks across different batches, ensuring that dependencies between tasks are correctly resolved and handled. In actual execution, for code units not cached in the task schedule, an existing Java compiler (such as Javac) is invoked for compilation; for cached code units, the cached bytecode files are directly reused. Finally, the newly generated bytecode files are integrated with the valid cached data to form a complete set of machine code files (i.e., a set of .class files). This approach fully utilizes existing toolchain support, supports integration with existing Java compilers, and requires no major modifications to development tools, thus significantly improving the system's scalability and compatibility.

[0110] In this implementation, the process of performing layered compilation of change event information in Java source code to obtain the machine code corresponding to the change event information through a layered compilation strategy can include:

[0111] Using a thread pool, compilation tasks in a visual task scheduler are executed in layers to obtain bytecode files and cached data for each layer.

[0112] By integrating the bytecode files and cached data from each layer, machine code corresponding to change event information is generated. This implementation effectively improves the execution efficiency of incremental compilation and the utilization of system resources through a layered compilation strategy. Utilizing a thread pool to execute compilation tasks in a visualized task scheduling table in layers significantly improves the parallelism of compilation tasks, fully utilizing multi-core processing capabilities. This layered execution method ensures that the dependencies of compilation tasks are correctly resolved and processed, while making task scheduling more efficient and reducing task waiting and resource idleness. By integrating the bytecode files and cached data generated from each layer to form complete machine code, the solution not only simplifies the code generation process but also ensures the consistency and integrity of the compilation results. Furthermore, the combination of the layered compilation strategy and caching mechanism allows the system to reuse intermediate results in subsequent compilation tasks, further reducing the overhead of redundant computation. This efficient compilation process is particularly suitable for large and complex projects, significantly shortening compilation time and improving development feedback speed.

[0113] After generating complete machine code, to ensure its quality and the correctness of dependencies, the generated bytecode file needs further verification. Binary verification tools can be used to perform integrity and consistency checks on the generated machine code file, ensuring that the compilation results meet expectations and do not introduce errors. Subsequently, to ensure that the dependency graph of subsequent tasks correctly reflects the current code state, the latest dependencies are recalculated based on the initial dependency graph, and the dependency graph (i.e., the optimized dependency graph used for the next incremental compilation) is updated accordingly, keeping it consistent with the current code state. This dual-protection strategy not only improves the reliability of the machine code but also provides accurate dependency information to support subsequent compilation and execution, thereby further improving the accuracy and efficiency of the entire compilation process.

[0114] In summary, this invention addresses the problems of low compilation efficiency caused by existing incremental compilation methods, such as large compilation scope, reliance on static analysis, inability to effectively handle the combination of static and dynamic dependencies, and low cache reuse rate. It proposes an automatic incremental compilation method for Java development, which significantly optimizes the incremental compilation process by accurately detecting and efficiently processing change event information in Java source code. First, hash value verification is used to quickly identify code changes and generate a change record table, providing comprehensive and efficient foundational data for subsequent dependency analysis. This intelligent identification technology avoids redundant calculations required for full compilation, ensuring that only the changed parts of the code are processed, thus greatly improving compilation efficiency. Based on change detection, a dependency graph is generated by combining static dependency information and dynamic call relationship analysis. Through dependency tracking technology, the dependency graph comprehensively captures the relationships between code units, clarifying the sets of directly and indirectly affected code units. This combined static and dynamic analysis method optimizes the scope of incremental compilation, lays the foundation for efficient compilation management, and provides optimization support for further improving incremental compilation efficiency. Based on dependency graphs, a topological sorting algorithm is used to generate a compilation task queue. Combined with a dynamic caching mechanism, the task scheduling logic is optimized. The incremental compilation plan table, by explicitly defining the task execution order and cache reuse strategy, not only ensures efficient task scheduling but also reduces the overhead of redundant computation, significantly shortening compilation time. For code units in the task plan table, their cache status is dynamically checked, and valid caches are directly loaded to avoid repeated compilation. For invalid cached parts, compilation is triggered to generate new bytecode files, which are ultimately integrated into a complete machine code file. This process ensures the correctness and consistency of the compilation results while meeting actual development needs. The overall solution accurately identifies changed parts of the source code and, combined with intelligent analysis and dependency optimization strategies, decomposes compilation tasks into controllable incremental execution units, achieving efficient support for continuous integration and rapid iteration of large projects. Furthermore, this solution supports seamless integration with existing Java compilers, improving system compatibility and scalability. Dynamic caching of intermediate results further optimizes resource utilization, perfectly balancing development efficiency and compilation performance, making it an ideal implementation of modern incremental compilation technology.

[0115] Example 2:

[0116] Based on the same inventive concept, this invention also provides an automatic incremental compilation system for Java development, the structural composition of which is shown in the schematic diagram below. Figure 4 As shown, it includes:

[0117] The hash verification module is used to verify the hash value of the obtained Java source code to obtain change event information in the Java source code;

[0118] The dependency graph construction module is used to extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship.

[0119] The task sorting module is used to generate a compilation task queue based on the dependency graph and using a topological sorting algorithm.

[0120] The automatic compilation module is used to compile the change event information in the Java source code according to the compilation task queue, and obtain the machine code corresponding to the change event information.

[0121] In one implementation, the hash verification module described above may include:

[0122] The hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block separately.

[0123] The hash comparison module is used to obtain the changed code blocks in the Java source code by performing hash comparison on the hash value of each logical block;

[0124] The consistency check module is used to perform syntax consistency checks on the changed code blocks using a syntax tree, and to obtain change event information in the Java source code.

[0125] For example, the code elements mentioned above may include one or more of the following: class definition, method definition, and comment section;

[0126] For example, the change event information mentioned above may include one or more of the following: changed file path, change type, and timestamp.

[0127] In one implementation, the dependency graph construction module described above may include:

[0128] The static graph construction submodule is used to represent static dependency information into a graph, resulting in the corresponding static directed graph.

[0129] The dynamic graph construction submodule is used to represent dynamic call relationships in graph form, resulting in the corresponding dynamic directed graph.

[0130] The node merging submodule is used to merge nodes in static and dynamic directed graphs using graph isomorphism algorithms to obtain a merged node directed graph.

[0131] The community partitioning submodule is used to partition the directed graph of merged nodes into communities using a graph clustering algorithm, and construct a relational dependency graph.

[0132] In one implementation, the task sorting module described above may include:

[0133] The connectivity analysis submodule is used to perform connectivity component analysis based on the dependency graph and extract acyclic key subgraphs from the dependency graph.

[0134] The topology sorting submodule is used to obtain the task execution order in the change event information based on the acyclic key subgraph using the topology sorting algorithm.

[0135] The queue generation submodule is used to generate a compilation task queue based on the task execution order.

[0136] In one implementation, the aforementioned automatic compilation module may include:

[0137] The queue partitioning submodule is used to divide the compilation task queue into multiple batches based on preset task dependencies, resulting in compilation task queues under different batches.

[0138] The priority sorting submodule is used to sort the compilation task queues under different batches by priority and generate a visual task scheduling table.

[0139] The tiered compilation submodule is used to perform tiered compilation of change event information in Java source code based on a visual task scheduling table and a tiered compilation strategy, so as to obtain the machine code corresponding to the change event information.

[0140] In this implementation, the aforementioned layered compilation submodule may include:

[0141] The task visualization unit is used to execute compilation tasks in the visualization task schedule table in layers using a thread pool, and obtain bytecode files and cached data for each layer.

[0142] The file integration unit is used to integrate the bytecode files and cached data of each layer to generate machine code corresponding to the change event information.

[0143] Example 3:

[0144] like Figure 5 As shown, the present invention also provides an electronic device, which may be a computer device, a microcontroller device, a smart mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, processor, and transceiver component are connected via a bus; the memory can be used to store executable programs, and an exemplary executable program may include instructions; the processor is used to execute the instructions stored in the memory. The memory can also be used to store data, which can be accessed and / or modified when instructions are executed.

[0145] The processor may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, and it is suitable for implementing one or more instructions. Specifically, it is suitable for loading and executing one or more instructions in the storage medium to implement the corresponding method flow or corresponding function, so as to implement the steps of an automatic incremental compilation method for Java development in the above embodiments.

[0146] Example 4:

[0147] Based on the same inventive concept, this invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory). An electronic device readable storage medium is a memory device within an electronic device used to store programs and data. It is understood that the storage medium here can include both built-in storage media within the electronic device and extended storage media supported by the electronic device. The storage medium provides storage space, which stores the terminal's operating system. Furthermore, this storage space also stores one or more instructions suitable for loading and execution by a processor. These instructions can be one or more executable programs (including program code). It should be noted that the storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device. Loading and executing one or more instructions stored in the storage medium by the processor can implement the steps of an automatic incremental compilation method for Java development in the above embodiments.

[0148] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied 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.

[0149] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0150] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0151] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0152] 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 its scope of protection. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that after reading the present invention, they 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 scope of protection of the claims pending approval.

Claims

1. An automatic incremental compilation method for Java development, characterized in that, include: The hash value of the obtained Java source code is verified to obtain the change event information in the Java source code; Extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information respectively, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship; Based on the relationship dependency graph, perform connected component analysis to extract acyclic key subgraphs related to change event information from the relationship dependency graph, ensuring that only the dependency paths actually affected by the change are processed; Based on the acyclic key subgraph, the task execution order in the change event information is obtained using a topological sorting algorithm; Generate a compilation task queue based on the task execution order; Based on the preset task dependencies, the compilation task queue is divided into multiple batches to obtain compilation task queues under different batches; Prioritize the compilation task queues under different batches and generate a visual task scheduling table; Based on the visualized task scheduling table, the compilation tasks in the visualized task scheduling table are executed in layers using a thread pool to obtain the bytecode file and cached data of each layer. The bytecode files and cached data of each layer are integrated to generate the machine code corresponding to the change event information; The step of generating a relational dependency graph of the change event information based on the static dependency information and dynamic call relationships includes: The static dependency information is represented by a graph to obtain the corresponding static directed graph; The dynamic calling relationship is represented by a graph to obtain the corresponding dynamic directed graph; Using a graph isomorphism algorithm, nodes are merged between the static directed graph and the dynamic directed graph to obtain a merged node directed graph; Using a graph clustering algorithm, the directed graph of the merged nodes is divided into communities to construct a relational dependency graph, including direct and indirect dependencies.

2. The method as described in 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: The obtained Java source code is divided into different logical blocks according to code elements, and a hash value is calculated for each logical block. By performing a hash comparison on the hash value of each logical block, the modified code blocks in the Java source code are obtained; The syntax tree is used to perform a syntax consistency check on the modified code block to obtain the change event information in the Java source code; The code elements include one or more of the following: class definitions, method definitions, and comment sections.

3. The method as described in claim 1, characterized in that, The change event information includes one or more of the following: changed file path, change type, and timestamp.

4. An automatic incremental compilation system for Java development, characterized in that, include: The 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; The dependency graph construction module is used to extract the static dependency information and dynamic call relationship corresponding to the change event information from the change event information, and generate the relationship dependency graph of the change event information based on the static dependency information and dynamic call relationship. The task sorting module is used to generate a compilation task queue based on the relational dependency graph using a topological sorting algorithm; The queue partitioning module is used to divide the compilation task queue into multiple batches based on a preset task dependency relationship, thereby obtaining compilation task queues under different batches. The priority sorting module is used to sort the compilation task queues under different batches by priority and generate a visual task scheduling table. The task visualization module is used to execute the compilation tasks in the visualized task scheduling table in layers using a thread pool, based on the visualized task scheduling table, to obtain the bytecode file and cached data of each layer. The file integration module is used to integrate the bytecode files and cached data of each layer to generate the machine code corresponding to the change event information; The dependency graph construction module includes: The static graph construction submodule is used to represent the static dependency information into a graph to obtain the corresponding static directed graph; The dynamic graph construction submodule is used to represent the dynamic calling relationship in a graph to obtain the corresponding dynamic directed graph; The node merging submodule is used to merge nodes in the static directed graph and the dynamic directed graph using a graph isomorphism algorithm to obtain a merged node directed graph. The community partitioning submodule is used to partition the directed graph of the merged nodes into communities using a graph clustering algorithm, and construct a relational dependency graph, including direct and indirect dependencies. The task sorting module includes: The connectivity analysis submodule is used to perform connectivity component analysis based on the dependency graph, extract acyclic key subgraphs related to change event information in the dependency graph, and ensure that only the dependency paths actually affected by the change are processed. The topology sorting submodule is used to obtain the task execution order in the change event information based on the acyclic key subgraph using the topology sorting algorithm. The queue generation submodule is used to generate a compilation task queue based on the task execution order.

5. The system as described in claim 4, characterized in that, The hash verification module includes: The hash value calculation module is used to divide the acquired Java source code into different logical blocks according to code elements, and calculate the hash value for each logical block separately. The hash comparison module is used to obtain the modified code blocks in the Java source code by performing hash comparison on the hash value of each logical block; The consistency check module is 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 definitions, method definitions, and comment sections.

Citation Information

Patent Citations

  • File compiling method and device, equipment and storage medium

    CN112783508A

  • Static detection method and detection system for incremental codes

    CN114510722A

  • Accelerated construction method and device for front-end development, equipment and storage medium

    CN119002926A