changeset 10847:d8f1fd8de0a9

8248214: Add paddings for TaskQueueSuper to reduce false-sharing cache contention Summary: This is a downport of a part of JDK-8243326 Reviewed-by: goetz, clanger
author qpzhang
date Tue, 16 Jun 2020 23:15:18 +0800
parents a9ac254e093c
children 19ab41f1f588
files src/share/vm/memory/padded.hpp src/share/vm/utilities/taskqueue.hpp
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/memory/padded.hpp	Mon Oct 26 07:23:15 2020 +0000
+++ b/src/share/vm/memory/padded.hpp	Tue Jun 16 23:15:18 2020 +0800
@@ -80,6 +80,12 @@
   // super class that is specialized for the pad_size == 0 case.
 };
 
+// Similar to PaddedEnd, this macro defines a _pad_buf#id field
+// that is (alignment - size) bytes in size. This macro is used
+// to add padding in between non-class fields in a class or struct.
+#define DEFINE_PAD_MINUS_SIZE(id, alignment, size) \
+          char _pad_buf##id[(alignment) - (size)]
+
 // Helper class to create an array of PaddedEnd<T> objects. All elements will
 // start at a multiple of alignment and the size will be aligned to alignment.
 template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
--- a/src/share/vm/utilities/taskqueue.hpp	Mon Oct 26 07:23:15 2020 +0000
+++ b/src/share/vm/utilities/taskqueue.hpp	Tue Jun 16 23:15:18 2020 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "memory/allocation.hpp"
 #include "memory/allocation.inline.hpp"
+#include "memory/padded.hpp"
 #include "runtime/mutex.hpp"
 #include "runtime/orderAccess.inline.hpp"
 #include "utilities/globalDefinitions.hpp"
@@ -112,9 +113,6 @@
   // Internal type for indexing the queue; also used for the tag.
   typedef NOT_LP64(uint16_t) LP64_ONLY(uint32_t) idx_t;
 
-  // The first free element after the last one pushed (mod N).
-  volatile uint _bottom;
-
   enum { MOD_N_MASK = N - 1 };
 
   class Age {
@@ -154,6 +152,10 @@
     };
   };
 
+  // The first free element after the last one pushed (mod N).
+  volatile uint _bottom;
+  // Add paddings to reduce false-sharing cache contention between _bottom and _age
+  DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE, sizeof(uint));
   volatile Age _age;
 
   // These both operate mod N.