Commit 4f6c75f8 authored by Daniel Vogelheim's avatar Daniel Vogelheim

Add a version tag for cached data.

BUG=399580,431699
LOG=N
R=dcarney@chromium.org, marja@chromium.org

Review URL: https://codereview.chromium.org/718043002

Cr-Commit-Position: refs/heads/master@{#25339}
parent 994094cc
......@@ -1238,6 +1238,26 @@ class V8_EXPORT ScriptCompiler {
static Local<Script> Compile(Isolate* isolate, StreamedSource* source,
Handle<String> full_source_string,
const ScriptOrigin& origin);
/**
* Return a version tag for CachedData for the current V8 version & flags.
*
* This value is meant only for determining whether a previously generated
* CachedData instance is still valid; the tag has no other meaing.
*
* Background: The data carried by CachedData may depend on the exact
* V8 version number or currently compiler flags. This means when
* persisting CachedData, the embedder must take care to not pass in
* data from another V8 version, or the same version with different
* features enabled.
*
* The easiest way to do so is to clear the embedder's cache on any
* such change.
*
* Alternatively, this tag can be stored alongside the cached data and
* compared when it is being used.
*/
static uint32_t CachedDataVersionTag();
};
......
......@@ -14,6 +14,7 @@
#include "include/v8-testing.h"
#include "src/assert-scope.h"
#include "src/background-parsing-task.h"
#include "src/base/functional.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/base/utils/random-number-generator.h"
......@@ -1846,6 +1847,13 @@ Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
}
uint32_t ScriptCompiler::CachedDataVersionTag() {
return static_cast<uint32_t>(base::hash_combine(
internal::Version::Hash(), internal::FlagList::Hash(),
static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
}
Local<Script> Script::Compile(v8::Handle<String> source,
v8::ScriptOrigin* origin) {
i::Handle<i::String> str = Utils::OpenHandle(*source);
......
......@@ -9,6 +9,7 @@
#include "src/v8.h"
#include "src/assembler.h"
#include "src/base/functional.h"
#include "src/base/platform/platform.h"
#include "src/ostreams.h"
......@@ -549,4 +550,17 @@ void FlagList::EnforceFlagImplications() {
#undef FLAG_MODE_DEFINE_IMPLICATIONS
}
uint32_t FlagList::Hash() {
std::ostringstream modified_args_as_string;
for (size_t i = 0; i < num_flags; ++i) {
Flag* current = &flags[i];
if (!current->IsDefault()) {
modified_args_as_string << *current;
}
}
std::string args(modified_args_as_string.str());
return static_cast<uint32_t>(
base::hash_range(args.c_str(), args.c_str() + args.length()));
}
} } // namespace v8::internal
......@@ -57,6 +57,9 @@ class FlagList {
// Set flags as consequence of being implied by another flag.
static void EnforceFlagImplications();
// Hash of current flags (to quickly determine flag changes).
static uint32_t Hash();
};
} } // namespace v8::internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment