Skip to content

Commit 660a3b9

Browse files
committed
Introduce Assembler.closeAligned.
1 parent bc0b09f commit 660a3b9

File tree

1 file changed

+17
-1
lines changed
  • compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm

1 file changed

+17
-1
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/Assembler.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,24 @@ public void emitString(String s, int pos) {
198198
* including) {@code position()} is returned
199199
* @return the data in this buffer or a trimmed copy if {@code trimmedCopy} is {@code true}
200200
*/
201-
public byte[] close(boolean trimmedCopy) {
201+
public final byte[] close(boolean trimmedCopy) {
202+
return closeAligned(trimmedCopy, 0);
203+
}
204+
205+
/**
206+
* Closes this assembler. No extra data can be written to this assembler after this call.
207+
*
208+
* @param trimmedCopy if {@code true}, then a copy of the underlying byte array up to (but not
209+
* including) {@code position()} is returned
210+
* @param alignment if {@code > 0}, then align the end of the code buffer with NOPs to the
211+
* specified alignment
212+
* @return the data in this buffer or a trimmed copy if {@code trimmedCopy} is {@code true}
213+
*/
214+
public byte[] closeAligned(boolean trimmedCopy, int alignment) {
202215
checkAndClearLabelsWithPatches();
216+
if (alignment > 0 && position() % alignment != 0) {
217+
this.align(alignment);
218+
}
203219
finalCodeSize = position();
204220
return codeBuffer.close(trimmedCopy);
205221
}

0 commit comments

Comments
 (0)