Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java @ 18510:cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 25 Nov 2014 13:21:50 +0100 |
parents | c9437b07c26a |
children | 62aac33db669 |
rev | line source |
---|---|
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
16854
fc6f12ee71e5
Truffle: fixed header dates.
Christian Humer <christian.humer@gmail.com>
parents:
16852
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * accompanied this code). |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 * questions. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 */ |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.utilities; |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
27 import com.oracle.truffle.api.*; |
18510
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
28 import com.oracle.truffle.api.nodes.*; |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
29 |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 /** |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 * Abstract utility class to speculate on conditions. Condition profiles are intended to be used as |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 * part of if conditions. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 * Example usage: |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 * <pre> |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
37 * private final ConditionProfile zero = ConditionProfile.createBinaryProfile(); |
16868
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16860
diff
changeset
|
38 * |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 * int value = ...; |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 * if (zero.profile(value == 0)) { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 * return 0; |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 * } else { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 * return value; |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 * } |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 * </pre> |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 * |
16868
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16860
diff
changeset
|
48 * All instances of {@code ConditionProfile} (and subclasses) must be held in {@code final} fields |
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16860
diff
changeset
|
49 * for compiler optimizations to take effect. |
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16860
diff
changeset
|
50 * |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
51 * @see #createCountingProfile() |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
52 * @see #createBinaryProfile() |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 */ |
18510
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
54 public abstract class ConditionProfile implements NodeCloneable { |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 public abstract boolean profile(boolean value); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
58 /** |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
59 * Returns a {@link ConditionProfile} that speculates on conditions to be never |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
60 * <code>true</code> or to be never <code>false</code>. Additionally to a binary profile this |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
61 * method returns a condition profile that also counts the number of times the condition was |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
62 * true and false. This information is reported to the underlying optimization system using |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
63 * {@link CompilerDirectives#injectBranchProbability(double, boolean)}. Condition profiles are |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
64 * intended to be used as part of if conditions. |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
65 * |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
66 * @see ConditionProfile |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
67 * @see #createBinaryProfile() |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
68 */ |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
69 public static ConditionProfile createCountingProfile() { |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
70 return new CountingConditionProfile(); |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
71 } |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
72 |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
73 /** |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
74 * Returns a {@link ConditionProfile} that speculates on conditions to be never true or to be |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
75 * never false. Condition profiles are intended to be used as part of if conditions. |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
76 * |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
77 * @see ConditionProfile |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
78 * @see ConditionProfile#createCountingProfile() |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
79 */ |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
80 public static ConditionProfile createBinaryProfile() { |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
81 return new BinaryConditionProfile(); |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
82 } |
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
83 |
18510
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
84 @Override |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
85 public final Object clone() { |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
86 try { |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
87 return super.clone(); |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
88 } catch (CloneNotSupportedException e) { |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
89 throw new AssertionError(e); |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
90 } |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
16910
diff
changeset
|
91 } |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 } |