CN111124484A - Java program parameter optimization method - Google Patents

Java program parameter optimization method Download PDF

Info

Publication number
CN111124484A
CN111124484A CN201811289564.6A CN201811289564A CN111124484A CN 111124484 A CN111124484 A CN 111124484A CN 201811289564 A CN201811289564 A CN 201811289564A CN 111124484 A CN111124484 A CN 111124484A
Authority
CN
China
Prior art keywords
parameter
java program
parameters
parameter optimization
variables
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.)
Granted
Application number
CN201811289564.6A
Other languages
Chinese (zh)
Other versions
CN111124484B (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

Images

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 to obtain parameter names and parameter positions of global variables and local variables in the java program, and constructing an array; step 2: performing parameter optimization processing on the java program according to the obtained array of the parameter names and the parameter positions; and step 3: and calling a general function to rewrite the code of the java program. The invention solves the problems that parameters in the prior art are optimized to be error detection property, automatic optimization cannot be carried out, and the maintenance and test cost of programs is high.

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 essential for people to work and live in daily life. Software and applications based on the android system are endless, wherein java language is not only applied to development of a server side, but also widely applied to application development of a mobile phone side.
In the development process of the application program, parameter optimization needs to be carried out on program parameters, and errors in the running process of the program are prevented. Most of the existing java program parameter optimization belongs to the nature of error detection, such as searching for null pointers, invalid parameters and the like, the program cannot be automatically optimized, and the modification of the program still needs a programmer to modify the program, so that the maintenance and test cost of the program is high.
Disclosure of Invention
In view of the above disadvantages of the prior art, the present invention aims to provide a java program parameter optimization method, which is used to solve the problems in the prior art that parameters are optimized to be error detection properties, automatic optimization cannot be performed, and the maintenance and test costs of programs are high.
The invention provides a java program parameter optimization method, which comprises the following steps:
step 1: preprocessing a java program file to obtain parameter names and parameter positions of global variables and local variables in the java program, and constructing an array;
step 2: performing parameter optimization processing on the java program according to the obtained array of the parameter names and the parameter positions;
and step 3: and calling a general function to rewrite the code 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, and judging keywords and symbols for starting and ending; if so, recording circulation by using a stack, judging the starting position and the ending position, establishing an array pair circulation, and storing the judged starting position and the judged ending position;
step 1.3: judging whether the segmented Token tree structure contains words defining data types or user-defined classes, if so, determining whether the segmented Token tree structure contains the words or the user-defined classes according to the positions of the words and the classes in the Token tree structure to obtain local variables or global variables, and creating a new group to store the parameter names and the use positions of the variables.
Further, the local variable is a variable for performing initialization processing in the logic function, and the global variable is a variable at 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 java program performs parameter optimization processing steps as follows:
step 2.1: calculating the life cycle of each parameter and judging whether the parameters are related or not according to the obtained parameter name of the record variable and the array of the using position;
step 2.2: merging the two unrelated parameters and judging whether the parameters are invalid parameters and null pointers, wherein if the parameters are invalid parameters, the java program cannot perform parameter optimization; if the pointer is null, the initial value of the parameter is determined according to the type of the parameter.
Further, the code rewriting is to call a general function and traverse the Token tree structure to execute java program code rewriting.
As described above, the java program parameter optimization method of the present invention has the following beneficial effects:
1. in the invention, the parameters of the java program are automatically optimized, so that the problem of program operation failure caused by a null pointer of the program is reduced.
2. In the invention, a programmer is not required to modify the program parameters, so that 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 present invention;
FIG. 2 is a flow chart of a pre-processing 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 view of a parameter life cycle disclosed in the embodiment of the present invention.
Detailed Description
The embodiments of the present invention are described below with reference to specific embodiments, and other advantages and effects of the present invention will be easily understood by those skilled in the art from the disclosure of the present specification. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present invention, and the components related to the present invention are only shown in the drawings rather than drawn according to the number, shape and size of the components in actual implementation, and the type, quantity and proportion of the components in actual implementation may be changed freely, and the layout of the components may be more complicated.
As shown in fig. 1, the present invention provides a java program parameter optimization method, before performing parameter optimization on a java program, a supported java version needs to be selected, where jdk1.6, jdk1.7 and jdk1.8 are mainly supported; then, carrying out parameter optimization processing on the java program, comprising the following steps:
step 1: preprocessing a java program file to obtain parameter names and parameter positions of global variables and local variables in the java program, and constructing an array;
as shown in fig. 2, firstly, a function is called to segment a character stream of a java program source code, and a Token tree structure is constructed;
then, judging whether the segmented Token tree structure contains function definition loops, and judging whether the segmented Token tree structure contains keywords and symbols for starting and ending, such as: if yes, using a stack to record circulation, judging the starting position and the ending position, creating an array to store the circulation, and judging the starting position and the ending position, thereby realizing the segmentation of the content plate of the java file;
finally, when there is assignment processing, it is determined whether the segmented Token includes a word defining a data type or a user-defined Class, for example: if the parameters exist, determining whether the parameters are local variables or global variables according to the positions of words and classes in the Token tree structure, and creating a number group to store the parameter names and the use positions of the variables, so that the later-stage parameter optimization use is facilitated.
The outermost layer of Token is a global variable, the initialization processing in the logic function for, if, … is a local variable, and the use positions of the recorded variables are the positions of the Token tree structure and the number of lines related to the code.
Step 2: performing parameter optimization processing on the java program according to the obtained array of the parameter names and the parameter positions;
as shown in fig. 3, first, the life cycle of each parameter is calculated according to the obtained array of the names and the use positions of the record variables;
for example, the 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 life cycles of the parameter variables a, b, c are all 2, and the life cycle 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 related to the life cycle, and therefore, it can be seen from the figure that the parameters with the overlapped life cycles are related parameters.
Then judging whether parameters which are not related to the life cycle exist, if so, merging the two parameters which are not related, and if not, the java program can not carry out parameter optimization processing;
for example, the parameter a and the parameter d are two parameters whose life cycles do not overlap, and are subjected to merging processing:
array of parameters (a):
a:{1,2,3};
b:{2,3,4};
c:{3,4,5};
d:{4,5};
and (c) combining the array (a) to obtain an array (b) based on two parameters of which the life cycles are not overlapped, namely the parameter a and the parameter d:
a:{1,2,3,4,5};
b:{2,3,4};
c:{3,4,5};
code optimization to obtain (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 and the life cycles of other parameters are not coincident completely, the parameter is an invalid parameter, the java program cannot carry out parameter optimization processing, and the nodes can be deleted;
for example, the actual form of the merged array (b) is (d):
Figure BDA0001849780570000042
the parameters of the array are the line number of the code, the content is subjected to assignment processing, the non-assignment state is marked when no assignment is carried out, and the parameter is marked as 'parameter use' when the parameter is used for carrying out assignment processing on other variables;
the arrangement form of the array (d) is simplified into a matrix form representation:
Figure BDA0001849780570000041
wherein "1" represents assignment operation, "0" represents use as parameter, "-" represents non-assignment operation or not use, and vertical represents assignment condition of the parameter, when there is 0 in the whole column, then there must be a 1 before 0 of this column, otherwise, it represents that the parameter is not assigned when used, and it is null pointer.
If the pointer is null, the initial value is given according to the parameter type, for example: int type is 0, String type is empty character, and the like, and finally code rewriting is executed according to the tree structure.
In conclusion, the method and the device automatically optimize the parameters of the java program, and reduce the problem that the program fails to run due to the null pointer. Therefore, the invention effectively overcomes various defects in the prior art and has high industrial utilization value.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical spirit of the present invention be covered by the claims of the present invention.

Claims (6)

1. A java program parameter optimization method, comprising the steps of:
step 1: preprocessing a java program file to obtain parameter names and parameter positions of global variables and local variables in the java program, and constructing an array;
step 2: performing parameter optimization processing on the java program according to the obtained array of the parameter names and the parameter positions;
and step 3: and calling a general function to rewrite the code of the java program.
2. The java program parameter optimization method of claim 1, wherein said preprocessing step is 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, and judging keywords and symbols for starting and ending; if so, recording circulation by using a stack, judging the starting position and the ending position, establishing an array pair circulation, and storing the judged starting position and the judged ending position;
step 1.3: judging whether the segmented Token tree structure contains words defining data types or user-defined classes, if so, determining whether the segmented Token tree structure contains the words or the user-defined classes according to the positions of the words and the classes in the Token tree structure to obtain local variables or global variables, and creating a new group to store the parameter names and the use positions of the variables.
3. The java program parameter optimization method of claim 2, wherein: the local variables are variables for initialization processing in the logic function, and the global variables are variables of the outermost layer of Token.
4. The java program parameter optimization method of claim 2, wherein: the parameter use position is the position of the parameter in the Token tree structure and the number of lines related to the code.
5. The java program parameter optimization method of claim 1, wherein the java program performs parameter optimization processing steps as follows:
step 2.1: calculating the life cycle of each parameter and judging whether the parameters are related or not according to the obtained parameter name of the record variable and the array of the using position;
step 2.2: merging the two unrelated parameters and judging whether the parameters are invalid parameters and null pointers, wherein if the parameters are invalid parameters, the java program cannot perform parameter optimization; if the pointer is null, the initial value of the parameter is determined according to the type of the parameter.
6. The java program parameter optimization method of claim 2, wherein the code rewrite is to call a general function to traverse a Token tree structure to perform java program code rewrite.
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 true CN111124484A (en) 2020-05-08
CN111124484B 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, device, equipment and storage medium for acquiring parameter name 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, device, equipment and storage medium for acquiring parameter name and local variable name

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
SHAWN HAGGETT.ET AL: "Tokenisation and compression of java class files", 《JOURNAL OF SYSTEMS ARCHITECTURE》 *
张青: "Java程序的优化", 《青海师范大学学报》(自然科学版), no. 04 *
邓凯: "面向Android平台的PJSIP协议栈优化设计与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》, no. 04 *

Also Published As

Publication number Publication date
CN111124484B (en) 2023-09-01

Similar Documents

Publication Publication Date Title
US10579344B2 (en) Converting visual diagrams into code
CN108139891B (en) Method and system for generating suggestions to correct undefined token errors
CN107924326A (en) The moving method of updated type is covered
CN117033249B (en) Test case generation method and device, computer equipment and storage medium
US12001823B2 (en) Systems and methods for building and deploying machine learning applications
CN108287708A (en) A kind of data processing method, device, server and computer readable storage medium
CN111240772B (en) Block chain-based data processing method, device and storage medium
CN115774552A (en) Configurated algorithm design method and device, electronic equipment and readable storage medium
US8578352B1 (en) Optimizing object oriented programs using limited customization
US11262986B2 (en) Automatic software generation for computer systems
CN116560683A (en) Software updating method, device, equipment and storage medium
CN110069243B (en) Java program thread optimization method
US10338891B2 (en) Migration between model elements of different types in a modeling environment
CN111124484A (en) Java program parameter optimization method
CN116069937A (en) Intelligent contract classification method and device based on neural network and computer equipment
CN116107623A (en) Software development method and device and electronic equipment
EP2488948A2 (en) Maintaining data integrity across execution environments
CN114356379A (en) Backup-based service upgrading method, device, equipment and storage medium
CN114625372A (en) Automatic component compiling method and device, computer equipment and storage medium
US11449317B2 (en) Detection of semantic equivalence of program source codes
CN109308256A (en) A kind of java dynamically analyzing of program method, equipment and storage medium
CN103150408A (en) System and method for finding and accessing database in real-time databases according to roll call
CN118034652B (en) Method for automatically generating service codes
CN118839350A (en) Code repairing method, device, equipment and medium
CN117369861A (en) Thread management policy configuration method and related device for application program

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