summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-03-15 09:34:07 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-03-22 09:42:39 -0400
commita51f30c6712798fc07e57f692d0d0e5ccc59acf1 (patch)
tree8dd5c4dc08d698a12ca143816315bacf78b16bd1 /include
parent414ad7714266abd741cf611b6d6fb5131f088eef (diff)
[Feature #18634] Implement Arrays on Variable Width Allocation
This commit implements arrays on Variable Width Allocation. This allows longer arrays to be embedded (i.e. contents directly follow the object header) which improves performance through better cache locality.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5660
Diffstat (limited to 'include')
-rw-r--r--include/ruby/internal/abi.h2
-rw-r--r--include/ruby/internal/core/rarray.h21
2 files changed, 21 insertions, 2 deletions
diff --git a/include/ruby/internal/abi.h b/include/ruby/internal/abi.h
index 7a6caa6e2e..98a63927c5 100644
--- a/include/ruby/internal/abi.h
+++ b/include/ruby/internal/abi.h
@@ -22,7 +22,7 @@
* In released versions of Ruby, this number should not be changed since teeny
* versions of Ruby should guarantee ABI compatibility.
*/
-#define RUBY_ABI_VERSION 0
+#define RUBY_ABI_VERSION 1
/* Windows does not support weak symbols so ruby_abi_version will not exist
* in the shared library. */
diff --git a/include/ruby/internal/core/rarray.h b/include/ruby/internal/core/rarray.h
index 9f1d0509ea..d9e08839cb 100644
--- a/include/ruby/internal/core/rarray.h
+++ b/include/ruby/internal/core/rarray.h
@@ -130,7 +130,13 @@ enum ruby_rarray_flags {
* 3rd parties must not be aware that there even is more than one way to
* store array elements. It was a bad idea to expose this to them.
*/
+#if USE_RVARGC
+ RARRAY_EMBED_LEN_MASK = RUBY_FL_USER8 | RUBY_FL_USER7 | RUBY_FL_USER6 |
+ RUBY_FL_USER5 | RUBY_FL_USER4 | RUBY_FL_USER3
+#else
RARRAY_EMBED_LEN_MASK = RUBY_FL_USER4 | RUBY_FL_USER3
+#endif
+
#if USE_TRANSIENT_HEAP
,
@@ -156,10 +162,14 @@ enum ruby_rarray_flags {
*/
enum ruby_rarray_consts {
/** Where ::RARRAY_EMBED_LEN_MASK resides. */
- RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3,
+ RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3
+
+#if !USE_RVARGC
+ ,
/** Max possible number elements that can be embedded. */
RARRAY_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
+#endif
};
/** Ruby's array. */
@@ -218,7 +228,16 @@ struct RArray {
* to store its elements. In this case the length is encoded into the
* flags.
*/
+#if USE_RVARGC
+ /* This is a length 1 array because:
+ * 1. GCC has a bug that does not optimize C flexible array members
+ * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
+ * 2. Zero length arrays are not supported by all compilers
+ */
+ const VALUE ary[1];
+#else
const VALUE ary[RARRAY_EMBED_LEN_MAX];
+#endif
} as;
};