Summary of the invention
The invention provides a kind of method and device of removing the flower instruction, it is slow to have solved virtual execution speed, easily analyzes problem out of control.
A kind of method of removing the flower instruction comprises:
Step a: dis-assembling is carried out in the instruction in the core buffer, and preserved the instruction that dis-assembling obtains;
Step b: judge whether the instruction that dis-assembling obtains is to write the internal memory instruction, if, then search and preserve and write the internal memory order register, change steps d, otherwise, change step c;
Step c: judge whether the instruction that dis-assembling obtains is the cycling jump instruction, if, then search and preserve control loop body register, change steps d, otherwise, directly change steps d;
Steps d: judge whether to reach the condition that stops to carry out dis-assembling, if, then change step e, otherwise, step a changeed;
Step e: for any one register of preserving, reversely in all instructions that dis-assembling obtains search the instruction relevant with described register, when the satisfied condition that stops to search, stop to search the instruction relevant with described register;
Step f: behind the dependent instruction of having searched all registers, the instruction different with the dependent instruction of register in all instructions that the deletion dis-assembling obtains.
In the described method, judge whether the instruction that dis-assembling obtains is to write the internal memory instruction to comprise:
Judge whether the destination operand in the instruction that dis-assembling obtains is memory address, if, then be defined as writing the internal memory instruction, otherwise, the internal memory instruction write for non-;
Perhaps, judge whether the instruction that dis-assembling obtains is the implicit operands instruction, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs.
In the described method, if the instruction that dis-assembling obtains is the cycling jump instruction, then searches and preserve control loop body register and comprise:
If the cycling jump instruction is then preserved the ECX register for LOOP instruction, LOOPNE instruction or LOOPZ instruction;
If the cycling jump instruction is the jcc instruction, then reverse first CMP instruction, SUB instruction, TEST instruction, OR instruction or the AND of searching instructs, and preserves CMP order register, SUB order register, TEST order register, OR order register or AND order register;
If the cycling jump instruction is then searched the combined command that can access loop body for the jmp instruction, preserve described combined command register.
In the described method, preservation is write the internal memory order register and is comprised: will write the internal memory order register and be saved in the register chained list;
Preserving control loop body register comprises: will control the loop body register holds in the register chained list;
Be specially for any one register of preserving: for any one register in the register chained list.
In the described method, judge whether to reach the condition that stops to carry out dis-assembling and be specially:
Judge whether the instruction that dis-assembling obtains is the loop body END instruction;
Perhaps, judge whether the quantity that dis-assembling is instructed reaches default quantity.
In the described method, the satisfied condition that stops to search is specially and finds the instruction that data is read CPU from internal memory.
A kind of device of removing the flower instruction comprises:
The dis-assembling unit is used for dis-assembling is carried out in the instruction of buffer zone, and preserves the instruction that dis-assembling obtains;
First judging unit is used for judging whether the instruction that dis-assembling obtains is to write the internal memory instruction;
Storage unit, be used for when instruction that the first judgment unit judges dis-assembling obtains be when writing internal memory and instructing, search and preserve and write the internal memory order register;
Second judging unit, be used for the instruction that the first judgment unit judges dis-assembling obtains be non-write the internal memory instruction after, judge whether the instruction that dis-assembling obtains is the cycling jump instruction, if then storage unit is searched and preserved and controls the loop body register;
The 3rd judging unit, be used for after instruction that the first judgment unit judges dis-assembling obtains is to write internal memory and instruct, perhaps after whether instruction that the second judgment unit judges dis-assembling obtains is the cycling jump instruction, judge whether to reach the condition that stops to carry out dis-assembling, if do not reach the condition that stops to carry out dis-assembling, then there is the dis-assembling unit that the next instruction of buffer zone is carried out dis-assembling;
Search the unit, be used for the 3rd judgment unit judges reach stop to carry out the condition of dis-assembling after, any one register for the storage unit preservation, in the dis-assembling unit carries out all instructions that dis-assembling obtains, reversely search the instruction relevant with described register, when satisfying when stopping search criterion, stop to search the instruction relevant with described register;
Comparing unit is used for after searching the unit and having searched the dependent instruction of all registers, the instruction different with the dependent instruction of register during all of deleting that dis-assembling obtains are instructed.
In the described device, first judging unit specifically is used for judging whether the destination operand of the instruction that dis-assembling obtains is memory address, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs;
Perhaps, first judging unit is used for specifically judging whether the instruction that dis-assembling obtains is the implicit operands instruction, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs.
In the described device, be LOOP instruction, LOOPNE instruction or LOOPZ instruction if second judgment unit judges goes out the cycling jump instruction, then storage unit is preserved the ECX register;
If going out the cycling jump instruction, second judgment unit judges is the jcc instruction, then reverse first CMP instruction, SUB instruction, TEST instruction, OR instruction or the AND of searching instructs, and then storage unit is preserved CMP order register, SUB order register, TEST order register, OR order register or AND order register;
Be the jmp instruction if second judgment unit judges goes out the cycling jump instruction, then storage unit is searched the combined command that can access loop body, and preserves described order register.
In the described device, storage unit specifically is used for writing the internal memory order register and is saved in the register chained list;
Storage unit is preserved control loop body register and is comprised: will control the loop body register holds in the register chained list;
Be specially for any one register of preserving: for any one register in the register chained list.
In the described device, the 3rd judging unit specifically is used for judging whether the instruction that dis-assembling obtains is the loop body END instruction;
Perhaps, the 3rd judging unit is used for specifically judging whether the quantity of dis-assembling instruction reaches default quantity.
In the described device, the satisfied condition that stops to search is specially and finds the instruction that data is read CPU from internal memory.
The invention provides a kind of method and apparatus of removing the flower instruction, by dis-assembling is carried out in the instruction in the buffer zone, and preserve the instruction that all dis-assemblings obtain, preserve all writing the internal memory instruction and write the internal memory order register, according to writing the internal memory order register, reversely search all instructions that dis-assembling obtains, find all instructions relevant with writing the internal memory order register, all instructions that dis-assembling is obtained compare with the register dependent instruction, delete different instructions, the instruction of deletion is the flower instruction, and the instruction of deletion flower does not influence the normal operation of program, and it is slow to have solved virtual execution speed, easily analyzes problem out of control.
Description of drawings
In order to be illustrated more clearly in the present invention or technical scheme of the prior art, to do to introduce simply to the accompanying drawing of required use in embodiment or the description of the Prior Art below, apparently, the accompanying drawing that describes below only is some embodiment that put down in writing among the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
Fig. 1 is a kind of method flow diagram of removing the flower instruction provided by the invention;
Fig. 2 is a kind of apparatus structure synoptic diagram of removing the flower instruction provided by the invention.
Embodiment
In order to make those skilled in the art person understand technical scheme in the embodiment of the invention better, and above-mentioned purpose of the present invention, feature and advantage can be become apparent more, below in conjunction with accompanying drawing technical scheme among the present invention is described in further detail.
The invention provides a kind of method and device of removing the flower instruction, it is slow to have solved virtual execution speed, easily analyzes problem out of control.
The invention provides a kind of method of removing the flower instruction, comprising:
Step a: dis-assembling is carried out in the instruction in the core buffer, and preserved the instruction that dis-assembling obtains;
Step b: judge whether the instruction that dis-assembling obtains is to write the internal memory instruction, if, then search and preserve and write the internal memory order register, change steps d, otherwise, change step c;
Step c: judge whether the instruction that dis-assembling obtains is the cycling jump instruction, if, then search and preserve control loop body register, change steps d, otherwise, directly change steps d;
Steps d: judge whether to reach the condition that stops to carry out dis-assembling, if, then change step e, otherwise, step a changeed;
Step e: for any one register of preserving, reversely in all instructions that dis-assembling obtains search the instruction relevant with described register, when the satisfied condition that stops to search, stop to search the instruction relevant with described register;
Step f: behind the dependent instruction of having searched all registers, the instruction different with the dependent instruction of register in all instructions that the deletion dis-assembling obtains.
In the described method, judge whether the instruction that dis-assembling obtains is to write the internal memory instruction to comprise:
Judge whether the destination operand in the instruction that dis-assembling obtains is memory address, if, then be defined as writing the internal memory instruction, otherwise, the internal memory instruction write for non-;
Perhaps, judge whether the instruction that dis-assembling obtains is the implicit operands instruction, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs.
In the described method, if the instruction that dis-assembling obtains is the cycling jump instruction, then searches and preserve control loop body register and comprise:
If the cycling jump instruction is then preserved the ECX register for LOOP instruction, LOOPNE instruction or LOOPZ instruction;
If the cycling jump instruction is the jcc instruction, then reverse first CMP instruction, SUB instruction, TEST instruction, OR instruction or the AND of searching instructs, and preserves CMP order register, SUB order register, TEST order register, OR order register or AND order register;
If the cycling jump instruction is then searched the combined command that can access loop body for the jmp instruction, preserve described combined command register.
In the described method, preservation is write the internal memory order register and is comprised: will write the internal memory order register and be saved in the register chained list;
Preserving control loop body register comprises: will control the loop body register holds in the register chained list;
Be specially for any one register of preserving: for any one register in the register chained list.
In the described method, judge whether to reach the condition that stops to carry out dis-assembling and be specially:
Judge whether the instruction that dis-assembling obtains is the loop body END instruction;
Perhaps, judge whether the quantity that dis-assembling is instructed reaches default quantity.
In the described method, the satisfied condition that stops to search is specially and finds the instruction that data is read CPU from internal memory.
In conjunction with the application of said method, the technical scheme that the present invention relates to done further illustrating, the invention provides a kind of method of removing the flower instruction, as shown in Figure 1, comprising:
S101: dis-assembling is carried out in the instruction in the core buffer, and preserved the instruction that dis-assembling obtains;
S102: judge whether the instruction that dis-assembling obtains is to write the internal memory instruction, if, then carry out S103, otherwise, S104 carried out;
S103: search and preserve all and write the internal memory order register in the register chained list, carry out S106;
Searching and preserve all writes the internal memory order register and comprises to the register chained list:
When writing internal memory instruction and instruct for STOS, directly record register EAX, EDI;
When writing internal memory instruction and instruct for pop, if described pop instruction operation note then records operated register, and reverse first push that finds instructs, and records the phase register;
Other situations then directly record register.
S104: judge whether it is the cycling jump instruction, if then carry out S105, otherwise directly carry out S106;
S105: search and preserve control loop body register to the register chained list, carry out S106;
S106: judge whether to arrive the condition that stops to carry out dis-assembling;
S107: according to any one register that records in the register chained list, reverse searching and storage and described register dependent instruction in the command chain that dis-assembling obtains one by one, when finding when data are read the instruction of CPU from internal memory, stop searching current register;
S108: the instruction different with the register dependent instruction in all instructions that the deletion dis-assembling obtains.
Judge whether the instruction that dis-assembling obtains is to write the internal memory instruction to comprise:
Judge whether the destination operand in the instruction that dis-assembling obtains is memory address, if, then be defined as writing the internal memory instruction, otherwise, the internal memory instruction write for non-;
Perhaps, judge whether the instruction that dis-assembling obtains is the implicit operands instruction, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs.
If the instruction that dis-assembling obtains is the cycling jump instruction, then searches and preserve control loop body register and comprise:
If the cycling jump instruction is then preserved the ECX register for LOOP instruction, LOOPNE instruction or LOOPZ instruction;
If the cycling jump instruction is the jcc instruction, then reverse first CMP instruction, SUB instruction, TEST instruction, OR instruction or the AND of searching instructs, and preserves CMP order register, SUB order register, TEST order register, OR order register or AND order register;
If the cycling jump instruction is then searched the combined command that can access loop body for the jmp instruction, preserve described combined command register.
Judging whether to reach the condition that stops to carry out dis-assembling is specially:
Judge whether the instruction that dis-assembling obtains is the loop body END instruction;
Perhaps, judge whether the quantity that dis-assembling is instructed reaches default quantity.
The present invention also provides a kind of device of removing the flower instruction, comprising:
Dis-assembling unit 201 is used for dis-assembling is carried out in the instruction of buffer zone, and preserves the instruction that dis-assembling obtains;
First judging unit 202 is used for judging whether the instruction that dis-assembling obtains is to write the internal memory instruction;
Storage unit 203, being used for judging instruction that dis-assemblings obtain when first judging unit 202 is when writing internal memory and instructing, and searches and preserve to write the internal memory order register;
Second judging unit 204, be used for first judging unit 202 judge instruction that dis-assemblings obtain be non-write the internal memory instruction after, judge whether the instruction that dis-assembling obtains is the cycling jump instruction, if then control loop body register is searched and preserved to storage unit 203;
The 3rd judging unit 205, be used for after first judging unit 202 judges that instruction that dis-assemblings obtain is to write internal memory and instruct, perhaps after second judging unit 204 judges whether instruction that dis-assembling obtains is the cycling jump instruction, judge whether to reach the condition that stops to carry out dis-assembling, if do not reach the condition that stops to carry out dis-assembling, then by the dis-assembling unit next instruction in the buffer zone is carried out dis-assembling;
Search unit 206, be used for the 3rd judging unit 205 judge reach stop to carry out the condition of dis-assembling after, any one register for the storage unit preservation, in dis-assembling unit 201 carries out all instructions that dis-assembling obtains, reversely search the instruction relevant with described register, when satisfying when stopping search criterion, stop to search the instruction relevant with described register;
Comparing unit 207 is used for after searching unit 206 and having searched the dependent instruction of all registers, the instruction different with the dependent instruction of register during all of deleting that dis-assembling obtains are instructed.
In the described device, first judging unit 202 specifically is used for judging whether the destination operand of the instruction that dis-assembling obtains is memory address, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs;
Perhaps, first judging unit 202 judges whether the instruction that dis-assembling obtains is the implicit operands instruction, if, then be defined as writing the internal memory instruction, otherwise, for the non-internal memory of writing instructs.
In the described device, be LOOP instruction, LOOPNE instruction or LOOPZ instruction if second judging unit 204 is judged the cycling jump instruction, then storage unit is preserved the ECX register;
If judging the cycling jump instruction, second judging unit 204 is the jcc instruction, then reverse first CMP instruction, SUB instruction, TEST instruction, OR instruction or the AND of searching instructs, and then storage unit is preserved CMP order register, SUB order register, TEST order register, OR order register or AND order register;
Be the jmp instruction if second judging unit 204 is judged the cycling jump instruction, then storage unit 203 is searched the combined command that can access loop body, and preserves described order register.
In the described device, storage unit 203 specifically is used for writing the internal memory order register and is saved in the register chained list;
Storage unit 203 is concrete for controlling the loop body register holds to the register chained list;
Be specially for any one register of preserving: for any one register in the register chained list.
In the described device, the 3rd judging unit 205 is concrete for judging whether the instruction that dis-assembling obtains is the loop body END instruction;
Perhaps, the 3rd judging unit 205 is concrete for judging whether the quantity that dis-assembling is instructed reaches default quantity.
In the described device, the satisfied condition that stops to search is specially and finds the instruction that data is read CPU from internal memory.
The invention provides a kind of method and apparatus of removing the flower instruction, by dis-assembling is carried out in the instruction in the buffer zone, and preserve the instruction that all dis-assemblings obtain, preserve all writing the internal memory instruction and write the internal memory order register, according to writing the internal memory order register, reversely search all instructions that dis-assembling obtains, find all instructions relevant with writing the internal memory order register, all instructions that dis-assembling is obtained compare with the register dependent instruction, delete different instructions, the instruction of deletion is the flower instruction, and the instruction of deletion flower does not influence the normal operation of program.
Though described the present invention by embodiment, those of ordinary skills know, the present invention has many distortion and variation and do not break away from spirit of the present invention, wish that appended claim comprises these distortion and variation and do not break away from spirit of the present invention.