Bug 1670323 - Prevent GC in between allocating strings and dependent strings in deduplication test. r=sfink
☠☠ backed out by 30afa0415409 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Mon, 12 Oct 2020 23:38:05 +0000
changeset 552759 361dcdc9f4d43bb09c9a9dceca12bf7656f4a019
parent 552758 5bfba9144099b4fedfad1ad2d8d020f45a2150e6
child 552760 9d453852d2fe30cd2968628a5b35f2af68e397a7
push id37857
push usermalexandru@mozilla.com
push dateTue, 13 Oct 2020 09:40:53 +0000
treeherdermozilla-central@b47b9a46d5f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1670323
milestone83.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1670323 - Prevent GC in between allocating strings and dependent strings in deduplication test. r=sfink Differential Revision: https://phabricator.services.mozilla.com/D93216
js/src/jsapi-tests/testDeduplication.cpp
--- a/js/src/jsapi-tests/testDeduplication.cpp
+++ b/js/src/jsapi-tests/testDeduplication.cpp
@@ -10,16 +10,17 @@
 #include "jsfriendapi.h"
 
 #include "js/RootingAPI.h"
 #include "js/StableStringChars.h"
 #include "js/String.h"  // JS::StringToLinearString
 
 #include "jsapi-tests/tests.h"
 
+#include "gc/GC.h"
 #include "vm/JSContext.h"
 #include "vm/StringType.h"
 
 #include "vm/JSContext-inl.h"
 
 static bool SameChars(JSContext* cx, JSString* str1, JSString* str2,
                       size_t offset) {
   JS::AutoCheckCannotGC nogc(cx);
@@ -35,39 +36,54 @@ static bool SameChars(JSContext* cx, JSS
 BEGIN_TEST(testDeduplication_ASSC) {
   // Test with a long enough string to avoid inline chars allocation.
   const char text[] =
       "Andthebeastshallcomeforthsurroundedbyaroilingcloudofvengeance."
       "Thehouseoftheunbelieversshallberazedandtheyshallbescorchedtoth"
       "eearth.Theirtagsshallblinkuntiltheendofdays.";
 
   // Create a string to deduplicate later strings to.
-  JS::RootedString original(cx, JS_NewStringCopyZ(cx, text));
-  CHECK(original);
+  JS::RootedString original(cx);
+  JS::RootedString str(cx);
+  JS::RootedString dep(cx);
+  JS::RootedString depdep(cx);
+  JS::RootedString str2(cx);
+  JS::RootedString dep2(cx);
+  JS::RootedString depdep2(cx);
 
-  // Create a chain of dependent strings, with a base string whose contents
-  // match `original`'s.
-  JS::RootedString str(cx, JS_NewStringCopyZ(cx, text));
-  CHECK(str);
+  {
+    // This test checks the behavior when GC is performed after allocating
+    // all the following strings.
+    // GC shouldn't happen in between them, even in compacting jobs.
+    js::gc::AutoSuppressGC suppress(cx);
 
-  JS::RootedString dep(cx, JS_NewDependentString(cx, str, 10, 100));
-  CHECK(str);
+    original = JS_NewStringCopyZ(cx, text);
+    CHECK(original);
 
-  JS::RootedString depdep(cx, JS_NewDependentString(cx, dep, 10, 80));
-  CHECK(str);
+    // Create a chain of dependent strings, with a base string whose contents
+    // match `original`'s.
+    str = JS_NewStringCopyZ(cx, text);
+    CHECK(str);
+
+    dep = JS_NewDependentString(cx, str, 10, 100);
+    CHECK(dep);
+
+    depdep = JS_NewDependentString(cx, dep, 10, 80);
+    CHECK(depdep);
 
-  // Repeat. This one will not be prevented from deduplication.
-  JS::RootedString str2(cx, JS_NewStringCopyZ(cx, text));
-  CHECK(str);
+    // Repeat. This one will not be prevented from deduplication.
+    str2 = JS_NewStringCopyZ(cx, text);
+    CHECK(str2);
 
-  JS::RootedString dep2(cx, JS_NewDependentString(cx, str2, 10, 100));
-  CHECK(str);
+    dep2 = JS_NewDependentString(cx, str2, 10, 100);
+    CHECK(dep2);
 
-  JS::RootedString depdep2(cx, JS_NewDependentString(cx, dep2, 10, 80));
-  CHECK(str);
+    depdep2 = JS_NewDependentString(cx, dep2, 10, 80);
+    CHECK(depdep2);
+  }
 
   // Initializing an AutoStableStringChars with `depdep` should prevent the
   // owner of its chars (`str`) from deduplication.
   JS::AutoStableStringChars stable(cx);
   CHECK(stable.init(cx, depdep));
 
   const JS::Latin1Char* chars = stable.latin1Chars();
   CHECK(memcmp(chars, text + 20, 80 * sizeof(JS::Latin1Char)) == 0);