8170812: Metaspace corruption caused by incorrect memory size for MethodCounters
authoraph
Fri, 07 Apr 2017 13:42:00 +0100
changeset 44524 b0d3e8ba6f27
parent 44523 4c7c8239720c
child 44526 731e3ea86eb2
8170812: Metaspace corruption caused by incorrect memory size for MethodCounters Reviewed-by: kbarrett, coleenp
hotspot/src/share/vm/oops/constMethod.hpp
hotspot/src/share/vm/oops/constantPool.hpp
hotspot/src/share/vm/oops/cpCache.hpp
hotspot/src/share/vm/oops/method.hpp
hotspot/src/share/vm/oops/methodCounters.hpp
--- a/hotspot/src/share/vm/oops/constMethod.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/hotspot/src/share/vm/oops/constMethod.hpp	Fri Apr 07 13:42:00 2017 +0100
@@ -359,7 +359,9 @@
   }
 
   // Sizing
-  static int header_size() { return sizeof(ConstMethod)/wordSize; }
+  static int header_size() {
+    return align_size_up(sizeof(ConstMethod), wordSize) / wordSize;
+  }
 
   // Size needed
   static int size(int code_size, InlineTableSizes* sizes);
--- a/hotspot/src/share/vm/oops/constantPool.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/hotspot/src/share/vm/oops/constantPool.hpp	Fri Apr 07 13:42:00 2017 +0100
@@ -705,7 +705,9 @@
   }
 
   // Sizing (in words)
-  static int header_size()             { return sizeof(ConstantPool)/wordSize; }
+  static int header_size()             {
+    return align_size_up(sizeof(ConstantPool), wordSize) / wordSize;
+  }
   static int size(int length)          { return align_metadata_size(header_size() + length); }
   int size() const                     { return size(length()); }
 #if INCLUDE_SERVICES
--- a/hotspot/src/share/vm/oops/cpCache.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/hotspot/src/share/vm/oops/cpCache.hpp	Fri Apr 07 13:42:00 2017 +0100
@@ -359,7 +359,9 @@
                                                    return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
 
   // Code generation support
-  static WordSize size()                         { return in_WordSize(sizeof(ConstantPoolCacheEntry) / wordSize); }
+  static WordSize size()                         {
+    return in_WordSize(align_size_up(sizeof(ConstantPoolCacheEntry), wordSize) / wordSize);
+  }
   static ByteSize size_in_bytes()                { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
   static ByteSize indices_offset()               { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
   static ByteSize f1_offset()                    { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
--- a/hotspot/src/share/vm/oops/method.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/hotspot/src/share/vm/oops/method.hpp	Fri Apr 07 13:42:00 2017 +0100
@@ -671,7 +671,9 @@
 #endif
 
   // sizing
-  static int header_size()                       { return sizeof(Method)/wordSize; }
+  static int header_size()                       {
+    return align_size_up(sizeof(Method), wordSize) / wordSize;
+  }
   static int size(bool is_native);
   int size() const                               { return method_size(); }
 #if INCLUDE_SERVICES
--- a/hotspot/src/share/vm/oops/methodCounters.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/hotspot/src/share/vm/oops/methodCounters.hpp	Fri Apr 07 13:42:00 2017 +0100
@@ -116,7 +116,9 @@
 
   AOT_ONLY(Method* method() const { return _method; })
 
-  static int size() { return sizeof(MethodCounters) / wordSize; }
+  static int size() {
+    return align_size_up(sizeof(MethodCounters), wordSize) / wordSize;
+  }
 
   bool is_klass() const { return false; }