11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package jdk.vm.ci.code.test;
25
26 import java.nio.ByteBuffer;
27 import java.nio.ByteOrder;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30
31 import jdk.vm.ci.code.CodeCacheProvider;
32 import jdk.vm.ci.code.DebugInfo;
33 import jdk.vm.ci.code.Register;
34 import jdk.vm.ci.code.StackSlot;
35 import jdk.vm.ci.code.site.Call;
36 import jdk.vm.ci.code.site.ConstantReference;
37 import jdk.vm.ci.code.site.DataPatch;
38 import jdk.vm.ci.code.site.DataSectionReference;
39 import jdk.vm.ci.code.site.Infopoint;
40 import jdk.vm.ci.code.site.InfopointReason;
41 import jdk.vm.ci.code.site.Mark;
42 import jdk.vm.ci.code.site.Reference;
43 import jdk.vm.ci.code.site.Site;
44 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
45 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
46 import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
47 import jdk.vm.ci.hotspot.HotSpotConstant;
48 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
49 import jdk.vm.ci.meta.Assumptions.Assumption;
50 import jdk.vm.ci.meta.InvokeTarget;
51 import jdk.vm.ci.meta.JavaKind;
52 import jdk.vm.ci.meta.PlatformKind;
53 import jdk.vm.ci.meta.ResolvedJavaMethod;
54 import jdk.vm.ci.meta.ValueKind;
55 import jdk.vm.ci.meta.VMConstant;
56
57 /**
58 * Simple assembler used by the code installation tests.
59 */
60 public abstract class TestAssembler {
61
62 /**
63 * Emit the method prologue code (e.g. building the new stack frame).
64 */
65 public abstract void emitPrologue();
66
67 /**
68 * Emit the method epilogue code (e.g. the deopt handler).
148 * Emit code to store a wide pointer from a register to a new stack slot.
149 */
150 public abstract StackSlot emitPointerToStack(Register a);
151
152 /**
153 * Emit code to store a narrow pointer from a register to a new stack slot.
154 */
155 public abstract StackSlot emitNarrowPointerToStack(Register a);
156
157 /**
158 * Emit code to uncompress a narrow pointer. The input pointer is guaranteed to be non-null.
159 */
160 public abstract Register emitUncompressPointer(Register compressed, long base, int shift);
161
162 /**
163 * Emit code to return from a function, returning a 32-bit integer.
164 */
165 public abstract void emitIntRet(Register a);
166
167 /**
168 * Emit code to return from a function, returning a wide oop pointer.
169 */
170 public abstract void emitPointerRet(Register a);
171
172 /**
173 * Emit code that traps, forcing a deoptimization.
174 */
175 public abstract void emitTrap(DebugInfo info);
176
177 public final ValueKind<?> narrowOopKind;
178
179 protected final Buffer code;
180 protected final Buffer data;
181 private final ArrayList<Site> sites;
182 private final ArrayList<DataPatch> dataPatches;
183
184 protected final CodeCacheProvider codeCache;
185 protected final TestHotSpotVMConfig config;
186
187 private final Register[] registers;
188 private int nextRegister;
189
190 protected int frameSize;
191 private int stackAlignment;
192 private int curStackSlot;
193
194 private StackSlot deoptRescue;
195
196 private static class TestValueKind extends ValueKind<TestValueKind> {
197
198 TestValueKind(PlatformKind kind) {
199 super(kind);
200 }
201
202 @Override
203 public TestValueKind changeType(PlatformKind kind) {
204 return new TestValueKind(kind);
205 }
206 }
207
208 protected TestAssembler(CodeCacheProvider codeCache, TestHotSpotVMConfig config, int initialFrameSize, int stackAlignment, PlatformKind narrowOopKind, Register... registers) {
209 this.narrowOopKind = new TestValueKind(narrowOopKind);
210
211 this.code = new Buffer();
212 this.data = new Buffer();
213 this.sites = new ArrayList<>();
214 this.dataPatches = new ArrayList<>();
215
216 this.codeCache = codeCache;
319 public void emitShort(int b) {
320 ensureSize(data.position() + 2);
321 data.putShort((short) b);
322 }
323
324 public void emitInt(int b) {
325 ensureSize(data.position() + 4);
326 data.putInt(b);
327 }
328
329 public void emitLong(long b) {
330 ensureSize(data.position() + 8);
331 data.putLong(b);
332 }
333
334 public void emitFloat(float f) {
335 ensureSize(data.position() + 4);
336 data.putFloat(f);
337 }
338
339 public void align(int alignment) {
340 int pos = data.position();
341 int misaligned = pos % alignment;
342 if (misaligned != 0) {
343 pos += alignment - misaligned;
344 data.position(pos);
345 }
346 }
347
348 private byte[] finish() {
349 return Arrays.copyOf(data.array(), data.position());
350 }
351 }
352 }
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package jdk.vm.ci.code.test;
25
26 import java.nio.ByteBuffer;
27 import java.nio.ByteOrder;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30
31 import jdk.vm.ci.code.CallingConvention;
32 import jdk.vm.ci.code.CodeCacheProvider;
33 import jdk.vm.ci.code.DebugInfo;
34 import jdk.vm.ci.code.Register;
35 import jdk.vm.ci.code.StackSlot;
36 import jdk.vm.ci.code.ValueKindFactory;
37 import jdk.vm.ci.code.site.Call;
38 import jdk.vm.ci.code.site.ConstantReference;
39 import jdk.vm.ci.code.site.DataPatch;
40 import jdk.vm.ci.code.site.DataSectionReference;
41 import jdk.vm.ci.code.site.Infopoint;
42 import jdk.vm.ci.code.site.InfopointReason;
43 import jdk.vm.ci.code.site.Mark;
44 import jdk.vm.ci.code.site.Reference;
45 import jdk.vm.ci.code.site.Site;
46 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
47 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
48 import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
49 import jdk.vm.ci.hotspot.HotSpotConstant;
50 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
51 import jdk.vm.ci.meta.AllocatableValue;
52 import jdk.vm.ci.meta.Assumptions.Assumption;
53 import jdk.vm.ci.meta.InvokeTarget;
54 import jdk.vm.ci.meta.JavaKind;
55 import jdk.vm.ci.meta.PlatformKind;
56 import jdk.vm.ci.meta.ResolvedJavaMethod;
57 import jdk.vm.ci.meta.ValueKind;
58 import jdk.vm.ci.meta.VMConstant;
59
60 /**
61 * Simple assembler used by the code installation tests.
62 */
63 public abstract class TestAssembler {
64
65 /**
66 * Emit the method prologue code (e.g. building the new stack frame).
67 */
68 public abstract void emitPrologue();
69
70 /**
71 * Emit the method epilogue code (e.g. the deopt handler).
151 * Emit code to store a wide pointer from a register to a new stack slot.
152 */
153 public abstract StackSlot emitPointerToStack(Register a);
154
155 /**
156 * Emit code to store a narrow pointer from a register to a new stack slot.
157 */
158 public abstract StackSlot emitNarrowPointerToStack(Register a);
159
160 /**
161 * Emit code to uncompress a narrow pointer. The input pointer is guaranteed to be non-null.
162 */
163 public abstract Register emitUncompressPointer(Register compressed, long base, int shift);
164
165 /**
166 * Emit code to return from a function, returning a 32-bit integer.
167 */
168 public abstract void emitIntRet(Register a);
169
170 /**
171 * Emit code to return from a function, returning a single precision float.
172 */
173 public abstract void emitFloatRet(Register a);
174
175 /**
176 * Emit code to return from a function, returning a wide oop pointer.
177 */
178 public abstract void emitPointerRet(Register a);
179
180 /**
181 * Emit code that traps, forcing a deoptimization.
182 */
183 public abstract void emitTrap(DebugInfo info);
184
185 public final ValueKind<?> narrowOopKind;
186
187 protected final Buffer code;
188 protected final Buffer data;
189 private final ArrayList<Site> sites;
190 private final ArrayList<DataPatch> dataPatches;
191
192 protected final CodeCacheProvider codeCache;
193 protected final TestHotSpotVMConfig config;
194
195 private final Register[] registers;
196 private int nextRegister;
197
198 protected int frameSize;
199 private int stackAlignment;
200 private int curStackSlot;
201
202 private StackSlot deoptRescue;
203
204 public ValueKindFactory<TestValueKind> valueKindFactory = new ValueKindFactory<TestAssembler.TestValueKind>() {
205 public TestValueKind getValueKind(JavaKind javaKind) {
206 return (TestValueKind) TestAssembler.this.getValueKind(javaKind);
207 }
208 };
209
210 static class TestValueKind extends ValueKind<TestValueKind> {
211
212 TestValueKind(PlatformKind kind) {
213 super(kind);
214 }
215
216 @Override
217 public TestValueKind changeType(PlatformKind kind) {
218 return new TestValueKind(kind);
219 }
220 }
221
222 protected TestAssembler(CodeCacheProvider codeCache, TestHotSpotVMConfig config, int initialFrameSize, int stackAlignment, PlatformKind narrowOopKind, Register... registers) {
223 this.narrowOopKind = new TestValueKind(narrowOopKind);
224
225 this.code = new Buffer();
226 this.data = new Buffer();
227 this.sites = new ArrayList<>();
228 this.dataPatches = new ArrayList<>();
229
230 this.codeCache = codeCache;
333 public void emitShort(int b) {
334 ensureSize(data.position() + 2);
335 data.putShort((short) b);
336 }
337
338 public void emitInt(int b) {
339 ensureSize(data.position() + 4);
340 data.putInt(b);
341 }
342
343 public void emitLong(long b) {
344 ensureSize(data.position() + 8);
345 data.putLong(b);
346 }
347
348 public void emitFloat(float f) {
349 ensureSize(data.position() + 4);
350 data.putFloat(f);
351 }
352
353 public void emitDouble(double f) {
354 ensureSize(data.position() + 8);
355 data.putDouble(f);
356 }
357
358 public void align(int alignment) {
359 int pos = data.position();
360 int misaligned = pos % alignment;
361 if (misaligned != 0) {
362 pos += alignment - misaligned;
363 data.position(pos);
364 }
365 }
366
367 private byte[] finish() {
368 return Arrays.copyOf(data.array(), data.position());
369 }
370 }
371
372 /**
373 * Loads a primitive into the Allocatable <code>av</code>. Implementors may only implement
374 * primitive types.
375 */
376 public abstract void emitLoad(AllocatableValue av, Object prim);
377
378 /**
379 * Emit a call to a fixed address <code>addr</code>
380 */
381 public abstract void emitCall(long addr);
382
383 /**
384 * Emit code which is necessary to call a method with {@link CallingConvention} <code>cc</code>
385 * and arguments <coe>prim</code>.
386 */
387 public abstract void emitCallPrologue(CallingConvention cc, Object... prim);
388
389 /**
390 * Emit code which is necessary after calling a method with CallingConvention <code>cc</code>.
391 */
392 public abstract void emitCallEpilogue(CallingConvention cc);
393
394 }
|