Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "src/snapshot/deserializer.h" | 43 #include "src/snapshot/deserializer.h" |
| 44 #include "src/snapshot/natives.h" | 44 #include "src/snapshot/natives.h" |
| 45 #include "src/snapshot/partial-serializer.h" | 45 #include "src/snapshot/partial-serializer.h" |
| 46 #include "src/snapshot/snapshot.h" | 46 #include "src/snapshot/snapshot.h" |
| 47 #include "src/snapshot/startup-serializer.h" | 47 #include "src/snapshot/startup-serializer.h" |
| 48 #include "test/cctest/cctest.h" | 48 #include "test/cctest/cctest.h" |
| 49 #include "test/cctest/heap/utils-inl.h" | 49 #include "test/cctest/heap/utils-inl.h" |
| 50 | 50 |
| 51 using namespace v8::internal; | 51 using namespace v8::internal; |
| 52 | 52 |
| 53 | |
| 54 bool DefaultSnapshotAvailable() { | |
| 55 return i::Snapshot::DefaultSnapshotBlob() != NULL; | |
| 56 } | |
| 57 | |
| 58 | |
| 59 void DisableTurbofan() { | 53 void DisableTurbofan() { |
| 60 const char* flag = "--turbo-filter=\"\""; | 54 const char* flag = "--turbo-filter=\"\""; |
| 61 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 55 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 62 } | 56 } |
| 63 | 57 |
| 64 | 58 |
| 65 // TestIsolate is used for testing isolate serialization. | 59 // TestIsolate is used for testing isolate serialization. |
| 66 class TestIsolate : public Isolate { | 60 class TestIsolate : public Isolate { |
| 67 public: | 61 public: |
| 68 static v8::Isolate* NewInitialized(bool enable_serializer) { | 62 static v8::Isolate* NewInitialized(bool enable_serializer) { |
| 69 i::Isolate* isolate = new TestIsolate(enable_serializer); | 63 i::Isolate* isolate = new TestIsolate(enable_serializer); |
| 70 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 64 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 71 v8::Isolate::Scope isolate_scope(v8_isolate); | 65 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 72 isolate->Init(NULL); | 66 isolate->Init(NULL); |
| 73 return v8_isolate; | 67 return v8_isolate; |
| 74 } | 68 } |
| 75 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) { | 69 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) { |
| 76 set_array_buffer_allocator(CcTest::array_buffer_allocator()); | 70 set_array_buffer_allocator(CcTest::array_buffer_allocator()); |
| 77 } | 71 } |
| 78 }; | 72 }; |
| 79 | 73 |
| 80 | 74 static Vector<const byte> WritePayload(const Vector<const byte>& payload) { |
| 81 void WritePayload(const Vector<const byte>& payload, const char* file_name) { | 75 int length = payload.length(); |
| 82 FILE* file = v8::base::OS::FOpen(file_name, "wb"); | 76 byte* blob = NewArray<byte>(length); |
| 83 if (file == NULL) { | 77 memcpy(blob, payload.begin(), length); |
| 84 PrintF("Unable to write to snapshot file \"%s\"\n", file_name); | 78 return Vector<const byte>(const_cast<const byte*>(blob), length); |
| 85 exit(1); | |
| 86 } | |
| 87 size_t written = fwrite(payload.begin(), 1, payload.length(), file); | |
| 88 if (written != static_cast<size_t>(payload.length())) { | |
| 89 i::PrintF("Writing snapshot file failed.. Aborting.\n"); | |
| 90 exit(1); | |
| 91 } | |
| 92 fclose(file); | |
| 93 } | 79 } |
| 94 | 80 |
| 95 | 81 static Vector<const byte> Serialize(v8::Isolate* isolate) { |
| 96 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { | |
| 97 SnapshotByteSink sink; | |
| 98 StartupSerializer ser(isolate, &sink); | |
| 99 ser.SerializeStrongReferences(); | |
| 100 ser.SerializeWeakReferencesAndDeferred(); | |
| 101 SnapshotData snapshot_data(ser); | |
| 102 WritePayload(snapshot_data.RawData(), snapshot_file); | |
| 103 return true; | |
| 104 } | |
| 105 | |
| 106 | |
| 107 static void Serialize(v8::Isolate* isolate) { | |
| 108 // We have to create one context. One reason for this is so that the builtins | 82 // We have to create one context. One reason for this is so that the builtins |
| 109 // can be loaded from v8natives.js and their addresses can be processed. This | 83 // can be loaded from v8natives.js and their addresses can be processed. This |
| 110 // will clear the pending fixups array, which would otherwise contain GC roots | 84 // will clear the pending fixups array, which would otherwise contain GC roots |
| 111 // that would confuse the serialization/deserialization process. | 85 // that would confuse the serialization/deserialization process. |
| 112 v8::Isolate::Scope isolate_scope(isolate); | 86 v8::Isolate::Scope isolate_scope(isolate); |
| 113 { | 87 { |
| 114 v8::HandleScope scope(isolate); | 88 v8::HandleScope scope(isolate); |
| 115 v8::Context::New(isolate); | 89 v8::Context::New(isolate); |
| 116 } | 90 } |
| 117 | 91 |
| 118 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); | 92 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); |
| 119 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); | 93 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); |
| 120 WriteToFile(internal_isolate, FLAG_testing_serialization_file); | 94 SnapshotByteSink sink; |
| 95 StartupSerializer ser(internal_isolate, &sink); | |
| 96 ser.SerializeStrongReferences(); | |
| 97 ser.SerializeWeakReferencesAndDeferred(); | |
| 98 SnapshotData snapshot_data(ser); | |
| 99 return WritePayload(snapshot_data.RawData()); | |
| 121 } | 100 } |
| 122 | 101 |
| 123 | 102 |
| 124 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, | 103 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, |
| 125 Vector<const uint8_t> body, | 104 Vector<const uint8_t> body, |
| 126 Vector<const uint8_t> tail, int repeats) { | 105 Vector<const uint8_t> tail, int repeats) { |
| 127 int source_length = head.length() + body.length() * repeats + tail.length(); | 106 int source_length = head.length() + body.length() * repeats + tail.length(); |
| 128 uint8_t* source = NewArray<uint8_t>(static_cast<size_t>(source_length)); | 107 uint8_t* source = NewArray<uint8_t>(static_cast<size_t>(source_length)); |
| 129 CopyChars(source, head.start(), head.length()); | 108 CopyChars(source, head.start(), head.length()); |
| 130 for (int i = 0; i < repeats; i++) { | 109 for (int i = 0; i < repeats; i++) { |
| 131 CopyChars(source + head.length() + i * body.length(), body.start(), | 110 CopyChars(source + head.length() + i * body.length(), body.start(), |
| 132 body.length()); | 111 body.length()); |
| 133 } | 112 } |
| 134 CopyChars(source + head.length() + repeats * body.length(), tail.start(), | 113 CopyChars(source + head.length() + repeats * body.length(), tail.start(), |
| 135 tail.length()); | 114 tail.length()); |
| 136 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), | 115 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), |
| 137 source_length); | 116 source_length); |
| 138 } | 117 } |
| 139 | 118 |
| 140 | 119 v8::Isolate* InitializeFromBlob(Vector<const byte> blob) { |
| 141 // Test that the whole heap can be serialized. | |
| 142 UNINITIALIZED_TEST(Serialize) { | |
| 143 DisableTurbofan(); | |
| 144 if (DefaultSnapshotAvailable()) return; | |
| 145 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | |
| 146 Serialize(isolate); | |
| 147 } | |
| 148 | |
| 149 | |
| 150 // Test that heap serialization is non-destructive. | |
| 151 UNINITIALIZED_TEST(SerializeTwice) { | |
| 152 DisableTurbofan(); | |
| 153 if (DefaultSnapshotAvailable()) return; | |
| 154 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | |
| 155 Serialize(isolate); | |
| 156 Serialize(isolate); | |
| 157 } | |
| 158 | |
| 159 | |
| 160 //---------------------------------------------------------------------------- | |
| 161 // Tests that the heap can be deserialized. | |
| 162 | |
| 163 v8::Isolate* InitializeFromFile(const char* snapshot_file) { | |
| 164 int len; | |
| 165 byte* str = ReadBytes(snapshot_file, &len); | |
| 166 if (!str) return NULL; | |
| 167 v8::Isolate* v8_isolate = NULL; | 120 v8::Isolate* v8_isolate = NULL; |
| 168 { | 121 { |
| 169 SnapshotData snapshot_data(Vector<const byte>(str, len)); | 122 SnapshotData snapshot_data(blob); |
| 170 Deserializer deserializer(&snapshot_data); | 123 Deserializer deserializer(&snapshot_data); |
| 171 Isolate* isolate = new TestIsolate(false); | 124 Isolate* isolate = new TestIsolate(false); |
| 172 v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 125 v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 173 v8::Isolate::Scope isolate_scope(v8_isolate); | 126 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 174 isolate->Init(&deserializer); | 127 isolate->Init(&deserializer); |
| 175 } | 128 } |
| 176 DeleteArray(str); | |
| 177 return v8_isolate; | 129 return v8_isolate; |
| 178 } | 130 } |
| 179 | 131 |
| 180 | 132 static v8::Isolate* Deserialize(Vector<const byte> blob) { |
| 181 static v8::Isolate* Deserialize() { | 133 v8::Isolate* isolate = InitializeFromBlob(blob); |
| 182 v8::Isolate* isolate = InitializeFromFile(FLAG_testing_serialization_file); | |
| 183 CHECK(isolate); | 134 CHECK(isolate); |
| 184 return isolate; | 135 return isolate; |
| 185 } | 136 } |
| 186 | 137 |
| 187 | 138 |
| 188 static void SanityCheck(v8::Isolate* v8_isolate) { | 139 static void SanityCheck(v8::Isolate* v8_isolate) { |
| 189 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 140 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 190 v8::HandleScope scope(v8_isolate); | 141 v8::HandleScope scope(v8_isolate); |
| 191 #ifdef VERIFY_HEAP | 142 #ifdef VERIFY_HEAP |
| 192 isolate->heap()->Verify(); | 143 isolate->heap()->Verify(); |
| 193 #endif | 144 #endif |
| 194 CHECK(isolate->global_object()->IsJSObject()); | 145 CHECK(isolate->global_object()->IsJSObject()); |
| 195 CHECK(isolate->native_context()->IsContext()); | 146 CHECK(isolate->native_context()->IsContext()); |
| 196 CHECK(isolate->heap()->string_table()->IsStringTable()); | 147 CHECK(isolate->heap()->string_table()->IsStringTable()); |
| 197 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); | 148 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); |
| 198 } | 149 } |
| 199 | 150 |
| 200 UNINITIALIZED_TEST(Deserialize) { | 151 UNINITIALIZED_TEST(StartupSerializerOnce) { |
| 201 // The serialize-deserialize tests only work if the VM is built without | 152 // The serialize-deserialize tests only work if the VM is built without |
| 202 // serialization. That doesn't matter. We don't need to be able to | 153 // serialization. That doesn't matter. We don't need to be able to |
| 203 // serialize a snapshot in a VM that is booted from a snapshot. | 154 // serialize a snapshot in a VM that is booted from a snapshot. |
| 204 DisableTurbofan(); | 155 DisableTurbofan(); |
| 205 if (DefaultSnapshotAvailable()) return; | |
|
Michael Achenbach
2016/03/10 09:26:46
So, the tests are now executed also with snapshot
Yang
2016/03/10 09:33:49
Yes. These tests should be fast enough. Each test
| |
| 206 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | 156 v8::Isolate* isolate = TestIsolate::NewInitialized(true); |
| 207 Serialize(isolate); | 157 Vector<const byte> blob = Serialize(isolate); |
| 208 isolate = Deserialize(); | 158 isolate = Deserialize(blob); |
| 159 blob.Dispose(); | |
| 209 { | 160 { |
| 210 v8::HandleScope handle_scope(isolate); | 161 v8::HandleScope handle_scope(isolate); |
| 211 v8::Isolate::Scope isolate_scope(isolate); | 162 v8::Isolate::Scope isolate_scope(isolate); |
| 212 | 163 |
| 213 v8::Local<v8::Context> env = v8::Context::New(isolate); | 164 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 214 env->Enter(); | 165 env->Enter(); |
| 215 | 166 |
| 216 SanityCheck(isolate); | 167 SanityCheck(isolate); |
| 217 } | 168 } |
| 218 isolate->Dispose(); | 169 isolate->Dispose(); |
| 219 } | 170 } |
| 220 | 171 |
| 221 UNINITIALIZED_TEST(DeserializeFromSecondSerialization) { | 172 UNINITIALIZED_TEST(StartupSerializerTwice) { |
| 222 DisableTurbofan(); | 173 DisableTurbofan(); |
| 223 if (DefaultSnapshotAvailable()) return; | |
| 224 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | 174 v8::Isolate* isolate = TestIsolate::NewInitialized(true); |
| 225 Serialize(isolate); | 175 Vector<const byte> blob1 = Serialize(isolate); |
| 226 Serialize(isolate); | 176 Vector<const byte> blob2 = Serialize(isolate); |
| 227 isolate = Deserialize(); | 177 blob1.Dispose(); |
| 178 isolate = Deserialize(blob2); | |
| 179 blob2.Dispose(); | |
| 228 { | 180 { |
| 229 v8::Isolate::Scope isolate_scope(isolate); | 181 v8::Isolate::Scope isolate_scope(isolate); |
| 230 v8::HandleScope handle_scope(isolate); | 182 v8::HandleScope handle_scope(isolate); |
| 231 | 183 |
| 232 v8::Local<v8::Context> env = v8::Context::New(isolate); | 184 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 233 env->Enter(); | 185 env->Enter(); |
| 234 | 186 |
| 235 SanityCheck(isolate); | 187 SanityCheck(isolate); |
| 236 } | 188 } |
| 237 isolate->Dispose(); | 189 isolate->Dispose(); |
| 238 } | 190 } |
| 239 | 191 |
| 240 UNINITIALIZED_TEST(DeserializeAndRunScript2) { | 192 UNINITIALIZED_TEST(StartupSerializerOnceRunScript) { |
| 241 DisableTurbofan(); | 193 DisableTurbofan(); |
| 242 if (DefaultSnapshotAvailable()) return; | |
| 243 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | 194 v8::Isolate* isolate = TestIsolate::NewInitialized(true); |
| 244 Serialize(isolate); | 195 Vector<const byte> blob = Serialize(isolate); |
| 245 isolate = Deserialize(); | 196 isolate = Deserialize(blob); |
| 197 blob.Dispose(); | |
| 246 { | 198 { |
| 247 v8::Isolate::Scope isolate_scope(isolate); | 199 v8::Isolate::Scope isolate_scope(isolate); |
| 248 v8::HandleScope handle_scope(isolate); | 200 v8::HandleScope handle_scope(isolate); |
| 249 | 201 |
| 250 | 202 |
| 251 v8::Local<v8::Context> env = v8::Context::New(isolate); | 203 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 252 env->Enter(); | 204 env->Enter(); |
| 253 | 205 |
| 254 const char* c_source = "\"1234\".length"; | 206 const char* c_source = "\"1234\".length"; |
| 255 v8::Local<v8::Script> script = v8_compile(c_source); | 207 v8::Local<v8::Script> script = v8_compile(c_source); |
| 256 v8::Maybe<int32_t> result = script->Run(isolate->GetCurrentContext()) | 208 v8::Maybe<int32_t> result = script->Run(isolate->GetCurrentContext()) |
| 257 .ToLocalChecked() | 209 .ToLocalChecked() |
| 258 ->Int32Value(isolate->GetCurrentContext()); | 210 ->Int32Value(isolate->GetCurrentContext()); |
| 259 CHECK_EQ(4, result.FromJust()); | 211 CHECK_EQ(4, result.FromJust()); |
| 260 } | 212 } |
| 261 isolate->Dispose(); | 213 isolate->Dispose(); |
| 262 } | 214 } |
| 263 | 215 |
| 264 UNINITIALIZED_TEST(DeserializeFromSecondSerializationAndRunScript2) { | 216 UNINITIALIZED_TEST(StartupSerializerTwiceRunScript) { |
| 265 DisableTurbofan(); | 217 DisableTurbofan(); |
| 266 if (DefaultSnapshotAvailable()) return; | |
| 267 v8::Isolate* isolate = TestIsolate::NewInitialized(true); | 218 v8::Isolate* isolate = TestIsolate::NewInitialized(true); |
| 268 Serialize(isolate); | 219 Vector<const byte> blob1 = Serialize(isolate); |
| 269 Serialize(isolate); | 220 Vector<const byte> blob2 = Serialize(isolate); |
| 270 isolate = Deserialize(); | 221 blob1.Dispose(); |
| 222 isolate = Deserialize(blob2); | |
| 223 blob2.Dispose(); | |
| 271 { | 224 { |
| 272 v8::Isolate::Scope isolate_scope(isolate); | 225 v8::Isolate::Scope isolate_scope(isolate); |
| 273 v8::HandleScope handle_scope(isolate); | 226 v8::HandleScope handle_scope(isolate); |
| 274 | 227 |
| 275 v8::Local<v8::Context> env = v8::Context::New(isolate); | 228 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 276 env->Enter(); | 229 env->Enter(); |
| 277 | 230 |
| 278 const char* c_source = "\"1234\".length"; | 231 const char* c_source = "\"1234\".length"; |
| 279 v8::Local<v8::Script> script = v8_compile(c_source); | 232 v8::Local<v8::Script> script = v8_compile(c_source); |
| 280 v8::Maybe<int32_t> result = script->Run(isolate->GetCurrentContext()) | 233 v8::Maybe<int32_t> result = script->Run(isolate->GetCurrentContext()) |
| 281 .ToLocalChecked() | 234 .ToLocalChecked() |
| 282 ->Int32Value(isolate->GetCurrentContext()); | 235 ->Int32Value(isolate->GetCurrentContext()); |
| 283 CHECK_EQ(4, result.FromJust()); | 236 CHECK_EQ(4, result.FromJust()); |
| 284 } | 237 } |
| 285 isolate->Dispose(); | 238 isolate->Dispose(); |
| 286 } | 239 } |
| 287 | 240 |
| 288 static void PartiallySerialize() { | 241 static void PartiallySerializeObject(Vector<const byte>* startup_blob_out, |
| 242 Vector<const byte>* partial_blob_out) { | |
| 289 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); | 243 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); |
| 290 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 244 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 291 v8_isolate->Enter(); | 245 v8_isolate->Enter(); |
| 292 { | 246 { |
| 293 Heap* heap = isolate->heap(); | 247 Heap* heap = isolate->heap(); |
| 294 | 248 |
| 295 v8::Persistent<v8::Context> env; | 249 v8::Persistent<v8::Context> env; |
| 296 { | 250 { |
| 297 HandleScope scope(isolate); | 251 HandleScope scope(isolate); |
| 298 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 252 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 313 heap->CollectAllGarbage(); | 267 heap->CollectAllGarbage(); |
| 314 | 268 |
| 315 Object* raw_foo; | 269 Object* raw_foo; |
| 316 { | 270 { |
| 317 v8::HandleScope handle_scope(v8_isolate); | 271 v8::HandleScope handle_scope(v8_isolate); |
| 318 v8::Local<v8::String> foo = v8_str("foo"); | 272 v8::Local<v8::String> foo = v8_str("foo"); |
| 319 CHECK(!foo.IsEmpty()); | 273 CHECK(!foo.IsEmpty()); |
| 320 raw_foo = *(v8::Utils::OpenHandle(*foo)); | 274 raw_foo = *(v8::Utils::OpenHandle(*foo)); |
| 321 } | 275 } |
| 322 | 276 |
| 323 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
| 324 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 325 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 326 | |
| 327 { | 277 { |
| 328 v8::HandleScope handle_scope(v8_isolate); | 278 v8::HandleScope handle_scope(v8_isolate); |
| 329 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 279 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 330 } | 280 } |
| 331 env.Reset(); | 281 env.Reset(); |
| 332 | 282 |
| 333 SnapshotByteSink startup_sink; | 283 SnapshotByteSink startup_sink; |
| 334 StartupSerializer startup_serializer(isolate, &startup_sink); | 284 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 335 startup_serializer.SerializeStrongReferences(); | 285 startup_serializer.SerializeStrongReferences(); |
| 336 | 286 |
| 337 SnapshotByteSink partial_sink; | 287 SnapshotByteSink partial_sink; |
| 338 PartialSerializer partial_serializer(isolate, &startup_serializer, | 288 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 339 &partial_sink); | 289 &partial_sink); |
| 340 partial_serializer.Serialize(&raw_foo); | 290 partial_serializer.Serialize(&raw_foo); |
| 341 | 291 |
| 342 startup_serializer.SerializeWeakReferencesAndDeferred(); | 292 startup_serializer.SerializeWeakReferencesAndDeferred(); |
| 343 | 293 |
| 344 SnapshotData startup_snapshot(startup_serializer); | 294 SnapshotData startup_snapshot(startup_serializer); |
| 345 SnapshotData partial_snapshot(partial_serializer); | 295 SnapshotData partial_snapshot(partial_serializer); |
| 346 | 296 |
| 347 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); | 297 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
| 348 WritePayload(startup_snapshot.RawData(), startup_name.start()); | 298 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
| 349 | |
| 350 startup_name.Dispose(); | |
| 351 } | 299 } |
| 352 v8_isolate->Exit(); | 300 v8_isolate->Exit(); |
| 353 v8_isolate->Dispose(); | 301 v8_isolate->Dispose(); |
| 354 } | 302 } |
| 355 | 303 |
| 356 UNINITIALIZED_TEST(PartialSerialization) { | 304 UNINITIALIZED_TEST(PartialSerializerObject) { |
| 357 DisableTurbofan(); | 305 DisableTurbofan(); |
| 358 if (DefaultSnapshotAvailable()) return; | 306 Vector<const byte> startup_blob; |
| 359 PartiallySerialize(); | 307 Vector<const byte> partial_blob; |
| 360 } | 308 PartiallySerializeObject(&startup_blob, &partial_blob); |
| 361 | 309 |
| 362 UNINITIALIZED_TEST(PartialDeserialization) { | 310 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob); |
| 363 DisableTurbofan(); | 311 startup_blob.Dispose(); |
| 364 if (DefaultSnapshotAvailable()) return; | |
| 365 PartiallySerialize(); | |
| 366 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
| 367 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 368 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 369 | |
| 370 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); | |
| 371 CHECK(v8_isolate); | 312 CHECK(v8_isolate); |
| 372 startup_name.Dispose(); | |
| 373 { | 313 { |
| 374 v8::Isolate::Scope isolate_scope(v8_isolate); | 314 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 375 | 315 |
| 376 const char* file_name = FLAG_testing_serialization_file; | |
| 377 | |
| 378 int snapshot_size = 0; | |
| 379 byte* snapshot = ReadBytes(file_name, &snapshot_size); | |
| 380 | |
| 381 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 316 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 382 HandleScope handle_scope(isolate); | 317 HandleScope handle_scope(isolate); |
| 383 Handle<Object> root; | 318 Handle<Object> root; |
| 384 // Intentionally empty handle. The deserializer should not come across | 319 // Intentionally empty handle. The deserializer should not come across |
| 385 // any references to the global proxy in this test. | 320 // any references to the global proxy in this test. |
| 386 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null(); | 321 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null(); |
| 387 { | 322 { |
| 388 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 323 SnapshotData snapshot_data(partial_blob); |
| 389 Deserializer deserializer(&snapshot_data); | 324 Deserializer deserializer(&snapshot_data); |
| 390 root = deserializer.DeserializePartial(isolate, global_proxy) | 325 root = deserializer.DeserializePartial(isolate, global_proxy) |
| 391 .ToHandleChecked(); | 326 .ToHandleChecked(); |
| 392 CHECK(root->IsString()); | 327 CHECK(root->IsString()); |
| 393 } | 328 } |
| 394 | 329 |
| 395 Handle<Object> root2; | 330 Handle<Object> root2; |
| 396 { | 331 { |
| 397 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 332 SnapshotData snapshot_data(partial_blob); |
| 398 Deserializer deserializer(&snapshot_data); | 333 Deserializer deserializer(&snapshot_data); |
| 399 root2 = deserializer.DeserializePartial(isolate, global_proxy) | 334 root2 = deserializer.DeserializePartial(isolate, global_proxy) |
| 400 .ToHandleChecked(); | 335 .ToHandleChecked(); |
| 401 CHECK(root2->IsString()); | 336 CHECK(root2->IsString()); |
| 402 CHECK(root.is_identical_to(root2)); | 337 CHECK(root.is_identical_to(root2)); |
| 403 } | 338 } |
| 404 | 339 partial_blob.Dispose(); |
| 405 DeleteArray(snapshot); | |
| 406 } | 340 } |
| 407 v8_isolate->Dispose(); | 341 v8_isolate->Dispose(); |
| 408 } | 342 } |
| 409 | 343 |
| 410 static void SerializeContext() { | 344 static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, |
| 345 Vector<const byte>* partial_blob_out) { | |
| 411 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); | 346 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); |
| 412 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 347 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 413 Heap* heap = isolate->heap(); | 348 Heap* heap = isolate->heap(); |
| 414 { | 349 { |
| 415 v8::Isolate::Scope isolate_scope(v8_isolate); | 350 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 416 | 351 |
| 417 v8::Persistent<v8::Context> env; | 352 v8::Persistent<v8::Context> env; |
| 418 { | 353 { |
| 419 HandleScope scope(isolate); | 354 HandleScope scope(isolate); |
| 420 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 355 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
| 421 } | 356 } |
| 422 CHECK(!env.IsEmpty()); | 357 CHECK(!env.IsEmpty()); |
| 423 { | 358 { |
| 424 v8::HandleScope handle_scope(v8_isolate); | 359 v8::HandleScope handle_scope(v8_isolate); |
| 425 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | 360 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 426 } | 361 } |
| 427 // Make sure all builtin scripts are cached. | 362 // Make sure all builtin scripts are cached. |
| 428 { | 363 { |
| 429 HandleScope scope(isolate); | 364 HandleScope scope(isolate); |
| 430 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 365 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 431 isolate->bootstrapper()->SourceLookup<Natives>(i); | 366 isolate->bootstrapper()->SourceLookup<Natives>(i); |
| 432 } | 367 } |
| 433 } | 368 } |
| 434 // If we don't do this then we end up with a stray root pointing at the | 369 // If we don't do this then we end up with a stray root pointing at the |
| 435 // context even after we have disposed of env. | 370 // context even after we have disposed of env. |
| 436 heap->CollectAllGarbage(); | 371 heap->CollectAllGarbage(); |
| 437 | 372 |
| 438 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
| 439 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 440 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 441 | |
| 442 { | 373 { |
| 443 v8::HandleScope handle_scope(v8_isolate); | 374 v8::HandleScope handle_scope(v8_isolate); |
| 444 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 375 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 445 } | 376 } |
| 446 | 377 |
| 447 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 378 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 448 | 379 |
| 449 env.Reset(); | 380 env.Reset(); |
| 450 | 381 |
| 451 SnapshotByteSink startup_sink; | 382 SnapshotByteSink startup_sink; |
| 452 StartupSerializer startup_serializer(isolate, &startup_sink); | 383 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 453 startup_serializer.SerializeStrongReferences(); | 384 startup_serializer.SerializeStrongReferences(); |
| 454 | 385 |
| 455 SnapshotByteSink partial_sink; | 386 SnapshotByteSink partial_sink; |
| 456 PartialSerializer partial_serializer(isolate, &startup_serializer, | 387 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 457 &partial_sink); | 388 &partial_sink); |
| 458 partial_serializer.Serialize(&raw_context); | 389 partial_serializer.Serialize(&raw_context); |
| 459 startup_serializer.SerializeWeakReferencesAndDeferred(); | 390 startup_serializer.SerializeWeakReferencesAndDeferred(); |
| 460 | 391 |
| 461 SnapshotData startup_snapshot(startup_serializer); | 392 SnapshotData startup_snapshot(startup_serializer); |
| 462 SnapshotData partial_snapshot(partial_serializer); | 393 SnapshotData partial_snapshot(partial_serializer); |
| 463 | 394 |
| 464 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); | 395 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
| 465 WritePayload(startup_snapshot.RawData(), startup_name.start()); | 396 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
| 466 | |
| 467 startup_name.Dispose(); | |
| 468 } | 397 } |
| 469 v8_isolate->Dispose(); | 398 v8_isolate->Dispose(); |
| 470 } | 399 } |
| 471 | 400 |
| 472 UNINITIALIZED_TEST(ContextSerialization) { | 401 UNINITIALIZED_TEST(PartialSerializerContext) { |
| 473 DisableTurbofan(); | 402 DisableTurbofan(); |
| 474 if (DefaultSnapshotAvailable()) return; | 403 Vector<const byte> startup_blob; |
| 475 SerializeContext(); | 404 Vector<const byte> partial_blob; |
| 476 } | 405 PartiallySerializeContext(&startup_blob, &partial_blob); |
| 477 | 406 |
| 478 UNINITIALIZED_TEST(ContextDeserialization) { | 407 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob); |
| 479 DisableTurbofan(); | |
| 480 if (DefaultSnapshotAvailable()) return; | |
| 481 SerializeContext(); | |
| 482 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
| 483 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 484 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 485 | |
| 486 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); | |
| 487 CHECK(v8_isolate); | 408 CHECK(v8_isolate); |
| 488 startup_name.Dispose(); | 409 startup_blob.Dispose(); |
| 489 { | 410 { |
| 490 v8::Isolate::Scope isolate_scope(v8_isolate); | 411 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 491 | 412 |
| 492 const char* file_name = FLAG_testing_serialization_file; | |
| 493 | |
| 494 int snapshot_size = 0; | |
| 495 byte* snapshot = ReadBytes(file_name, &snapshot_size); | |
| 496 | |
| 497 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 413 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 498 HandleScope handle_scope(isolate); | 414 HandleScope handle_scope(isolate); |
| 499 Handle<Object> root; | 415 Handle<Object> root; |
| 500 Handle<JSGlobalProxy> global_proxy = | 416 Handle<JSGlobalProxy> global_proxy = |
| 501 isolate->factory()->NewUninitializedJSGlobalProxy(); | 417 isolate->factory()->NewUninitializedJSGlobalProxy(); |
| 502 { | 418 { |
| 503 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 419 SnapshotData snapshot_data(partial_blob); |
| 504 Deserializer deserializer(&snapshot_data); | 420 Deserializer deserializer(&snapshot_data); |
| 505 root = deserializer.DeserializePartial(isolate, global_proxy) | 421 root = deserializer.DeserializePartial(isolate, global_proxy) |
| 506 .ToHandleChecked(); | 422 .ToHandleChecked(); |
| 507 CHECK(root->IsContext()); | 423 CHECK(root->IsContext()); |
| 508 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); | 424 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); |
| 509 } | 425 } |
| 510 | 426 |
| 511 Handle<Object> root2; | 427 Handle<Object> root2; |
| 512 { | 428 { |
| 513 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 429 SnapshotData snapshot_data(partial_blob); |
| 514 Deserializer deserializer(&snapshot_data); | 430 Deserializer deserializer(&snapshot_data); |
| 515 root2 = deserializer.DeserializePartial(isolate, global_proxy) | 431 root2 = deserializer.DeserializePartial(isolate, global_proxy) |
| 516 .ToHandleChecked(); | 432 .ToHandleChecked(); |
| 517 CHECK(root2->IsContext()); | 433 CHECK(root2->IsContext()); |
| 518 CHECK(!root.is_identical_to(root2)); | 434 CHECK(!root.is_identical_to(root2)); |
| 519 } | 435 } |
| 520 DeleteArray(snapshot); | 436 partial_blob.Dispose(); |
| 521 } | 437 } |
| 522 v8_isolate->Dispose(); | 438 v8_isolate->Dispose(); |
| 523 } | 439 } |
| 524 | 440 |
| 525 static void SerializeCustomContext() { | 441 static void PartiallySerializeCustomContext( |
| 442 Vector<const byte>* startup_blob_out, | |
| 443 Vector<const byte>* partial_blob_out) { | |
| 526 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); | 444 v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); |
| 527 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 445 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 528 { | 446 { |
| 529 v8::Isolate::Scope isolate_scope(v8_isolate); | 447 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 530 | 448 |
| 531 v8::Persistent<v8::Context> env; | 449 v8::Persistent<v8::Context> env; |
| 532 { | 450 { |
| 533 HandleScope scope(isolate); | 451 HandleScope scope(isolate); |
| 534 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 452 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
| 535 } | 453 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 562 { | 480 { |
| 563 HandleScope scope(isolate); | 481 HandleScope scope(isolate); |
| 564 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 482 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 565 isolate->bootstrapper()->SourceLookup<Natives>(i); | 483 isolate->bootstrapper()->SourceLookup<Natives>(i); |
| 566 } | 484 } |
| 567 } | 485 } |
| 568 // If we don't do this then we end up with a stray root pointing at the | 486 // If we don't do this then we end up with a stray root pointing at the |
| 569 // context even after we have disposed of env. | 487 // context even after we have disposed of env. |
| 570 isolate->heap()->CollectAllAvailableGarbage("snapshotting"); | 488 isolate->heap()->CollectAllAvailableGarbage("snapshotting"); |
| 571 | 489 |
| 572 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
| 573 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 574 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 575 | |
| 576 { | 490 { |
| 577 v8::HandleScope handle_scope(v8_isolate); | 491 v8::HandleScope handle_scope(v8_isolate); |
| 578 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 492 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 579 } | 493 } |
| 580 | 494 |
| 581 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 495 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 582 | 496 |
| 583 env.Reset(); | 497 env.Reset(); |
| 584 | 498 |
| 585 SnapshotByteSink startup_sink; | 499 SnapshotByteSink startup_sink; |
| 586 StartupSerializer startup_serializer(isolate, &startup_sink); | 500 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 587 startup_serializer.SerializeStrongReferences(); | 501 startup_serializer.SerializeStrongReferences(); |
| 588 | 502 |
| 589 SnapshotByteSink partial_sink; | 503 SnapshotByteSink partial_sink; |
| 590 PartialSerializer partial_serializer(isolate, &startup_serializer, | 504 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 591 &partial_sink); | 505 &partial_sink); |
| 592 partial_serializer.Serialize(&raw_context); | 506 partial_serializer.Serialize(&raw_context); |
| 593 startup_serializer.SerializeWeakReferencesAndDeferred(); | 507 startup_serializer.SerializeWeakReferencesAndDeferred(); |
| 594 | 508 |
| 595 SnapshotData startup_snapshot(startup_serializer); | 509 SnapshotData startup_snapshot(startup_serializer); |
| 596 SnapshotData partial_snapshot(partial_serializer); | 510 SnapshotData partial_snapshot(partial_serializer); |
| 597 | 511 |
| 598 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); | 512 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
| 599 WritePayload(startup_snapshot.RawData(), startup_name.start()); | 513 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
| 600 | |
| 601 startup_name.Dispose(); | |
| 602 } | 514 } |
| 603 v8_isolate->Dispose(); | 515 v8_isolate->Dispose(); |
| 604 } | 516 } |
| 605 | 517 |
| 606 UNINITIALIZED_TEST(CustomContextSerialization) { | 518 UNINITIALIZED_TEST(PartialSerializerCustomContext) { |
| 607 DisableTurbofan(); | |
| 608 if (DefaultSnapshotAvailable()) return; | |
| 609 SerializeCustomContext(); | |
| 610 } | |
| 611 | |
| 612 UNINITIALIZED_TEST(CustomContextDeserialization) { | |
| 613 DisableTurbofan(); | 519 DisableTurbofan(); |
| 614 FLAG_crankshaft = false; | 520 FLAG_crankshaft = false; |
| 615 if (DefaultSnapshotAvailable()) return; | 521 Vector<const byte> startup_blob; |
| 616 SerializeCustomContext(); | 522 Vector<const byte> partial_blob; |
| 617 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 523 PartiallySerializeCustomContext(&startup_blob, &partial_blob); |
| 618 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 619 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 620 | 524 |
| 621 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); | 525 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob); |
| 622 CHECK(v8_isolate); | 526 CHECK(v8_isolate); |
| 623 startup_name.Dispose(); | 527 startup_blob.Dispose(); |
| 624 { | 528 { |
| 625 v8::Isolate::Scope isolate_scope(v8_isolate); | 529 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 626 | 530 |
| 627 const char* file_name = FLAG_testing_serialization_file; | |
| 628 | |
| 629 int snapshot_size = 0; | |
| 630 byte* snapshot = ReadBytes(file_name, &snapshot_size); | |
| 631 | |
| 632 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 531 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 633 HandleScope handle_scope(isolate); | 532 HandleScope handle_scope(isolate); |
| 634 Handle<Object> root; | 533 Handle<Object> root; |
| 635 Handle<JSGlobalProxy> global_proxy = | 534 Handle<JSGlobalProxy> global_proxy = |
| 636 isolate->factory()->NewUninitializedJSGlobalProxy(); | 535 isolate->factory()->NewUninitializedJSGlobalProxy(); |
| 637 { | 536 { |
| 638 SnapshotData snapshot_data(Vector<const byte>(snapshot, snapshot_size)); | 537 SnapshotData snapshot_data(partial_blob); |
| 639 Deserializer deserializer(&snapshot_data); | 538 Deserializer deserializer(&snapshot_data); |
| 640 root = deserializer.DeserializePartial(isolate, global_proxy) | 539 root = deserializer.DeserializePartial(isolate, global_proxy) |
| 641 .ToHandleChecked(); | 540 .ToHandleChecked(); |
| 642 CHECK(root->IsContext()); | 541 CHECK(root->IsContext()); |
| 643 Handle<Context> context = Handle<Context>::cast(root); | 542 Handle<Context> context = Handle<Context>::cast(root); |
| 644 CHECK(context->global_proxy() == *global_proxy); | 543 CHECK(context->global_proxy() == *global_proxy); |
| 645 Handle<String> o = isolate->factory()->NewStringFromAsciiChecked("o"); | 544 Handle<String> o = isolate->factory()->NewStringFromAsciiChecked("o"); |
| 646 Handle<JSObject> global_object(context->global_object(), isolate); | 545 Handle<JSObject> global_object(context->global_object(), isolate); |
| 647 Handle<Object> property = JSReceiver::GetDataProperty(global_object, o); | 546 Handle<Object> property = JSReceiver::GetDataProperty(global_object, o); |
| 648 CHECK(property.is_identical_to(global_proxy)); | 547 CHECK(property.is_identical_to(global_proxy)); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 677 ->Int32Value(v8_isolate->GetCurrentContext()) | 576 ->Int32Value(v8_isolate->GetCurrentContext()) |
| 678 .FromJust(); | 577 .FromJust(); |
| 679 CHECK_EQ(100001, a); | 578 CHECK_EQ(100001, a); |
| 680 int b = CompileRun("b.length") | 579 int b = CompileRun("b.length") |
| 681 ->ToNumber(v8_isolate->GetCurrentContext()) | 580 ->ToNumber(v8_isolate->GetCurrentContext()) |
| 682 .ToLocalChecked() | 581 .ToLocalChecked() |
| 683 ->Int32Value(v8_isolate->GetCurrentContext()) | 582 ->Int32Value(v8_isolate->GetCurrentContext()) |
| 684 .FromJust(); | 583 .FromJust(); |
| 685 CHECK_EQ(100002, b); | 584 CHECK_EQ(100002, b); |
| 686 } | 585 } |
| 687 DeleteArray(snapshot); | 586 partial_blob.Dispose(); |
| 688 } | 587 } |
| 689 v8_isolate->Dispose(); | 588 v8_isolate->Dispose(); |
| 690 } | 589 } |
| 691 | 590 |
| 692 | 591 TEST(CustomSnapshotDataBlob) { |
| 693 TEST(PerIsolateSnapshotBlobs) { | |
| 694 DisableTurbofan(); | 592 DisableTurbofan(); |
| 695 const char* source1 = "function f() { return 42; }"; | 593 const char* source1 = "function f() { return 42; }"; |
| 696 const char* source2 = | 594 const char* source2 = |
| 697 "function f() { return g() * 2; }" | 595 "function f() { return g() * 2; }" |
| 698 "function g() { return 43; }" | 596 "function g() { return 43; }" |
| 699 "/./.test('a')"; | 597 "/./.test('a')"; |
| 700 | 598 |
| 701 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1); | 599 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1); |
| 702 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2); | 600 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2); |
| 703 | 601 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 } | 635 } |
| 738 isolate2->Dispose(); | 636 isolate2->Dispose(); |
| 739 } | 637 } |
| 740 | 638 |
| 741 | 639 |
| 742 static void SerializationFunctionTemplate( | 640 static void SerializationFunctionTemplate( |
| 743 const v8::FunctionCallbackInfo<v8::Value>& args) { | 641 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 744 args.GetReturnValue().Set(args[0]); | 642 args.GetReturnValue().Set(args[0]); |
| 745 } | 643 } |
| 746 | 644 |
| 747 | 645 TEST(CustomSnapshotDataBlobOutdatedContextWithOverflow) { |
| 748 TEST(PerIsolateSnapshotBlobsOutdatedContextWithOverflow) { | |
| 749 DisableTurbofan(); | 646 DisableTurbofan(); |
| 750 | 647 |
| 751 const char* source1 = | 648 const char* source1 = |
| 752 "var o = {};" | 649 "var o = {};" |
| 753 "(function() {" | 650 "(function() {" |
| 754 " function f1(x) { return f2(x) instanceof Array; }" | 651 " function f1(x) { return f2(x) instanceof Array; }" |
| 755 " function f2(x) { return foo.bar(x); }" | 652 " function f2(x) { return foo.bar(x); }" |
| 756 " o.a = f2.bind(null);" | 653 " o.a = f2.bind(null);" |
| 757 " o.b = 1;" | 654 " o.b = 1;" |
| 758 " o.c = 2;" | 655 " o.c = 2;" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 784 delete[] data.data; // We can dispose of the snapshot blob now. | 681 delete[] data.data; // We can dispose of the snapshot blob now. |
| 785 v8::Context::Scope c_scope(context); | 682 v8::Context::Scope c_scope(context); |
| 786 v8::Local<v8::Value> result = CompileRun(source2); | 683 v8::Local<v8::Value> result = CompileRun(source2); |
| 787 v8::Maybe<bool> compare = v8_str("42")->Equals( | 684 v8::Maybe<bool> compare = v8_str("42")->Equals( |
| 788 v8::Isolate::GetCurrent()->GetCurrentContext(), result); | 685 v8::Isolate::GetCurrent()->GetCurrentContext(), result); |
| 789 CHECK(compare.FromJust()); | 686 CHECK(compare.FromJust()); |
| 790 } | 687 } |
| 791 isolate->Dispose(); | 688 isolate->Dispose(); |
| 792 } | 689 } |
| 793 | 690 |
| 794 | 691 TEST(CustomSnapshotDataBlobWithLocker) { |
| 795 TEST(PerIsolateSnapshotBlobsWithLocker) { | |
| 796 DisableTurbofan(); | 692 DisableTurbofan(); |
| 797 v8::Isolate::CreateParams create_params; | 693 v8::Isolate::CreateParams create_params; |
| 798 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 694 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 799 v8::Isolate* isolate0 = v8::Isolate::New(create_params); | 695 v8::Isolate* isolate0 = v8::Isolate::New(create_params); |
| 800 { | 696 { |
| 801 v8::Locker locker(isolate0); | 697 v8::Locker locker(isolate0); |
| 802 v8::Isolate::Scope i_scope(isolate0); | 698 v8::Isolate::Scope i_scope(isolate0); |
| 803 v8::HandleScope h_scope(isolate0); | 699 v8::HandleScope h_scope(isolate0); |
| 804 v8::Local<v8::Context> context = v8::Context::New(isolate0); | 700 v8::Local<v8::Context> context = v8::Context::New(isolate0); |
| 805 v8::Context::Scope c_scope(context); | 701 v8::Context::Scope c_scope(context); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 823 v8::HandleScope h_scope(isolate1); | 719 v8::HandleScope h_scope(isolate1); |
| 824 v8::Local<v8::Context> context = v8::Context::New(isolate1); | 720 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
| 825 delete[] data1.data; // We can dispose of the snapshot blob now. | 721 delete[] data1.data; // We can dispose of the snapshot blob now. |
| 826 v8::Context::Scope c_scope(context); | 722 v8::Context::Scope c_scope(context); |
| 827 v8::Maybe<int32_t> result = CompileRun("f()")->Int32Value(context); | 723 v8::Maybe<int32_t> result = CompileRun("f()")->Int32Value(context); |
| 828 CHECK_EQ(42, result.FromJust()); | 724 CHECK_EQ(42, result.FromJust()); |
| 829 } | 725 } |
| 830 isolate1->Dispose(); | 726 isolate1->Dispose(); |
| 831 } | 727 } |
| 832 | 728 |
| 833 | 729 TEST(CustomSnapshotDataBlobStackOverflow) { |
| 834 TEST(SnapshotBlobsStackOverflow) { | |
| 835 DisableTurbofan(); | 730 DisableTurbofan(); |
| 836 const char* source = | 731 const char* source = |
| 837 "var a = [0];" | 732 "var a = [0];" |
| 838 "var b = a;" | 733 "var b = a;" |
| 839 "for (var i = 0; i < 10000; i++) {" | 734 "for (var i = 0; i < 10000; i++) {" |
| 840 " var c = [i];" | 735 " var c = [i];" |
| 841 " b.push(c);" | 736 " b.push(c);" |
| 842 " b.push(c);" | 737 " b.push(c);" |
| 843 " b = c;" | 738 " b = c;" |
| 844 "}"; | 739 "}"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 | 790 |
| 896 static Handle<SharedFunctionInfo> CompileScript( | 791 static Handle<SharedFunctionInfo> CompileScript( |
| 897 Isolate* isolate, Handle<String> source, Handle<String> name, | 792 Isolate* isolate, Handle<String> source, Handle<String> name, |
| 898 ScriptData** cached_data, v8::ScriptCompiler::CompileOptions options) { | 793 ScriptData** cached_data, v8::ScriptCompiler::CompileOptions options) { |
| 899 return Compiler::GetSharedFunctionInfoForScript( | 794 return Compiler::GetSharedFunctionInfoForScript( |
| 900 source, name, 0, 0, v8::ScriptOriginOptions(), Handle<Object>(), | 795 source, name, 0, 0, v8::ScriptOriginOptions(), Handle<Object>(), |
| 901 Handle<Context>(isolate->native_context()), NULL, cached_data, options, | 796 Handle<Context>(isolate->native_context()), NULL, cached_data, options, |
| 902 NOT_NATIVES_CODE, false); | 797 NOT_NATIVES_CODE, false); |
| 903 } | 798 } |
| 904 | 799 |
| 905 | 800 TEST(CodeSerializerOnePlusOne) { |
| 906 TEST(SerializeToplevelOnePlusOne) { | |
| 907 FLAG_serialize_toplevel = true; | 801 FLAG_serialize_toplevel = true; |
| 908 LocalContext context; | 802 LocalContext context; |
| 909 Isolate* isolate = CcTest::i_isolate(); | 803 Isolate* isolate = CcTest::i_isolate(); |
| 910 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 804 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 911 | 805 |
| 912 v8::HandleScope scope(CcTest::isolate()); | 806 v8::HandleScope scope(CcTest::isolate()); |
| 913 | 807 |
| 914 const char* source = "1 + 1"; | 808 const char* source = "1 + 1"; |
| 915 | 809 |
| 916 Handle<String> orig_source = isolate->factory() | 810 Handle<String> orig_source = isolate->factory() |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 946 Handle<JSObject> global(isolate->context()->global_object()); | 840 Handle<JSObject> global(isolate->context()->global_object()); |
| 947 Handle<Object> copy_result = | 841 Handle<Object> copy_result = |
| 948 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 842 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 949 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); | 843 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); |
| 950 | 844 |
| 951 CHECK_EQ(builtins_count, CountBuiltins()); | 845 CHECK_EQ(builtins_count, CountBuiltins()); |
| 952 | 846 |
| 953 delete cache; | 847 delete cache; |
| 954 } | 848 } |
| 955 | 849 |
| 956 | 850 TEST(CodeSerializerPromotedToCompilationCache) { |
| 957 TEST(CodeCachePromotedToCompilationCache) { | |
| 958 FLAG_serialize_toplevel = true; | 851 FLAG_serialize_toplevel = true; |
| 959 LocalContext context; | 852 LocalContext context; |
| 960 Isolate* isolate = CcTest::i_isolate(); | 853 Isolate* isolate = CcTest::i_isolate(); |
| 961 | 854 |
| 962 v8::HandleScope scope(CcTest::isolate()); | 855 v8::HandleScope scope(CcTest::isolate()); |
| 963 | 856 |
| 964 const char* source = "1 + 1"; | 857 const char* source = "1 + 1"; |
| 965 | 858 |
| 966 Handle<String> src = isolate->factory() | 859 Handle<String> src = isolate->factory() |
| 967 ->NewStringFromUtf8(CStrVector(source)) | 860 ->NewStringFromUtf8(CStrVector(source)) |
| 968 .ToHandleChecked(); | 861 .ToHandleChecked(); |
| 969 ScriptData* cache = NULL; | 862 ScriptData* cache = NULL; |
| 970 | 863 |
| 971 CompileScript(isolate, src, src, &cache, | 864 CompileScript(isolate, src, src, &cache, |
| 972 v8::ScriptCompiler::kProduceCodeCache); | 865 v8::ScriptCompiler::kProduceCodeCache); |
| 973 | 866 |
| 974 DisallowCompilation no_compile_expected(isolate); | 867 DisallowCompilation no_compile_expected(isolate); |
| 975 Handle<SharedFunctionInfo> copy = CompileScript( | 868 Handle<SharedFunctionInfo> copy = CompileScript( |
| 976 isolate, src, src, &cache, v8::ScriptCompiler::kConsumeCodeCache); | 869 isolate, src, src, &cache, v8::ScriptCompiler::kConsumeCodeCache); |
| 977 | 870 |
| 978 CHECK(isolate->compilation_cache() | 871 CHECK(isolate->compilation_cache() |
| 979 ->LookupScript(src, src, 0, 0, v8::ScriptOriginOptions(), | 872 ->LookupScript(src, src, 0, 0, v8::ScriptOriginOptions(), |
| 980 isolate->native_context(), SLOPPY) | 873 isolate->native_context(), SLOPPY) |
| 981 .ToHandleChecked() | 874 .ToHandleChecked() |
| 982 .is_identical_to(copy)); | 875 .is_identical_to(copy)); |
| 983 | 876 |
| 984 delete cache; | 877 delete cache; |
| 985 } | 878 } |
| 986 | 879 |
| 987 | 880 TEST(CodeSerializerInternalizedString) { |
| 988 TEST(SerializeToplevelInternalizedString) { | |
| 989 FLAG_serialize_toplevel = true; | 881 FLAG_serialize_toplevel = true; |
| 990 LocalContext context; | 882 LocalContext context; |
| 991 Isolate* isolate = CcTest::i_isolate(); | 883 Isolate* isolate = CcTest::i_isolate(); |
| 992 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 884 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 993 | 885 |
| 994 v8::HandleScope scope(CcTest::isolate()); | 886 v8::HandleScope scope(CcTest::isolate()); |
| 995 | 887 |
| 996 const char* source = "'string1'"; | 888 const char* source = "'string1'"; |
| 997 | 889 |
| 998 Handle<String> orig_source = isolate->factory() | 890 Handle<String> orig_source = isolate->factory() |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 CHECK(orig_result.is_identical_to(copy_result)); | 929 CHECK(orig_result.is_identical_to(copy_result)); |
| 1038 Handle<String> expected = | 930 Handle<String> expected = |
| 1039 isolate->factory()->NewStringFromAsciiChecked("string1"); | 931 isolate->factory()->NewStringFromAsciiChecked("string1"); |
| 1040 | 932 |
| 1041 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); | 933 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); |
| 1042 CHECK_EQ(builtins_count, CountBuiltins()); | 934 CHECK_EQ(builtins_count, CountBuiltins()); |
| 1043 | 935 |
| 1044 delete cache; | 936 delete cache; |
| 1045 } | 937 } |
| 1046 | 938 |
| 1047 | 939 TEST(CodeSerializerLargeCodeObject) { |
| 1048 TEST(SerializeToplevelLargeCodeObject) { | |
| 1049 FLAG_serialize_toplevel = true; | 940 FLAG_serialize_toplevel = true; |
| 1050 LocalContext context; | 941 LocalContext context; |
| 1051 Isolate* isolate = CcTest::i_isolate(); | 942 Isolate* isolate = CcTest::i_isolate(); |
| 1052 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 943 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1053 | 944 |
| 1054 v8::HandleScope scope(CcTest::isolate()); | 945 v8::HandleScope scope(CcTest::isolate()); |
| 1055 | 946 |
| 1056 Vector<const uint8_t> source = | 947 Vector<const uint8_t> source = |
| 1057 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), | 948 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), |
| 1058 STATIC_CHAR_VECTOR("for(var i=0;i<1;i++)j++;"), | 949 STATIC_CHAR_VECTOR("for(var i=0;i<1;i++)j++;"), |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1085 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 976 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 1086 | 977 |
| 1087 int result_int; | 978 int result_int; |
| 1088 CHECK(copy_result->ToInt32(&result_int)); | 979 CHECK(copy_result->ToInt32(&result_int)); |
| 1089 CHECK_EQ(7, result_int); | 980 CHECK_EQ(7, result_int); |
| 1090 | 981 |
| 1091 delete cache; | 982 delete cache; |
| 1092 source.Dispose(); | 983 source.Dispose(); |
| 1093 } | 984 } |
| 1094 | 985 |
| 1095 | 986 TEST(CodeSerializerLargeStrings) { |
| 1096 TEST(SerializeToplevelLargeStrings) { | |
| 1097 FLAG_serialize_toplevel = true; | 987 FLAG_serialize_toplevel = true; |
| 1098 LocalContext context; | 988 LocalContext context; |
| 1099 Isolate* isolate = CcTest::i_isolate(); | 989 Isolate* isolate = CcTest::i_isolate(); |
| 1100 Factory* f = isolate->factory(); | 990 Factory* f = isolate->factory(); |
| 1101 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 991 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1102 | 992 |
| 1103 v8::HandleScope scope(CcTest::isolate()); | 993 v8::HandleScope scope(CcTest::isolate()); |
| 1104 | 994 |
| 1105 Vector<const uint8_t> source_s = ConstructSource( | 995 Vector<const uint8_t> source_s = ConstructSource( |
| 1106 STATIC_CHAR_VECTOR("var s = \""), STATIC_CHAR_VECTOR("abcdef"), | 996 STATIC_CHAR_VECTOR("var s = \""), STATIC_CHAR_VECTOR("abcdef"), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 f->NewStringFromAsciiChecked("t")); | 1033 f->NewStringFromAsciiChecked("t")); |
| 1144 CHECK(isolate->heap()->InSpace(HeapObject::cast(*property), LO_SPACE)); | 1034 CHECK(isolate->heap()->InSpace(HeapObject::cast(*property), LO_SPACE)); |
| 1145 // Make sure we do not serialize too much, e.g. include the source string. | 1035 // Make sure we do not serialize too much, e.g. include the source string. |
| 1146 CHECK_LT(cache->length(), 13000000); | 1036 CHECK_LT(cache->length(), 13000000); |
| 1147 | 1037 |
| 1148 delete cache; | 1038 delete cache; |
| 1149 source_s.Dispose(); | 1039 source_s.Dispose(); |
| 1150 source_t.Dispose(); | 1040 source_t.Dispose(); |
| 1151 } | 1041 } |
| 1152 | 1042 |
| 1153 | 1043 TEST(CodeSerializerThreeBigStrings) { |
| 1154 TEST(SerializeToplevelThreeBigStrings) { | |
| 1155 FLAG_serialize_toplevel = true; | 1044 FLAG_serialize_toplevel = true; |
| 1156 LocalContext context; | 1045 LocalContext context; |
| 1157 Isolate* isolate = CcTest::i_isolate(); | 1046 Isolate* isolate = CcTest::i_isolate(); |
| 1158 Factory* f = isolate->factory(); | 1047 Factory* f = isolate->factory(); |
| 1159 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 1048 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1160 | 1049 |
| 1161 v8::HandleScope scope(CcTest::isolate()); | 1050 v8::HandleScope scope(CcTest::isolate()); |
| 1162 | 1051 |
| 1163 Vector<const uint8_t> source_a = | 1052 Vector<const uint8_t> source_a = |
| 1164 ConstructSource(STATIC_CHAR_VECTOR("var a = \""), STATIC_CHAR_VECTOR("a"), | 1053 ConstructSource(STATIC_CHAR_VECTOR("var a = \""), STATIC_CHAR_VECTOR("a"), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1254 ~SerializerTwoByteResource() { DeleteArray<const uint16_t>(data_); } | 1143 ~SerializerTwoByteResource() { DeleteArray<const uint16_t>(data_); } |
| 1255 | 1144 |
| 1256 virtual const uint16_t* data() const { return data_; } | 1145 virtual const uint16_t* data() const { return data_; } |
| 1257 virtual size_t length() const { return length_; } | 1146 virtual size_t length() const { return length_; } |
| 1258 | 1147 |
| 1259 private: | 1148 private: |
| 1260 const uint16_t* data_; | 1149 const uint16_t* data_; |
| 1261 size_t length_; | 1150 size_t length_; |
| 1262 }; | 1151 }; |
| 1263 | 1152 |
| 1264 | 1153 TEST(CodeSerializerExternalString) { |
| 1265 TEST(SerializeToplevelExternalString) { | |
| 1266 FLAG_serialize_toplevel = true; | 1154 FLAG_serialize_toplevel = true; |
| 1267 LocalContext context; | 1155 LocalContext context; |
| 1268 Isolate* isolate = CcTest::i_isolate(); | 1156 Isolate* isolate = CcTest::i_isolate(); |
| 1269 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 1157 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1270 | 1158 |
| 1271 v8::HandleScope scope(CcTest::isolate()); | 1159 v8::HandleScope scope(CcTest::isolate()); |
| 1272 | 1160 |
| 1273 // Obtain external internalized one-byte string. | 1161 // Obtain external internalized one-byte string. |
| 1274 SerializerOneByteResource one_byte_resource("one_byte", 8); | 1162 SerializerOneByteResource one_byte_resource("one_byte", 8); |
| 1275 Handle<String> one_byte_string = | 1163 Handle<String> one_byte_string = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1317 copy, isolate->native_context()); | 1205 copy, isolate->native_context()); |
| 1318 | 1206 |
| 1319 Handle<Object> copy_result = | 1207 Handle<Object> copy_result = |
| 1320 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 1208 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 1321 | 1209 |
| 1322 CHECK_EQ(15.0, copy_result->Number()); | 1210 CHECK_EQ(15.0, copy_result->Number()); |
| 1323 | 1211 |
| 1324 delete cache; | 1212 delete cache; |
| 1325 } | 1213 } |
| 1326 | 1214 |
| 1327 | 1215 TEST(CodeSerializerLargeExternalString) { |
| 1328 TEST(SerializeToplevelLargeExternalString) { | |
| 1329 FLAG_serialize_toplevel = true; | 1216 FLAG_serialize_toplevel = true; |
| 1330 LocalContext context; | 1217 LocalContext context; |
| 1331 Isolate* isolate = CcTest::i_isolate(); | 1218 Isolate* isolate = CcTest::i_isolate(); |
| 1332 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 1219 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1333 | 1220 |
| 1334 Factory* f = isolate->factory(); | 1221 Factory* f = isolate->factory(); |
| 1335 | 1222 |
| 1336 v8::HandleScope scope(CcTest::isolate()); | 1223 v8::HandleScope scope(CcTest::isolate()); |
| 1337 | 1224 |
| 1338 // Create a huge external internalized string to use as variable name. | 1225 // Create a huge external internalized string to use as variable name. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1376 | 1263 |
| 1377 Handle<Object> copy_result = | 1264 Handle<Object> copy_result = |
| 1378 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 1265 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 1379 | 1266 |
| 1380 CHECK_EQ(42.0, copy_result->Number()); | 1267 CHECK_EQ(42.0, copy_result->Number()); |
| 1381 | 1268 |
| 1382 delete cache; | 1269 delete cache; |
| 1383 string.Dispose(); | 1270 string.Dispose(); |
| 1384 } | 1271 } |
| 1385 | 1272 |
| 1386 | 1273 TEST(CodeSerializerExternalScriptName) { |
| 1387 TEST(SerializeToplevelExternalScriptName) { | |
| 1388 FLAG_serialize_toplevel = true; | 1274 FLAG_serialize_toplevel = true; |
| 1389 LocalContext context; | 1275 LocalContext context; |
| 1390 Isolate* isolate = CcTest::i_isolate(); | 1276 Isolate* isolate = CcTest::i_isolate(); |
| 1391 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 1277 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1392 | 1278 |
| 1393 Factory* f = isolate->factory(); | 1279 Factory* f = isolate->factory(); |
| 1394 | 1280 |
| 1395 v8::HandleScope scope(CcTest::isolate()); | 1281 v8::HandleScope scope(CcTest::isolate()); |
| 1396 | 1282 |
| 1397 const char* source = | 1283 const char* source = |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 .ToLocalChecked(); | 1362 .ToLocalChecked(); |
| 1477 v8::Local<v8::String> result_string = | 1363 v8::Local<v8::String> result_string = |
| 1478 result->ToString(isolate1->GetCurrentContext()).ToLocalChecked(); | 1364 result->ToString(isolate1->GetCurrentContext()).ToLocalChecked(); |
| 1479 CHECK(result_string->Equals(isolate1->GetCurrentContext(), v8_str("abcdef")) | 1365 CHECK(result_string->Equals(isolate1->GetCurrentContext(), v8_str("abcdef")) |
| 1480 .FromJust()); | 1366 .FromJust()); |
| 1481 } | 1367 } |
| 1482 isolate1->Dispose(); | 1368 isolate1->Dispose(); |
| 1483 return cache; | 1369 return cache; |
| 1484 } | 1370 } |
| 1485 | 1371 |
| 1486 | 1372 TEST(CodeSerializerIsolates) { |
| 1487 TEST(SerializeToplevelIsolates) { | |
| 1488 FLAG_serialize_toplevel = true; | 1373 FLAG_serialize_toplevel = true; |
| 1489 | 1374 |
| 1490 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 1375 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
| 1491 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); | 1376 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); |
| 1492 | 1377 |
| 1493 v8::Isolate::CreateParams create_params; | 1378 v8::Isolate::CreateParams create_params; |
| 1494 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1379 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 1495 v8::Isolate* isolate2 = v8::Isolate::New(create_params); | 1380 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 1496 isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault, | 1381 isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault, |
| 1497 SerializerCodeEventListener); | 1382 SerializerCodeEventListener); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1518 .ToLocalChecked(); | 1403 .ToLocalChecked(); |
| 1519 CHECK(result->ToString(isolate2->GetCurrentContext()) | 1404 CHECK(result->ToString(isolate2->GetCurrentContext()) |
| 1520 .ToLocalChecked() | 1405 .ToLocalChecked() |
| 1521 ->Equals(isolate2->GetCurrentContext(), v8_str("abcdef")) | 1406 ->Equals(isolate2->GetCurrentContext(), v8_str("abcdef")) |
| 1522 .FromJust()); | 1407 .FromJust()); |
| 1523 } | 1408 } |
| 1524 CHECK(toplevel_test_code_event_found); | 1409 CHECK(toplevel_test_code_event_found); |
| 1525 isolate2->Dispose(); | 1410 isolate2->Dispose(); |
| 1526 } | 1411 } |
| 1527 | 1412 |
| 1528 | 1413 TEST(CodeSerializerFlagChange) { |
| 1529 TEST(SerializeToplevelFlagChange) { | |
| 1530 FLAG_serialize_toplevel = true; | 1414 FLAG_serialize_toplevel = true; |
| 1531 | 1415 |
| 1532 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 1416 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
| 1533 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); | 1417 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); |
| 1534 | 1418 |
| 1535 v8::Isolate::CreateParams create_params; | 1419 v8::Isolate::CreateParams create_params; |
| 1536 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1420 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 1537 v8::Isolate* isolate2 = v8::Isolate::New(create_params); | 1421 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 1538 | 1422 |
| 1539 FLAG_allow_natives_syntax = true; // Flag change should trigger cache reject. | 1423 FLAG_allow_natives_syntax = true; // Flag change should trigger cache reject. |
| 1540 FlagList::EnforceFlagImplications(); | 1424 FlagList::EnforceFlagImplications(); |
| 1541 { | 1425 { |
| 1542 v8::Isolate::Scope iscope(isolate2); | 1426 v8::Isolate::Scope iscope(isolate2); |
| 1543 v8::HandleScope scope(isolate2); | 1427 v8::HandleScope scope(isolate2); |
| 1544 v8::Local<v8::Context> context = v8::Context::New(isolate2); | 1428 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
| 1545 v8::Context::Scope context_scope(context); | 1429 v8::Context::Scope context_scope(context); |
| 1546 | 1430 |
| 1547 v8::Local<v8::String> source_str = v8_str(source); | 1431 v8::Local<v8::String> source_str = v8_str(source); |
| 1548 v8::ScriptOrigin origin(v8_str("test")); | 1432 v8::ScriptOrigin origin(v8_str("test")); |
| 1549 v8::ScriptCompiler::Source source(source_str, origin, cache); | 1433 v8::ScriptCompiler::Source source(source_str, origin, cache); |
| 1550 v8::ScriptCompiler::CompileUnboundScript( | 1434 v8::ScriptCompiler::CompileUnboundScript( |
| 1551 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache) | 1435 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache) |
| 1552 .ToLocalChecked(); | 1436 .ToLocalChecked(); |
| 1553 CHECK(cache->rejected); | 1437 CHECK(cache->rejected); |
| 1554 } | 1438 } |
| 1555 isolate2->Dispose(); | 1439 isolate2->Dispose(); |
| 1556 } | 1440 } |
| 1557 | 1441 |
| 1558 | 1442 TEST(CodeSerializerBitFlip) { |
| 1559 TEST(SerializeToplevelBitFlip) { | |
| 1560 FLAG_serialize_toplevel = true; | 1443 FLAG_serialize_toplevel = true; |
| 1561 | 1444 |
| 1562 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 1445 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
| 1563 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); | 1446 v8::ScriptCompiler::CachedData* cache = ProduceCache(source); |
| 1564 | 1447 |
| 1565 // Random bit flip. | 1448 // Random bit flip. |
| 1566 const_cast<uint8_t*>(cache->data)[337] ^= 0x40; | 1449 const_cast<uint8_t*>(cache->data)[337] ^= 0x40; |
| 1567 | 1450 |
| 1568 v8::Isolate::CreateParams create_params; | 1451 v8::Isolate::CreateParams create_params; |
| 1569 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1452 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 1570 v8::Isolate* isolate2 = v8::Isolate::New(create_params); | 1453 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 1571 { | 1454 { |
| 1572 v8::Isolate::Scope iscope(isolate2); | 1455 v8::Isolate::Scope iscope(isolate2); |
| 1573 v8::HandleScope scope(isolate2); | 1456 v8::HandleScope scope(isolate2); |
| 1574 v8::Local<v8::Context> context = v8::Context::New(isolate2); | 1457 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
| 1575 v8::Context::Scope context_scope(context); | 1458 v8::Context::Scope context_scope(context); |
| 1576 | 1459 |
| 1577 v8::Local<v8::String> source_str = v8_str(source); | 1460 v8::Local<v8::String> source_str = v8_str(source); |
| 1578 v8::ScriptOrigin origin(v8_str("test")); | 1461 v8::ScriptOrigin origin(v8_str("test")); |
| 1579 v8::ScriptCompiler::Source source(source_str, origin, cache); | 1462 v8::ScriptCompiler::Source source(source_str, origin, cache); |
| 1580 v8::ScriptCompiler::CompileUnboundScript( | 1463 v8::ScriptCompiler::CompileUnboundScript( |
| 1581 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache) | 1464 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache) |
| 1582 .ToLocalChecked(); | 1465 .ToLocalChecked(); |
| 1583 CHECK(cache->rejected); | 1466 CHECK(cache->rejected); |
| 1584 } | 1467 } |
| 1585 isolate2->Dispose(); | 1468 isolate2->Dispose(); |
| 1586 } | 1469 } |
| 1587 | 1470 |
| 1588 | 1471 TEST(CodeSerializerWithHarmonyScoping) { |
| 1589 TEST(SerializeWithHarmonyScoping) { | |
| 1590 FLAG_serialize_toplevel = true; | 1472 FLAG_serialize_toplevel = true; |
| 1591 | 1473 |
| 1592 const char* source1 = "'use strict'; let x = 'X'"; | 1474 const char* source1 = "'use strict'; let x = 'X'"; |
| 1593 const char* source2 = "'use strict'; let y = 'Y'"; | 1475 const char* source2 = "'use strict'; let y = 'Y'"; |
| 1594 const char* source3 = "'use strict'; x + y"; | 1476 const char* source3 = "'use strict'; x + y"; |
| 1595 | 1477 |
| 1596 v8::ScriptCompiler::CachedData* cache; | 1478 v8::ScriptCompiler::CachedData* cache; |
| 1597 | 1479 |
| 1598 v8::Isolate::CreateParams create_params; | 1480 v8::Isolate::CreateParams create_params; |
| 1599 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1481 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1657 ->Run(isolate2->GetCurrentContext()) | 1539 ->Run(isolate2->GetCurrentContext()) |
| 1658 .ToLocalChecked(); | 1540 .ToLocalChecked(); |
| 1659 v8::Local<v8::String> result_str = | 1541 v8::Local<v8::String> result_str = |
| 1660 result->ToString(isolate2->GetCurrentContext()).ToLocalChecked(); | 1542 result->ToString(isolate2->GetCurrentContext()).ToLocalChecked(); |
| 1661 CHECK(result_str->Equals(isolate2->GetCurrentContext(), v8_str("XY")) | 1543 CHECK(result_str->Equals(isolate2->GetCurrentContext(), v8_str("XY")) |
| 1662 .FromJust()); | 1544 .FromJust()); |
| 1663 } | 1545 } |
| 1664 isolate2->Dispose(); | 1546 isolate2->Dispose(); |
| 1665 } | 1547 } |
| 1666 | 1548 |
| 1667 | 1549 TEST(CodeSerializerInternalReference) { |
| 1668 TEST(SerializeInternalReference) { | |
| 1669 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 | 1550 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 |
| 1670 return; | 1551 return; |
| 1671 #endif | 1552 #endif |
| 1672 // Disable experimental natives that are loaded after deserialization. | 1553 // Disable experimental natives that are loaded after deserialization. |
| 1673 FLAG_function_context_specialization = false; | 1554 FLAG_function_context_specialization = false; |
| 1674 FLAG_always_opt = true; | 1555 FLAG_always_opt = true; |
| 1675 const char* flag = "--turbo-filter=foo"; | 1556 const char* flag = "--turbo-filter=foo"; |
| 1676 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 1557 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 1677 | 1558 |
| 1678 const char* source = | 1559 const char* source = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1746 ->Int32Value(isolate->GetCurrentContext()) | 1627 ->Int32Value(isolate->GetCurrentContext()) |
| 1747 .FromJust()); | 1628 .FromJust()); |
| 1748 } | 1629 } |
| 1749 isolate->Dispose(); | 1630 isolate->Dispose(); |
| 1750 } | 1631 } |
| 1751 | 1632 |
| 1752 | 1633 |
| 1753 TEST(Regress503552) { | 1634 TEST(Regress503552) { |
| 1754 // Test that the code serializer can deal with weak cells that form a linked | 1635 // Test that the code serializer can deal with weak cells that form a linked |
| 1755 // list during incremental marking. | 1636 // list during incremental marking. |
| 1756 | |
| 1757 CcTest::InitializeVM(); | 1637 CcTest::InitializeVM(); |
| 1758 Isolate* isolate = CcTest::i_isolate(); | 1638 Isolate* isolate = CcTest::i_isolate(); |
| 1759 | 1639 |
| 1760 HandleScope scope(isolate); | 1640 HandleScope scope(isolate); |
| 1761 Handle<String> source = isolate->factory()->NewStringFromAsciiChecked( | 1641 Handle<String> source = isolate->factory()->NewStringFromAsciiChecked( |
| 1762 "function f() {} function g() {}"); | 1642 "function f() {} function g() {}"); |
| 1763 ScriptData* script_data = NULL; | 1643 ScriptData* script_data = NULL; |
| 1764 Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript( | 1644 Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript( |
| 1765 source, Handle<String>(), 0, 0, v8::ScriptOriginOptions(), | 1645 source, Handle<String>(), 0, 0, v8::ScriptOriginOptions(), |
| 1766 Handle<Object>(), Handle<Context>(isolate->native_context()), NULL, | 1646 Handle<Object>(), Handle<Context>(isolate->native_context()), NULL, |
| 1767 &script_data, v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE, | 1647 &script_data, v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE, |
| 1768 false); | 1648 false); |
| 1769 delete script_data; | 1649 delete script_data; |
| 1770 | 1650 |
| 1771 SimulateIncrementalMarking(isolate->heap()); | 1651 SimulateIncrementalMarking(isolate->heap()); |
| 1772 | 1652 |
| 1773 script_data = CodeSerializer::Serialize(isolate, shared, source); | 1653 script_data = CodeSerializer::Serialize(isolate, shared, source); |
| 1774 delete script_data; | 1654 delete script_data; |
| 1775 } | 1655 } |
| 1776 | 1656 |
| 1777 | 1657 |
| 1778 TEST(SerializationMemoryStats) { | 1658 TEST(SerializationMemoryStats) { |
| 1779 FLAG_profile_deserialization = true; | 1659 FLAG_profile_deserialization = true; |
| 1780 FLAG_always_opt = false; | 1660 FLAG_always_opt = false; |
| 1781 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1661 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 1782 delete[] blob.data; | 1662 delete[] blob.data; |
| 1783 } | 1663 } |
| OLD | NEW |