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 27 matching lines...) Expand all Loading... |
38 #include "src/natives.h" | 38 #include "src/natives.h" |
39 #include "src/objects.h" | 39 #include "src/objects.h" |
40 #include "src/runtime.h" | 40 #include "src/runtime.h" |
41 #include "src/scopeinfo.h" | 41 #include "src/scopeinfo.h" |
42 #include "src/serialize.h" | 42 #include "src/serialize.h" |
43 #include "src/snapshot.h" | 43 #include "src/snapshot.h" |
44 #include "test/cctest/cctest.h" | 44 #include "test/cctest/cctest.h" |
45 | 45 |
46 using namespace v8::internal; | 46 using namespace v8::internal; |
47 | 47 |
| 48 static const unsigned kCounters = 256; |
| 49 static int local_counters[kCounters]; |
| 50 static const char* local_counter_names[kCounters]; |
| 51 |
| 52 |
| 53 static unsigned CounterHash(const char* s) { |
| 54 unsigned hash = 0; |
| 55 while (*++s) { |
| 56 hash |= hash << 5; |
| 57 hash += *s; |
| 58 } |
| 59 return hash; |
| 60 } |
| 61 |
| 62 |
| 63 // Callback receiver to track counters in test. |
| 64 static int* counter_function(const char* name) { |
| 65 unsigned hash = CounterHash(name) % kCounters; |
| 66 unsigned original_hash = hash; |
| 67 USE(original_hash); |
| 68 while (true) { |
| 69 if (local_counter_names[hash] == name) { |
| 70 return &local_counters[hash]; |
| 71 } |
| 72 if (local_counter_names[hash] == 0) { |
| 73 local_counter_names[hash] = name; |
| 74 return &local_counters[hash]; |
| 75 } |
| 76 if (strcmp(local_counter_names[hash], name) == 0) { |
| 77 return &local_counters[hash]; |
| 78 } |
| 79 hash = (hash + 1) % kCounters; |
| 80 DCHECK(hash != original_hash); // Hash table has been filled up. |
| 81 } |
| 82 } |
| 83 |
48 | 84 |
49 template <class T> | 85 template <class T> |
50 static Address AddressOf(T id) { | 86 static Address AddressOf(T id) { |
51 return ExternalReference(id, CcTest::i_isolate()).address(); | 87 return ExternalReference(id, CcTest::i_isolate()).address(); |
52 } | 88 } |
53 | 89 |
54 | 90 |
55 template <class T> | 91 template <class T> |
56 static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) { | 92 static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) { |
57 return encoder.Encode(AddressOf(id)); | 93 return encoder.Encode(AddressOf(id)); |
58 } | 94 } |
59 | 95 |
60 | 96 |
61 static int make_code(TypeCode type, int id) { | 97 static int make_code(TypeCode type, int id) { |
62 return static_cast<uint32_t>(type) << kReferenceTypeShift | id; | 98 return static_cast<uint32_t>(type) << kReferenceTypeShift | id; |
63 } | 99 } |
64 | 100 |
65 | 101 |
66 TEST(ExternalReferenceEncoder) { | 102 TEST(ExternalReferenceEncoder) { |
67 Isolate* isolate = CcTest::i_isolate(); | 103 Isolate* isolate = CcTest::i_isolate(); |
| 104 isolate->stats_table()->SetCounterFunction(counter_function); |
68 v8::V8::Initialize(); | 105 v8::V8::Initialize(); |
69 | 106 |
70 ExternalReferenceEncoder encoder(isolate); | 107 ExternalReferenceEncoder encoder(isolate); |
71 CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), | 108 CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), |
72 Encode(encoder, Builtins::kArrayCode)); | 109 Encode(encoder, Builtins::kArrayCode)); |
73 CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), | 110 CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), |
74 Encode(encoder, Runtime::kAbort)); | 111 Encode(encoder, Runtime::kAbort)); |
| 112 ExternalReference total_compile_size = |
| 113 ExternalReference(isolate->counters()->total_compile_size()); |
| 114 CHECK_EQ(make_code(STATS_COUNTER, Counters::k_total_compile_size), |
| 115 encoder.Encode(total_compile_size.address())); |
75 ExternalReference stack_limit_address = | 116 ExternalReference stack_limit_address = |
76 ExternalReference::address_of_stack_limit(isolate); | 117 ExternalReference::address_of_stack_limit(isolate); |
77 CHECK_EQ(make_code(UNCLASSIFIED, 2), | 118 CHECK_EQ(make_code(UNCLASSIFIED, 2), |
78 encoder.Encode(stack_limit_address.address())); | 119 encoder.Encode(stack_limit_address.address())); |
79 ExternalReference real_stack_limit_address = | 120 ExternalReference real_stack_limit_address = |
80 ExternalReference::address_of_real_stack_limit(isolate); | 121 ExternalReference::address_of_real_stack_limit(isolate); |
81 CHECK_EQ(make_code(UNCLASSIFIED, 3), | 122 CHECK_EQ(make_code(UNCLASSIFIED, 3), |
82 encoder.Encode(real_stack_limit_address.address())); | 123 encoder.Encode(real_stack_limit_address.address())); |
83 CHECK_EQ(make_code(UNCLASSIFIED, 8), | 124 CHECK_EQ(make_code(UNCLASSIFIED, 8), |
84 encoder.Encode(ExternalReference::debug_break(isolate).address())); | 125 encoder.Encode(ExternalReference::debug_break(isolate).address())); |
85 CHECK_EQ( | 126 CHECK_EQ( |
86 make_code(UNCLASSIFIED, 4), | 127 make_code(UNCLASSIFIED, 4), |
87 encoder.Encode(ExternalReference::new_space_start(isolate).address())); | 128 encoder.Encode(ExternalReference::new_space_start(isolate).address())); |
88 CHECK_EQ( | 129 CHECK_EQ( |
89 make_code(UNCLASSIFIED, 1), | 130 make_code(UNCLASSIFIED, 1), |
90 encoder.Encode(ExternalReference::roots_array_start(isolate).address())); | 131 encoder.Encode(ExternalReference::roots_array_start(isolate).address())); |
91 CHECK_EQ(make_code(UNCLASSIFIED, 34), | 132 CHECK_EQ(make_code(UNCLASSIFIED, 34), |
92 encoder.Encode(ExternalReference::cpu_features().address())); | 133 encoder.Encode(ExternalReference::cpu_features().address())); |
93 } | 134 } |
94 | 135 |
95 | 136 |
96 TEST(ExternalReferenceDecoder) { | 137 TEST(ExternalReferenceDecoder) { |
97 Isolate* isolate = CcTest::i_isolate(); | 138 Isolate* isolate = CcTest::i_isolate(); |
| 139 isolate->stats_table()->SetCounterFunction(counter_function); |
98 v8::V8::Initialize(); | 140 v8::V8::Initialize(); |
99 | 141 |
100 ExternalReferenceDecoder decoder(isolate); | 142 ExternalReferenceDecoder decoder(isolate); |
101 CHECK_EQ(AddressOf(Builtins::kArrayCode), | 143 CHECK_EQ(AddressOf(Builtins::kArrayCode), |
102 decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); | 144 decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); |
103 CHECK_EQ(AddressOf(Runtime::kAbort), | 145 CHECK_EQ(AddressOf(Runtime::kAbort), |
104 decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, | 146 decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, |
105 Runtime::kAbort))); | 147 Runtime::kAbort))); |
| 148 ExternalReference total_compile_size = |
| 149 ExternalReference(isolate->counters()->total_compile_size()); |
| 150 CHECK_EQ(total_compile_size.address(), |
| 151 decoder.Decode( |
| 152 make_code(STATS_COUNTER, |
| 153 Counters::k_total_compile_size))); |
106 CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(), | 154 CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(), |
107 decoder.Decode(make_code(UNCLASSIFIED, 2))); | 155 decoder.Decode(make_code(UNCLASSIFIED, 2))); |
108 CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), | 156 CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), |
109 decoder.Decode(make_code(UNCLASSIFIED, 3))); | 157 decoder.Decode(make_code(UNCLASSIFIED, 3))); |
110 CHECK_EQ(ExternalReference::debug_break(isolate).address(), | 158 CHECK_EQ(ExternalReference::debug_break(isolate).address(), |
111 decoder.Decode(make_code(UNCLASSIFIED, 8))); | 159 decoder.Decode(make_code(UNCLASSIFIED, 8))); |
112 CHECK_EQ(ExternalReference::new_space_start(isolate).address(), | 160 CHECK_EQ(ExternalReference::new_space_start(isolate).address(), |
113 decoder.Decode(make_code(UNCLASSIFIED, 4))); | 161 decoder.Decode(make_code(UNCLASSIFIED, 4))); |
114 } | 162 } |
115 | 163 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 235 ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
188 ser.CurrentAllocationAddress(CODE_SPACE), | 236 ser.CurrentAllocationAddress(CODE_SPACE), |
189 ser.CurrentAllocationAddress(MAP_SPACE), | 237 ser.CurrentAllocationAddress(MAP_SPACE), |
190 ser.CurrentAllocationAddress(CELL_SPACE), | 238 ser.CurrentAllocationAddress(CELL_SPACE), |
191 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 239 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
192 | 240 |
193 return true; | 241 return true; |
194 } | 242 } |
195 | 243 |
196 | 244 |
197 static void Serialize(v8::Isolate* isolate) { | 245 static void Serialize() { |
198 // We have to create one context. One reason for this is so that the builtins | 246 // We have to create one context. One reason for this is so that the builtins |
199 // can be loaded from v8natives.js and their addresses can be processed. This | 247 // can be loaded from v8natives.js and their addresses can be processed. This |
200 // will clear the pending fixups array, which would otherwise contain GC roots | 248 // will clear the pending fixups array, which would otherwise contain GC roots |
201 // that would confuse the serialization/deserialization process. | 249 // that would confuse the serialization/deserialization process. |
| 250 v8::Isolate* isolate = CcTest::isolate(); |
202 { | 251 { |
203 v8::HandleScope scope(isolate); | 252 v8::HandleScope scope(isolate); |
204 v8::Context::New(isolate); | 253 v8::Context::New(isolate); |
205 } | 254 } |
206 | 255 |
207 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); | 256 Isolate* internal_isolate = CcTest::i_isolate(); |
208 internal_isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, "serialize"); | 257 internal_isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, "serialize"); |
209 WriteToFile(internal_isolate, FLAG_testing_serialization_file); | 258 WriteToFile(internal_isolate, FLAG_testing_serialization_file); |
210 } | 259 } |
211 | 260 |
212 | 261 |
213 // Test that the whole heap can be serialized. | 262 // Test that the whole heap can be serialized. |
214 UNINITIALIZED_TEST(Serialize) { | 263 TEST(Serialize) { |
215 if (!Snapshot::HaveASnapshotToStartFrom()) { | 264 if (!Snapshot::HaveASnapshotToStartFrom()) { |
216 v8::Isolate::CreateParams params; | 265 CcTest::i_isolate()->enable_serializer(); |
217 params.enable_serializer = true; | 266 v8::V8::Initialize(); |
218 v8::Isolate* isolate = v8::Isolate::New(params); | 267 Serialize(); |
219 Serialize(isolate); | |
220 } | 268 } |
221 } | 269 } |
222 | 270 |
223 | 271 |
224 // Test that heap serialization is non-destructive. | 272 // Test that heap serialization is non-destructive. |
225 UNINITIALIZED_TEST(SerializeTwice) { | 273 TEST(SerializeTwice) { |
226 if (!Snapshot::HaveASnapshotToStartFrom()) { | 274 if (!Snapshot::HaveASnapshotToStartFrom()) { |
227 v8::Isolate::CreateParams params; | 275 CcTest::i_isolate()->enable_serializer(); |
228 params.enable_serializer = true; | 276 v8::V8::Initialize(); |
229 v8::Isolate* isolate = v8::Isolate::New(params); | 277 Serialize(); |
230 Serialize(isolate); | 278 Serialize(); |
231 Serialize(isolate); | |
232 } | 279 } |
233 } | 280 } |
234 | 281 |
235 | 282 |
236 //---------------------------------------------------------------------------- | 283 //---------------------------------------------------------------------------- |
237 // Tests that the heap can be deserialized. | 284 // Tests that the heap can be deserialized. |
238 | 285 |
239 | 286 |
240 static void ReserveSpaceForSnapshot(Deserializer* deserializer, | 287 static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
241 const char* file_name) { | 288 const char* file_name) { |
(...skipping 23 matching lines...) Expand all Loading... |
265 deserializer->set_reservation(NEW_SPACE, new_size); | 312 deserializer->set_reservation(NEW_SPACE, new_size); |
266 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); | 313 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); |
267 deserializer->set_reservation(OLD_DATA_SPACE, data_size); | 314 deserializer->set_reservation(OLD_DATA_SPACE, data_size); |
268 deserializer->set_reservation(CODE_SPACE, code_size); | 315 deserializer->set_reservation(CODE_SPACE, code_size); |
269 deserializer->set_reservation(MAP_SPACE, map_size); | 316 deserializer->set_reservation(MAP_SPACE, map_size); |
270 deserializer->set_reservation(CELL_SPACE, cell_size); | 317 deserializer->set_reservation(CELL_SPACE, cell_size); |
271 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size); | 318 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size); |
272 } | 319 } |
273 | 320 |
274 | 321 |
275 v8::Isolate* InitializeFromFile(const char* snapshot_file) { | 322 bool InitializeFromFile(const char* snapshot_file) { |
276 int len; | 323 int len; |
277 byte* str = ReadBytes(snapshot_file, &len); | 324 byte* str = ReadBytes(snapshot_file, &len); |
278 if (!str) return NULL; | 325 if (!str) return false; |
279 v8::Isolate* v8_isolate = NULL; | 326 bool success; |
280 { | 327 { |
281 SnapshotByteSource source(str, len); | 328 SnapshotByteSource source(str, len); |
282 Deserializer deserializer(&source); | 329 Deserializer deserializer(&source); |
283 ReserveSpaceForSnapshot(&deserializer, snapshot_file); | 330 ReserveSpaceForSnapshot(&deserializer, snapshot_file); |
284 Isolate* isolate = Isolate::NewForTesting(); | 331 success = V8::Initialize(&deserializer); |
285 v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | |
286 v8::Isolate::Scope isolate_scope(v8_isolate); | |
287 isolate->Init(&deserializer); | |
288 } | 332 } |
289 DeleteArray(str); | 333 DeleteArray(str); |
290 return v8_isolate; | 334 return success; |
291 } | 335 } |
292 | 336 |
293 | 337 |
294 static v8::Isolate* Deserialize() { | 338 static void Deserialize() { |
295 v8::Isolate* isolate = InitializeFromFile(FLAG_testing_serialization_file); | 339 CHECK(InitializeFromFile(FLAG_testing_serialization_file)); |
296 CHECK(isolate); | 340 } |
297 return isolate; | 341 |
298 } | 342 |
299 | 343 static void SanityCheck() { |
300 | 344 Isolate* isolate = CcTest::i_isolate(); |
301 static void SanityCheck(v8::Isolate* v8_isolate) { | 345 v8::HandleScope scope(CcTest::isolate()); |
302 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | |
303 v8::HandleScope scope(v8_isolate); | |
304 #ifdef VERIFY_HEAP | 346 #ifdef VERIFY_HEAP |
305 isolate->heap()->Verify(); | 347 CcTest::heap()->Verify(); |
306 #endif | 348 #endif |
307 CHECK(isolate->global_object()->IsJSObject()); | 349 CHECK(isolate->global_object()->IsJSObject()); |
308 CHECK(isolate->native_context()->IsContext()); | 350 CHECK(isolate->native_context()->IsContext()); |
309 CHECK(isolate->heap()->string_table()->IsStringTable()); | 351 CHECK(CcTest::heap()->string_table()->IsStringTable()); |
310 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); | 352 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); |
311 } | 353 } |
312 | 354 |
313 | 355 |
314 UNINITIALIZED_DEPENDENT_TEST(Deserialize, Serialize) { | 356 DEPENDENT_TEST(Deserialize, Serialize) { |
315 // The serialize-deserialize tests only work if the VM is built without | 357 // The serialize-deserialize tests only work if the VM is built without |
316 // serialization. That doesn't matter. We don't need to be able to | 358 // serialization. That doesn't matter. We don't need to be able to |
317 // serialize a snapshot in a VM that is booted from a snapshot. | 359 // serialize a snapshot in a VM that is booted from a snapshot. |
318 if (!Snapshot::HaveASnapshotToStartFrom()) { | 360 if (!Snapshot::HaveASnapshotToStartFrom()) { |
319 v8::Isolate* isolate = Deserialize(); | 361 v8::Isolate* isolate = CcTest::isolate(); |
320 { | 362 v8::HandleScope scope(isolate); |
321 v8::HandleScope handle_scope(isolate); | 363 Deserialize(); |
322 v8::Isolate::Scope isolate_scope(isolate); | 364 |
323 | 365 v8::Local<v8::Context> env = v8::Context::New(isolate); |
324 v8::Local<v8::Context> env = v8::Context::New(isolate); | 366 env->Enter(); |
325 env->Enter(); | 367 |
326 | 368 SanityCheck(); |
327 SanityCheck(isolate); | 369 } |
328 } | 370 } |
329 isolate->Dispose(); | 371 |
330 } | 372 |
331 } | 373 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { |
332 | 374 if (!Snapshot::HaveASnapshotToStartFrom()) { |
333 | 375 v8::Isolate* isolate = CcTest::isolate(); |
334 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerialization, | 376 v8::HandleScope scope(isolate); |
335 SerializeTwice) { | 377 Deserialize(); |
336 if (!Snapshot::HaveASnapshotToStartFrom()) { | 378 |
337 v8::Isolate* isolate = Deserialize(); | 379 v8::Local<v8::Context> env = v8::Context::New(isolate); |
338 { | 380 env->Enter(); |
339 v8::Isolate::Scope isolate_scope(isolate); | 381 |
340 v8::HandleScope handle_scope(isolate); | 382 SanityCheck(); |
341 | 383 } |
342 v8::Local<v8::Context> env = v8::Context::New(isolate); | 384 } |
343 env->Enter(); | 385 |
344 | 386 |
345 SanityCheck(isolate); | 387 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { |
346 } | 388 if (!Snapshot::HaveASnapshotToStartFrom()) { |
347 isolate->Dispose(); | 389 v8::Isolate* isolate = CcTest::isolate(); |
348 } | 390 v8::HandleScope scope(isolate); |
349 } | 391 Deserialize(); |
350 | 392 |
351 | 393 v8::Local<v8::Context> env = v8::Context::New(isolate); |
352 UNINITIALIZED_DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { | 394 env->Enter(); |
353 if (!Snapshot::HaveASnapshotToStartFrom()) { | 395 |
354 v8::Isolate* isolate = Deserialize(); | 396 const char* c_source = "\"1234\".length"; |
355 { | 397 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); |
356 v8::Isolate::Scope isolate_scope(isolate); | 398 v8::Local<v8::Script> script = v8::Script::Compile(source); |
357 v8::HandleScope handle_scope(isolate); | 399 CHECK_EQ(4, script->Run()->Int32Value()); |
358 | 400 } |
359 | 401 } |
360 v8::Local<v8::Context> env = v8::Context::New(isolate); | 402 |
361 env->Enter(); | 403 |
362 | 404 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, |
363 const char* c_source = "\"1234\".length"; | 405 SerializeTwice) { |
364 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); | 406 if (!Snapshot::HaveASnapshotToStartFrom()) { |
365 v8::Local<v8::Script> script = v8::Script::Compile(source); | 407 v8::Isolate* isolate = CcTest::isolate(); |
366 CHECK_EQ(4, script->Run()->Int32Value()); | 408 v8::HandleScope scope(isolate); |
367 } | 409 Deserialize(); |
368 isolate->Dispose(); | 410 |
369 } | 411 v8::Local<v8::Context> env = v8::Context::New(isolate); |
370 } | 412 env->Enter(); |
371 | 413 |
372 | 414 const char* c_source = "\"1234\".length"; |
373 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, | 415 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); |
374 SerializeTwice) { | 416 v8::Local<v8::Script> script = v8::Script::Compile(source); |
375 if (!Snapshot::HaveASnapshotToStartFrom()) { | 417 CHECK_EQ(4, script->Run()->Int32Value()); |
376 v8::Isolate* isolate = Deserialize(); | 418 } |
377 { | 419 } |
378 v8::Isolate::Scope isolate_scope(isolate); | 420 |
379 v8::HandleScope handle_scope(isolate); | 421 |
380 | 422 TEST(PartialSerialization) { |
381 v8::Local<v8::Context> env = v8::Context::New(isolate); | 423 if (!Snapshot::HaveASnapshotToStartFrom()) { |
382 env->Enter(); | 424 Isolate* isolate = CcTest::i_isolate(); |
383 | 425 CcTest::i_isolate()->enable_serializer(); |
384 const char* c_source = "\"1234\".length"; | 426 v8::V8::Initialize(); |
385 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); | 427 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
386 v8::Local<v8::Script> script = v8::Script::Compile(source); | 428 Heap* heap = isolate->heap(); |
387 CHECK_EQ(4, script->Run()->Int32Value()); | 429 |
388 } | 430 v8::Persistent<v8::Context> env; |
389 isolate->Dispose(); | 431 { |
390 } | 432 HandleScope scope(isolate); |
391 } | 433 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
392 | 434 } |
393 | 435 DCHECK(!env.IsEmpty()); |
394 UNINITIALIZED_TEST(PartialSerialization) { | 436 { |
395 if (!Snapshot::HaveASnapshotToStartFrom()) { | 437 v8::HandleScope handle_scope(v8_isolate); |
396 v8::Isolate::CreateParams params; | 438 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
397 params.enable_serializer = true; | 439 } |
398 v8::Isolate* v8_isolate = v8::Isolate::New(params); | 440 // Make sure all builtin scripts are cached. |
399 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 441 { HandleScope scope(isolate); |
400 v8_isolate->Enter(); | 442 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
401 { | 443 isolate->bootstrapper()->NativesSourceLookup(i); |
402 Heap* heap = isolate->heap(); | |
403 | |
404 v8::Persistent<v8::Context> env; | |
405 { | |
406 HandleScope scope(isolate); | |
407 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | |
408 } | 444 } |
409 DCHECK(!env.IsEmpty()); | 445 } |
410 { | 446 heap->CollectAllGarbage(Heap::kNoGCFlags); |
411 v8::HandleScope handle_scope(v8_isolate); | 447 heap->CollectAllGarbage(Heap::kNoGCFlags); |
412 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | 448 |
413 } | 449 Object* raw_foo; |
414 // Make sure all builtin scripts are cached. | 450 { |
415 { | 451 v8::HandleScope handle_scope(v8_isolate); |
416 HandleScope scope(isolate); | 452 v8::Local<v8::String> foo = v8::String::NewFromUtf8(v8_isolate, "foo"); |
417 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 453 DCHECK(!foo.IsEmpty()); |
418 isolate->bootstrapper()->NativesSourceLookup(i); | 454 raw_foo = *(v8::Utils::OpenHandle(*foo)); |
419 } | 455 } |
420 } | 456 |
421 heap->CollectAllGarbage(Heap::kNoGCFlags); | |
422 heap->CollectAllGarbage(Heap::kNoGCFlags); | |
423 | |
424 Object* raw_foo; | |
425 { | |
426 v8::HandleScope handle_scope(v8_isolate); | |
427 v8::Local<v8::String> foo = v8::String::NewFromUtf8(v8_isolate, "foo"); | |
428 DCHECK(!foo.IsEmpty()); | |
429 raw_foo = *(v8::Utils::OpenHandle(*foo)); | |
430 } | |
431 | |
432 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
433 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
434 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
435 | |
436 { | |
437 v8::HandleScope handle_scope(v8_isolate); | |
438 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | |
439 } | |
440 env.Reset(); | |
441 | |
442 FileByteSink startup_sink(startup_name.start()); | |
443 StartupSerializer startup_serializer(isolate, &startup_sink); | |
444 startup_serializer.SerializeStrongReferences(); | |
445 | |
446 FileByteSink partial_sink(FLAG_testing_serialization_file); | |
447 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); | |
448 p_ser.Serialize(&raw_foo); | |
449 startup_serializer.SerializeWeakReferences(); | |
450 | |
451 partial_sink.WriteSpaceUsed( | |
452 p_ser.CurrentAllocationAddress(NEW_SPACE), | |
453 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | |
454 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | |
455 p_ser.CurrentAllocationAddress(CODE_SPACE), | |
456 p_ser.CurrentAllocationAddress(MAP_SPACE), | |
457 p_ser.CurrentAllocationAddress(CELL_SPACE), | |
458 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | |
459 | |
460 startup_sink.WriteSpaceUsed( | |
461 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | |
462 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | |
463 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | |
464 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | |
465 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | |
466 startup_serializer.CurrentAllocationAddress(CELL_SPACE), | |
467 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | |
468 startup_name.Dispose(); | |
469 } | |
470 v8_isolate->Exit(); | |
471 v8_isolate->Dispose(); | |
472 } | |
473 } | |
474 | |
475 | |
476 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | |
477 if (!Snapshot::HaveASnapshotToStartFrom()) { | |
478 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 457 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
479 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 458 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
480 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 459 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
481 | 460 |
482 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); | 461 { |
483 CHECK(v8_isolate); | 462 v8::HandleScope handle_scope(v8_isolate); |
| 463 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 464 } |
| 465 env.Reset(); |
| 466 |
| 467 FileByteSink startup_sink(startup_name.start()); |
| 468 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 469 startup_serializer.SerializeStrongReferences(); |
| 470 |
| 471 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 472 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); |
| 473 p_ser.Serialize(&raw_foo); |
| 474 startup_serializer.SerializeWeakReferences(); |
| 475 |
| 476 partial_sink.WriteSpaceUsed( |
| 477 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 478 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 479 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 480 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 481 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 482 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 483 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 484 |
| 485 startup_sink.WriteSpaceUsed( |
| 486 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 487 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 488 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 489 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 490 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 491 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
| 492 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
484 startup_name.Dispose(); | 493 startup_name.Dispose(); |
485 { | 494 } |
486 v8::Isolate::Scope isolate_scope(v8_isolate); | 495 } |
487 | 496 |
488 const char* file_name = FLAG_testing_serialization_file; | 497 |
489 | 498 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
490 int snapshot_size = 0; | |
491 byte* snapshot = ReadBytes(file_name, &snapshot_size); | |
492 | |
493 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | |
494 Object* root; | |
495 { | |
496 SnapshotByteSource source(snapshot, snapshot_size); | |
497 Deserializer deserializer(&source); | |
498 ReserveSpaceForSnapshot(&deserializer, file_name); | |
499 deserializer.DeserializePartial(isolate, &root); | |
500 CHECK(root->IsString()); | |
501 } | |
502 HandleScope handle_scope(isolate); | |
503 Handle<Object> root_handle(root, isolate); | |
504 | |
505 | |
506 Object* root2; | |
507 { | |
508 SnapshotByteSource source(snapshot, snapshot_size); | |
509 Deserializer deserializer(&source); | |
510 ReserveSpaceForSnapshot(&deserializer, file_name); | |
511 deserializer.DeserializePartial(isolate, &root2); | |
512 CHECK(root2->IsString()); | |
513 CHECK(*root_handle == root2); | |
514 } | |
515 } | |
516 v8_isolate->Dispose(); | |
517 } | |
518 } | |
519 | |
520 | |
521 UNINITIALIZED_TEST(ContextSerialization) { | |
522 if (!Snapshot::HaveASnapshotToStartFrom()) { | |
523 v8::Isolate::CreateParams params; | |
524 params.enable_serializer = true; | |
525 v8::Isolate* v8_isolate = v8::Isolate::New(params); | |
526 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | |
527 Heap* heap = isolate->heap(); | |
528 { | |
529 v8::Isolate::Scope isolate_scope(v8_isolate); | |
530 | |
531 v8::Persistent<v8::Context> env; | |
532 { | |
533 HandleScope scope(isolate); | |
534 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | |
535 } | |
536 DCHECK(!env.IsEmpty()); | |
537 { | |
538 v8::HandleScope handle_scope(v8_isolate); | |
539 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | |
540 } | |
541 // Make sure all builtin scripts are cached. | |
542 { | |
543 HandleScope scope(isolate); | |
544 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | |
545 isolate->bootstrapper()->NativesSourceLookup(i); | |
546 } | |
547 } | |
548 // If we don't do this then we end up with a stray root pointing at the | |
549 // context even after we have disposed of env. | |
550 heap->CollectAllGarbage(Heap::kNoGCFlags); | |
551 | |
552 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | |
553 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
554 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
555 | |
556 { | |
557 v8::HandleScope handle_scope(v8_isolate); | |
558 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | |
559 } | |
560 | |
561 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | |
562 | |
563 env.Reset(); | |
564 | |
565 FileByteSink startup_sink(startup_name.start()); | |
566 StartupSerializer startup_serializer(isolate, &startup_sink); | |
567 startup_serializer.SerializeStrongReferences(); | |
568 | |
569 FileByteSink partial_sink(FLAG_testing_serialization_file); | |
570 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); | |
571 p_ser.Serialize(&raw_context); | |
572 startup_serializer.SerializeWeakReferences(); | |
573 | |
574 partial_sink.WriteSpaceUsed( | |
575 p_ser.CurrentAllocationAddress(NEW_SPACE), | |
576 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | |
577 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | |
578 p_ser.CurrentAllocationAddress(CODE_SPACE), | |
579 p_ser.CurrentAllocationAddress(MAP_SPACE), | |
580 p_ser.CurrentAllocationAddress(CELL_SPACE), | |
581 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | |
582 | |
583 startup_sink.WriteSpaceUsed( | |
584 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | |
585 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | |
586 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | |
587 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | |
588 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | |
589 startup_serializer.CurrentAllocationAddress(CELL_SPACE), | |
590 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | |
591 startup_name.Dispose(); | |
592 } | |
593 v8_isolate->Dispose(); | |
594 } | |
595 } | |
596 | |
597 | |
598 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { | |
599 if (!Snapshot::HaveASnapshotToStartFrom()) { | 499 if (!Snapshot::HaveASnapshotToStartFrom()) { |
600 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 500 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
601 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 501 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
602 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 502 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
603 | 503 |
604 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); | 504 CHECK(InitializeFromFile(startup_name.start())); |
605 CHECK(v8_isolate); | |
606 startup_name.Dispose(); | 505 startup_name.Dispose(); |
607 { | 506 |
608 v8::Isolate::Scope isolate_scope(v8_isolate); | 507 const char* file_name = FLAG_testing_serialization_file; |
609 | 508 |
610 const char* file_name = FLAG_testing_serialization_file; | 509 int snapshot_size = 0; |
611 | 510 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
612 int snapshot_size = 0; | 511 |
613 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 512 Isolate* isolate = CcTest::i_isolate(); |
614 | 513 Object* root; |
615 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 514 { |
616 Object* root; | 515 SnapshotByteSource source(snapshot, snapshot_size); |
617 { | 516 Deserializer deserializer(&source); |
618 SnapshotByteSource source(snapshot, snapshot_size); | 517 ReserveSpaceForSnapshot(&deserializer, file_name); |
619 Deserializer deserializer(&source); | 518 deserializer.DeserializePartial(isolate, &root); |
620 ReserveSpaceForSnapshot(&deserializer, file_name); | 519 CHECK(root->IsString()); |
621 deserializer.DeserializePartial(isolate, &root); | 520 } |
622 CHECK(root->IsContext()); | 521 HandleScope handle_scope(isolate); |
| 522 Handle<Object> root_handle(root, isolate); |
| 523 |
| 524 |
| 525 Object* root2; |
| 526 { |
| 527 SnapshotByteSource source(snapshot, snapshot_size); |
| 528 Deserializer deserializer(&source); |
| 529 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 530 deserializer.DeserializePartial(isolate, &root2); |
| 531 CHECK(root2->IsString()); |
| 532 CHECK(*root_handle == root2); |
| 533 } |
| 534 } |
| 535 } |
| 536 |
| 537 |
| 538 TEST(ContextSerialization) { |
| 539 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 540 Isolate* isolate = CcTest::i_isolate(); |
| 541 CcTest::i_isolate()->enable_serializer(); |
| 542 v8::V8::Initialize(); |
| 543 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 544 Heap* heap = isolate->heap(); |
| 545 |
| 546 v8::Persistent<v8::Context> env; |
| 547 { |
| 548 HandleScope scope(isolate); |
| 549 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
| 550 } |
| 551 DCHECK(!env.IsEmpty()); |
| 552 { |
| 553 v8::HandleScope handle_scope(v8_isolate); |
| 554 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 555 } |
| 556 // Make sure all builtin scripts are cached. |
| 557 { HandleScope scope(isolate); |
| 558 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 559 isolate->bootstrapper()->NativesSourceLookup(i); |
623 } | 560 } |
624 HandleScope handle_scope(isolate); | 561 } |
625 Handle<Object> root_handle(root, isolate); | 562 // If we don't do this then we end up with a stray root pointing at the |
626 | 563 // context even after we have disposed of env. |
627 | 564 heap->CollectAllGarbage(Heap::kNoGCFlags); |
628 Object* root2; | 565 |
629 { | 566 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
630 SnapshotByteSource source(snapshot, snapshot_size); | 567 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
631 Deserializer deserializer(&source); | 568 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
632 ReserveSpaceForSnapshot(&deserializer, file_name); | 569 |
633 deserializer.DeserializePartial(isolate, &root2); | 570 { |
634 CHECK(root2->IsContext()); | 571 v8::HandleScope handle_scope(v8_isolate); |
635 CHECK(*root_handle != root2); | 572 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
636 } | 573 } |
637 } | 574 |
638 v8_isolate->Dispose(); | 575 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
639 } | 576 |
640 } | 577 env.Reset(); |
641 | 578 |
| 579 FileByteSink startup_sink(startup_name.start()); |
| 580 StartupSerializer startup_serializer(isolate, &startup_sink); |
| 581 startup_serializer.SerializeStrongReferences(); |
| 582 |
| 583 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 584 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); |
| 585 p_ser.Serialize(&raw_context); |
| 586 startup_serializer.SerializeWeakReferences(); |
| 587 |
| 588 partial_sink.WriteSpaceUsed( |
| 589 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 590 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 591 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 592 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 593 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 594 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 595 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 596 |
| 597 startup_sink.WriteSpaceUsed( |
| 598 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 599 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 600 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 601 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 602 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 603 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
| 604 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 605 startup_name.Dispose(); |
| 606 } |
| 607 } |
| 608 |
| 609 |
| 610 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
| 611 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 612 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 613 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 614 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 615 |
| 616 CHECK(InitializeFromFile(startup_name.start())); |
| 617 startup_name.Dispose(); |
| 618 |
| 619 const char* file_name = FLAG_testing_serialization_file; |
| 620 |
| 621 int snapshot_size = 0; |
| 622 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 623 |
| 624 Isolate* isolate = CcTest::i_isolate(); |
| 625 Object* root; |
| 626 { |
| 627 SnapshotByteSource source(snapshot, snapshot_size); |
| 628 Deserializer deserializer(&source); |
| 629 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 630 deserializer.DeserializePartial(isolate, &root); |
| 631 CHECK(root->IsContext()); |
| 632 } |
| 633 HandleScope handle_scope(isolate); |
| 634 Handle<Object> root_handle(root, isolate); |
| 635 |
| 636 |
| 637 Object* root2; |
| 638 { |
| 639 SnapshotByteSource source(snapshot, snapshot_size); |
| 640 Deserializer deserializer(&source); |
| 641 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 642 deserializer.DeserializePartial(isolate, &root2); |
| 643 CHECK(root2->IsContext()); |
| 644 CHECK(*root_handle != root2); |
| 645 } |
| 646 } |
| 647 } |
| 648 |
642 | 649 |
643 TEST(TestThatAlwaysSucceeds) { | 650 TEST(TestThatAlwaysSucceeds) { |
644 } | 651 } |
645 | 652 |
646 | 653 |
647 TEST(TestThatAlwaysFails) { | 654 TEST(TestThatAlwaysFails) { |
648 bool ArtificialFailure = false; | 655 bool ArtificialFailure = false; |
649 CHECK(ArtificialFailure); | 656 CHECK(ArtificialFailure); |
650 } | 657 } |
651 | 658 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 } | 792 } |
786 | 793 |
787 | 794 |
788 TEST(SerializeToplevelIsolates) { | 795 TEST(SerializeToplevelIsolates) { |
789 FLAG_serialize_toplevel = true; | 796 FLAG_serialize_toplevel = true; |
790 | 797 |
791 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 798 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
792 v8::ScriptCompiler::CachedData* cache; | 799 v8::ScriptCompiler::CachedData* cache; |
793 | 800 |
794 v8::Isolate* isolate1 = v8::Isolate::New(); | 801 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 802 v8::Isolate* isolate2 = v8::Isolate::New(); |
795 { | 803 { |
796 v8::Isolate::Scope iscope(isolate1); | 804 v8::Isolate::Scope iscope(isolate1); |
797 v8::HandleScope scope(isolate1); | 805 v8::HandleScope scope(isolate1); |
798 v8::Local<v8::Context> context = v8::Context::New(isolate1); | 806 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
799 v8::Context::Scope context_scope(context); | 807 v8::Context::Scope context_scope(context); |
800 | 808 |
801 v8::Local<v8::String> source_str = v8_str(source); | 809 v8::Local<v8::String> source_str = v8_str(source); |
802 v8::ScriptOrigin origin(v8_str("test")); | 810 v8::ScriptOrigin origin(v8_str("test")); |
803 v8::ScriptCompiler::Source source(source_str, origin); | 811 v8::ScriptCompiler::Source source(source_str, origin); |
804 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( | 812 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( |
805 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache); | 813 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache); |
806 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); | 814 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); |
807 // Persist cached data. | 815 // Persist cached data. |
808 uint8_t* buffer = NewArray<uint8_t>(data->length); | 816 uint8_t* buffer = NewArray<uint8_t>(data->length); |
809 MemCopy(buffer, data->data, data->length); | 817 MemCopy(buffer, data->data, data->length); |
810 cache = new v8::ScriptCompiler::CachedData( | 818 cache = new v8::ScriptCompiler::CachedData( |
811 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); | 819 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); |
812 | 820 |
813 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 821 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
814 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 822 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
815 } | 823 } |
816 isolate1->Dispose(); | 824 isolate1->Dispose(); |
817 | 825 |
818 v8::Isolate* isolate2 = v8::Isolate::New(); | |
819 { | 826 { |
820 v8::Isolate::Scope iscope(isolate2); | 827 v8::Isolate::Scope iscope(isolate2); |
821 v8::HandleScope scope(isolate2); | 828 v8::HandleScope scope(isolate2); |
822 v8::Local<v8::Context> context = v8::Context::New(isolate2); | 829 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
823 v8::Context::Scope context_scope(context); | 830 v8::Context::Scope context_scope(context); |
824 | 831 |
825 v8::Local<v8::String> source_str = v8_str(source); | 832 v8::Local<v8::String> source_str = v8_str(source); |
826 v8::ScriptOrigin origin(v8_str("test")); | 833 v8::ScriptOrigin origin(v8_str("test")); |
827 v8::ScriptCompiler::Source source(source_str, origin, cache); | 834 v8::ScriptCompiler::Source source(source_str, origin, cache); |
828 v8::Local<v8::UnboundScript> script; | 835 v8::Local<v8::UnboundScript> script; |
829 { | 836 { |
830 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 837 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
831 script = v8::ScriptCompiler::CompileUnbound( | 838 script = v8::ScriptCompiler::CompileUnbound( |
832 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 839 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
833 } | 840 } |
834 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 841 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
835 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 842 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
836 } | 843 } |
837 isolate2->Dispose(); | 844 isolate2->Dispose(); |
838 } | 845 } |
OLD | NEW |