src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm/src/org/graalvm/compiler/asm/Buffer.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
22 */ |
22 */ |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.asm; |
25 package org.graalvm.compiler.asm; |
26 |
26 |
27 import org.graalvm.compiler.core.common.NumUtil; |
|
28 |
|
29 import java.nio.ByteBuffer; |
27 import java.nio.ByteBuffer; |
30 import java.nio.ByteOrder; |
28 import java.nio.ByteOrder; |
31 import java.util.Arrays; |
29 import java.util.Arrays; |
|
30 |
|
31 import org.graalvm.compiler.core.common.NumUtil; |
|
32 import org.graalvm.compiler.serviceprovider.BufferUtil; |
32 |
33 |
33 /** |
34 /** |
34 * Code buffer management for the assembler. |
35 * Code buffer management for the assembler. |
35 */ |
36 */ |
36 final class Buffer { |
37 final class Buffer { |
46 return data.position(); |
47 return data.position(); |
47 } |
48 } |
48 |
49 |
49 public void setPosition(int position) { |
50 public void setPosition(int position) { |
50 assert position >= 0 && position <= data.limit(); |
51 assert position >= 0 && position <= data.limit(); |
51 data.position(position); |
52 BufferUtil.asBaseBuffer(data).position(position); |
52 } |
53 } |
53 |
54 |
54 /** |
55 /** |
55 * Closes this buffer. Any further operations on a closed buffer will result in a |
56 * Closes this buffer. Any further operations on a closed buffer will result in a |
56 * {@link NullPointerException}. |
57 * {@link NullPointerException}. |
91 protected void ensureSize(int length) { |
92 protected void ensureSize(int length) { |
92 if (length >= data.limit()) { |
93 if (length >= data.limit()) { |
93 byte[] newBuf = Arrays.copyOf(data.array(), length * 4); |
94 byte[] newBuf = Arrays.copyOf(data.array(), length * 4); |
94 ByteBuffer newData = ByteBuffer.wrap(newBuf); |
95 ByteBuffer newData = ByteBuffer.wrap(newBuf); |
95 newData.order(data.order()); |
96 newData.order(data.order()); |
96 newData.position(data.position()); |
97 BufferUtil.asBaseBuffer(newData).position(data.position()); |
97 data = newData; |
98 data = newData; |
98 } |
99 } |
99 } |
100 } |
100 |
101 |
101 public void emitBytes(byte[] arr, int off, int len) { |
102 public void emitBytes(byte[] arr, int off, int len) { |
168 public int getInt(int pos) { |
169 public int getInt(int pos) { |
169 return data.getInt(pos); |
170 return data.getInt(pos); |
170 } |
171 } |
171 |
172 |
172 public void reset() { |
173 public void reset() { |
173 data.clear(); |
174 BufferUtil.asBaseBuffer(data).clear(); |
174 } |
175 } |
175 } |
176 } |