Bytecode Reflection for Precise Dead-Branch Code Cleaning

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code cleaning methods, both dynamic and static, face challenges in accurately identifying dead code due to limitations in traversing all possible code branches during execution and matching diverse coding styles, leading to inefficiencies and inaccurate results.

Innovation Solution

A method involving running a target test case to obtain metadata through bytecode reflection, determining member dependencies, and using real values to identify dead branches in decision structures, allowing for precise deletion of dead code without complex static analysis or additional execution steps.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If dynamic code cleaning scheme is used to determine dead code based on execution, then code cleaning can be performed, but branches that may be in effect cannot be traversed in actual running, leading to inaccurate dead code determination

Engineering Contradiction:
Improvedead code determination accuracyVSAvoidcode branch traversal capability
Core Design Contradiction:
ReliabilityVSEase of operation

Solution Approach 1:

The patent introduces an intermediary mechanism by inserting a flag variable and conditional judgment code at the entry point of the code being cleaned. This flag acts as a mediator between the test case execution and the dead code determination process, allowing the system to track whether code branches are actually executed during testing, thereby resolving the limitation of not being able to traverse all possible branches in dynamic execution

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If static code cleaning scheme is used to perform code cleaning based on syntactic analysis, then code cleaning can be performed without running the code, but the writing style of code development user is often difficult to completely match the code template, limiting the range of static code cleaning

Engineering Contradiction:
Improvecode cleaning efficiencyVSAvoidcode style adaptation capability
Core Design Contradiction:
ProductivityVSAdaptability or versatility

Solution Approach 1:

The patent transforms the static code cleaning approach into a dynamic one by actually executing the code under test and observing the real execution results. Instead of relying on pre-defined templates that may not match diverse coding styles, the system dynamically adapts to the actual code structure and behavior during execution, thereby achieving both high productivity and broad adaptability across different coding styles

Inventive Principle:
Principle #15Dynamics

3Measurement precision

If existing dynamic code cleaning scheme is used, then code execution can be performed, but branches that may be in effect usually cannot be traversed, resulting in dead code that cannot be accurately determined

Engineering Contradiction:
Improvedead code identification precisionVSAvoidcode execution traversal mechanism
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent applies preliminary action by inserting a flag variable and conditional judgment code at the entry point of the code before execution begins. This preliminary setup creates a tracking mechanism that records whether code branches are executed during testing, enabling precise dead code identification without requiring complex traversal mechanisms during execution

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS20250291706A1Code cleaning
Publication Date: 2025.09.18 BEIJING ZITIAO NETWORK TECH CO LTD
  • US20250291706A1 patent drawing
  • US20250291706A1 patent drawing
  • US20250291706A1 patent drawing

AI summary

The embodiment of the disclose provides a method and device, and medium of code cleaning. A specific embodiment of the method comprises the following steps: running a target test case; obtaining metadata of a target class through reflection of the target class in a target bytecode called in the target test case; determining, based on the metadata, a dependency relationship between members comprised in the target class; determining real values of the members associated with the dependency relationship based on the running of the target test case; determining a dead branch in a decision structure comprised in the target class based on the real values; and deleting a corresponding statement of the dead branch from a source code corresponding to the target class.