Skip to content

Some tests assume that a single compilation is not cached #6258

Description

@jeisinger

I'd like to cache scripts immediately instead of recompiling the same script twice before caching it. This breaks two tests:

parallel/test-v8-flags assumes that running the same script twice will result in the script being compiled twice, specifically, it flips the --allow-natives-syntax between the two compilations. This could be fixed by using eval() also when testing execution in a different context.

Note that in general, V8 makes no guarantees about flags being changeable after the first isolate was created

The other test is test-vm-cached-data.js which creates a cache for a valid script, and then corrupts the cache and compiles the script again. But since the script is now already in the memory cache, the passed in cache is ignored. Not sure what to do about this one. It looks like this also relies on a pretty borderline case. If you corrupted the cache between the second and third compilation, it would already get ignored now.

Sample output here: https://build.chromium.org/p/client.v8.fyi/builders/V8%20-%20node.js%20integration%20-%20lkgr/builds/243/steps/build%20and%20test%20node.js/logs/stdio

/cc @nodejs/v8

Activity

  1. added
    testIssues and PRs related to Node.js core tests and test infrastructure.
    on Apr 18, 2016
  2. ofrobots commented on Apr 19, 2016

    @ofrobots
    Contributor

    I wonder if the v8.setFlagsFromString API even makes sense in Node.js. Here's the current documentation:

    Set additional V8 command line flags. Use with care; changing settings after the VM has started may result in unpredictable behavior, including crashes and data loss. Or it may simply do nothing.

    @ChALkeR do you know if this gets much use by user-space modules on npm?

    /cc @indutny for test-vm-cache-data.

  3. bnoordhuis commented on Apr 19, 2016

    @bnoordhuis
    Member

    We use it quite a bit within StrongLoop (and yes, we're well aware of the gotchas - I wrote the code and the docs.)

  4. bnoordhuis commented on Apr 19, 2016

    @bnoordhuis
    Member

    parallel/test-v8-flags assumes that running the same script twice will result in the script being compiled twice, specifically, it flips the --allow-natives-syntax between the two compilations. This could be fixed by using eval() also when testing execution in a different context.

    I'm not 100% sure how to parse that sentence. The test executes eval('%_IsSmi(42)') and vm.runInThisContext('%_IsSmi(42)') twice. Is the idea to have a cache keyed on the source string so that the second invocation produces the exact same (identity-wise) v8::Script?

  5. jeisinger commented on Apr 19, 2016

    @jeisinger
    ContributorAuthor

    eval and runInThisContext hit different caches. The cache currently works like this: the first time we compile something, we put a marker in the cache, but not the actual script. On the second compilation, we replace the marker with the actual script, so the third and future attempts to compile will just get the entry from the cache.

    This was introduced for eval() on the assumption that it's unlikely that you'll eval the same string twice, so in order to safe memory, we wait until you actually compile it twice before caching.

    For scripts this makes less sense, as you might run in several times in different contexts (or iframes in a browser). Anyways,

    so if you changed the test to call eval() twice before flipping the flag, it would also fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testIssues and PRs related to Node.js core tests and test infrastructure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions