22 * 23 */ 24 25 package sun.jvm.hotspot.oops; 26 27 import java.io.*; 28 29 import sun.jvm.hotspot.runtime.*; 30 31 // Super class for all fields in an object 32 public class Field { 33 34 Field(FieldIdentifier id, long offset, boolean isVMField) { 35 this.offset = offset; 36 this.id = id; 37 this.isVMField = isVMField; 38 } 39 40 /** Constructor for fields that are named in an InstanceKlass's 41 fields array (i.e., named, non-VM fields) */ 42 Field(InstanceKlass holder, int fieldArrayIndex) { 43 this.holder = holder; 44 this.fieldArrayIndex = fieldArrayIndex; 45 46 ConstantPool cp = holder.getConstants(); 47 TypeArray fields = holder.getFields(); 48 short access = fields.getShortAt(fieldArrayIndex + InstanceKlass.ACCESS_FLAGS_OFFSET); 49 short nameIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.NAME_INDEX_OFFSET); 50 short signatureIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.SIGNATURE_INDEX_OFFSET); 51 offset = VM.getVM().buildIntFromShorts(fields.getShortAt(fieldArrayIndex + InstanceKlass.LOW_OFFSET), 52 fields.getShortAt(fieldArrayIndex + InstanceKlass.HIGH_OFFSET)); 53 short genericSignatureIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET); 54 Symbol name = cp.getSymbolAt(nameIndex); 55 id = new NamedFieldIdentifier(name.asString()); 56 signature = cp.getSymbolAt(signatureIndex); 57 if (genericSignatureIndex != 0) { 58 genericSignature = cp.getSymbolAt(genericSignatureIndex); 59 } else { 60 genericSignature = null; 61 } 62 63 fieldType = new FieldType(signature); 64 accessFlags = new AccessFlags(access); 65 } 66 67 private long offset; 68 private FieldIdentifier id; 69 private boolean isVMField; 70 // Java fields only 71 private InstanceKlass holder; 72 private FieldType fieldType; 73 private Symbol signature; 74 private Symbol genericSignature; 75 private AccessFlags accessFlags; 76 private int fieldArrayIndex; 77 78 /** Returns the byte offset of the field within the object or klass */ 79 public long getOffset() { return offset; } 80 81 /** Returns the identifier of the field */ 82 public FieldIdentifier getID() { return id; } 83 84 /** Indicates whether this is a VM field */ 85 public boolean isVMField() { return isVMField; } 86 87 /** Indicates whether this is a named field */ 88 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); } 89 90 public void printOn(PrintStream tty) { 91 getID().printOn(tty); 92 tty.print(" {" + getOffset() + "} :"); 93 } 94 95 /** (Named, non-VM fields only) Returns the InstanceKlass containing 96 this (static or non-static) field. */ 97 public InstanceKlass getFieldHolder() { 98 return holder; 99 } 100 101 /** (Named, non-VM fields only) Returns the index in the fields 102 TypeArray for this field. Equivalent to the "index" in the VM's 103 fieldDescriptors. */ 104 public int getFieldArrayIndex() { 105 return fieldArrayIndex; 106 } 107 108 /** (Named, non-VM fields only) Retrieves the access flags. */ 109 public long getAccessFlags() { return accessFlags.getValue(); } 110 public AccessFlags getAccessFlagsObj() { return accessFlags; } 111 112 /** (Named, non-VM fields only) Returns the type of this field. */ 113 public FieldType getFieldType() { return fieldType; } 114 115 /** (Named, non-VM fields only) Returns the signature of this 116 field. */ 117 public Symbol getSignature() { return signature; } 118 public Symbol getGenericSignature() { return genericSignature; } 119 120 // 121 // Following acccessors are for named, non-VM fields only 122 // 123 public boolean isPublic() { return accessFlags.isPublic(); } 124 public boolean isPrivate() { return accessFlags.isPrivate(); } 125 public boolean isProtected() { return accessFlags.isProtected(); } | 22 * 23 */ 24 25 package sun.jvm.hotspot.oops; 26 27 import java.io.*; 28 29 import sun.jvm.hotspot.runtime.*; 30 31 // Super class for all fields in an object 32 public class Field { 33 34 Field(FieldIdentifier id, long offset, boolean isVMField) { 35 this.offset = offset; 36 this.id = id; 37 this.isVMField = isVMField; 38 } 39 40 /** Constructor for fields that are named in an InstanceKlass's 41 fields array (i.e., named, non-VM fields) */ 42 Field(InstanceKlass holder, int fieldIndex) { 43 this.holder = holder; 44 this.fieldIndex = fieldIndex; 45 46 offset = holder.getFieldOffset(fieldIndex); 47 genericSignature = holder.getFieldGenericSignature(fieldIndex); 48 49 Symbol name = holder.getFieldName(fieldIndex); 50 id = new NamedFieldIdentifier(name.asString()); 51 52 signature = holder.getFieldSignature(fieldIndex); 53 fieldType = new FieldType(signature); 54 55 short access = holder.getFieldAccessFlags(fieldIndex); 56 accessFlags = new AccessFlags(access); 57 } 58 59 private long offset; 60 private FieldIdentifier id; 61 private boolean isVMField; 62 // Java fields only 63 private InstanceKlass holder; 64 private FieldType fieldType; 65 private Symbol signature; 66 private Symbol genericSignature; 67 private AccessFlags accessFlags; 68 private int fieldIndex; 69 70 /** Returns the byte offset of the field within the object or klass */ 71 public long getOffset() { return offset; } 72 73 /** Returns the identifier of the field */ 74 public FieldIdentifier getID() { return id; } 75 76 /** Indicates whether this is a VM field */ 77 public boolean isVMField() { return isVMField; } 78 79 /** Indicates whether this is a named field */ 80 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); } 81 82 public void printOn(PrintStream tty) { 83 getID().printOn(tty); 84 tty.print(" {" + getOffset() + "} :"); 85 } 86 87 /** (Named, non-VM fields only) Returns the InstanceKlass containing 88 this (static or non-static) field. */ 89 public InstanceKlass getFieldHolder() { 90 return holder; 91 } 92 93 /** (Named, non-VM fields only) Returns the index in the fields 94 TypeArray for this field. Equivalent to the "index" in the VM's 95 fieldDescriptors. */ 96 public int getFieldIndex() { 97 return fieldIndex; 98 } 99 100 /** (Named, non-VM fields only) Retrieves the access flags. */ 101 public long getAccessFlags() { return accessFlags.getValue(); } 102 public AccessFlags getAccessFlagsObj() { return accessFlags; } 103 104 /** (Named, non-VM fields only) Returns the type of this field. */ 105 public FieldType getFieldType() { return fieldType; } 106 107 /** (Named, non-VM fields only) Returns the signature of this 108 field. */ 109 public Symbol getSignature() { return signature; } 110 public Symbol getGenericSignature() { return genericSignature; } 111 112 // 113 // Following acccessors are for named, non-VM fields only 114 // 115 public boolean isPublic() { return accessFlags.isPublic(); } 116 public boolean isPrivate() { return accessFlags.isPrivate(); } 117 public boolean isProtected() { return accessFlags.isProtected(); } |