annotate agent/src/share/classes/sun/jvm/hotspot/compiler/OopMapValue.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.compiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public class OopMapValue {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private short value;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private short contentReg;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 /** Read from target VM; located in compiler/oopMap.hpp */
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // How bits are organized
a61af66fc99e Initial load
duke
parents:
diff changeset
40 static int TYPE_BITS;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 static int REGISTER_BITS;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 static int TYPE_SHIFT;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static int REGISTER_SHIFT;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static int TYPE_MASK;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static int TYPE_MASK_IN_PLACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static int REGISTER_MASK;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static int REGISTER_MASK_IN_PLACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Types of OopValues
a61af66fc99e Initial load
duke
parents:
diff changeset
50 static int UNUSED_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 static int OOP_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 static int VALUE_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 static int DEAD_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 static int CALLEE_SAVED_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 static int DERIVED_OOP_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 });
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private static void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 TYPE_BITS = db.lookupIntConstant("OopMapValue::type_bits").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 REGISTER_BITS = db.lookupIntConstant("OopMapValue::register_bits").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 TYPE_SHIFT = db.lookupIntConstant("OopMapValue::type_shift").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 REGISTER_SHIFT = db.lookupIntConstant("OopMapValue::register_shift").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 TYPE_MASK = db.lookupIntConstant("OopMapValue::type_mask").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 TYPE_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 REGISTER_MASK = db.lookupIntConstant("OopMapValue::register_mask").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 UNUSED_VALUE = db.lookupIntConstant("OopMapValue::unused_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 OOP_VALUE = db.lookupIntConstant("OopMapValue::oop_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 VALUE_VALUE = db.lookupIntConstant("OopMapValue::value_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 DEAD_VALUE = db.lookupIntConstant("OopMapValue::dead_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 CALLEE_SAVED_VALUE = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 DERIVED_OOP_VALUE = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public static abstract class OopTypes {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public static final OopTypes UNUSED_VALUE = new OopTypes() { int getValue() { return OopMapValue.UNUSED_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
84 public static final OopTypes OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public static final OopTypes VALUE_VALUE = new OopTypes() { int getValue() { return OopMapValue.VALUE_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
86 public static final OopTypes DEAD_VALUE = new OopTypes() { int getValue() { return OopMapValue.DEAD_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public static final OopTypes DERIVED_OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE; }};
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 abstract int getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 protected OopTypes() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 public OopMapValue() { setValue((short) 0); setContentReg(new VMReg(0)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public OopMapValue(VMReg reg, OopTypes t) { setReg(reg); setType(t); }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public OopMapValue(CompressedReadStream stream) { readFrom(stream); }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public void readFrom(CompressedReadStream stream) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 setValue((short) stream.readInt());
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (isCalleeSaved() || isDerivedOop()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 setContentReg(new VMReg(stream.readInt()));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Querying
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public boolean isOop() { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public boolean isValue() { return (getValue() & TYPE_MASK_IN_PLACE) == VALUE_VALUE; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean isDead() { return (getValue() & TYPE_MASK_IN_PLACE) == DEAD_VALUE; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public boolean isDerivedOop() { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public void setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public OopTypes getType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 int which = (getValue() & TYPE_MASK_IN_PLACE);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (which == UNUSED_VALUE) return OopTypes.UNUSED_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 else if (which == OOP_VALUE) return OopTypes.OOP_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 else if (which == VALUE_VALUE) return OopTypes.VALUE_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 else if (which == DEAD_VALUE) return OopTypes.DEAD_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 else if (which == DERIVED_OOP_VALUE) return OopTypes.DERIVED_OOP_VALUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public VMReg getContentReg() { return new VMReg(contentReg); }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public void setContentReg(VMReg r) { contentReg = (short) r.getValue(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 /** Physical location queries */
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public boolean isRegisterLoc() { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public boolean isStackLoc() { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 /** Returns offset from sp. */
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public int getStackOffset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Assert.that(isStackLoc(), "must be stack location");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
145 //
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 private void setValue(short value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 this.value = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private int getValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }