sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2007-2010 the V8 project authors. All rights reserved. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include <signal.h> |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 29 | |
| 30 | #include "sys/stat.h" |
| 31 | #include "v8.h" |
| 32 | |
| 33 | #include "debug.h" |
| 34 | #include "ic-inl.h" |
| 35 | #include "runtime.h" |
| 36 | #include "serialize.h" |
| 37 | #include "scopeinfo.h" |
| 38 | #include "snapshot.h" |
| 39 | #include "cctest.h" |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 40 | #include "spaces.h" |
| 41 | #include "objects.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 42 | #include "natives.h" |
| 43 | #include "bootstrapper.h" |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 45 | using namespace v8::internal; |
| 46 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 47 | static const unsigned kCounters = 256; |
| 48 | static int local_counters[kCounters]; |
| 49 | static const char* local_counter_names[kCounters]; |
| 50 | |
| 51 | |
| 52 | static unsigned CounterHash(const char* s) { |
| 53 | unsigned hash = 0; |
| 54 | while (*++s) { |
| 55 | hash |= hash << 5; |
| 56 | hash += *s; |
| 57 | } |
| 58 | return hash; |
| 59 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 60 | |
| 61 | |
| 62 | // Callback receiver to track counters in test. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 63 | static int* counter_function(const char* name) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 64 | unsigned hash = CounterHash(name) % kCounters; |
| 65 | unsigned original_hash = hash; |
| 66 | USE(original_hash); |
| 67 | while (true) { |
| 68 | if (local_counter_names[hash] == name) { |
| 69 | return &local_counters[hash]; |
| 70 | } |
| 71 | if (local_counter_names[hash] == 0) { |
| 72 | local_counter_names[hash] = name; |
| 73 | return &local_counters[hash]; |
| 74 | } |
| 75 | if (strcmp(local_counter_names[hash], name) == 0) { |
| 76 | return &local_counters[hash]; |
| 77 | } |
| 78 | hash = (hash + 1) % kCounters; |
| 79 | ASSERT(hash != original_hash); // Hash table has been filled up. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 80 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | template <class T> |
| 85 | static Address AddressOf(T id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 86 | return ExternalReference(id, i::Isolate::Current()).address(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
| 90 | template <class T> |
| 91 | static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) { |
| 92 | return encoder.Encode(AddressOf(id)); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | static int make_code(TypeCode type, int id) { |
| 97 | return static_cast<uint32_t>(type) << kReferenceTypeShift | id; |
| 98 | } |
| 99 | |
| 100 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 101 | TEST(ExternalReferenceEncoder) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 102 | Isolate* isolate = i::Isolate::Current(); |
| 103 | isolate->stats_table()->SetCounterFunction(counter_function); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 104 | v8::V8::Initialize(); |
| 105 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 106 | ExternalReferenceEncoder encoder; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 107 | CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), |
| 108 | Encode(encoder, Builtins::kArrayCode)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 109 | CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 110 | Encode(encoder, Runtime::kAbort)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 111 | ExternalReference keyed_load_function_prototype = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 112 | ExternalReference(isolate->counters()->keyed_load_function_prototype()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 113 | CHECK_EQ(make_code(STATS_COUNTER, Counters::k_keyed_load_function_prototype), |
| 114 | encoder.Encode(keyed_load_function_prototype.address())); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 115 | ExternalReference stack_limit_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 116 | ExternalReference::address_of_stack_limit(isolate); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 117 | CHECK_EQ(make_code(UNCLASSIFIED, 4), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 118 | encoder.Encode(stack_limit_address.address())); |
| 119 | ExternalReference real_stack_limit_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 120 | ExternalReference::address_of_real_stack_limit(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 121 | CHECK_EQ(make_code(UNCLASSIFIED, 5), |
| 122 | encoder.Encode(real_stack_limit_address.address())); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 123 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 124 | CHECK_EQ(make_code(UNCLASSIFIED, 16), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 125 | encoder.Encode(ExternalReference::debug_break(isolate).address())); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 126 | #endif // ENABLE_DEBUGGER_SUPPORT |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 127 | CHECK_EQ(make_code(UNCLASSIFIED, 10), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | encoder.Encode( |
| 129 | ExternalReference::new_space_start(isolate).address())); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 130 | CHECK_EQ(make_code(UNCLASSIFIED, 3), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 131 | encoder.Encode( |
| 132 | ExternalReference::roots_array_start(isolate).address())); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 133 | CHECK_EQ(make_code(UNCLASSIFIED, 52), |
| 134 | encoder.Encode(ExternalReference::cpu_features().address())); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
| 138 | TEST(ExternalReferenceDecoder) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | Isolate* isolate = i::Isolate::Current(); |
| 140 | isolate->stats_table()->SetCounterFunction(counter_function); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 141 | v8::V8::Initialize(); |
| 142 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 143 | ExternalReferenceDecoder decoder; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 144 | CHECK_EQ(AddressOf(Builtins::kArrayCode), |
| 145 | decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 146 | CHECK_EQ(AddressOf(Runtime::kAbort), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 147 | decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, |
| 148 | Runtime::kAbort))); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 149 | ExternalReference keyed_load_function = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 150 | ExternalReference(isolate->counters()->keyed_load_function_prototype()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 151 | CHECK_EQ(keyed_load_function.address(), |
| 152 | decoder.Decode( |
| 153 | make_code(STATS_COUNTER, |
| 154 | Counters::k_keyed_load_function_prototype))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 155 | CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(), |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 156 | decoder.Decode(make_code(UNCLASSIFIED, 4))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 157 | CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 158 | decoder.Decode(make_code(UNCLASSIFIED, 5))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 159 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 160 | CHECK_EQ(ExternalReference::debug_break(isolate).address(), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 161 | decoder.Decode(make_code(UNCLASSIFIED, 16))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 162 | #endif // ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 163 | CHECK_EQ(ExternalReference::new_space_start(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 164 | decoder.Decode(make_code(UNCLASSIFIED, 10))); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 168 | class FileByteSink : public SnapshotByteSink { |
| 169 | public: |
| 170 | explicit FileByteSink(const char* snapshot_file) { |
| 171 | fp_ = OS::FOpen(snapshot_file, "wb"); |
| 172 | file_name_ = snapshot_file; |
| 173 | if (fp_ == NULL) { |
| 174 | PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); |
| 175 | exit(1); |
| 176 | } |
| 177 | } |
| 178 | virtual ~FileByteSink() { |
| 179 | if (fp_ != NULL) { |
| 180 | fclose(fp_); |
| 181 | } |
| 182 | } |
| 183 | virtual void Put(int byte, const char* description) { |
| 184 | if (fp_ != NULL) { |
| 185 | fputc(byte, fp_); |
| 186 | } |
| 187 | } |
| 188 | virtual int Position() { |
| 189 | return ftell(fp_); |
| 190 | } |
| 191 | void WriteSpaceUsed( |
| 192 | int new_space_used, |
| 193 | int pointer_space_used, |
| 194 | int data_space_used, |
| 195 | int code_space_used, |
| 196 | int map_space_used, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 197 | int cell_space_used); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 198 | |
| 199 | private: |
| 200 | FILE* fp_; |
| 201 | const char* file_name_; |
| 202 | }; |
| 203 | |
| 204 | |
| 205 | void FileByteSink::WriteSpaceUsed( |
| 206 | int new_space_used, |
| 207 | int pointer_space_used, |
| 208 | int data_space_used, |
| 209 | int code_space_used, |
| 210 | int map_space_used, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 211 | int cell_space_used) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 212 | int file_name_length = StrLength(file_name_) + 10; |
| 213 | Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 214 | OS::SNPrintF(name, "%s.size", file_name_); |
| 215 | FILE* fp = OS::FOpen(name.start(), "w"); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 216 | name.Dispose(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 217 | fprintf(fp, "new %d\n", new_space_used); |
| 218 | fprintf(fp, "pointer %d\n", pointer_space_used); |
| 219 | fprintf(fp, "data %d\n", data_space_used); |
| 220 | fprintf(fp, "code %d\n", code_space_used); |
| 221 | fprintf(fp, "map %d\n", map_space_used); |
| 222 | fprintf(fp, "cell %d\n", cell_space_used); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 223 | fclose(fp); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | static bool WriteToFile(const char* snapshot_file) { |
| 228 | FileByteSink file(snapshot_file); |
| 229 | StartupSerializer ser(&file); |
| 230 | ser.Serialize(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 231 | |
| 232 | file.WriteSpaceUsed( |
| 233 | ser.CurrentAllocationAddress(NEW_SPACE), |
| 234 | ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 235 | ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 236 | ser.CurrentAllocationAddress(CODE_SPACE), |
| 237 | ser.CurrentAllocationAddress(MAP_SPACE), |
| 238 | ser.CurrentAllocationAddress(CELL_SPACE)); |
| 239 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 240 | return true; |
| 241 | } |
| 242 | |
| 243 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 244 | static void Serialize() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 245 | // We have to create one context. One reason for this is so that the builtins |
| 246 | // can be loaded from v8natives.js and their addresses can be processed. This |
| 247 | // will clear the pending fixups array, which would otherwise contain GC roots |
| 248 | // that would confuse the serialization/deserialization process. |
| 249 | v8::Persistent<v8::Context> env = v8::Context::New(); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 250 | env.Dispose(env->GetIsolate()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 251 | WriteToFile(FLAG_testing_serialization_file); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 255 | // Test that the whole heap can be serialized. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 256 | TEST(Serialize) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 257 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 258 | Serializer::Enable(); |
| 259 | v8::V8::Initialize(); |
| 260 | Serialize(); |
| 261 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 262 | } |
| 263 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 264 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 265 | // Test that heap serialization is non-destructive. |
| 266 | TEST(SerializeTwice) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 267 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 268 | Serializer::Enable(); |
| 269 | v8::V8::Initialize(); |
| 270 | Serialize(); |
| 271 | Serialize(); |
| 272 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 276 | //---------------------------------------------------------------------------- |
| 277 | // Tests that the heap can be deserialized. |
| 278 | |
| 279 | static void Deserialize() { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 280 | CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
| 284 | static void SanityCheck() { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 285 | v8::HandleScope scope(v8::Isolate::GetCurrent()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 286 | #ifdef VERIFY_HEAP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 287 | HEAP->Verify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 288 | #endif |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 289 | CHECK(Isolate::Current()->global_object()->IsJSObject()); |
| 290 | CHECK(Isolate::Current()->native_context()->IsContext()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 291 | CHECK(HEAP->string_table()->IsStringTable()); |
| 292 | CHECK(!FACTORY->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 293 | STATIC_ASCII_VECTOR("Empty"))->IsFailure()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 297 | DEPENDENT_TEST(Deserialize, Serialize) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 298 | // The serialize-deserialize tests only work if the VM is built without |
| 299 | // serialization. That doesn't matter. We don't need to be able to |
| 300 | // serialize a snapshot in a VM that is booted from a snapshot. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 301 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 302 | v8::HandleScope scope(v8::Isolate::GetCurrent()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 303 | Deserialize(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 304 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 305 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 306 | env->Enter(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 307 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 308 | SanityCheck(); |
| 309 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
| 313 | DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 314 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 315 | v8::HandleScope scope(v8::Isolate::GetCurrent()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 316 | Deserialize(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 317 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 318 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 319 | env->Enter(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 320 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 321 | SanityCheck(); |
| 322 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 326 | DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 327 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 328 | v8::HandleScope scope(v8::Isolate::GetCurrent()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 329 | Deserialize(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 330 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 331 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 332 | env->Enter(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 333 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 334 | const char* c_source = "\"1234\".length"; |
| 335 | v8::Local<v8::String> source = v8::String::New(c_source); |
| 336 | v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 337 | CHECK_EQ(4, script->Run()->Int32Value()); |
| 338 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 342 | DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, |
| 343 | SerializeTwice) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 344 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 345 | v8::HandleScope scope(v8::Isolate::GetCurrent()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 346 | Deserialize(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 347 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 348 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 349 | env->Enter(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 350 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 351 | const char* c_source = "\"1234\".length"; |
| 352 | v8::Local<v8::String> source = v8::String::New(c_source); |
| 353 | v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 354 | CHECK_EQ(4, script->Run()->Int32Value()); |
| 355 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 359 | TEST(PartialSerialization) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 360 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 361 | Serializer::Enable(); |
| 362 | v8::V8::Initialize(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 363 | Isolate* isolate = Isolate::Current(); |
| 364 | Heap* heap = isolate->heap(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 365 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 366 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 367 | ASSERT(!env.IsEmpty()); |
| 368 | env->Enter(); |
| 369 | // Make sure all builtin scripts are cached. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 370 | { HandleScope scope(isolate); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 371 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 372 | isolate->bootstrapper()->NativesSourceLookup(i); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 373 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 374 | } |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 375 | heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 376 | heap->CollectAllGarbage(Heap::kNoGCFlags); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 377 | |
| 378 | Object* raw_foo; |
| 379 | { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 380 | v8::HandleScope handle_scope(env->GetIsolate()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 381 | v8::Local<v8::String> foo = v8::String::New("foo"); |
| 382 | ASSERT(!foo.IsEmpty()); |
| 383 | raw_foo = *(v8::Utils::OpenHandle(*foo)); |
| 384 | } |
| 385 | |
| 386 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 387 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 388 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 389 | |
| 390 | env->Exit(); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 391 | env.Dispose(env->GetIsolate()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 392 | |
| 393 | FileByteSink startup_sink(startup_name.start()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 394 | StartupSerializer startup_serializer(&startup_sink); |
| 395 | startup_serializer.SerializeStrongReferences(); |
| 396 | |
| 397 | FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 398 | PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 399 | p_ser.Serialize(&raw_foo); |
| 400 | startup_serializer.SerializeWeakReferences(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 401 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 402 | partial_sink.WriteSpaceUsed( |
| 403 | p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 404 | p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 405 | p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 406 | p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 407 | p_ser.CurrentAllocationAddress(MAP_SPACE), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 408 | p_ser.CurrentAllocationAddress(CELL_SPACE)); |
| 409 | |
| 410 | startup_sink.WriteSpaceUsed( |
| 411 | startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 412 | startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 413 | startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 414 | startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 415 | startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 416 | startup_serializer.CurrentAllocationAddress(CELL_SPACE)); |
| 417 | startup_name.Dispose(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 418 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 422 | static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
| 423 | const char* file_name) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 424 | int file_name_length = StrLength(file_name) + 10; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 425 | Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 426 | OS::SNPrintF(name, "%s.size", file_name); |
| 427 | FILE* fp = OS::FOpen(name.start(), "r"); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 428 | name.Dispose(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 429 | int new_size, pointer_size, data_size, code_size, map_size, cell_size; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 430 | #ifdef _MSC_VER |
| 431 | // Avoid warning about unsafe fscanf from MSVC. |
| 432 | // Please note that this is only fine if %c and %s are not being used. |
| 433 | #define fscanf fscanf_s |
| 434 | #endif |
| 435 | CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
| 436 | CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
| 437 | CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
| 438 | CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
| 439 | CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
| 440 | CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 441 | #ifdef _MSC_VER |
| 442 | #undef fscanf |
| 443 | #endif |
| 444 | fclose(fp); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 445 | deserializer->set_reservation(NEW_SPACE, new_size); |
| 446 | deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); |
| 447 | deserializer->set_reservation(OLD_DATA_SPACE, data_size); |
| 448 | deserializer->set_reservation(CODE_SPACE, code_size); |
| 449 | deserializer->set_reservation(MAP_SPACE, map_size); |
| 450 | deserializer->set_reservation(CELL_SPACE, cell_size); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 451 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 452 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 453 | |
| 454 | DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
| 455 | if (!Snapshot::IsEnabled()) { |
| 456 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 457 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 458 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 459 | |
| 460 | CHECK(Snapshot::Initialize(startup_name.start())); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 461 | startup_name.Dispose(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 462 | |
| 463 | const char* file_name = FLAG_testing_serialization_file; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 464 | |
| 465 | int snapshot_size = 0; |
| 466 | byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 467 | |
| 468 | Object* root; |
| 469 | { |
| 470 | SnapshotByteSource source(snapshot, snapshot_size); |
| 471 | Deserializer deserializer(&source); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 472 | ReserveSpaceForSnapshot(&deserializer, file_name); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 473 | deserializer.DeserializePartial(&root); |
| 474 | CHECK(root->IsString()); |
| 475 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 476 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 477 | Handle<Object> root_handle(root, Isolate::Current()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 478 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 479 | |
| 480 | Object* root2; |
| 481 | { |
| 482 | SnapshotByteSource source(snapshot, snapshot_size); |
| 483 | Deserializer deserializer(&source); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 484 | ReserveSpaceForSnapshot(&deserializer, file_name); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 485 | deserializer.DeserializePartial(&root2); |
| 486 | CHECK(root2->IsString()); |
| 487 | CHECK(*root_handle == root2); |
| 488 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 489 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 490 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 491 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 492 | |
| 493 | TEST(ContextSerialization) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 494 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 495 | Serializer::Enable(); |
| 496 | v8::V8::Initialize(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 497 | Isolate* isolate = Isolate::Current(); |
| 498 | Heap* heap = isolate->heap(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 499 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 500 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 501 | ASSERT(!env.IsEmpty()); |
| 502 | env->Enter(); |
| 503 | // Make sure all builtin scripts are cached. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 504 | { HandleScope scope(isolate); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 505 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 506 | isolate->bootstrapper()->NativesSourceLookup(i); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 507 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 508 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 509 | // If we don't do this then we end up with a stray root pointing at the |
| 510 | // context even after we have disposed of env. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 511 | heap->CollectAllGarbage(Heap::kNoGCFlags); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 512 | |
| 513 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 514 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 515 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 516 | |
| 517 | env->Exit(); |
| 518 | |
| 519 | Object* raw_context = *(v8::Utils::OpenHandle(*env)); |
| 520 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 521 | env.Dispose(env->GetIsolate()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 522 | |
| 523 | FileByteSink startup_sink(startup_name.start()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 524 | StartupSerializer startup_serializer(&startup_sink); |
| 525 | startup_serializer.SerializeStrongReferences(); |
| 526 | |
| 527 | FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 528 | PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 529 | p_ser.Serialize(&raw_context); |
| 530 | startup_serializer.SerializeWeakReferences(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 531 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 532 | partial_sink.WriteSpaceUsed( |
| 533 | p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 534 | p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 535 | p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 536 | p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 537 | p_ser.CurrentAllocationAddress(MAP_SPACE), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 538 | p_ser.CurrentAllocationAddress(CELL_SPACE)); |
| 539 | |
| 540 | startup_sink.WriteSpaceUsed( |
| 541 | startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 542 | startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 543 | startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 544 | startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 545 | startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 546 | startup_serializer.CurrentAllocationAddress(CELL_SPACE)); |
| 547 | startup_name.Dispose(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 548 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
| 552 | DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 553 | if (!Snapshot::HaveASnapshotToStartFrom()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 554 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 555 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 556 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 557 | |
| 558 | CHECK(Snapshot::Initialize(startup_name.start())); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 559 | startup_name.Dispose(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 560 | |
| 561 | const char* file_name = FLAG_testing_serialization_file; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 562 | |
| 563 | int snapshot_size = 0; |
| 564 | byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 565 | |
| 566 | Object* root; |
| 567 | { |
| 568 | SnapshotByteSource source(snapshot, snapshot_size); |
| 569 | Deserializer deserializer(&source); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 570 | ReserveSpaceForSnapshot(&deserializer, file_name); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 571 | deserializer.DeserializePartial(&root); |
| 572 | CHECK(root->IsContext()); |
| 573 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 574 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 575 | Handle<Object> root_handle(root, Isolate::Current()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 576 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 577 | |
| 578 | Object* root2; |
| 579 | { |
| 580 | SnapshotByteSource source(snapshot, snapshot_size); |
| 581 | Deserializer deserializer(&source); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 582 | ReserveSpaceForSnapshot(&deserializer, file_name); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 583 | deserializer.DeserializePartial(&root2); |
| 584 | CHECK(root2->IsContext()); |
| 585 | CHECK(*root_handle != root2); |
| 586 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 587 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 591 | TEST(TestThatAlwaysSucceeds) { |
| 592 | } |
| 593 | |
| 594 | |
| 595 | TEST(TestThatAlwaysFails) { |
| 596 | bool ArtificialFailure = false; |
| 597 | CHECK(ArtificialFailure); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 602 | bool ArtificialFailure2 = false; |
| 603 | CHECK(ArtificialFailure2); |
| 604 | } |