Skip to content

Commit

Permalink
Bug 1677417 - treat this as a parameter for purposes of live range …
Browse files Browse the repository at this point in the history
…r=jonco

Differential Revision: https://phabricator.services.mozilla.com/D97198
  • Loading branch information
hotsphink committed Nov 18, 2020
1 parent 64ac371 commit 34722de
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/src/devtools/rootAnalysis/analyzeRoots.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ function findGCBeforeValueUse(start_body, start_point, suppressed, variable)
// iteration.
worklist.push({body: body, ppoint: body.Index[1],
gcInfo: gcInfo, why: entry});
} else if (variable.Kind == "Arg" && gcInfo) {
} else if ((variable.Kind == "Arg" || variable.Kind == "This") && gcInfo) {
// The scope of arguments starts at the beginning of the
// function
return entry;
Expand Down
8 changes: 8 additions & 0 deletions js/src/devtools/rootAnalysis/t/hazards/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,11 @@ void safevals() {
consume(std::move(unsafe10));
}
}

// Make sure `this` is live at the beginning of a function.
class Subcell : public Cell {
int method() {
GC();
return f; // this->f
}
};
19 changes: 17 additions & 2 deletions js/src/devtools/rootAnalysis/t/hazards/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# flake8: noqa: F821

from collections import defaultdict

test.compile("source.cpp")
test.run_analysis_script("gcTypes")

Expand All @@ -10,6 +12,7 @@
assert "void suppressedFunction()" not in gcFunctions
assert "void halfSuppressedFunction()" in gcFunctions
assert "void unsuppressedFunction()" in gcFunctions
assert "int32 Subcell::method()" in gcFunctions
assert "Cell* f()" in gcFunctions

hazards = test.load_hazards()
Expand All @@ -21,11 +24,12 @@
assert "cell5" not in hazmap
assert "cell6" not in hazmap
assert "<returnvalue>" in hazmap
assert "this" in hazmap

# All hazards should be in f(), loopy(), and safevals()
# All hazards should be in f(), loopy(), safevals(), and method()
assert hazmap["cell2"].function == "Cell* f()"
print(len(set(haz.function for haz in hazards)))
assert len(set(haz.function for haz in hazards)) == 3
assert len(set(haz.function for haz in hazards)) == 4

# Check that the correct GC call is reported for each hazard. (cell3 has a
# hazard from two different GC calls; it doesn't really matter which is
Expand All @@ -43,6 +47,7 @@
# Type names are handy to have in the report.
assert hazmap["cell2"].type == "Cell*"
assert hazmap["<returnvalue>"].type == "Cell*"
assert hazmap["this"].type == "Subcell*"

# loopy hazards. See comments in source.
assert "haz1" not in hazmap
Expand All @@ -66,3 +71,13 @@
assert "safe8" not in hazmap
assert "safe9" not in hazmap
assert "safe10" not in hazmap

# method hazard.

byfunc = defaultdict(lambda: defaultdict(dict))
for haz in hazards:
byfunc[haz.function][haz.variable] = haz

methhaz = byfunc["int32 Subcell::method()"]
assert "this" in methhaz
assert methhaz["this"].type == "Subcell*"

0 comments on commit 34722de

Please sign in to comment.