From e8842d862cee16b5ef2cc1260e8088a5857791e0 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 8 Feb 2023 17:07:43 +0000 Subject: [PATCH] [vm] Use atomics when setting RegExp bytecode. TEST=tsan Bug: https://github.com/dart-lang/sdk/issues/51305 Change-Id: I3e93716d31809be76a4017db68557a9b7263d2f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281560 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/vm/object.cc | 8 ++++---- runtime/vm/object.h | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 8432df50215..c2c6c11b498 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -27184,15 +27184,15 @@ void RegExp::set_bytecode(bool is_one_byte, const TypedData& bytecode) const { if (sticky) { if (is_one_byte) { - untag()->set_one_byte_sticky(bytecode.ptr()); + untag()->set_one_byte_sticky(bytecode.ptr()); } else { - untag()->set_two_byte_sticky(bytecode.ptr()); + untag()->set_two_byte_sticky(bytecode.ptr()); } } else { if (is_one_byte) { - untag()->set_one_byte(bytecode.ptr()); + untag()->set_one_byte(bytecode.ptr()); } else { - untag()->set_two_byte(bytecode.ptr()); + untag()->set_two_byte(bytecode.ptr()); } } } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index dbfd737dc10..891b1b539d6 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -12484,8 +12484,9 @@ class RegExp : public Instance { bool is_complex() const { return (type() == kComplex); } intptr_t num_registers(bool is_one_byte) const { - return is_one_byte ? untag()->num_one_byte_registers_ - : untag()->num_two_byte_registers_; + return LoadNonPointer( + is_one_byte ? &untag()->num_one_byte_registers_ + : &untag()->num_two_byte_registers_); } StringPtr pattern() const { return untag()->pattern(); } @@ -12496,11 +12497,13 @@ class RegExp : public Instance { TypedDataPtr bytecode(bool is_one_byte, bool sticky) const { if (sticky) { - return TypedData::RawCast(is_one_byte ? untag()->one_byte_sticky() - : untag()->two_byte_sticky()); + return TypedData::RawCast( + is_one_byte ? untag()->one_byte_sticky() + : untag()->two_byte_sticky()); } else { - return TypedData::RawCast(is_one_byte ? untag()->one_byte() - : untag()->two_byte()); + return TypedData::RawCast( + is_one_byte ? untag()->one_byte() + : untag()->two_byte()); } } @@ -12590,11 +12593,10 @@ class RegExp : public Instance { void set_is_simple() const { set_type(kSimple); } void set_is_complex() const { set_type(kComplex); } void set_num_registers(bool is_one_byte, intptr_t value) const { - if (is_one_byte) { - StoreNonPointer(&untag()->num_one_byte_registers_, value); - } else { - StoreNonPointer(&untag()->num_two_byte_registers_, value); - } + StoreNonPointer( + is_one_byte ? &untag()->num_one_byte_registers_ + : &untag()->num_two_byte_registers_, + value); } RegExpFlags flags() const {