< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Array.java

Print this page
@@ -55,36 +55,44 @@
    // Size of the arrayOopDesc
    private static long headerSize=0;
    private static long lengthOffsetInBytes=0;
    private static long typeSize;
  
+   // Check whether an element of a typeArrayOop with the given type must be
+   // aligned 0 mod 8.  The typeArrayOop itself must be aligned at least this
+   // strongly.
+   private static boolean elementTypeShouldBeAligned(BasicType type) {
+     if (VM.getVM().isLP64()) {
+       if (type == BasicType.T_OBJECT || type == BasicType.T_ARRAY) {
+         return !VM.getVM().isCompressedOopsEnabled();
+       }
+     }
+     return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
+   }
+ 
    private static long headerSizeInBytes() {
      if (headerSize != 0) {
        return headerSize;
      }
-     if (VM.getVM().isCompressedKlassPointersEnabled()) {
+     if (VM.getVM().isCompactObjectHeadersEnabled()) {
+       headerSize = lengthOffsetInBytes() + VM.getVM().getIntSize();
+     } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
        headerSize = typeSize;
      } else {
        headerSize = VM.getVM().alignUp(typeSize + VM.getVM().getIntSize(),
                                        VM.getVM().getHeapWordSize());
      }
      return headerSize;
    }
  
-   private static long headerSize(BasicType type) {
-     if (Universe.elementTypeShouldBeAligned(type)) {
-        return alignObjectSize(headerSizeInBytes())/VM.getVM().getHeapWordSize();
-     } else {
-       return headerSizeInBytes()/VM.getVM().getHeapWordSize();
-     }
-   }
- 
-   private long lengthOffsetInBytes() {
+   private static long lengthOffsetInBytes() {
      if (lengthOffsetInBytes != 0) {
        return lengthOffsetInBytes;
      }
-     if (VM.getVM().isCompressedKlassPointersEnabled()) {
+     if (VM.getVM().isCompactObjectHeadersEnabled()) {
+       lengthOffsetInBytes = Oop.getHeaderSize();
+     } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
        lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
      } else {
        lengthOffsetInBytes = typeSize;
      }
      return lengthOffsetInBytes;

@@ -106,11 +114,17 @@
      s = Oop.alignObjectSize(s);
      return s;
    }
  
    public static long baseOffsetInBytes(BasicType type) {
-     return headerSize(type) * VM.getVM().getHeapWordSize();
+     long typeSizeInBytes = headerSizeInBytes();
+     if (elementTypeShouldBeAligned(type)) {
+       VM vm = VM.getVM();
+       return vm.alignUp(typeSizeInBytes, vm.getVM().getHeapWordSize());
+     } else {
+       return typeSizeInBytes;
+     }
    }
  
    public boolean isArray()             { return true; }
  
    public void iterateFields(OopVisitor visitor, boolean doVMFields) {
< prev index next >