Chromium Code Reviews

Unified Diff: test/cctest/test-serialize.cc

Issue 394793002: Verify that source string matches serialized code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add check that compilation did not trigger when deserializing Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-serialize.cc
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc
index f025d8f26c152d7952e2043b24a1ea590a13ec32..7c934d9d38055eaf27b0e669a906c1b46c90f056 100644
--- a/test/cctest/test-serialize.cc
+++ b/test/cctest/test-serialize.cc
@@ -32,6 +32,7 @@
#include "src/v8.h"
#include "src/bootstrapper.h"
+#include "src/compilation-cache.h"
#include "src/debug.h"
#include "src/ic-inl.h"
#include "src/natives.h"
@@ -675,39 +676,61 @@ int CountBuiltins() {
}
+static int compile_counter = 0;
+
+void* CreateHistogramForCompiling(const char* name, int min, int max,
+ size_t buckets) {
+ if (strcmp(name, "V8.Compile") == 0) return reinterpret_cast<void*>(1);
+ return NULL;
+}
+
+
+void AddHistogramSampleCallback(void* histogram, int sample) {
+ compile_counter++;
+}
+
+
TEST(SerializeToplevelOnePlusOne) {
FLAG_serialize_toplevel = true;
LocalContext context;
- v8::HandleScope scope(CcTest::isolate());
+ // We use histogram counters to verify that compile did not trigger when
mvstanton 2014/07/15 14:39:36 Could this "VerifyNoCompilation" stuff be wrapped
+ // we intend to deserialize code from cache.
+ CcTest::isolate()->SetCreateHistogramFunction(CreateHistogramForCompiling);
+ CcTest::isolate()->SetAddHistogramSampleFunction(AddHistogramSampleCallback);
+ Isolate* isolate = CcTest::i_isolate();
+ isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
- const char* source1 = "1 + 1";
- const char* source2 = "1 + 2"; // Use alternate string to verify caching.
+ v8::HandleScope scope(CcTest::isolate());
- Isolate* isolate = CcTest::i_isolate();
- Handle<String> source1_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source1))
- .ToHandleChecked();
+ const char* source = "1 + 1";
- Handle<String> source2_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source2))
- .ToHandleChecked();
+ Handle<String> orig_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ Handle<String> copy_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ CHECK(!orig_source.is_identical_to(copy_source));
+ CHECK(orig_source->Equals(*copy_source));
ScriptData* cache = NULL;
+ compile_counter = 0;
Handle<SharedFunctionInfo> orig =
- Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
+ CHECK_EQ(1, compile_counter); // Compile counter was incremented.
int builtins_count = CountBuiltins();
Handle<SharedFunctionInfo> copy =
- Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
-
+ CHECK_EQ(1, compile_counter); // Compile counter was not incremented.
CHECK_NE(*orig, *copy);
- CHECK(Script::cast(copy->script())->source() == *source2_string);
+ CHECK(Script::cast(copy->script())->source() == *copy_source);
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
@@ -726,26 +749,35 @@ TEST(SerializeToplevelOnePlusOne) {
TEST(SerializeToplevelInternalizedString) {
FLAG_serialize_toplevel = true;
LocalContext context;
+ // We use histogram counters to verify that compile did not trigger when
+ // we intend to deserialize code from cache.
+ CcTest::isolate()->SetCreateHistogramFunction(CreateHistogramForCompiling);
+ CcTest::isolate()->SetAddHistogramSampleFunction(AddHistogramSampleCallback);
+ Isolate* isolate = CcTest::i_isolate();
+ isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
+
v8::HandleScope scope(CcTest::isolate());
- const char* source1 = "'string1'";
- const char* source2 = "'string2'"; // Use alternate string to verify caching.
+ const char* source = "'string1'";
- Isolate* isolate = CcTest::i_isolate();
- Handle<String> source1_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source1))
- .ToHandleChecked();
+ Handle<String> orig_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ Handle<String> copy_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ CHECK(!orig_source.is_identical_to(copy_source));
+ CHECK(orig_source->Equals(*copy_source));
- Handle<String> source2_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source2))
- .ToHandleChecked();
Handle<JSObject> global(isolate->context()->global_object());
ScriptData* cache = NULL;
+ compile_counter = 0;
Handle<SharedFunctionInfo> orig =
- Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
+ CHECK_EQ(1, compile_counter); // Compile counter was incremented.
Handle<JSFunction> orig_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
orig, isolate->native_context());
@@ -756,11 +788,12 @@ TEST(SerializeToplevelInternalizedString) {
int builtins_count = CountBuiltins();
Handle<SharedFunctionInfo> copy =
- Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
+ CHECK_EQ(1, compile_counter); // Compile counter was not incremented.
CHECK_NE(*orig, *copy);
- CHECK(Script::cast(copy->script())->source() == *source2_string);
+ CHECK(Script::cast(copy->script())->source() == *copy_source);
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine