changeset 4621:dd7d57bcd749

8017588: SA: jstack -l throws UnalignedAddressException while attaching to core file for java that was started with CMS GC Reviewed-by: allwin, jiangli, tschatzl, dholmes
author ehelin
date Tue, 09 Jul 2013 10:03:28 +0200
parents b29fc5f70d65
children 1478a623482d 1331bffeb46e 3a41a31ecbd7
files agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java src/share/vm/oops/instanceKlass.hpp src/share/vm/runtime/vmStructs.cpp
diffstat 3 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Thu Jul 04 03:38:59 2013 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Tue Jul 09 10:03:28 2013 +0200
@@ -89,6 +89,7 @@
     genericSignature     = type.getAddressField("_generic_signature");
     majorVersion         = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize());
     minorVersion         = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize());
+    miscFlags            = new CIntField(type.getCIntegerField("_misc_flags"), Oop.getHeaderSize());
     headerSize           = alignObjectOffset(Oop.getHeaderSize() + type.getSize());
 
     // read field offset constants
@@ -147,6 +148,16 @@
   private static AddressField  genericSignature;
   private static CIntField majorVersion;
   private static CIntField minorVersion;
+  private static CIntField miscFlags;
+
+  private static final long MISC_REWRITTEN            = 1 << 0; // methods rewritten.
+  private static final long MISC_HAS_NONSTATIC_FIELDS = 1 << 1; // for sizing with UseCompressedOops
+  private static final long MISC_SHOULD_VERIFY_CLASS  = 1 << 1; // allow caching of preverification
+  private static final long MISC_IS_ANONYMOUS         = 1 << 3; // has embedded _inner_classes field
+
+  public boolean isAnonymous() {
+    return (miscFlags.getValue(this) & MISC_IS_ANONYMOUS) != 0;
+  }
 
   // type safe enum for ClassState from instanceKlass.hpp
   public static class ClassState {
@@ -799,9 +810,22 @@
 
 
   public long getObjectSize() {
-    long bodySize =    alignObjectOffset(getVtableLen() * getHeap().getOopSize())
-                     + alignObjectOffset(getItableLen() * getHeap().getOopSize())
-                     + (getNonstaticOopMapSize()) * getHeap().getOopSize();
+    final long oopSize = getHeap().getOopSize();
+
+    long vtableSize = alignObjectOffset(getVtableLen() * oopSize);
+    long itableSize = alignObjectOffset(getItableLen() * oopSize);
+
+    long nonStaticOopMapSizeBytes = getNonstaticOopMapSize() * oopSize;
+    long alignedNonStaticOopMapSize = isInterface() || isAnonymous() ?
+                                        alignObjectOffset(nonStaticOopMapSizeBytes) :
+                                        nonStaticOopMapSizeBytes;
+
+    long interfaceImplementorSize = isInterface() ? oopSize : 0;
+    long hostKlassSize = isAnonymous() ? oopSize : 0;
+
+    long bodySize = vtableSize + itableSize + nonStaticOopMapSizeBytes +
+                    interfaceImplementorSize + hostKlassSize;
+
     return alignObjectSize(headerSize + bodySize);
   }
 
--- a/src/share/vm/oops/instanceKlass.hpp	Thu Jul 04 03:38:59 2013 -0700
+++ b/src/share/vm/oops/instanceKlass.hpp	Tue Jul 09 10:03:28 2013 +0200
@@ -779,13 +779,16 @@
 
   int object_size() const
   {
-    return object_size(align_object_offset(vtable_length()) +
-                       align_object_offset(itable_length()) +
-                       ((is_interface() || is_anonymous()) ?
-                         align_object_offset(nonstatic_oop_map_size()) :
-                         nonstatic_oop_map_size()) +
-                       (is_interface() ? (int)sizeof(klassOop)/HeapWordSize : 0) +
-                       (is_anonymous() ? (int)sizeof(klassOop)/HeapWordSize : 0));
+    int vtable_size = align_object_offset(vtable_length());
+    int itable_size = align_object_offset(itable_length());
+    int aligned_nonstatic_oop_map_size = is_interface() || is_anonymous() ?
+                                        align_object_offset(nonstatic_oop_map_size()) :
+                                        nonstatic_oop_map_size();
+    int interface_implementor_size = is_interface() ? (int) sizeof(klassOop) / HeapWordSize : 0;
+    int host_klass_size = is_anonymous() ? (int) sizeof(klassOop) / HeapWordSize : 0;
+
+    return object_size(vtable_size + itable_size + aligned_nonstatic_oop_map_size +
+                       interface_implementor_size + host_klass_size);
   }
   static int vtable_start_offset()    { return header_size(); }
   static int vtable_length_offset()   { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
--- a/src/share/vm/runtime/vmStructs.cpp	Thu Jul 04 03:38:59 2013 -0700
+++ b/src/share/vm/runtime/vmStructs.cpp	Tue Jul 09 10:03:28 2013 +0200
@@ -316,6 +316,7 @@
   nonstatic_field(instanceKlass,               _static_oop_field_count,                       u2)                                   \
   nonstatic_field(instanceKlass,               _nonstatic_oop_map_size,                       int)                                   \
   nonstatic_field(instanceKlass,               _is_marked_dependent,                          bool)                                  \
+  nonstatic_field(instanceKlass,               _misc_flags,                                   u2)                                    \
   nonstatic_field(instanceKlass,               _minor_version,                                u2)                                    \
   nonstatic_field(instanceKlass,               _major_version,                                u2)                                    \
   nonstatic_field(instanceKlass,               _init_state,                                   u1)                                    \