annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 9c8c0937da41
children a63bda98cfdb
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import com.oracle.truffle.api.CompilerDirectives;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
28 import com.oracle.truffle.api.nodes.NodeCloneable;
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.
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
diff changeset
33 *
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 * Example usage:
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
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();
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
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 * }
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
diff changeset
45 *
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 * </pre>
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
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.
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
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 {
21268
7d998dd2d1b0 The expected intention with ConditionProfile's seems to be to control all existing implementations. Making externally unsubclasssable.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 19507
diff changeset
55 ConditionProfile() {
7d998dd2d1b0 The expected intention with ConditionProfile's seems to be to control all existing implementations. Making externally unsubclasssable.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 19507
diff changeset
56 }
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 public abstract boolean profile(boolean value);
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59
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
60 /**
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 * 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
62 * <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
63 * 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
64 * 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
65 * {@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
66 * intended to be used as part of if conditions.
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
diff changeset
67 *
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
68 * @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
69 * @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
70 */
16910
c9437b07c26a Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents: 16868
diff changeset
71 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
72 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
73 }
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
74
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 /**
16910
c9437b07c26a Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents: 16868
diff changeset
76 * 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
77 * never false. Condition profiles are intended to be used as part of if conditions.
19507
1cde96b96673 Fixed code format issues.
Roland Schatz <roland.schatz@oracle.com>
parents: 18845
diff changeset
78 *
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 * @see ConditionProfile
16910
c9437b07c26a Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents: 16868
diff changeset
80 * @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
81 */
16910
c9437b07c26a Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents: 16868
diff changeset
82 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
83 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
84 }
16828
2834af86f398 Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 }