Mercurial > hg > truffle
annotate graal/com.oracle.graal.truffle.test/sl/TestIsCompilationConstant1.sl @ 18371:837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 13 Nov 2014 14:30:15 -0800 |
parents | 2834b4432586 |
children |
rev | line source |
---|---|
17444
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 function testConstantValue1() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 return isCompilationConstant(42); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 function testConstantValue2() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 return isCompilationConstant(21 + 21); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 function testConstantSequence() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 40; |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 return isCompilationConstant(42); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 function testConstantLocalVariable() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 x = 42; |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 return isCompilationConstant(x); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 function testNonConstantAdd() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 return isCompilationConstant(42 + "42"); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 function main() { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 callFunctionsWith("testConstant", harnessTrue); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 callFunctionsWith("testNonConstant", harnessFalse); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 function harnessTrue(testFunction) { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 callUntilOptimized(testFunction); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 assertTrue(testFunction(), "test function " + testFunction + " is not constant"); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 } |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 function harnessFalse(testFunction) { |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 callUntilOptimized(testFunction); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 assertFalse(testFunction(), "test function " + testFunction + " is constant"); |
2834b4432586
Truffle: introduce CompilerDirectives.isCompilationConstant.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 } |