# US 2013/0159678 A1 · Code optimization by memory barrier removal and enclosure within transaction

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2013/0159678 A1
- Document ID: US20130159678A1
- Status: Published application
- Kind: A1
- Application number: 13/326,320
- Filed: 2011-12-15
- Published: 2013-06-20
- Earliest claimed: 2011-12-15
- Assignees: International Business Machines Corporation
- Inventors: Toshihiko Koju; Takuya Nakaike; Ali Ijaz Sheikh; Harold Wade Cain, III; Maged M. Michael
- Web page: https://patentgrep.com/patent/US20130159678A1

## CPC

- G06F 9/30087: {Synchronisation or serialisation instructions}
- G06F 8/4441: {Reducing the execution time required by the program code}
- G06F 8/458: {Synchronisation, e.g. post-wait, barriers, locks (synchronisation among tasks G06F9/52)}
- G06F 9/467: {Transactional memory (G06F9/528 takes precedence)}
- G06F 9/522: {Barrier synchronisation}
- G06F 11/3409: {for performance assessment}
- G06F 9/3004: {to perform operations on memory}
- G06F 9/30043: {LOAD or STORE instructions; Clear instruction}
- G06F 9/466: {Transaction processing}
- G06F 11/3466: {Performance evaluation by tracing or monitoring}
- G06F 2201/81: Threshold
- G06F 2201/865: Monitoring of software
- G06F 2201/88: Monitoring involving counting
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A code section of a computer program to be executed by a computing device includes memory barrier instructions. Where the code section satisfies a threshold, the code section is modified, by enclosing the code section within a transaction that employs hardware transactional memory of the computing device, and removing the memory barrier instructions from the code section. Execution of the code section as has been enclosed within the transaction can be monitored to yield monitoring results. Where the monitoring results satisfy an abort threshold corresponding to excessive aborting of the execution of the code section as has been enclosed within the transaction, the code section is split into code sub-sections, and each code sub-section enclosed within a separate transaction that employs the hardware transactional memory. Splitting the code section sections and enclosing each code sub-section within a separate transaction can decrease occurrence of the code section aborting during execution.

## Claims

### Claim 1

A method comprising:
receiving, by a processor, a code section of a computer program to be executed by a computing device, the code section including one or more memory barrier instructions;
determining, by the processor, whether the code section satisfies one or more thresholds;
responsive to determining that the code section satisfies the thresholds, modifying the code section by:
enclosing, by the processor, the code section within a transaction that employs hardware transactional memory of the computing device, such that an entirety of the code section is executed or none of the code section is executed; and,
removing, by the processor, the memory barrier instructions from the code section.

### Claim 2 (depends on 1)

The method of claim 1, wherein execution of the memory barrier instructions has a first associated processing cost and employing the hardware transactional memory has a second associated processing cost,
and wherein the thresholds comprise the second associated processing cost being less than the first associated processing cost.

### Claim 3 (depends on 1)

The method of claim 1, wherein the hardware transactional memory has a memory size and the transaction enclosing the code section has an estimated transaction size,
and wherein the thresholds comprise the estimated transaction size being less than the memory size.

### Claim 4 (depends on 1)

The method of claim 1, wherein the threshold comprise the code section including no calls to functions outside of the code section.

### Claim 5 (depends on 1)

The method of claim 1, wherein enclosing the code section within the transaction comprises:
adding a transaction-start instruction prior to a first instruction within the code section;
adding a transaction-end instruction after the last instruction within the code section, the transaction-end instruction corresponding to non-exceptional and normal exit from the code section; and,
adding a transaction-abort instruction.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
monitoring, by the processor, execution of the code section as has been enclosed within the transaction, to yield monitoring results;
determining, by the processor, whether the monitoring results satisfy an abort threshold, the abort threshold corresponding to excessive aborting of the execution of the code section as has been enclosed within the transaction;
responsive to determining that the monitoring results satisfy the abort threshold:
splitting the code section into a plurality of code sub-sections;
enclosing each code sub-section within a separate transaction that employs the hardware transactional memory of the computing device,
wherein splitting the code section into the code sub-sections and enclosing each code sub-section within a separate transaction are adapted to decreasing occurrence of aborting of the execution of the code section.

### Claim 7 (depends on 6)

The method of claim 6, wherein splitting the code section into the code sub-sections comprises, where the monitoring results indicate that a primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that an actual transaction size of the transaction is exceeding a memory size of the hardware transactional memory,
splitting the code section into the code sub-sections such that each instruction of all instructions of the code section is assigned to one of the code sub-sections.

### Claim 8 (depends on 6)

The method of claim 6, wherein splitting the code section into the code sub-sections comprises, where the monitoring results indicate that a primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that a particular instruction of the code section is causing a memory conflict,
splitting the code section into the code sub-sections such that the particular instruction is not assigned to any of the code sub-sections,
such that the particular instruction is not part of any transaction that employs the hardware transactional memory,
and such that one of the code sub-sections is located immediately prior to the particular instruction and is enclosed within a first separate transaction, and another of the code sub-sections is located immediately after the particular instruction and is enclosed within a second separate transaction.

### Claim 9 (depends on 1)

The method of claim 1, wherein modifying the code section further comprises, prior to enclosing the code section within the transaction:
monitoring, by the processor, execution of the code section to acquire information regarding the code section;
revising, by the processor, the code section, based on the information acquired, so that the code section is better optimized for subsequent enclosure within the transaction.

### Claim 10

A computer program product comprising a computer-readable storage medium having computer-readable code embodied therein and executable by a processor to modify a code section of a computer program to be executed by a computing device, the code section including one or more memory barrier instructions, wherein modifying the code section comprises:
enclosing the code section within a transaction that employs hardware transactional memory of the computing device, such that an entirety of the code section is executed or none of the code section is executed; and,
removing the memory barrier instructions from the code section.

### Claim 11 (depends on 10)

The computer program product of claim 10, wherein modifying the code section is responsive to the computer-readable code determining that the code section satisfies one or more thresholds, each threshold comprising one of:
a first processing cost being greater than a second processing cost, the first processing cost associated with execution of the memory barrier instructions, the second processing cost associated with employing the hardware transactional memory;
an estimated transaction size of the transaction enclosing the code section being less than a memory size of the hardware transactional memory;
the code section including no calls to functions outside the code section.

### Claim 12 (depends on 10)

The computer program product of claim 10, wherein enclosing the code section within the transaction comprises:
adding a transaction-start instruction prior to a first instruction within the code section;
adding a transaction-end instruction after the last instruction within the code section, the transaction-end instruction corresponding to non-exceptional and normal exit from the code section; and,
adding a transaction-abort instruction.

### Claim 13 (depends on 10)

The computer program product of claim 10, wherein the computer-readable code is further executable by the processor to:
monitor execution of the code section as has been enclosed within the transaction, to yield monitoring results;
determine whether the monitoring results satisfy an abort threshold, the abort threshold corresponding to excessive aborting of the execution of the code section as has been enclosed within the transaction;
responsive to determining that the monitoring results satisfy the abort threshold:
split the code section into a plurality of code sub-sections;
enclose each code sub-section within a separate transaction that employs the hardware transactional memory of the computing device,
wherein splitting the code section into the code sub-sections and enclosing each code sub-section within a separate transaction are adapted to decreasing occurrence of aborting of the execution of the code section.

### Claim 14 (depends on 13)

The computer program product of claim 13, wherein splitting the code section into the code sub-sections comprises:
where the monitoring results indicate that a primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that an actual transaction size of the transaction is exceeding a memory size of the hardware transactional memory,
splitting the code section into the code sub-sections such that each instruction of all instructions of the code section is assigned to one of the code sub-sections;
where the monitoring results indicate that the primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that a particular instruction of the code section is causing a memory conflict,
splitting the code section into the code sub-sections such that the particular instruction is not assigned to any of the code sub-sections, such that the particular instruction is not part of any transaction that employs the hardware transactional memory, and such that one of the code sub-sections is located immediately prior to the particular instruction and is enclosed within a first separate transaction, and another of the code sub-sections is located immediately after the particular instruction and is enclosed within a second separate transaction.

### Claim 15 (depends on 10)

The computer program product of claim 10, wherein modifying the code section further comprises, prior to enclosing the code section within the transaction:
monitoring execution of the code section to acquire information regarding the code section;
revising the code section, based on the information acquired, so that the code section is better optimized for subsequent enclosure within the transaction.

### Claim 16

A system comprising:
a processor;
a storage device to store a code section of a computer program to be executed by a computing device, the code section including one or more memory barrier instructions;
a software component executable by the processor to modify the code section by:
enclosing the code section within a transaction that employs hardware transactional memory of the computing device, such that an entirety of the code section is executed or none of the code section is executed; and,
removing the memory barrier instructions from the code section.

### Claim 17 (depends on 16)

The system of claim 16, wherein the software component is to modify the code section responsive to determining that the code section satisfies one or more thresholds, each threshold comprising one of:
a first processing cost being greater than a second processing cost, the first processing cost associated with execution of the memory barrier instructions, the second processing cost associated with employing the hardware transactional memory;
an estimated transaction size of the transaction enclosing the code section being less than a memory size of the hardware transactional memory;
the code section including no calls to functions outside the code section.

### Claim 18 (depends on 16)

The system of claim 16, wherein the software component is to enclose the code section within the transaction by:
adding a transaction-start instruction prior to a first instruction within the code section;
adding a transaction-end instruction after the last instruction within the code section, the transaction-end instruction corresponding to non-exceptional and normal exit from the code section; and,
adding a transaction-abort instruction.

### Claim 19 (depends on 16)

The system of claim 16, wherein the software component is further to:
monitor execution of the code section as has been enclosed within the transaction, to yield monitoring results;
determine whether the monitoring results satisfy an abort threshold, the abort threshold corresponding to excessive aborting of the execution of the code section as has been enclosed within the transaction;
responsive to determining that the monitoring results satisfy the abort threshold:
split the code section into a plurality of code sub-sections;
enclose each code sub-section within a separate transaction that employs the hardware transactional memory of the computing device,
wherein splitting the code section into the code sub-sections and enclosing each code sub-section within a separate transaction are adapted to decreasing occurrence of aborting of the execution of the code section.

### Claim 20 (depends on 19)

The system of claim 19, wherein the software component is to split the code section into the code sub-sections by:
where the monitoring results indicate that a primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that an actual transaction size of the transaction is exceeding a memory size of the hardware transactional memory,
split the code section into the code sub-sections such that each instruction of all instructions of the code section is assigned to one of the code sub-sections;
where the monitoring results indicate that the primary reason why the execution of the code section as has been enclosed within the transaction is excessively aborting is that a particular instruction of the code section is causing a memory conflict,
split the code section into the code sub-sections such that the particular instruction is not assigned to any of the code sub-sections, such that the particular instruction is not part of any transaction that employs the hardware transactional memory, and such that one of the code sub-sections is located immediately prior to the particular instruction and is enclosed within a first separate transaction, and another of the code sub-sections is located immediately after the particular instruction and is enclosed within a second separate transaction.
