changeset 12727:f19b6d14a035

8170812: Metaspace corruption caused by incorrect memory size for MethodCounters Reviewed-by: kbarrett, coleenp
author aph
date Fri, 07 Apr 2017 13:42:00 +0100
parents d80c43d9a99e
children c92c6416ca03
files src/share/vm/oops/constMethod.hpp src/share/vm/oops/constantPool.hpp src/share/vm/oops/cpCache.hpp src/share/vm/oops/method.hpp src/share/vm/oops/methodCounters.hpp
diffstat 5 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/constMethod.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/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/src/share/vm/oops/constantPool.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/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/src/share/vm/oops/cpCache.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/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/src/share/vm/oops/method.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/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/src/share/vm/oops/methodCounters.hpp	Fri Apr 07 10:51:28 2017 +0000
+++ b/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; }