annotate agent/src/share/classes/sun/jvm/hotspot/oops/Field.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents f6f3bb0ee072
children bd7a7ce2e264
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
2 * Copyright (c) 2000, 2012, 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.oops;
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
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.*;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
30 import sun.jvm.hotspot.utilities.*;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Super class for all fields in an object
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class Field {
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 Field(FieldIdentifier id, long offset, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 this.offset = offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 this.id = id;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 this.isVMField = isVMField;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 /** Constructor for fields that are named in an InstanceKlass's
a61af66fc99e Initial load
duke
parents:
diff changeset
42 fields array (i.e., named, non-VM fields) */
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
43 Field(InstanceKlass holder, int fieldIndex) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.holder = holder;
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
45 this.fieldIndex = fieldIndex;
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
46
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
47 offset = holder.getFieldOffset(fieldIndex);
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
48 genericSignature = holder.getFieldGenericSignature(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
50 Symbol name = holder.getFieldName(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51 id = new NamedFieldIdentifier(name.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
52
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
53 signature = holder.getFieldSignature(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 fieldType = new FieldType(signature);
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
55
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
56 short access = holder.getFieldAccessFlags(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 accessFlags = new AccessFlags(access);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private long offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private FieldIdentifier id;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private boolean isVMField;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Java fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private InstanceKlass holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private FieldType fieldType;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private Symbol signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private Symbol genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private AccessFlags accessFlags;
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
69 private int fieldIndex;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 /** Returns the byte offset of the field within the object or klass */
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public long getOffset() { return offset; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 /** Returns the identifier of the field */
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public FieldIdentifier getID() { return id; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 /** Indicates whether this is a VM field */
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public boolean isVMField() { return isVMField; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 /** Indicates whether this is a named field */
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 getID().printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 tty.print(" {" + getOffset() + "} :");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 /** (Named, non-VM fields only) Returns the InstanceKlass containing
a61af66fc99e Initial load
duke
parents:
diff changeset
89 this (static or non-static) field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public InstanceKlass getFieldHolder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 /** (Named, non-VM fields only) Returns the index in the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
95 TypeArray for this field. Equivalent to the "index" in the VM's
a61af66fc99e Initial load
duke
parents:
diff changeset
96 fieldDescriptors. */
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
97 public int getFieldIndex() {
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
98 return fieldIndex;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 /** (Named, non-VM fields only) Retrieves the access flags. */
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public long getAccessFlags() { return accessFlags.getValue(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public AccessFlags getAccessFlagsObj() { return accessFlags; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /** (Named, non-VM fields only) Returns the type of this field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public FieldType getFieldType() { return fieldType; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 /** (Named, non-VM fields only) Returns the signature of this
a61af66fc99e Initial load
duke
parents:
diff changeset
109 field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public Symbol getSignature() { return signature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public Symbol getGenericSignature() { return genericSignature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 //
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // Following acccessors are for named, non-VM fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
115 //
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public boolean isPublic() { return accessFlags.isPublic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public boolean isPrivate() { return accessFlags.isPrivate(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean isProtected() { return accessFlags.isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public boolean isStatic() { return accessFlags.isStatic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public boolean isFinal() { return accessFlags.isFinal(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public boolean isVolatile() { return accessFlags.isVolatile(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public boolean isTransient() { return accessFlags.isTransient(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public boolean isSynthetic() { return accessFlags.isSynthetic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public boolean isEnumConstant() { return accessFlags.isEnum(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (! (obj instanceof Field)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Field other = (Field) obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return this.getFieldHolder().equals(other.getFieldHolder()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
140 this.getID().equals(other.getID());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return getFieldHolder().hashCode() ^ getID().hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }