< prev index next >

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

Print this page
*** 55,39 ***
    // Size of the arrayOopDesc
    private static long headerSize=0;
    private static long lengthOffsetInBytes=0;
    private static long typeSize;
  
    private static long headerSizeInBytes() {
      if (headerSize != 0) {
        return headerSize;
      }
!     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() {
      if (lengthOffsetInBytes != 0) {
        return lengthOffsetInBytes;
      }
!     if (VM.getVM().isCompressedKlassPointersEnabled()) {
!       lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
      } else {
!       lengthOffsetInBytes = typeSize;
      }
      return lengthOffsetInBytes;
    }
  
    // Accessors for declared fields
--- 55,59 ---
    // 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.
+   public 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().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 (elementTypeShouldBeAligned(type)) {
!         return alignObjectSize(headerSizeInBytes())/VM.getVM().getHeapWordSize();
!      } else {
!        return headerSizeInBytes()/VM.getVM().getHeapWordSize();
!      }
!    }
  
!   private static long lengthOffsetInBytes() {
      if (lengthOffsetInBytes != 0) {
        return lengthOffsetInBytes;
      }
!     if (VM.getVM().isCompactObjectHeadersEnabled()) {
!       lengthOffsetInBytes = Oop.getHeaderSize();
      } else {
!       if (VM.getVM().isCompressedKlassPointersEnabled()) {
+         lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
+       } else {
+         lengthOffsetInBytes = typeSize;
+       }
      }
      return lengthOffsetInBytes;
    }
  
    // Accessors for declared fields

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