56 __ByValue final class MyValue {
57 final int x;
58 final long y;
59 final double z;
60
61 private MyValue(int x, long y, double z) {
62 this.x = x;
63 this.y = y;
64 this.z = z;
65 }
66
67 @DontInline
68 public static MyValue createDontInline(int x, long y, double z) {
69 return __Make MyValue(x, y, z);
70 }
71
72 @ForceInline
73 public static MyValue createInline(int x, long y, double z) {
74 return __Make MyValue(x, y, z);
75 }
76 }
77
78 public class ValueTypeTestBench {
79 // Print ideal graph after execution of each test
80 private static final boolean PRINT_GRAPH = true;
81
82 // ========== Test definitions ==========
83
84 // Receive value type through call to interpreter
85 @Test(failOn = ALLOC + STORE)
86 public double test1() {
87 MyValue v = MyValue.createDontInline(rI, rL, rD);
88 return v.x + v.y + v.z;
89 }
90
91 @DontCompile
92 public void test1_verifier(boolean warmup) {
93 double result = test1();
94 Asserts.assertEQ(result, rI + rL + rD);
95 }
298 MyValue v = MyValue.createDontInline(rI, rL, rD);
299 double result = 42;
300 for (int i = 0; i < 1000; ++i) {
301 if (b) {
302 result += v.x;
303 } else {
304 // Uncommon trap referencing v. Should not allocate
305 // but just pass the existing oop to the uncommon trap.
306 result = sumValue(v);
307 }
308 }
309 return result;
310 }
311
312 @DontCompile
313 public void test13_verifier(boolean warmup) {
314 double result = test13(warmup);
315 Asserts.assertEQ(result, warmup ? 42 + (1000*(double)rI) : (rI + rL + rD));
316 }
317
318
319 // ========== Helper methods ==========
320
321 @DontCompile
322 public double sumValue(MyValue v) {
323 return v.x + v.y + v.z;
324 }
325
326 // ========== Test infrastructure ==========
327
328 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
329 private static final int COMP_LEVEL_ANY = -1;
330 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
331 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
332 private static final int WARMUP = 10;
333
334 // Regular expressions used to match nodes in the PrintIdeal output
335 private static final String START = "(\\d+\\t(.*";
336 private static final String MID = ".*)+\\t===.*";
337 private static final String END = ")|";
|
56 __ByValue final class MyValue {
57 final int x;
58 final long y;
59 final double z;
60
61 private MyValue(int x, long y, double z) {
62 this.x = x;
63 this.y = y;
64 this.z = z;
65 }
66
67 @DontInline
68 public static MyValue createDontInline(int x, long y, double z) {
69 return __Make MyValue(x, y, z);
70 }
71
72 @ForceInline
73 public static MyValue createInline(int x, long y, double z) {
74 return __Make MyValue(x, y, z);
75 }
76
77 @DontInline
78 public String toStringDontInline() {
79 return "MyValue: x=" + x + " y=" + y + " z=" + z;
80 }
81
82 @ForceInline
83 public String toStringInline() {
84 return "MyValue: x=" + x + " y=" + y + " z=" + z;
85 }
86 }
87
88 public class ValueTypeTestBench {
89 // Print ideal graph after execution of each test
90 private static final boolean PRINT_GRAPH = true;
91
92 // ========== Test definitions ==========
93
94 // Receive value type through call to interpreter
95 @Test(failOn = ALLOC + STORE)
96 public double test1() {
97 MyValue v = MyValue.createDontInline(rI, rL, rD);
98 return v.x + v.y + v.z;
99 }
100
101 @DontCompile
102 public void test1_verifier(boolean warmup) {
103 double result = test1();
104 Asserts.assertEQ(result, rI + rL + rD);
105 }
308 MyValue v = MyValue.createDontInline(rI, rL, rD);
309 double result = 42;
310 for (int i = 0; i < 1000; ++i) {
311 if (b) {
312 result += v.x;
313 } else {
314 // Uncommon trap referencing v. Should not allocate
315 // but just pass the existing oop to the uncommon trap.
316 result = sumValue(v);
317 }
318 }
319 return result;
320 }
321
322 @DontCompile
323 public void test13_verifier(boolean warmup) {
324 double result = test13(warmup);
325 Asserts.assertEQ(result, warmup ? 42 + (1000*(double)rI) : (rI + rL + rD));
326 }
327
328 // Create a value type in a non-inlined method and then call a
329 // non-inlined method on that value type.
330 @Test(failOn = (ALLOC + STORE))
331 public String test14() {
332 MyValue v = MyValue.createDontInline(32, 64L, 128.0);
333 String s = v.toStringDontInline();
334 return s;
335 }
336
337 @DontCompile
338 public void test14_verifier(boolean b) {
339 String s = test14();
340 System.out.println("Result is: " + s);
341 }
342
343 // Create a value type in an inlined method and then call a
344 // non-inlined method on that value type.
345 @Test(match = {ALLOC}, matchCount = {1})
346 public String test15() {
347 MyValue v = MyValue.createInline(65, 129L, 257.0);
348 String s = v.toStringDontInline();
349 return s;
350 }
351
352 @DontCompile
353 public void test15_verifier(boolean b) {
354 String s = test15();
355 System.out.println("Result is: " + s);
356 }
357
358 // Create a value type in a non-inlined method and then call an
359 // inlined method on that value type. Allocations are due to building
360 // String objects and not due to allocating value types.
361 @Test(match = {ALLOC}, matchCount = {2})
362 public String test16() {
363 MyValue v = MyValue.createDontInline(130, 258L, 514.0);
364 String s = v.toStringInline();
365 return s;
366 }
367
368 @DontCompile
369 public void test16_verifier(boolean b) {
370 String s = test16();
371 System.out.println("Result is: " + s);
372 }
373
374 // Create a value type in an inlined method and then call an
375 // inlined method on that value type. Allocations are due to
376 // building String objects and not due to allocating value types.
377 @Test(match = {ALLOC}, matchCount = {2})
378 public String test17() {
379 MyValue v = MyValue.createInline(259, 515L, 1027.0);
380 String s = v.toStringInline();
381 return s;
382 }
383
384 @DontCompile
385 public void test17_verifier(boolean b) {
386 String s = test17();
387 System.out.println("Result is: " + s);
388 }
389
390 // ========== Helper methods ==========
391
392 @DontCompile
393 public double sumValue(MyValue v) {
394 return v.x + v.y + v.z;
395 }
396
397 // ========== Test infrastructure ==========
398
399 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
400 private static final int COMP_LEVEL_ANY = -1;
401 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
402 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
403 private static final int WARMUP = 10;
404
405 // Regular expressions used to match nodes in the PrintIdeal output
406 private static final String START = "(\\d+\\t(.*";
407 private static final String MID = ".*)+\\t===.*";
408 private static final String END = ")|";
|