1 /*
2 * Copyright (c) 2000, 2013, 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 *
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");
53 javaMirror = new OopField(type.getOopField("_java_mirror"), 0);
54 superField = new MetadataField(type.getAddressField("_super"), 0);
55 layoutHelper = new IntField(type.getJIntField("_layout_helper"), 0);
56 name = type.getAddressField("_name");
57 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
58 try {
59 traceIDField = type.getField("_trace_id");
60 } catch(Exception e) {
61 }
62 subklass = new MetadataField(type.getAddressField("_subklass"), 0);
63 nextSibling = new MetadataField(type.getAddressField("_next_sibling"), 0);
64
65 LH_INSTANCE_SLOW_PATH_BIT = db.lookupIntConstant("Klass::_lh_instance_slow_path_bit").intValue();
66 LH_LOG2_ELEMENT_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_log2_element_size_shift").intValue();
67 LH_ELEMENT_TYPE_SHIFT = db.lookupIntConstant("Klass::_lh_element_type_shift").intValue();
68 LH_HEADER_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_header_size_shift").intValue();
69 LH_ARRAY_TAG_SHIFT = db.lookupIntConstant("Klass::_lh_array_tag_shift").intValue();
70 LH_ARRAY_TAG_TYPE_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_type_value").intValue();
71 LH_ARRAY_TAG_OBJ_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_obj_value").intValue();
72 }
73
74 public Klass(Address addr) {
75 super(addr);
76 }
77
78 // jvmdi support - see also class_status in VM code
79 public int getClassStatus() {
80 return 0; // overridden in derived classes
81 }
82
83 public boolean isKlass() { return true; }
84
85 // Fields
86 private static OopField javaMirror;
87 private static MetadataField superField;
88 private static IntField layoutHelper;
89 private static AddressField name;
90 private static CIntField accessFlags;
91 private static MetadataField subklass;
92 private static MetadataField nextSibling;
93 private static sun.jvm.hotspot.types.Field traceIDField;
94
95 private Address getValue(AddressField field) {
96 return addr.getAddressAt(field.getOffset());
97 }
98
99 protected Symbol getSymbol(AddressField field) {
100 return Symbol.create(addr.getAddressAt(field.getOffset()));
101 }
102
103 // Accessors for declared fields
104 public Instance getJavaMirror() { return (Instance) javaMirror.getValue(this); }
105 public Klass getSuper() { return (Klass) superField.getValue(this); }
106 public Klass getJavaSuper() { return null; }
107 public int getLayoutHelper() { return (int) layoutHelper.getValue(this); }
108 public Symbol getName() { return getSymbol(name); }
109 public long getAccessFlags() { return accessFlags.getValue(this); }
110 // Convenience routine
111 public AccessFlags getAccessFlagsObj(){ return new AccessFlags(getAccessFlags()); }
112 public Klass getSubklassKlass() { return (Klass) subklass.getValue(this); }
113 public Klass getNextSiblingKlass() { return (Klass) nextSibling.getValue(this); }
114
115 public long traceID() {
116 if (traceIDField == null) return 0;
117 return traceIDField.getJLong(addr);
118 }
119
120 // computed access flags - takes care of inner classes etc.
121 // This is closer to actual source level than getAccessFlags() etc.
122 public long computeModifierFlags() {
123 return 0L; // Unless overridden, modifier_flags is 0.
124 }
125
126 // same as JVM_GetClassModifiers
127 public final long getClassModifiers() {
128 // unlike the VM counterpart we never have to deal with primitive type,
129 // because we operator on Klass and not an instance of java.lang.Class.
130 long flags = computeModifierFlags();
131 if (isSuper()) {
132 flags |= JVM_ACC_SUPER;
133 }
162 while ( true ) {
163 if ( k1.isSubtypeOf(k2) ) return k2;
164 if ( k2.isSubtypeOf(k1) ) return k1;
165 k1 = k1.getSuper();
166 k2 = k2.getSuper();
167 }
168 }
169
170 public void printValueOn(PrintStream tty) {
171 tty.print("Klass");
172 }
173
174 public void iterateFields(MetadataVisitor visitor) {
175 visitor.doOop(javaMirror, true);
176 visitor.doMetadata(superField, true);
177 visitor.doInt(layoutHelper, true);
178 // visitor.doOop(name, true);
179 visitor.doCInt(accessFlags, true);
180 visitor.doMetadata(subklass, true);
181 visitor.doMetadata(nextSibling, true);
182 }
183
184 public long getObjectSize() {
185 throw new RuntimeException("should not reach here");
186 }
187
188 /** Array class with specific rank */
189 public Klass arrayKlass(int rank) { return arrayKlassImpl(false, rank); }
190 /** Array class with this klass as element type */
191 public Klass arrayKlass() { return arrayKlassImpl(false); }
192 /** These will return null instead of allocating on the heap */
193 public Klass arrayKlassOrNull(int rank) { return arrayKlassImpl(true, rank); }
194 public Klass arrayKlassOrNull() { return arrayKlassImpl(true); }
195
196 public Klass arrayKlassImpl(boolean orNull, int rank) {
197 throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
198 }
199
200 public Klass arrayKlassImpl(boolean orNull) {
201 throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
|
1 /*
2 * Copyright (c) 2000, 2016, 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 *
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");
53 javaMirror = new OopField(type.getOopField("_java_mirror"), 0);
54 superField = new MetadataField(type.getAddressField("_super"), 0);
55 layoutHelper = new IntField(type.getJIntField("_layout_helper"), 0);
56 name = type.getAddressField("_name");
57 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
58 try {
59 traceIDField = type.getField("_trace_id");
60 } catch(Exception e) {
61 }
62 subklass = new MetadataField(type.getAddressField("_subklass"), 0);
63 nextSibling = new MetadataField(type.getAddressField("_next_sibling"), 0);
64 vtableLen = new CIntField(type.getCIntegerField("_vtable_len"), 0);
65
66 LH_INSTANCE_SLOW_PATH_BIT = db.lookupIntConstant("Klass::_lh_instance_slow_path_bit").intValue();
67 LH_LOG2_ELEMENT_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_log2_element_size_shift").intValue();
68 LH_ELEMENT_TYPE_SHIFT = db.lookupIntConstant("Klass::_lh_element_type_shift").intValue();
69 LH_HEADER_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_header_size_shift").intValue();
70 LH_ARRAY_TAG_SHIFT = db.lookupIntConstant("Klass::_lh_array_tag_shift").intValue();
71 LH_ARRAY_TAG_TYPE_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_type_value").intValue();
72 LH_ARRAY_TAG_OBJ_VALUE = db.lookupIntConstant("Klass::_lh_array_tag_obj_value").intValue();
73 }
74
75
76 public Klass(Address addr) {
77 super(addr);
78 }
79
80 // jvmdi support - see also class_status in VM code
81 public int getClassStatus() {
82 return 0; // overridden in derived classes
83 }
84
85 public boolean isKlass() { return true; }
86
87 // Fields
88 private static OopField javaMirror;
89 private static MetadataField superField;
90 private static IntField layoutHelper;
91 private static AddressField name;
92 private static CIntField accessFlags;
93 private static MetadataField subklass;
94 private static MetadataField nextSibling;
95 private static sun.jvm.hotspot.types.Field traceIDField;
96 private static CIntField vtableLen;
97
98 private Address getValue(AddressField field) {
99 return addr.getAddressAt(field.getOffset());
100 }
101
102 protected Symbol getSymbol(AddressField field) {
103 return Symbol.create(addr.getAddressAt(field.getOffset()));
104 }
105
106 // Accessors for declared fields
107 public Instance getJavaMirror() { return (Instance) javaMirror.getValue(this); }
108 public Klass getSuper() { return (Klass) superField.getValue(this); }
109 public Klass getJavaSuper() { return null; }
110 public int getLayoutHelper() { return (int) layoutHelper.getValue(this); }
111 public Symbol getName() { return getSymbol(name); }
112 public long getAccessFlags() { return accessFlags.getValue(this); }
113 // Convenience routine
114 public AccessFlags getAccessFlagsObj(){ return new AccessFlags(getAccessFlags()); }
115 public Klass getSubklassKlass() { return (Klass) subklass.getValue(this); }
116 public Klass getNextSiblingKlass() { return (Klass) nextSibling.getValue(this); }
117 public long getVtableLen() { return vtableLen.getValue(this); }
118
119 public long traceID() {
120 if (traceIDField == null) return 0;
121 return traceIDField.getJLong(addr);
122 }
123
124 // computed access flags - takes care of inner classes etc.
125 // This is closer to actual source level than getAccessFlags() etc.
126 public long computeModifierFlags() {
127 return 0L; // Unless overridden, modifier_flags is 0.
128 }
129
130 // same as JVM_GetClassModifiers
131 public final long getClassModifiers() {
132 // unlike the VM counterpart we never have to deal with primitive type,
133 // because we operator on Klass and not an instance of java.lang.Class.
134 long flags = computeModifierFlags();
135 if (isSuper()) {
136 flags |= JVM_ACC_SUPER;
137 }
166 while ( true ) {
167 if ( k1.isSubtypeOf(k2) ) return k2;
168 if ( k2.isSubtypeOf(k1) ) return k1;
169 k1 = k1.getSuper();
170 k2 = k2.getSuper();
171 }
172 }
173
174 public void printValueOn(PrintStream tty) {
175 tty.print("Klass");
176 }
177
178 public void iterateFields(MetadataVisitor visitor) {
179 visitor.doOop(javaMirror, true);
180 visitor.doMetadata(superField, true);
181 visitor.doInt(layoutHelper, true);
182 // visitor.doOop(name, true);
183 visitor.doCInt(accessFlags, true);
184 visitor.doMetadata(subklass, true);
185 visitor.doMetadata(nextSibling, true);
186 visitor.doCInt(vtableLen, true);
187 }
188
189 public long getObjectSize() {
190 throw new RuntimeException("should not reach here");
191 }
192
193 /** Array class with specific rank */
194 public Klass arrayKlass(int rank) { return arrayKlassImpl(false, rank); }
195 /** Array class with this klass as element type */
196 public Klass arrayKlass() { return arrayKlassImpl(false); }
197 /** These will return null instead of allocating on the heap */
198 public Klass arrayKlassOrNull(int rank) { return arrayKlassImpl(true, rank); }
199 public Klass arrayKlassOrNull() { return arrayKlassImpl(true); }
200
201 public Klass arrayKlassImpl(boolean orNull, int rank) {
202 throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
203 }
204
205 public Klass arrayKlassImpl(boolean orNull) {
206 throw new RuntimeException("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
|