Reviewers: marja, dcarney,

Message:
Does this version of the API make any sense?

Also, any ideas for unit tests? I'll add one that the tag changes when the flag
list changes; but I don't see how I can easily unit test any of the other
issues.

Description:
Add a version tag for cached data.

BUG=399580,431699
LOG=N

Please review this at https://codereview.chromium.org/718043002/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+42, -0 lines):
  M include/v8.h
  M src/api.cc
  M src/flags.h
  M src/flags.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index e4a8be6aea4f63071d21b633c815f1ac306f23f4..963ebf535787d4d7844dc011f338b57c629f6873 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -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();
 };


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index dfb452b2a2707f1a697cc248bcff8b8a3c995b84..fddd9e82f4b286cdd49952833d81f87d300f8297 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1846,6 +1846,12 @@ Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
 }


+uint32_t ScriptCompiler::CachedDataVersionTag() {
+  return internal::Version::Hash() ^ internal::FlagList::Hash() ^
+         internal::CpuFeatures::SupportedFeatures();
+}
+
+
 Local<Script> Script::Compile(v8::Handle<String> source,
                               v8::ScriptOrigin* origin) {
   i::Handle<i::String> str = Utils::OpenHandle(*source);
Index: src/flags.cc
diff --git a/src/flags.cc b/src/flags.cc
index e53c45e69d3a35e904f6853035cf6f7c24826f12..90ce752fea871fb57b009cefa6669b0298378711 100644
--- a/src/flags.cc
+++ b/src/flags.cc
@@ -549,4 +549,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 StringHasher::HashSequentialString(args.c_str(), args.length(),
+                                            StringHasher::kZeroHash);
+}
 } }  // namespace v8::internal
Index: src/flags.h
diff --git a/src/flags.h b/src/flags.h
index 78522ffce62b52a707953e15333e944d994bd2b6..9ec5d30119fd3547283ca94683bae30d80ba08ef 100644
--- a/src/flags.h
+++ b/src/flags.h
@@ -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


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to