Mercurial > hg > truffle
comparison test/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java @ 17616:d1760952ebdd
8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
Reviewed-by: twisti
Contributed-by: anton.ivanov@oracle.com
author | iignatyev |
---|---|
date | Tue, 31 Dec 2013 19:26:57 +0400 |
parents | |
children | 17d3ee6e9d3c |
comparison
equal
deleted
inserted
replaced
17615:6d2fe9c23878 | 17616:d1760952ebdd |
---|---|
1 /* | |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
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 import com.oracle.java.testlibrary.Platform; | |
25 | |
26 import java.io.FileOutputStream; | |
27 import java.lang.reflect.Executable; | |
28 import java.util.Properties; | |
29 | |
30 public abstract class IntrinsicBase extends CompilerWhiteBoxTest { | |
31 protected String javaVmName; | |
32 protected String useMathExactIntrinsics; | |
33 | |
34 protected IntrinsicBase(TestCase testCase) { | |
35 super(testCase); | |
36 javaVmName = System.getProperty("java.vm.name"); | |
37 useMathExactIntrinsics = getVMOption("UseMathExactIntrinsics"); | |
38 } | |
39 | |
40 @Override | |
41 protected void test() throws Exception { | |
42 //java.lang.Math should be loaded to allow a compilation of the methods that use Math's method | |
43 System.out.println("class java.lang.Math should be loaded. Proof: " + Math.class); | |
44 printEnvironmentInfo(); | |
45 | |
46 int expectedIntrinsicCount = 0; | |
47 | |
48 switch (MODE) { | |
49 case "compiled mode": | |
50 case "mixed mode": | |
51 if (isServerVM()) { | |
52 if (TIERED_COMPILATION) { | |
53 int max_level = TIERED_STOP_AT_LEVEL; | |
54 expectedIntrinsicCount = (max_level == COMP_LEVEL_MAX) ? 1 : 0; | |
55 for (int i = CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE; i <= max_level; ++i) { | |
56 deoptimize(); | |
57 compileAtLevel(i); | |
58 } | |
59 } else { | |
60 expectedIntrinsicCount = 1; | |
61 deoptimize(); | |
62 compileAtLevel(CompilerWhiteBoxTest.COMP_LEVEL_MAX); | |
63 } | |
64 } else { | |
65 deoptimize(); | |
66 compileAtLevel(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE); | |
67 } | |
68 | |
69 if (!isIntrinsicSupported()) { | |
70 expectedIntrinsicCount = 0; | |
71 } | |
72 break; | |
73 case "interpreted mode": //test is not applicable in this mode; | |
74 System.err.println("Warning: This test is not applicable in mode: " + MODE); | |
75 break; | |
76 default: | |
77 throw new RuntimeException("Test bug, unknown VM mode: " + MODE); | |
78 } | |
79 | |
80 System.out.println("Expected intrinsic count is " + expectedIntrinsicCount + " name " + getIntrinsicId()); | |
81 | |
82 final FileOutputStream out = new FileOutputStream(getVMOption("LogFile") + ".verify.properties"); | |
83 Properties expectedProps = new Properties(); | |
84 expectedProps.setProperty("intrinsic.name", getIntrinsicId()); | |
85 expectedProps.setProperty("intrinsic.expectedCount", String.valueOf(expectedIntrinsicCount)); | |
86 expectedProps.store(out, null); | |
87 | |
88 out.close(); | |
89 } | |
90 | |
91 protected void printEnvironmentInfo() { | |
92 System.out.println("java.vm.name=" + javaVmName); | |
93 System.out.println("os.arch=" + Platform.getOsArch()); | |
94 System.out.println("java.vm.info=" + MODE); | |
95 System.out.println("useMathExactIntrinsics=" + useMathExactIntrinsics); | |
96 } | |
97 | |
98 protected void compileAtLevel(int level) { | |
99 WHITE_BOX.enqueueMethodForCompilation(method, level); | |
100 waitBackgroundCompilation(); | |
101 checkCompilation(method, level); | |
102 } | |
103 | |
104 protected void checkCompilation(Executable executable, int level) { | |
105 if (!WHITE_BOX.isMethodCompiled(executable)) { | |
106 throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but not compiled"); | |
107 } | |
108 final int compilationLevel = WHITE_BOX.getMethodCompilationLevel(executable); | |
109 if (compilationLevel != level) { | |
110 if (!(TIERED_COMPILATION && level == COMP_LEVEL_FULL_PROFILE && compilationLevel == COMP_LEVEL_LIMITED_PROFILE)) { //possible case | |
111 throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but level: " + compilationLevel); | |
112 } | |
113 } | |
114 } | |
115 | |
116 protected abstract boolean isIntrinsicSupported(); | |
117 | |
118 protected abstract String getIntrinsicId(); | |
119 | |
120 protected boolean isServerVM() { | |
121 return javaVmName.toLowerCase().contains("server"); | |
122 } | |
123 | |
124 static class IntTest extends IntrinsicBase { | |
125 protected IntTest(MathIntrinsic.IntIntrinsic testCase) { | |
126 super(testCase); | |
127 } | |
128 | |
129 @Override | |
130 protected boolean isIntrinsicSupported() { | |
131 return isServerVM() && Boolean.valueOf(useMathExactIntrinsics) && (Platform.isX86() || Platform.isX64()); | |
132 } | |
133 | |
134 @Override | |
135 protected String getIntrinsicId() { | |
136 return "_" + testCase.name().toLowerCase() + "ExactI"; | |
137 } | |
138 } | |
139 | |
140 static class LongTest extends IntrinsicBase { | |
141 protected LongTest(MathIntrinsic.LongIntrinsic testCase) { | |
142 super(testCase); | |
143 } | |
144 | |
145 @Override | |
146 protected boolean isIntrinsicSupported() { | |
147 return isServerVM() && Boolean.valueOf(useMathExactIntrinsics) && Platform.isX64(); | |
148 } | |
149 | |
150 @Override | |
151 protected String getIntrinsicId() { | |
152 return "_" + testCase.name().toLowerCase() + "ExactL"; | |
153 } | |
154 } | |
155 } |