Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/MultiBranchData.java @ 18665:96861e3f8cc5
made CFGPrinterObserver reset (upon close) properly
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 11 Dec 2014 22:14:30 +0100 |
parents | b9a9ed0f8eeb |
children |
rev | line source |
---|---|
3939 | 1 /* |
6842
b9a9ed0f8eeb
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
5981
diff
changeset
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
5981
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3939 | 4 * |
5981
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
7 * published by the Free Software Foundation. |
3939 | 8 * |
5981
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
13 * accompanied this code). |
3939 | 14 * |
5981
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3939 | 18 * |
5981
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4bec1b1f7b33
7156960: Incorrect copyright headers in parts of the Serviceability agent
minqi
parents:
3939
diff
changeset
|
21 * questions. |
3939 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.oops; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.debugger.*; | |
30 import sun.jvm.hotspot.runtime.*; | |
31 import sun.jvm.hotspot.types.*; | |
32 import sun.jvm.hotspot.utilities.*; | |
33 | |
34 // MultiBranchData | |
35 // | |
36 // A MultiBranchData is used to access profiling information for | |
37 // a multi-way branch (*switch bytecodes). It consists of a series | |
38 // of (count, displacement) pairs, which count the number of times each | |
39 // case was taken and specify the data displacment for each branch target. | |
40 public class MultiBranchData extends ArrayData { | |
41 static final int defaultCountOffSet = 0; | |
42 static final int defaultDisaplacementOffSet = 1; | |
43 static final int caseArrayStart = 2; | |
44 static final int relativeCountOffSet = 0; | |
45 static final int relativeDisplacementOffSet = 1; | |
46 static final int perCaseCellCount = 2; | |
47 | |
48 public MultiBranchData(DataLayout layout) { | |
49 super(layout); | |
50 //assert(layout.tag() == DataLayout.multiBranchDataTag, "wrong type"); | |
51 } | |
52 | |
53 // static int computeCellCount(BytecodeStream stream); | |
54 | |
55 int numberOfCases() { | |
56 int alen = arrayLen() - 2; // get rid of default case here. | |
57 //assert(alen % perCaseCellCount == 0, "must be even"); | |
58 return (alen / perCaseCellCount); | |
59 } | |
60 | |
61 int defaultCount() { | |
62 return arrayUintAt(defaultCountOffSet); | |
63 } | |
64 int defaultDisplacement() { | |
65 return arrayIntAt(defaultDisaplacementOffSet); | |
66 } | |
67 | |
68 int countAt(int index) { | |
69 return arrayUintAt(caseArrayStart + | |
70 index * perCaseCellCount + | |
71 relativeCountOffSet); | |
72 } | |
73 int displacementAt(int index) { | |
74 return arrayIntAt(caseArrayStart + | |
75 index * perCaseCellCount + | |
76 relativeDisplacementOffSet); | |
77 } | |
78 | |
79 // Code generation support | |
80 static int defaultCountOffset() { | |
81 return arrayElementOffset(defaultCountOffSet); | |
82 } | |
83 static int defaultDisplacementOffset() { | |
84 return arrayElementOffset(defaultDisaplacementOffSet); | |
85 } | |
86 static int caseCountOffset(int index) { | |
87 return caseArrayOffset() + | |
88 (perCaseSize() * index) + | |
89 relativeCountOffset(); | |
90 } | |
91 static int caseArrayOffset() { | |
92 return arrayElementOffset(caseArrayStart); | |
93 } | |
94 static int perCaseSize() { | |
95 return (perCaseCellCount) * MethodData.cellSize; | |
96 } | |
97 static int relativeCountOffset() { | |
98 return (relativeCountOffSet) * MethodData.cellSize; | |
99 } | |
100 static int relativeDisplacementOffset() { | |
101 return (relativeDisplacementOffSet) * MethodData.cellSize; | |
102 } | |
103 | |
104 public void printDataOn(PrintStream st) { | |
105 printShared(st, "MultiBranchData"); | |
106 st.println("default_count(" + defaultCount() + ") displacement(" + defaultDisplacement() + ")"); | |
107 int cases = numberOfCases(); | |
108 for (int i = 0; i < cases; i++) { | |
109 tab(st); | |
110 st.println("count(" + countAt(i) + ") displacement(" + displacementAt(i) + ")"); | |
111 } | |
112 } | |
113 } |