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 Yves)

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.

Original:
Profiling original

Patch:
Profiling after applying the patch

Attachments (3)

Remove_ValueCloner_v1.0.diff (4.2 KB ) - added by Yves 10 years ago.
Removes ValueCloner and replaces it with a much simple implementation using StructuredClones
Alpine_Valleys_CloneValueFromOtherContext_modified.png (92.6 KB ) - added by Yves 10 years ago.
Profiling after applying the patch
Alpine_Valleys_CloneValueFromOtherContext_original.png (89.9 KB ) - added by Yves 10 years ago.
Profiling original

Download all attachments as: .zip

Change History (13)

by Yves, 10 years ago

Removes ValueCloner and replaces it with a much simple implementation using StructuredClones

by Yves, 10 years ago

Profiling after applying the patch

by Yves, 10 years ago

Profiling original

comment:1 by Yves, 10 years ago

Description: modified (diff)

comment:2 by Yves, 10 years ago

Description: modified (diff)

comment:3 by Yves, 10 years ago

Description: modified (diff)

comment:4 by Yves, 10 years ago

Description: modified (diff)

comment:5 by Yves, 10 years ago

Owner: set to Yves
Resolution: fixed
Status: newclosed

In 14724:

Removes ValueCloner.

Fixes #2416
Refs #2415
Refs #1886

comment:6 by Yves, 10 years ago

Resolution: fixed
Status: closedreopened

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 Yves, 10 years ago

Status: reopenednew

comment:8 by Yves, 10 years ago

Status: newassigned

comment:9 by Yves, 10 years ago

In 14733:

Reverts r14724. Structured clones don't support cyclic references in SpiderMonkey v1.8.5.
SpiderMonkey v24 supports it and I'll add this change to #1886 instead.

Refs #2416
Refs #2415
Refs #1886

comment:10 by Yves, 10 years ago

Resolution: fixed
Status: assignedclosed

In 14877:

Second (main) commit for the SpiderMonkey upgrade.

This commit contains all the required changes to our source files and build scripts (hopefully).
A next commit will remove the old stuff of SpiderMonkey 1.8.5.

Spcial thanks to:

  • H4writer who helped a lot mainly with the performance issues we had/have, but also with other problems or questions.
  • Leper for the review.
  • Historic_bruno for implementing the build scripts on Mac OS X and testing on the Mac.
  • The people from the #jsapi channel and from mozilla.dev.tech.js-engine who answered a lot of questions and helped solving problems.
  • All the other people who helped

Refs #1886
Fixes #2442
Fixes #2416

Note: See TracTickets for help on using tickets.