40 public void update(Observable o, Object data) {
41 initialize(VM.getVM().getTypeDataBase());
42 }
43 });
44 }
45
46 Array(OopHandle handle, ObjectHeap heap) {
47 super(handle, heap);
48 }
49
50 private static void initialize(TypeDataBase db) throws WrongTypeException {
51 Type type = db.lookupType("arrayOopDesc");
52 typeSize = (int)type.getSize();
53 }
54
55 // Size of the arrayOopDesc
56 private static long headerSize=0;
57 private static long lengthOffsetInBytes=0;
58 private static long typeSize;
59
60 private static long headerSizeInBytes() {
61 if (headerSize != 0) {
62 return headerSize;
63 }
64 if (VM.getVM().isCompressedKlassPointersEnabled()) {
65 headerSize = typeSize;
66 } else {
67 headerSize = VM.getVM().alignUp(typeSize + VM.getVM().getIntSize(),
68 VM.getVM().getHeapWordSize());
69 }
70 return headerSize;
71 }
72
73 private static long headerSize(BasicType type) {
74 if (Universe.elementTypeShouldBeAligned(type)) {
75 return alignObjectSize(headerSizeInBytes())/VM.getVM().getHeapWordSize();
76 } else {
77 return headerSizeInBytes()/VM.getVM().getHeapWordSize();
78 }
79 }
80
81 private long lengthOffsetInBytes() {
82 if (lengthOffsetInBytes != 0) {
83 return lengthOffsetInBytes;
84 }
85 if (VM.getVM().isCompressedKlassPointersEnabled()) {
86 lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
87 } else {
88 lengthOffsetInBytes = typeSize;
89 }
90 return lengthOffsetInBytes;
91 }
92
93 // Accessors for declared fields
94 public long getLength() {
95 boolean isUnsigned = true;
96 return this.getHandle().getCIntegerAt(lengthOffsetInBytes(), VM.getVM().getIntSize(), isUnsigned);
97 }
98
99 public long getObjectSize() {
100 ArrayKlass klass = (ArrayKlass) getKlass();
101 // We have to fetch the length of the array, shift (multiply) it
102 // appropriately, up to wordSize, add the header, and align to
103 // object size.
104 long s = getLength() << klass.getLog2ElementSize();
105 s += klass.getArrayHeaderInBytes();
106 s = Oop.alignObjectSize(s);
107 return s;
108 }
109
110 public static long baseOffsetInBytes(BasicType type) {
111 return headerSize(type) * VM.getVM().getHeapWordSize();
112 }
113
114 public boolean isArray() { return true; }
115
116 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
117 super.iterateFields(visitor, doVMFields);
118 }
119 }
|
40 public void update(Observable o, Object data) {
41 initialize(VM.getVM().getTypeDataBase());
42 }
43 });
44 }
45
46 Array(OopHandle handle, ObjectHeap heap) {
47 super(handle, heap);
48 }
49
50 private static void initialize(TypeDataBase db) throws WrongTypeException {
51 Type type = db.lookupType("arrayOopDesc");
52 typeSize = (int)type.getSize();
53 }
54
55 // Size of the arrayOopDesc
56 private static long headerSize=0;
57 private static long lengthOffsetInBytes=0;
58 private static long typeSize;
59
60 // Check whether an element of a typeArrayOop with the given type must be
61 // aligned 0 mod 8. The typeArrayOop itself must be aligned at least this
62 // strongly.
63 public static boolean elementTypeShouldBeAligned(BasicType type) {
64 if (VM.getVM().isLP64()) {
65 if (type == BasicType.T_OBJECT || type == BasicType.T_ARRAY) {
66 return !VM.getVM().isCompressedOopsEnabled();
67 }
68 }
69 return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
70 }
71
72 private static long headerSizeInBytes() {
73 if (headerSize != 0) {
74 return headerSize;
75 }
76 if (VM.getVM().isCompactObjectHeadersEnabled()) {
77 headerSize = lengthOffsetInBytes() + VM.getVM().getIntSize();
78 } else {
79 if (VM.getVM().isCompressedKlassPointersEnabled()) {
80 headerSize = typeSize;
81 } else {
82 headerSize = VM.getVM().alignUp(typeSize + VM.getVM().getIntSize(),
83 VM.getVM().getHeapWordSize());
84 }
85 }
86 return headerSize;
87 }
88
89 private static long headerSize(BasicType type) {
90 if (elementTypeShouldBeAligned(type)) {
91 return alignObjectSize(headerSizeInBytes())/VM.getVM().getHeapWordSize();
92 } else {
93 return headerSizeInBytes()/VM.getVM().getHeapWordSize();
94 }
95 }
96
97 private static long lengthOffsetInBytes() {
98 if (lengthOffsetInBytes != 0) {
99 return lengthOffsetInBytes;
100 }
101 if (VM.getVM().isCompactObjectHeadersEnabled()) {
102 lengthOffsetInBytes = Oop.getHeaderSize();
103 } else {
104 if (VM.getVM().isCompressedKlassPointersEnabled()) {
105 lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
106 } else {
107 lengthOffsetInBytes = typeSize;
108 }
109 }
110 return lengthOffsetInBytes;
111 }
112
113 // Accessors for declared fields
114 public long getLength() {
115 boolean isUnsigned = true;
116 return this.getHandle().getCIntegerAt(lengthOffsetInBytes(), VM.getVM().getIntSize(), isUnsigned);
117 }
118
119 public long getObjectSize() {
120 ArrayKlass klass = (ArrayKlass) getKlass();
121 // We have to fetch the length of the array, shift (multiply) it
122 // appropriately, up to wordSize, add the header, and align to
123 // object size.
124 long s = getLength() << klass.getLog2ElementSize();
125 s += klass.getArrayHeaderInBytes();
126 s = Oop.alignObjectSize(s);
127 return s;
128 }
129
130 public static long baseOffsetInBytes(BasicType type) {
131 if (VM.getVM().isCompactObjectHeadersEnabled()) {
132 long typeSizeInBytes = headerSizeInBytes();
133 if (elementTypeShouldBeAligned(type)) {
134 VM vm = VM.getVM();
135 return vm.alignUp(typeSizeInBytes, vm.getVM().getHeapWordSize());
136 } else {
137 return typeSizeInBytes;
138 }
139 } else {
140 return headerSize(type) * VM.getVM().getHeapWordSize();
141 }
142 }
143
144 public boolean isArray() { return true; }
145
146 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
147 super.iterateFields(visitor, doVMFields);
148 }
149 }
|