author | coleenp |
Sat, 29 Sep 2012 06:40:00 -0400 | |
changeset 13952 | e3cf184080bc |
parent 13728 | 882756847a04 |
child 18687 | 5a0543c157c9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
2 |
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
21 |
* questions. |
1 | 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 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
33 |
public class Klass extends Metadata implements ClassConstants { |
1 | 34 |
static { |
35 |
VM.registerVMInitializedObserver(new Observer() { |
|
36 |
public void update(Observable o, Object data) { |
|
37 |
initialize(VM.getVM().getTypeDataBase()); |
|
38 |
} |
|
39 |
}); |
|
40 |
} |
|
41 |
||
42 |
// anon-enum constants for _layout_helper. |
|
43 |
public static int LH_INSTANCE_SLOW_PATH_BIT; |
|
44 |
public static int LH_LOG2_ELEMENT_SIZE_SHIFT; |
|
45 |
public static int LH_ELEMENT_TYPE_SHIFT; |
|
46 |
public static int LH_HEADER_SIZE_SHIFT; |
|
47 |
public static int LH_ARRAY_TAG_SHIFT; |
|
48 |
public static int LH_ARRAY_TAG_TYPE_VALUE; |
|
49 |
public static int LH_ARRAY_TAG_OBJ_VALUE; |
|
50 |
||
51 |
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
|
52 |
Type type = db.lookupType("Klass"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
53 |
javaMirror = new OopField(type.getOopField("_java_mirror"), 0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
54 |
superField = new MetadataField(type.getAddressField("_super"), 0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
55 |
layoutHelper = new IntField(type.getJIntField("_layout_helper"), 0); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
56 |
name = type.getAddressField("_name"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
57 |
accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
58 |
subklass = new MetadataField(type.getAddressField("_subklass"), 0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
59 |
nextSibling = new MetadataField(type.getAddressField("_next_sibling"), 0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
60 |
allocCount = new CIntField(type.getCIntegerField("_alloc_count"), 0); |
1 | 61 |
|
62 |
LH_INSTANCE_SLOW_PATH_BIT = db.lookupIntConstant("Klass::_lh_instance_slow_path_bit").intValue(); |
|
63 |
LH_LOG2_ELEMENT_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_log2_element_size_shift").intValue(); |
|
64 |
LH_ELEMENT_TYPE_SHIFT = db.lookupIntConstant("Klass::_lh_element_type_shift").intValue(); |
|
65 |
LH_HEADER_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_header_size_shift").intValue(); |
|
66 |
LH_ARRAY_TAG_SHIFT = db.lookupIntConstant("Klass::_lh_array_tag_shift").intValue(); |
|
67 |
LH_ARRAY_TAG_TYPE_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_type_value").intValue(); |
|
68 |
LH_ARRAY_TAG_OBJ_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_obj_value").intValue(); |
|
69 |
} |
|
70 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
71 |
public Klass(Address addr) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
72 |
super(addr); |
1 | 73 |
} |
74 |
||
75 |
// jvmdi support - see also class_status in VM code |
|
76 |
public int getClassStatus() { |
|
77 |
return 0; // overridden in derived classes |
|
78 |
} |
|
79 |
||
80 |
public boolean isKlass() { return true; } |
|
81 |
||
82 |
// Fields |
|
83 |
private static OopField javaMirror; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
84 |
private static MetadataField superField; |
1 | 85 |
private static IntField layoutHelper; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
86 |
private static AddressField name; |
1 | 87 |
private static CIntField accessFlags; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
88 |
private static MetadataField subklass; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
89 |
private static MetadataField nextSibling; |
1 | 90 |
private static CIntField allocCount; |
91 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
92 |
private Address getValue(AddressField field) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
93 |
return addr.getAddressAt(field.getOffset()); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
94 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
95 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
96 |
protected Symbol getSymbol(AddressField field) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
97 |
return Symbol.create(addr.getAddressAt(field.getOffset())); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
98 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
99 |
|
1 | 100 |
// Accessors for declared fields |
101 |
public Instance getJavaMirror() { return (Instance) javaMirror.getValue(this); } |
|
102 |
public Klass getSuper() { return (Klass) superField.getValue(this); } |
|
103 |
public Klass getJavaSuper() { return null; } |
|
104 |
public int getLayoutHelper() { return (int) layoutHelper.getValue(this); } |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
105 |
public Symbol getName() { return getSymbol(name); } |
1 | 106 |
public long getAccessFlags() { return accessFlags.getValue(this); } |
107 |
// Convenience routine |
|
108 |
public AccessFlags getAccessFlagsObj(){ return new AccessFlags(getAccessFlags()); } |
|
109 |
public Klass getSubklassKlass() { return (Klass) subklass.getValue(this); } |
|
110 |
public Klass getNextSiblingKlass() { return (Klass) nextSibling.getValue(this); } |
|
111 |
public long getAllocCount() { return allocCount.getValue(this); } |
|
112 |
||
113 |
// computed access flags - takes care of inner classes etc. |
|
114 |
// This is closer to actual source level than getAccessFlags() etc. |
|
115 |
public long computeModifierFlags() { |
|
116 |
return 0L; // Unless overridden, modifier_flags is 0. |
|
117 |
} |
|
118 |
||
119 |
// same as JVM_GetClassModifiers |
|
120 |
public final long getClassModifiers() { |
|
121 |
// unlike the VM counterpart we never have to deal with primitive type, |
|
122 |
// because we operator on Klass and not an instance of java.lang.Class. |
|
123 |
long flags = computeModifierFlags(); |
|
124 |
if (isSuper()) { |
|
125 |
flags |= JVM_ACC_SUPER; |
|
126 |
} |
|
127 |
return flags; |
|
128 |
} |
|
129 |
||
130 |
// subclass check |
|
131 |
public boolean isSubclassOf(Klass k) { |
|
132 |
if (k != null) { |
|
133 |
Klass t = this; |
|
134 |
// Run up the super chain and check |
|
135 |
while (t != null) { |
|
136 |
if (t.equals(k)) return true; |
|
137 |
t = t.getSuper(); |
|
138 |
} |
|
139 |
} |
|
140 |
return false; |
|
141 |
} |
|
142 |
||
143 |
// subtype check |
|
144 |
public boolean isSubtypeOf(Klass k) { |
|
145 |
return computeSubtypeOf(k); |
|
146 |
} |
|
147 |
||
148 |
boolean computeSubtypeOf(Klass k) { |
|
149 |
return isSubclassOf(k); |
|
150 |
} |
|
151 |
||
152 |
// Find LCA (Least Common Ancester) in class heirarchy |
|
153 |
public Klass lca( Klass k2 ) { |
|
154 |
Klass k1 = this; |
|
155 |
while ( true ) { |
|
156 |
if ( k1.isSubtypeOf(k2) ) return k2; |
|
157 |
if ( k2.isSubtypeOf(k1) ) return k1; |
|
158 |
k1 = k1.getSuper(); |
|
159 |
k2 = k2.getSuper(); |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
public void printValueOn(PrintStream tty) { |
|
164 |
tty.print("Klass"); |
|
165 |
} |
|
166 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
167 |
public void iterateFields(MetadataVisitor visitor) { |
1 | 168 |
visitor.doOop(javaMirror, true); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
169 |
visitor.doMetadata(superField, true); |
1 | 170 |
visitor.doInt(layoutHelper, true); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
171 |
// visitor.doOop(name, true); |
1 | 172 |
visitor.doCInt(accessFlags, true); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
173 |
visitor.doMetadata(subklass, true); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
174 |
visitor.doMetadata(nextSibling, true); |
1 | 175 |
visitor.doCInt(allocCount, true); |
176 |
} |
|
177 |
||
178 |
public long getObjectSize() { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
179 |
throw new RuntimeException("should not reach here"); |
1 | 180 |
} |
181 |
||
182 |
/** Array class with specific rank */ |
|
183 |
public Klass arrayKlass(int rank) { return arrayKlassImpl(false, rank); } |
|
184 |
/** Array class with this klass as element type */ |
|
185 |
public Klass arrayKlass() { return arrayKlassImpl(false); } |
|
186 |
/** These will return null instead of allocating on the heap */ |
|
187 |
public Klass arrayKlassOrNull(int rank) { return arrayKlassImpl(true, rank); } |
|
188 |
public Klass arrayKlassOrNull() { return arrayKlassImpl(true); } |
|
189 |
||
190 |
public Klass arrayKlassImpl(boolean orNull, int rank) { |
|
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
191 |
throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); |
1 | 192 |
} |
193 |
||
194 |
public Klass arrayKlassImpl(boolean orNull) { |
|
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
195 |
throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); |
1 | 196 |
} |
197 |
||
198 |
// This returns the name in the form java/lang/String which isn't really a signature |
|
199 |
// The subclasses override this to produce the correct form, eg |
|
200 |
// Ljava/lang/String; For ArrayKlasses getName itself is the signature. |
|
201 |
public String signature() { return getName().asString(); } |
|
202 |
||
203 |
// Convenience routines |
|
204 |
public boolean isPublic() { return getAccessFlagsObj().isPublic(); } |
|
205 |
public boolean isFinal() { return getAccessFlagsObj().isFinal(); } |
|
206 |
public boolean isInterface() { return getAccessFlagsObj().isInterface(); } |
|
207 |
public boolean isAbstract() { return getAccessFlagsObj().isAbstract(); } |
|
208 |
public boolean isSuper() { return getAccessFlagsObj().isSuper(); } |
|
209 |
public boolean isSynthetic() { return getAccessFlagsObj().isSynthetic(); } |
|
210 |
public boolean hasFinalizer() { return getAccessFlagsObj().hasFinalizer(); } |
|
211 |
public boolean isCloneable() { return getAccessFlagsObj().isCloneable(); } |
|
212 |
public boolean hasVanillaConstructor() { return getAccessFlagsObj().hasVanillaConstructor(); } |
|
213 |
public boolean hasMirandaMethods () { return getAccessFlagsObj().hasMirandaMethods(); } |
|
214 |
} |