|
1 /* |
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
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 public class DataLayout { |
|
35 public static final int noTag = 0; |
|
36 public static final int bitDataTag = 1; |
|
37 public static final int counterDataTag = 2; |
|
38 public static final int jumpDataTag= 3; |
|
39 public static final int receiverTypeDataTag = 4; |
|
40 public static final int virtualCallDataTag = 5; |
|
41 public static final int retDataTag = 6; |
|
42 public static final int branchDataTag = 7; |
|
43 public static final int multiBranchDataTag = 8; |
|
44 public static final int argInfoDataTag = 9; |
|
45 public static final int callTypeDataTag = 10; |
|
46 public static final int virtualCallTypeDataTag = 11; |
|
47 public static final int parametersTypeDataTag = 12; |
|
48 public static final int speculativeTrapDataTag = 13; |
|
49 |
|
50 // The _struct._flags word is formatted as [trapState:4 | flags:4]. |
|
51 // The trap state breaks down further as [recompile:1 | reason:3]. |
|
52 // This further breakdown is defined in deoptimization.cpp. |
|
53 // See Deoptimization.trapStateReason for an assert that |
|
54 // trapBits is big enough to hold reasons < reasonRecordedLimit. |
|
55 // |
|
56 // The trapState is collected only if ProfileTraps is true. |
|
57 public static final int trapBits = 1+3; // 3: enough to distinguish [0..reasonRecordedLimit]. |
|
58 public static final int trapShift = 8 - trapBits; |
|
59 public static final int trapMask = Bits.rightNBits(trapBits); |
|
60 public static final int trapMaskInPlace = (trapMask << trapShift); |
|
61 public static final int flagLimit = trapShift; |
|
62 public static final int flagMask = Bits.rightNBits(flagLimit); |
|
63 public static final int firstFlag = 0; |
|
64 |
|
65 private Address data; |
|
66 |
|
67 private int offset; |
|
68 |
|
69 public DataLayout(MethodData d, int o) { |
|
70 data = d.getAddress(); |
|
71 offset = o; |
|
72 } |
|
73 |
|
74 public DataLayout(Address d, int o) { |
|
75 data = d; |
|
76 offset = o; |
|
77 } |
|
78 |
|
79 public int dp() { return offset; } |
|
80 |
|
81 private int getU11(int at) { |
|
82 return data.getJByteAt(offset + at) & 0xff; |
|
83 } |
|
84 |
|
85 private int getU22(int at) { |
|
86 return data.getJShortAt(offset + at) & 0xffff; |
|
87 } |
|
88 |
|
89 int cellAt(int index) { |
|
90 // Cells are intptr_t sized but only contain ints as raw values |
|
91 return (int)data.getCIntegerAt(offset + cellOffset(index), MethodData.cellSize, false); |
|
92 } |
|
93 |
|
94 public Address addressAt(int index) { |
|
95 return data.getAddressAt(offset + cellOffset(index)); |
|
96 } |
|
97 |
|
98 // Every data layout begins with a header. This header |
|
99 // contains a tag, which is used to indicate the size/layout |
|
100 // of the data, 4 bits of flags, which can be used in any way, |
|
101 // 4 bits of trap history (none/one reason/many reasons), |
|
102 // and a bci, which is used to tie this piece of data to a |
|
103 // specific bci in the bytecodes. |
|
104 // union { |
|
105 // intptrT _bits; |
|
106 // struct { |
|
107 // u1 _tag; |
|
108 // u1 _flags; |
|
109 // u2 _bci; |
|
110 // } _struct; |
|
111 // } _header; |
|
112 |
|
113 // Some types of data layouts need a length field. |
|
114 static boolean needsArrayLen(int tag) { |
|
115 return (tag == multiBranchDataTag); |
|
116 } |
|
117 |
|
118 public static final int counterIncrement = 1; |
|
119 |
|
120 // Size computation |
|
121 static int headerSizeInBytes() { |
|
122 return MethodData.cellSize; |
|
123 } |
|
124 static int headerSizeInCells() { |
|
125 return 1; |
|
126 } |
|
127 |
|
128 static public int computeSizeInBytes(int cellCount) { |
|
129 return headerSizeInBytes() + cellCount * MethodData.cellSize; |
|
130 } |
|
131 |
|
132 // Initialization |
|
133 // void initialize(int tag, int bci, int cellCount); |
|
134 |
|
135 // Accessors |
|
136 public int tag() { |
|
137 return getU11(0); |
|
138 } |
|
139 |
|
140 // Return a few bits of trap state. Range is [0..trapMask]. |
|
141 // The state tells if traps with zero, one, or many reasons have occurred. |
|
142 // It also tells whether zero or many recompilations have occurred. |
|
143 // The associated trap histogram in the MDO itself tells whether |
|
144 // traps are common or not. If a BCI shows that a trap X has |
|
145 // occurred, and the MDO shows N occurrences of X, we make the |
|
146 // simplifying assumption that all N occurrences can be blamed |
|
147 // on that BCI. |
|
148 int trapState() { |
|
149 return (flags() >> trapShift) & trapMask; |
|
150 } |
|
151 |
|
152 int flags() { |
|
153 return getU11(1); |
|
154 } |
|
155 |
|
156 int bci() { |
|
157 return getU22(2); |
|
158 } |
|
159 |
|
160 boolean flagAt(int flagNumber) { |
|
161 // assert(flagNumber < flagLimit, "oob"); |
|
162 return (flags() & (0x1 << flagNumber)) != 0; |
|
163 } |
|
164 |
|
165 // Low-level support for code generation. |
|
166 static int headerOffset() { |
|
167 return 0; |
|
168 } |
|
169 static int tagOffset() { |
|
170 return 0; |
|
171 } |
|
172 static int flagsOffset() { |
|
173 return 1; |
|
174 } |
|
175 static int bciOffset() { |
|
176 return 2; |
|
177 } |
|
178 public static int cellOffset(int index) { |
|
179 return MethodData.cellSize + index * MethodData.cellSize; |
|
180 } |
|
181 // // Return a value which, when or-ed as a byte into _flags, sets the flag. |
|
182 // static int flagNumberToByteConstant(int flagNumber) { |
|
183 // assert(0 <= flagNumber && flagNumber < flagLimit, "oob"); |
|
184 // DataLayout temp; temp.setHeader(0); |
|
185 // temp.setFlagAt(flagNumber); |
|
186 // return temp._header._struct._flags; |
|
187 // } |
|
188 // // Return a value which, when or-ed as a word into _header, sets the flag. |
|
189 // static intptrT flagMaskToHeaderMask(int byteConstant) { |
|
190 // DataLayout temp; temp.setHeader(0); |
|
191 // temp._header._struct._flags = byteConstant; |
|
192 // return temp._header._bits; |
|
193 // } |
|
194 } |