CN111124484B - Java program parameter optimization method - Google Patents

Java program parameter optimization method Download PDF

Info

Publication number
CN111124484B
CN111124484B CN201811289564.6A CN201811289564A CN111124484B CN 111124484 B CN111124484 B CN 111124484B CN 201811289564 A CN201811289564 A CN 201811289564A CN 111124484 B CN111124484 B CN 111124484B
Authority
CN
China
Prior art keywords
parameter
java program
parameters
tree structure
array
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811289564.6A
Other languages
Chinese (zh)
Other versions
CN111124484A (en
Inventor
陆辰姣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Ordox Network Technology Co ltd
Original Assignee
Shanghai Ordox Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Ordox Network Technology Co ltd filed Critical Shanghai Ordox Network Technology Co ltd
Priority to CN201811289564.6A priority Critical patent/CN111124484B/en
Publication of CN111124484A publication Critical patent/CN111124484A/en
Application granted granted Critical
Publication of CN111124484B publication Critical patent/CN111124484B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a java program parameter optimization method, which relates to the field of program parameter optimization, and comprises the following steps: step 1: preprocessing a java program file, obtaining the parameter names and the parameter positions of global variables and local variables in the java program, and constructing an array; step 2: carrying out parameter optimization processing on the java program according to the acquired array of the parameter names and the parameter positions; step 3: and calling the general function to rewrite codes of the java program. The invention solves the problems that the parameter optimization is error detection property, automatic optimization can not be carried out, and the maintenance and test cost of the program is higher in the prior art.

Description

Java program parameter optimization method
Technical Field
The invention relates to the field of program parameter optimization, in particular to a java program parameter optimization method.
Background
With the rapid development of information technology, mobile phones have become a necessity for people to work and live daily. Software and application layers based on the android system are endless, wherein java language is widely applied to development of a server side and application development of a mobile phone side.
In the development process of the application program, parameter optimization is needed to be carried out on the program parameters, so that the program is prevented from being in error in the running process. Most of the existing java program parameter optimization belongs to error detection properties, such as searching for null pointers, invalid parameters and the like, the program cannot be automatically optimized, and the program is modified or needs to be modified by a programmer, so that the maintenance and test costs of the program are high.
Disclosure of Invention
In view of the above drawbacks of the prior art, the present invention is directed to providing a java program parameter optimization method, which is used for solving the problems that parameters are optimized to be error detection property, automatic optimization cannot be performed, and maintenance and test costs of a program are high in the prior art.
The invention provides a java program parameter optimization method, which comprises the following steps:
step 1: preprocessing a java program file, obtaining the parameter names and the parameter positions of global variables and local variables in the java program, and constructing an array;
step 2: carrying out parameter optimization processing on the java program according to the acquired array of the parameter names and the parameter positions;
step 3: and calling the general function to rewrite codes of the java program.
Further, the preprocessing steps are as follows:
step 1.1: segmenting a character stream of a java program source code, and constructing a Token tree structure;
step 1.2: judging whether the segmented Token tree structure contains function definition loops or not, judging, and starting and ending keywords and symbols; if yes, using stack record circulation, judging start and end positions, creating an array pair circulation, and judging the start and end positions for storage;
step 1.3: judging whether the segmented Token tree structure contains words defining data types or custom classes of users, if so, determining whether the segmented Token tree structure is a local variable or a global variable according to the positions of the words and the classes in the Token tree structure, and creating an array to store the parameter names and the use positions of the variables.
Further, the local variable is a variable for initializing processing in the logic function, and the global variable is a variable of the outermost layer of Token.
Further, the parameter use position is the position of the parameter in the Token tree structure and the number of lines related to the code.
Further, the step of parameter optimization processing by the java program is as follows:
step 2.1: calculating the life cycle of each parameter according to the acquired parameter name of the record variable and the array of the use position, and judging whether the parameters are associated;
step 2.2: combining the two unassociated parameters, judging whether the parameters are invalid parameters and null pointers, and if the parameters are invalid parameters, disabling parameter optimization processing by the java program; if the pointer is null pointer, the parameter is initialized according to the parameter type.
Further, the code rewriting is to call a general function, traverse the Token tree structure and execute java program code rewriting.
As described above, the java program parameter optimization method provided by the invention has the following beneficial effects:
1. according to the invention, the parameters of the java program are automatically optimized, so that the problem that the program fails to run because of a null pointer is solved.
2. In the invention, the programmer is not required to modify the program parameters, and the maintenance and test cost of the program is reduced.
Drawings
FIG. 1 is a flow chart of a parameter optimization method disclosed in an embodiment of the invention;
FIG. 2 is a flowchart of a pre-process disclosed in an embodiment of the present invention;
FIG. 3 is a flow chart of a parameter optimization process disclosed in an embodiment of the present invention;
fig. 4 is a schematic diagram of a parameter life cycle disclosed in an embodiment of the present invention.
Detailed Description
Other advantages and effects of the present invention will become apparent to those skilled in the art from the following disclosure, which describes the embodiments of the present invention with reference to specific examples. The invention may be practiced or carried out in other embodiments that depart from the specific details, and the details of the present description may be modified or varied from the spirit and scope of the present invention. It should be noted that the following embodiments and features in the embodiments may be combined with each other without conflict.
It should be noted that the illustrations provided in the following embodiments merely illustrate the basic concept of the present invention by way of illustration, and only the components related to the present invention are shown in the drawings and are not drawn according to the number, shape and size of the components in actual implementation, and the form, number and proportion of the components in actual implementation may be arbitrarily changed, and the layout of the components may be more complicated.
As shown in FIG. 1, the invention provides a java program parameter optimization method, which is characterized in that before parameter optimization is performed on a java program, a supported java version is required to be selected, wherein jdk1.6, jdk1.7 and jdk1.8 are mainly supported; then, parameter optimization processing is carried out on the java program, and the method comprises the following steps:
step 1: preprocessing a java program file, obtaining the parameter names and the parameter positions of global variables and local variables in the java program, and constructing an array;
as shown in fig. 2, firstly, calling a function to divide a character stream of a java program source code, and constructing a Token tree structure;
then, judging whether the segmented Token tree structure contains function definition loops, judging, starting and ending keywords and symbols, for example: "while, for, do … while, if, else", and brackets and semicolons, if any, use the stack record circulation, judge the start and end position, and establish an array pair circulation, judge the start and end position to preserve, thus realize the segmentation to the java file content plate;
finally, when assignment processing exists, whether the segmented Token contains words with defined data types or custom classes is judged, for example: if the character exists, whether the character is a local variable or a global variable is determined according to the positions of words and classes in the Token tree structure, and an array is newly established to store the parameter names and the use positions of the variables, so that the optimization and the use of later parameters are facilitated.
The global variable is the outermost layer of Token, the local variable is initialized in the logic functions of 'for, if and …', and the recorded using positions of the variables are the positions of the Token tree structure and the number of lines related to codes.
Step 2: carrying out parameter optimization processing on the java program according to the acquired array of the parameter names and the parameter positions;
as shown in fig. 3, the life cycle of each parameter is calculated first according to the acquired name of the record variable and the array of the use positions;
for example, code:
1:a=1;
2:b=a+3;
3:c=a+b;
4:d=c+b;
5:System.out.println(c+d);
as shown in fig. 4, the lifecycle of the parameter variables a, b, c is 2 and the lifecycle of d is 1.
The parameter a is used when the parameter b is defined, so the parameter a and the parameter b are parameters associated with the life cycle, and therefore, it can be seen from the figure that the parameters with overlapping life cycles are the associated parameters.
Then judging whether parameters which are not associated with the life cycle exist or not, if so, combining the two parameters which are not associated with each other, and if not, enabling the java program to not perform parameter optimization;
for example, the parameters a and d are two parameters whose period is not overlapped, and the two parameters are combined:
array of parameters (a):
a:{1,2,3};
b:{2,3,4};
c:{3,4,5};
d:{4,5};
based on the parameters of which the life cycles are not overlapped, combining the array (a) to obtain an array (b):
a:{1,2,3,4,5};
b:{2,3,4};
c:{3,4,5};
code optimization results in (c):
1:a=1;
2:b=a+3;
3:c=a+b;
4:a=c+b;
5:System.out.println(c+a);
in the process of parameter combination, if the life cycle of the parameter is completely misaligned with the life cycle of other parameters, the parameter is invalid, the java program cannot perform parameter optimization processing, and the node can be deleted;
wherein, for whether the parameter is a null pointer, a judgment needs to be made on the starting node of the parameter after merging, if the actual form after merging of the array (b) is (d):
the parameters of the array are the number of lines of the codes, the content is subjected to assignment processing, the non-assignment is marked when no assignment is performed, and the non-assignment is marked as "parameter use" when other variables are subjected to assignment processing as parameters;
the array form of the array (d) is simplified into a matrix form representation:
where "1" indicates an assignment operation, "0" indicates use as a parameter, "-" indicates a non-assignment operation or not, and vertical indicates an assignment of the parameter, when there is a 0 in the entire column, then there must be a 1 before the 0 in this column, otherwise it indicates that the parameter has not been assigned when in use, and is a null pointer.
If the pointer is null, the initial value is given according to the parameter type, for example: and the Int type is 0, the string type is blank text, and the like, and finally, the code rewriting is executed according to the tree structure.
In summary, the method and the device automatically optimize the parameters of the java program, and reduce the problem that the program fails to run because of the null pointer. Therefore, the invention effectively overcomes various defects in the prior art and has high industrial utilization value.
The above embodiments are merely illustrative of the principles of the present invention and its effectiveness, and are not intended to limit the invention. Modifications and variations may be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the invention. Accordingly, it is intended that all equivalent modifications and variations of the invention be covered by the claims, which are within the ordinary skill of the art, be within the spirit and scope of the present disclosure.

Claims (2)

1. A method for optimizing parameters of a java program, the method comprising the steps of:
step 1: preprocessing a java program file, obtaining the parameter names and the parameter positions of global variables and local variables in the java program, and constructing an array;
step 2: carrying out parameter optimization processing on the java program according to the acquired array of the parameter names and the parameter positions;
step 3: calling a general function to rewrite codes of java programs;
the pretreatment steps are as follows: step 1.1: segmenting a character stream of a java program source code, and constructing a Token tree structure;
step 1.2: judging whether the segmented Token tree structure contains function definition loops or not, judging, and starting and ending keywords and symbols; if yes, using stack record circulation, judging start and end positions, creating an array pair circulation, and judging the start and end positions for storage;
step 1.3: judging whether the segmented Token tree structure contains words defining data types or custom classes of users, if so, determining whether the segmented Token tree structure is a local variable or a global variable according to the positions of the words and the classes in the Token tree structure, and creating an array to store the parameter names and the use positions of the variables;
the local variable is a variable for initializing processing in the logic function, and the global variable is a variable of the outermost layer of Token;
the parameter use position is the position of the parameter in the Token tree structure and the number of lines related to codes;
the parameter optimization processing steps of the java program are as follows: step 2.1: calculating the life cycle of each parameter according to the acquired parameter name of the record variable and the array of the use position, and judging whether the parameters are associated;
step 2.2: the method comprises the steps of carrying out combination processing on two parameters which are not related, judging whether the parameters are invalid parameters and null pointers, if the life cycle of the parameters is not coincident with the life cycle of other parameters in the parameter combination process, carrying out parameter optimization processing on the parameters by a java program, and deleting nodes of the invalid parameters; if the pointer is null pointer, the parameter is initialized according to the parameter type.
2. The method for optimizing parameters of a java program according to claim 1, wherein the code rewriting is a general function call, and the java program code rewriting is performed by traversing a Token tree structure.
CN201811289564.6A 2018-10-31 2018-10-31 Java program parameter optimization method Active CN111124484B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811289564.6A CN111124484B (en) 2018-10-31 2018-10-31 Java program parameter optimization method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811289564.6A CN111124484B (en) 2018-10-31 2018-10-31 Java program parameter optimization method

Publications (2)

Publication Number Publication Date
CN111124484A CN111124484A (en) 2020-05-08
CN111124484B true CN111124484B (en) 2023-09-01

Family

ID=70494075

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811289564.6A Active CN111124484B (en) 2018-10-31 2018-10-31 Java program parameter optimization method

Country Status (1)

Country Link
CN (1) CN111124484B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1754151A (en) * 2000-09-21 2006-03-29 国际商业机器公司 Mutability analysis in java
JP2012014526A (en) * 2010-07-01 2012-01-19 Hitachi Ltd Structure conversion apparatus for program code, and code structure conversion program
CN102736973A (en) * 2011-04-07 2012-10-17 中国科学技术大学 Invariant-booted random test case automatic generation method
CN103218296A (en) * 2013-04-22 2013-07-24 北京邮电大学 Method of fully detecting null pointer reference defects
WO2014176950A1 (en) * 2013-05-03 2014-11-06 飞天诚信科技股份有限公司 Method for protecting java programs
CN107861807A (en) * 2017-11-20 2018-03-30 北京奇虎科技有限公司 The optimization method and device of routine call
CN108628635A (en) * 2018-05-07 2018-10-09 广州视源电子科技股份有限公司 Method, apparatus, equipment and the storage medium of the name that gets parms and local variable name

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1754151A (en) * 2000-09-21 2006-03-29 国际商业机器公司 Mutability analysis in java
JP2012014526A (en) * 2010-07-01 2012-01-19 Hitachi Ltd Structure conversion apparatus for program code, and code structure conversion program
CN102736973A (en) * 2011-04-07 2012-10-17 中国科学技术大学 Invariant-booted random test case automatic generation method
CN103218296A (en) * 2013-04-22 2013-07-24 北京邮电大学 Method of fully detecting null pointer reference defects
WO2014176950A1 (en) * 2013-05-03 2014-11-06 飞天诚信科技股份有限公司 Method for protecting java programs
CN107861807A (en) * 2017-11-20 2018-03-30 北京奇虎科技有限公司 The optimization method and device of routine call
CN108628635A (en) * 2018-05-07 2018-10-09 广州视源电子科技股份有限公司 Method, apparatus, equipment and the storage medium of the name that gets parms and local variable name

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
面向Android平台的PJSIP协议栈优化设计与实现;邓凯;《中国优秀硕士学位论文全文数据库 信息科技辑》(第04期);全文 *

Also Published As

Publication number Publication date
CN111124484A (en) 2020-05-08

Similar Documents

Publication Publication Date Title
US10579344B2 (en) Converting visual diagrams into code
CN106796522B (en) System and method for updating source code file
US10951492B2 (en) System and a method for automatic conversion of monolithic services to micro-services
WO2021137757A1 (en) Authority management method and apparatus, and electronic device, and storage medium thereof
CN103092742A (en) Optimization method and system of program logging
AU2017216248B2 (en) Systems and methods for generating electronic document templates and electronic documents
US20170220613A1 (en) Systems and methods for database orientation transformation
CN106873952B (en) Data processing system and method for mobile terminal webpage development and application device
CN104407863A (en) Abstract control model programming device and method
US20170315830A1 (en) On-demand loading of dynamic scripting language code for reduced memory usage
CN107305488A (en) One kind application method for internationalizing, device and terminal
CN111324619A (en) Object updating method, device, equipment and storage medium in micro service system
CN111240772A (en) Data processing method and device based on block chain and storage medium
CN111124484B (en) Java program parameter optimization method
CN117033249A (en) Test case generation method and device, computer equipment and storage medium
US10338891B2 (en) Migration between model elements of different types in a modeling environment
CN111666216B (en) Intelligent contract analysis method and device
CN102270126B (en) Method and equipment for quickly determining interface code and test script parameter value
US9250878B1 (en) Function attribute for dynamic stack allocation
CN109426720B (en) Interface parameter verification method and related device
CN116400927B (en) Code block translation method and device, electronic equipment and storage medium
CN114237732A (en) Special ring script engine and script operation method
CN115983624A (en) Design method, device and equipment for arranging wind control strategy
CN116244536A (en) Resource reference control method and system for low-code platform
CN113408597A (en) Java method name recommendation method based on two-stage framework

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant