Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BranchProfile.java @ 21550:f48a6cea31eb
fixed canonicalizeprojects issues
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 12:27:05 +0200 |
parents | 62aac33db669 |
children |
rev | line source |
---|---|
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * accompanied this code). |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 * questions. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 */ |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.utilities; |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13335
diff
changeset
|
28 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
18510
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
17421
diff
changeset
|
29 import com.oracle.truffle.api.nodes.*; |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 /** |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 * Utility class to speculate on branches to be never visited. If the {@link #enter()} method is |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 * invoked first the optimized code is invalidated and the branch where {@link #enter()} is invoked |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 * is enabled for compilation. Otherwise if the {@link #enter()} method was never invoked the branch |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 * will not get compiled. |
16868
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16747
diff
changeset
|
36 * |
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16747
diff
changeset
|
37 * All {@code BranchProfile} instances must be held in {@code final} fields for compiler |
db090a8d3705
clarify documentation about assumption and profile storage in final fields
Michael Haupt <michael.haupt@oracle.com>
parents:
16747
diff
changeset
|
38 * optimizations to take effect. |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 */ |
18511
62aac33db669
Truffle: refactor NodeCloneable interface to abstract class
Andreas Woess <andreas.woess@jku.at>
parents:
18510
diff
changeset
|
40 public final class BranchProfile extends NodeCloneable { |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 @CompilationFinal private boolean visited; |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 |
17421
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
44 private BranchProfile() { |
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
45 } |
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
46 |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 public void enter() { |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 if (!visited) { |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 CompilerDirectives.transferToInterpreterAndInvalidate(); |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 visited = true; |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 } |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 |
16747
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
54 public boolean isVisited() { |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
55 return visited; |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
56 } |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
57 |
17421
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
58 public static BranchProfile create() { |
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
59 return new BranchProfile(); |
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
60 } |
87ea195b66ff
Truffle: Make BranchProfile constructor private and introduce a factory Method BranchProfile.create().
Christian Humer <christian.humer@gmail.com>
parents:
16868
diff
changeset
|
61 |
14990
a0200c215fb2
Include the visited state in BranchProfile#toString, so it shows up in printed ASTs.
Chris Seaton <chris.seaton@oracle.com>
parents:
13335
diff
changeset
|
62 @Override |
a0200c215fb2
Include the visited state in BranchProfile#toString, so it shows up in printed ASTs.
Chris Seaton <chris.seaton@oracle.com>
parents:
13335
diff
changeset
|
63 public String toString() { |
a0200c215fb2
Include the visited state in BranchProfile#toString, so it shows up in printed ASTs.
Chris Seaton <chris.seaton@oracle.com>
parents:
13335
diff
changeset
|
64 return String.format("%s(%s)@%x", getClass().getSimpleName(), visited ? "visited" : "not-visited", hashCode()); |
a0200c215fb2
Include the visited state in BranchProfile#toString, so it shows up in printed ASTs.
Chris Seaton <chris.seaton@oracle.com>
parents:
13335
diff
changeset
|
65 } |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |