annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java @ 18845:f57d86eb036f

removed Node factory methods
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Jan 2015 20:39:04 +0100
parents 62aac33db669
children 1cde96b96673
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
diff changeset
33 *
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 * Example usage:
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
diff changeset
35 *
16828
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 * }
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
diff changeset
45 *
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 * </pre>
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
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.
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
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 */
18511
62aac33db669 Truffle: refactor NodeCloneable interface to abstract class
Andreas Woess <andreas.woess@jku.at>
parents: 18510
diff changeset
54 public abstract class ConditionProfile extends 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.
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
diff changeset
65 *
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
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.
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18511
diff changeset
76 *
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
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 }
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 }