Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BranchProfile.java @ 16747:d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:04 +0200 |
parents | 602c090252e0 |
children | db090a8d3705 |
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; |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
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 * 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
|
32 * 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
|
33 * 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
|
34 * will not get compiled. |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 */ |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public final class BranchProfile { |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 @CompilationFinal private boolean visited; |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 public void enter() { |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 if (!visited) { |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 CompilerDirectives.transferToInterpreterAndInvalidate(); |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 visited = true; |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 } |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 } |
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
16747
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
47 public boolean isVisited() { |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
48 return visited; |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
49 } |
d9d496d77d37
Truffle: Added option to query a BranchProfile for visited.
Christian Humer <christian.humer@gmail.com>
parents:
14992
diff
changeset
|
50 |
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
|
51 @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
|
52 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
|
53 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
|
54 } |
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
|
55 |
13335
8531c47138dc
Truffle: introduced new profiling utility BranchProfile.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |