annotate agent/src/share/classes/sun/jvm/hotspot/runtime/RegisterMap.java @ 12226:7944aba7ba41

8015107: NPG: Use consistent naming for metaspace concepts Reviewed-by: coleenp, mgerdin, hseigel
author ehelin
date Mon, 12 Aug 2013 17:37:02 +0200
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.interpreter.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** <P> A companion structure used for stack traversal. The
a61af66fc99e Initial load
duke
parents:
diff changeset
37 RegisterMap contains misc. information needed in order to do
a61af66fc99e Initial load
duke
parents:
diff changeset
38 correct stack traversal of stack frames. Hence, it must always be
a61af66fc99e Initial load
duke
parents:
diff changeset
39 passed in as an argument to Frame.sender(RegisterMap). </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 <P> The use of RegisterMaps is slightly different in the
a61af66fc99e Initial load
duke
parents:
diff changeset
42 Serviceability Agent APIs than in the VM itself. In the VM, a
a61af66fc99e Initial load
duke
parents:
diff changeset
43 RegisterMap is created either for a particular thread or cloned
a61af66fc99e Initial load
duke
parents:
diff changeset
44 from another RegisterMap. In these APIs, a JavaThread is the
a61af66fc99e Initial load
duke
parents:
diff changeset
45 top-level factory for RegisterMaps, and RegisterMaps know how to
a61af66fc99e Initial load
duke
parents:
diff changeset
46 copy themselves (through either the clone() or copy()
a61af66fc99e Initial load
duke
parents:
diff changeset
47 methods). </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public abstract class RegisterMap implements Cloneable {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 /** Location of registers */
a61af66fc99e Initial load
duke
parents:
diff changeset
51 protected Address[] location;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // FIXME: don't know about LocationValidType
a61af66fc99e Initial load
duke
parents:
diff changeset
53 protected long[] locationValid;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 /** Should include argument_oop marked locations for compiler */
a61af66fc99e Initial load
duke
parents:
diff changeset
55 protected boolean includeArgumentOops;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 /** Reference to current thread */
a61af66fc99e Initial load
duke
parents:
diff changeset
57 protected JavaThread thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 /** Tells if the register map needs to be updated when traversing the stack */
a61af66fc99e Initial load
duke
parents:
diff changeset
59 protected boolean updateMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 /** Location of a frame where the pc is not at a call (NULL if no frame exists) */
a61af66fc99e Initial load
duke
parents:
diff changeset
61 protected static int regCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 protected static int locationValidTypeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 protected static int locationValidSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 });
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private static void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 regCount = db.lookupIntConstant("ConcreteRegisterImpl::number_of_registers").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // FIXME: don't know about LocationValidType. The LocationValidType is typedef'ed as julong
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // so used julong to get the size of LocationValidType.
a61af66fc99e Initial load
duke
parents:
diff changeset
77 locationValidTypeSize = (int)db.lookupType("julong").getSize() * 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 locationValidSize = (regCount + locationValidTypeSize - 1) / locationValidTypeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 protected RegisterMap(JavaThread thread, boolean updateMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 this.thread = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 this.updateMap = updateMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 location = new Address[regCount];
a61af66fc99e Initial load
duke
parents:
diff changeset
85 locationValid = new long[locationValidSize];
a61af66fc99e Initial load
duke
parents:
diff changeset
86 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 /** Makes a copy of map into this */
a61af66fc99e Initial load
duke
parents:
diff changeset
90 protected RegisterMap(RegisterMap map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 Assert.that(map != null, "RegisterMap must be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 this.thread = map.getThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 this.updateMap = map.getUpdateMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 this.includeArgumentOops = map.getIncludeArgumentOops();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 location = new Address[map.location.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
98 locationValid = new long[map.locationValid.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
99 initializeFromPD(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (updateMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (int i = 0; i < locationValidSize; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 long bits = (!getUpdateMap()) ? 0 : map.locationValid[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
103 locationValid[i] = bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // for whichever bits are set, pull in the corresponding map->_location
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int j = i*locationValidTypeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 while (bits != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if ((bits & 1) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 Assert.that(0 <= j && j < regCount, "range check");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 location[j] = map.location[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 bits >>>= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 j += 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public abstract Object clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public RegisterMap copy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return (RegisterMap) clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public void clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 setIncludeArgumentOops(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (!VM.getVM().isCore()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (updateMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 for (int i = 0; i < locationValid.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 locationValid[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 clearPD();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 initializePD();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public Address getLocation(VMReg reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 int i = reg.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 int index = i / locationValidTypeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 Assert.that(0 <= i && i < regCount, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Assert.that(0 <= index && index < locationValidSize, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if ((locationValid[index] & (1 << i % locationValidTypeSize)) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return location[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return getLocationPD(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 public void setLocation(VMReg reg, Address loc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 int i = reg.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 int index = i / locationValidTypeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 Assert.that(0 <= i && i < regCount, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Assert.that(0 <= index && index < locationValidSize, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 Assert.that(updateMap, "updating map that does not need updating");
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 location[i] = loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 locationValid[index] |= (1 << (i % locationValidTypeSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 public boolean getIncludeArgumentOops() {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return includeArgumentOops;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public void setIncludeArgumentOops(boolean f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 includeArgumentOops = f;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public JavaThread getThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public boolean getUpdateMap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return updateMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 printOn(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 tty.println("Register map");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 for (int i = 0; i < location.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 Address src = getLocation(new VMReg(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (src != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 tty.print(" " + VMRegImpl.getRegisterName(i) +
a61af66fc99e Initial load
duke
parents:
diff changeset
192 " [" + src + "] = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (src.andWithMask(VM.getVM().getAddressSize() - 1) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 tty.print("<misaligned>");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 tty.print(src.getAddressAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 /** Platform-dependent clear() functionality */
a61af66fc99e Initial load
duke
parents:
diff changeset
203 protected abstract void clearPD();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 /** Platform-dependent initialize() functionality */
a61af66fc99e Initial load
duke
parents:
diff changeset
205 protected abstract void initializePD();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 /** Platform-dependent initializeFrom() functionality */
a61af66fc99e Initial load
duke
parents:
diff changeset
207 protected abstract void initializeFromPD(RegisterMap map);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 /** Platform-dependent getLocation() functionality */
a61af66fc99e Initial load
duke
parents:
diff changeset
209 protected abstract Address getLocationPD(VMReg reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }