Opened 10 years ago
Closed 10 years ago
#2416 closed task (fixed)
Fix moving GC and rooting issues with ValueCloner
Reported by: | Yves | Owned by: | Yves |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 16 |
Component: | Core engine | Keywords: | Spidermonkey |
Cc: | Patch: |
Description (last modified by )
The ValueCloner in ScriptInterface.cpp implements caching of cloned values by associating a GCThing pointer from another compartment with the cloned version of that value in the current compartment.
This fails with a moving GC because the GCThing pointer can change and because the jsval it uses as value in the map can also change.
There's some more information about moving GC in #2415.
Proposed solution 1
At the moment I don't see why we even need this ValueCloner. I've replaced it with a much simpler implementation with structured clones. ValueCloner was probably introduced earlier when structured clones weren't available yet or when there were some issues with them.
This solution should work with a moving GC and doesn't require special care for rooting (CloneValueFromOtherContext still returns a jsval in this patch, but that should be easy to fix later). CloneValueFromOtherContext is currently mainly used for getting data from the simulation to the GUI. There's another use of it for the serialization test mode in Simulation2.cpp.
Of course when talking about removing something that does caching, the first concern is performance. Since a new instance of ValueCloner is created for each call to CloneValueFromOtherContext, it only caches objects that are linked multiple times in the value to clone. The structured clone most likely does this too internally (otherwise it would get problems with cyclic references).
I've tested it in practice by profiling a game against the AI on Alpine Valleys. Because this cloning is mainly used in the GUI, I couldn't use a non-visual replay. This means the graphs are from different games.
Attachments (3)
Change History (13)
by , 10 years ago
Attachment: | Remove_ValueCloner_v1.0.diff added |
---|
by , 10 years ago
Attachment: | Alpine_Valleys_CloneValueFromOtherContext_modified.png added |
---|
Profiling after applying the patch
by , 10 years ago
Attachment: | Alpine_Valleys_CloneValueFromOtherContext_original.png added |
---|
Profiling original
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Description: | modified (diff) |
---|
comment:4 by , 10 years ago
Description: | modified (diff) |
---|
comment:6 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I'm reopening this ticket because there are problems with cyclic references which causes the tests to fail at the moment (I don't know if we try to clone any cyclic references somewhere else). Cyclic references work with structured clones in SpiderMonkey 24, but I have to fix the tests because sharp variables were removed. I will probably revert r14724 and add it to my WIP patch in #1886 together with the fixed tests.
comment:7 by , 10 years ago
Status: | reopened → new |
---|
comment:8 by , 10 years ago
Status: | new → assigned |
---|
Removes ValueCloner and replaces it with a much simple implementation using StructuredClones