Bug 1805337 - Remove use of increment on volatile data r=sfink

This removes a custom version of AutoSuppressGCAnalysis that wasn't really
needed and replaces increment with assignment in gbd-tests.cpp.

Differential Revision: https://phabricator.services.mozilla.com/D164576
This commit is contained in:
Jon Coppeard 2022-12-13 17:46:18 +00:00
Родитель 373e513a9f
Коммит c0af6e30a3
5 изменённых файлов: 18 добавлений и 39 удалений

Просмотреть файл

@ -23,7 +23,7 @@ static const JSClass global_class = {"global", JSCLASS_GLOBAL_FLAGS,
static volatile int dontOptimizeMeAway = 0;
void usePointer(const void* ptr) { dontOptimizeMeAway++; }
void usePointer(const void* ptr) { dontOptimizeMeAway = 1; }
template <typename T>
static inline T* checkPtr(T* ptr) {

Просмотреть файл

@ -33,15 +33,6 @@ void use(const T& thing) {
usePointer(&thing);
}
struct AutoSuppressHazardsForTest {
int dummy;
AutoSuppressHazardsForTest() : dummy(3) {}
~AutoSuppressHazardsForTest() {
// Need nontrivial destructor.
usePointer(&dummy);
}
} JS_HAZ_GC_SUPPRESSED;
struct GDBFragment {
GDBFragment() {
next = allFragments;

Просмотреть файл

@ -4,8 +4,6 @@
#include "js/Object.h" // JS::GetClass
FRAGMENT(JSObject, simple) {
AutoSuppressHazardsForTest noanalysis;
JS::Rooted<JSObject*> glob(cx, JS::CurrentGlobalOrNull(cx));
JS::Rooted<JSObject*> plain(cx, JS_NewPlainObject(cx));
JS::Rooted<JSObject*> objectProto(cx, JS::GetRealmObjectPrototype(cx));
@ -17,18 +15,19 @@ FRAGMENT(JSObject, simple) {
JS::Rooted<JSFunction*> funcPtr(
cx, JS_NewFunction(cx, (JSNative)1, 0, 0, "formFollows"));
JSObject& plainRef = *plain;
JSFunction& funcRef = *funcPtr;
JSObject* plainRaw = plain;
JSObject* funcRaw = func;
// JS_NewObject will now assert if you feed it a bad class name, so mangle
// the name after construction.
char namebuf[20] = "goodname";
static JSClass cls{namebuf};
JS::RootedObject badClassName(cx, JS_NewObject(cx, &cls));
MOZ_RELEASE_ASSERT(badClassName);
strcpy(namebuf, "\xc7X");
JSObject& plainRef = *plain;
JSFunction& funcRef = *funcPtr;
JSObject* plainRaw = plain;
JSObject* funcRaw = func;
breakpoint();
use(glob);

Просмотреть файл

@ -6,8 +6,6 @@
#include "vm/StringType.h"
FRAGMENT(JSString, simple) {
AutoSuppressHazardsForTest noanalysis;
JS::Rooted<JSString*> empty(cx, JS_NewStringCopyN(cx, nullptr, 0));
JS::Rooted<JSString*> x(cx, JS_NewStringCopyN(cx, "x", 1));
JS::Rooted<JSString*> z(cx, JS_NewStringCopyZ(cx, "z"));
@ -41,8 +39,6 @@ FRAGMENT(JSString, simple) {
}
FRAGMENT(JSString, null) {
AutoSuppressHazardsForTest noanalysis;
JS::Rooted<JSString*> null(cx, nullptr);
JSString* nullRaw = null;

Просмотреть файл

@ -6,18 +6,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gc/Barrier.h"
#include "js/GCAPI.h"
#include "jsapi-tests/tests.h"
using namespace JS;
using namespace js;
struct AutoIgnoreRootingHazards {
// Force a nontrivial destructor so the compiler sees the whole RAII scope
static volatile int depth;
AutoIgnoreRootingHazards() { depth++; }
~AutoIgnoreRootingHazards() { depth--; }
} JS_HAZ_GC_SUPPRESSED;
volatile int AutoIgnoreRootingHazards::depth = 0;
// Name this constant without creating a GC hazard.
#define BAD_OBJECT_PTR reinterpret_cast<JSObject*>(1)
BEGIN_TEST(testGCStoreBufferRemoval) {
// Sanity check - objects start in the nursery and then become tenured.
@ -28,33 +24,29 @@ BEGIN_TEST(testGCStoreBufferRemoval) {
CHECK(!js::gc::IsInsideNursery(obj.get()));
JS::RootedObject tenuredObject(cx, obj);
// Hide the horrors herein from the static rooting analysis.
AutoIgnoreRootingHazards ignore;
// Test removal of store buffer entries added by HeapPtr<T>.
{
JSObject* badObject = reinterpret_cast<JSObject*>(1);
JSObject* punnedPtr = nullptr;
HeapPtr<JSObject*>* relocPtr =
reinterpret_cast<HeapPtr<JSObject*>*>(&punnedPtr);
new (relocPtr) HeapPtr<JSObject*>;
*relocPtr = NurseryObject();
relocPtr->~HeapPtr<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (relocPtr) HeapPtr<JSObject*>;
*relocPtr = NurseryObject();
*relocPtr = tenuredObject;
relocPtr->~HeapPtr<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (relocPtr) HeapPtr<JSObject*>;
*relocPtr = NurseryObject();
*relocPtr = nullptr;
relocPtr->~HeapPtr<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
}
@ -86,27 +78,26 @@ BEGIN_TEST(testGCStoreBufferRemoval) {
// Test removal of store buffer entries added by Heap<T>.
{
JSObject* badObject = reinterpret_cast<JSObject*>(1);
JSObject* punnedPtr = nullptr;
Heap<JSObject*>* heapPtr = reinterpret_cast<Heap<JSObject*>*>(&punnedPtr);
new (heapPtr) Heap<JSObject*>;
*heapPtr = NurseryObject();
heapPtr->~Heap<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (heapPtr) Heap<JSObject*>;
*heapPtr = NurseryObject();
*heapPtr = tenuredObject;
heapPtr->~Heap<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
new (heapPtr) Heap<JSObject*>;
*heapPtr = NurseryObject();
*heapPtr = nullptr;
heapPtr->~Heap<JSObject*>();
punnedPtr = badObject;
punnedPtr = BAD_OBJECT_PTR;
JS_GC(cx);
}
@ -115,3 +106,5 @@ BEGIN_TEST(testGCStoreBufferRemoval) {
JSObject* NurseryObject() { return JS_NewPlainObject(cx); }
END_TEST(testGCStoreBufferRemoval)
#undef BAD_OBJECT_PTR