Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1 | // Copyright 2007-2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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> |
| 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" |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 40 | #include "spaces.h" |
| 41 | #include "objects.h" |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 42 | #include "natives.h" |
| 43 | #include "bootstrapper.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | |
| 45 | using namespace v8::internal; |
| 46 | |
| 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 | } |
| 60 | |
| 61 | |
| 62 | // Callback receiver to track counters in test. |
| 63 | static int* counter_function(const char* name) { |
| 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. |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | template <class T> |
| 85 | static Address AddressOf(T id) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 86 | return ExternalReference(id, i::Isolate::Current()).address(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | TEST(ExternalReferenceEncoder) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 102 | Isolate* isolate = i::Isolate::Current(); |
| 103 | isolate->stats_table()->SetCounterFunction(counter_function); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 104 | v8::V8::Initialize(); |
| 105 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | ExternalReferenceEncoder encoder; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 107 | CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), |
| 108 | Encode(encoder, Builtins::kArrayCode)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 109 | CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 110 | Encode(encoder, Runtime::kAbort)); |
| 111 | CHECK_EQ(make_code(IC_UTILITY, IC::kLoadCallbackProperty), |
| 112 | Encode(encoder, IC_Utility(IC::kLoadCallbackProperty))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 113 | ExternalReference keyed_load_function_prototype = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 114 | ExternalReference(isolate->counters()->keyed_load_function_prototype()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 115 | CHECK_EQ(make_code(STATS_COUNTER, Counters::k_keyed_load_function_prototype), |
| 116 | encoder.Encode(keyed_load_function_prototype.address())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | ExternalReference the_hole_value_location = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 118 | ExternalReference::the_hole_value_location(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 119 | CHECK_EQ(make_code(UNCLASSIFIED, 2), |
| 120 | encoder.Encode(the_hole_value_location.address())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 121 | ExternalReference stack_limit_address = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 122 | ExternalReference::address_of_stack_limit(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | CHECK_EQ(make_code(UNCLASSIFIED, 4), |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 124 | encoder.Encode(stack_limit_address.address())); |
| 125 | ExternalReference real_stack_limit_address = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 126 | ExternalReference::address_of_real_stack_limit(isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 127 | CHECK_EQ(make_code(UNCLASSIFIED, 5), |
| 128 | encoder.Encode(real_stack_limit_address.address())); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 129 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 130 | CHECK_EQ(make_code(UNCLASSIFIED, 15), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 131 | encoder.Encode(ExternalReference::debug_break(isolate).address())); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 132 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 133 | CHECK_EQ(make_code(UNCLASSIFIED, 10), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 134 | encoder.Encode( |
| 135 | ExternalReference::new_space_start(isolate).address())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 136 | CHECK_EQ(make_code(UNCLASSIFIED, 3), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 137 | encoder.Encode(ExternalReference::roots_address(isolate).address())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | TEST(ExternalReferenceDecoder) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 142 | Isolate* isolate = i::Isolate::Current(); |
| 143 | isolate->stats_table()->SetCounterFunction(counter_function); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 144 | v8::V8::Initialize(); |
| 145 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 146 | ExternalReferenceDecoder decoder; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 147 | CHECK_EQ(AddressOf(Builtins::kArrayCode), |
| 148 | decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 149 | CHECK_EQ(AddressOf(Runtime::kAbort), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 150 | decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, |
| 151 | Runtime::kAbort))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 152 | CHECK_EQ(AddressOf(IC_Utility(IC::kLoadCallbackProperty)), |
| 153 | decoder.Decode(make_code(IC_UTILITY, IC::kLoadCallbackProperty))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | ExternalReference keyed_load_function = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 155 | ExternalReference(isolate->counters()->keyed_load_function_prototype()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 156 | CHECK_EQ(keyed_load_function.address(), |
| 157 | decoder.Decode( |
| 158 | make_code(STATS_COUNTER, |
| 159 | Counters::k_keyed_load_function_prototype))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 160 | CHECK_EQ(ExternalReference::the_hole_value_location(isolate).address(), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 161 | decoder.Decode(make_code(UNCLASSIFIED, 2))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 162 | CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 163 | decoder.Decode(make_code(UNCLASSIFIED, 4))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 164 | CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 165 | decoder.Decode(make_code(UNCLASSIFIED, 5))); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 166 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 167 | CHECK_EQ(ExternalReference::debug_break(isolate).address(), |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 168 | decoder.Decode(make_code(UNCLASSIFIED, 15))); |
| 169 | #endif // ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 170 | CHECK_EQ(ExternalReference::new_space_start(isolate).address(), |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 171 | decoder.Decode(make_code(UNCLASSIFIED, 10))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 175 | class FileByteSink : public SnapshotByteSink { |
| 176 | public: |
| 177 | explicit FileByteSink(const char* snapshot_file) { |
| 178 | fp_ = OS::FOpen(snapshot_file, "wb"); |
| 179 | file_name_ = snapshot_file; |
| 180 | if (fp_ == NULL) { |
| 181 | PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); |
| 182 | exit(1); |
| 183 | } |
| 184 | } |
| 185 | virtual ~FileByteSink() { |
| 186 | if (fp_ != NULL) { |
| 187 | fclose(fp_); |
| 188 | } |
| 189 | } |
| 190 | virtual void Put(int byte, const char* description) { |
| 191 | if (fp_ != NULL) { |
| 192 | fputc(byte, fp_); |
| 193 | } |
| 194 | } |
| 195 | virtual int Position() { |
| 196 | return ftell(fp_); |
| 197 | } |
| 198 | void WriteSpaceUsed( |
| 199 | int new_space_used, |
| 200 | int pointer_space_used, |
| 201 | int data_space_used, |
| 202 | int code_space_used, |
| 203 | int map_space_used, |
| 204 | int cell_space_used, |
| 205 | int large_space_used); |
| 206 | |
| 207 | private: |
| 208 | FILE* fp_; |
| 209 | const char* file_name_; |
| 210 | }; |
| 211 | |
| 212 | |
| 213 | void FileByteSink::WriteSpaceUsed( |
| 214 | int new_space_used, |
| 215 | int pointer_space_used, |
| 216 | int data_space_used, |
| 217 | int code_space_used, |
| 218 | int map_space_used, |
| 219 | int cell_space_used, |
| 220 | int large_space_used) { |
| 221 | int file_name_length = StrLength(file_name_) + 10; |
| 222 | Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 223 | OS::SNPrintF(name, "%s.size", file_name_); |
| 224 | FILE* fp = OS::FOpen(name.start(), "w"); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 225 | name.Dispose(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 226 | fprintf(fp, "new %d\n", new_space_used); |
| 227 | fprintf(fp, "pointer %d\n", pointer_space_used); |
| 228 | fprintf(fp, "data %d\n", data_space_used); |
| 229 | fprintf(fp, "code %d\n", code_space_used); |
| 230 | fprintf(fp, "map %d\n", map_space_used); |
| 231 | fprintf(fp, "cell %d\n", cell_space_used); |
| 232 | fprintf(fp, "large %d\n", large_space_used); |
| 233 | fclose(fp); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | static bool WriteToFile(const char* snapshot_file) { |
| 238 | FileByteSink file(snapshot_file); |
| 239 | StartupSerializer ser(&file); |
| 240 | ser.Serialize(); |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 245 | static void Serialize() { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 246 | // We have to create one context. One reason for this is so that the builtins |
| 247 | // can be loaded from v8natives.js and their addresses can be processed. This |
| 248 | // will clear the pending fixups array, which would otherwise contain GC roots |
| 249 | // that would confuse the serialization/deserialization process. |
| 250 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 251 | env.Dispose(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 252 | WriteToFile(FLAG_testing_serialization_file); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 256 | // Test that the whole heap can be serialized. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 257 | TEST(Serialize) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 258 | Serializer::Enable(); |
| 259 | v8::V8::Initialize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 260 | Serialize(); |
| 261 | } |
| 262 | |
| 263 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 264 | // Test that heap serialization is non-destructive. |
| 265 | TEST(SerializeTwice) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 266 | Serializer::Enable(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 267 | v8::V8::Initialize(); |
| 268 | Serialize(); |
| 269 | Serialize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 272 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 273 | //---------------------------------------------------------------------------- |
| 274 | // Tests that the heap can be deserialized. |
| 275 | |
| 276 | static void Deserialize() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 277 | CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static void SanityCheck() { |
| 282 | v8::HandleScope scope; |
| 283 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 284 | HEAP->Verify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 285 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 286 | CHECK(Isolate::Current()->global()->IsJSObject()); |
| 287 | CHECK(Isolate::Current()->global_context()->IsContext()); |
| 288 | CHECK(HEAP->symbol_table()->IsSymbolTable()); |
| 289 | CHECK(!FACTORY->LookupAsciiSymbol("Empty")->IsFailure()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | |
| 293 | DEPENDENT_TEST(Deserialize, Serialize) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 294 | // The serialize-deserialize tests only work if the VM is built without |
| 295 | // serialization. That doesn't matter. We don't need to be able to |
| 296 | // serialize a snapshot in a VM that is booted from a snapshot. |
| 297 | if (!Snapshot::IsEnabled()) { |
| 298 | v8::HandleScope scope; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 299 | Deserialize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 300 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 301 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 302 | env->Enter(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 303 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 304 | SanityCheck(); |
| 305 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 308 | |
| 309 | DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 310 | if (!Snapshot::IsEnabled()) { |
| 311 | v8::HandleScope scope; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 312 | Deserialize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 314 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 315 | env->Enter(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 316 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 317 | SanityCheck(); |
| 318 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
| 322 | DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 323 | if (!Snapshot::IsEnabled()) { |
| 324 | v8::HandleScope scope; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 325 | Deserialize(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 326 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 327 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 328 | env->Enter(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 329 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 330 | const char* c_source = "\"1234\".length"; |
| 331 | v8::Local<v8::String> source = v8::String::New(c_source); |
| 332 | v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 333 | CHECK_EQ(4, script->Run()->Int32Value()); |
| 334 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 338 | DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, |
| 339 | SerializeTwice) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 340 | if (!Snapshot::IsEnabled()) { |
| 341 | v8::HandleScope scope; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 342 | Deserialize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 344 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 345 | env->Enter(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 346 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 347 | const char* c_source = "\"1234\".length"; |
| 348 | v8::Local<v8::String> source = v8::String::New(c_source); |
| 349 | v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 350 | CHECK_EQ(4, script->Run()->Int32Value()); |
| 351 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 355 | TEST(PartialSerialization) { |
| 356 | Serializer::Enable(); |
| 357 | v8::V8::Initialize(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 358 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 359 | v8::Persistent<v8::Context> env = v8::Context::New(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 360 | ASSERT(!env.IsEmpty()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 361 | env->Enter(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 362 | // Make sure all builtin scripts are cached. |
| 363 | { HandleScope scope; |
| 364 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 365 | Isolate::Current()->bootstrapper()->NativesSourceLookup(i); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 368 | HEAP->CollectAllGarbage(true); |
| 369 | HEAP->CollectAllGarbage(true); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 370 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 371 | Object* raw_foo; |
| 372 | { |
| 373 | v8::HandleScope handle_scope; |
| 374 | v8::Local<v8::String> foo = v8::String::New("foo"); |
| 375 | ASSERT(!foo.IsEmpty()); |
| 376 | raw_foo = *(v8::Utils::OpenHandle(*foo)); |
| 377 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 378 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 379 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 380 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 381 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 382 | |
| 383 | env->Exit(); |
| 384 | env.Dispose(); |
| 385 | |
| 386 | FileByteSink startup_sink(startup_name.start()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 387 | startup_name.Dispose(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 388 | StartupSerializer startup_serializer(&startup_sink); |
| 389 | startup_serializer.SerializeStrongReferences(); |
| 390 | |
| 391 | FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 392 | PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 393 | p_ser.Serialize(&raw_foo); |
| 394 | startup_serializer.SerializeWeakReferences(); |
| 395 | partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 396 | p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 397 | p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 398 | p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 399 | p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 400 | p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 401 | p_ser.CurrentAllocationAddress(LO_SPACE)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 405 | static void ReserveSpaceForPartialSnapshot(const char* file_name) { |
| 406 | int file_name_length = StrLength(file_name) + 10; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 407 | Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 408 | OS::SNPrintF(name, "%s.size", file_name); |
| 409 | FILE* fp = OS::FOpen(name.start(), "r"); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 410 | name.Dispose(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 411 | int new_size, pointer_size, data_size, code_size, map_size, cell_size; |
| 412 | int large_size; |
| 413 | #ifdef _MSC_VER |
| 414 | // Avoid warning about unsafe fscanf from MSVC. |
| 415 | // Please note that this is only fine if %c and %s are not being used. |
| 416 | #define fscanf fscanf_s |
| 417 | #endif |
| 418 | CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
| 419 | CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
| 420 | CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
| 421 | CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
| 422 | CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
| 423 | CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
| 424 | CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size)); |
| 425 | #ifdef _MSC_VER |
| 426 | #undef fscanf |
| 427 | #endif |
| 428 | fclose(fp); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 429 | HEAP->ReserveSpace(new_size, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 430 | pointer_size, |
| 431 | data_size, |
| 432 | code_size, |
| 433 | map_size, |
| 434 | cell_size, |
| 435 | large_size); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 436 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 437 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 438 | |
| 439 | DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
| 440 | if (!Snapshot::IsEnabled()) { |
| 441 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 442 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 443 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 444 | |
| 445 | CHECK(Snapshot::Initialize(startup_name.start())); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 446 | startup_name.Dispose(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 447 | |
| 448 | const char* file_name = FLAG_testing_serialization_file; |
| 449 | ReserveSpaceForPartialSnapshot(file_name); |
| 450 | |
| 451 | int snapshot_size = 0; |
| 452 | byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 453 | |
| 454 | Object* root; |
| 455 | { |
| 456 | SnapshotByteSource source(snapshot, snapshot_size); |
| 457 | Deserializer deserializer(&source); |
| 458 | deserializer.DeserializePartial(&root); |
| 459 | CHECK(root->IsString()); |
| 460 | } |
| 461 | v8::HandleScope handle_scope; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 462 | Handle<Object> root_handle(root); |
| 463 | |
| 464 | ReserveSpaceForPartialSnapshot(file_name); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 465 | |
| 466 | Object* root2; |
| 467 | { |
| 468 | SnapshotByteSource source(snapshot, snapshot_size); |
| 469 | Deserializer deserializer(&source); |
| 470 | deserializer.DeserializePartial(&root2); |
| 471 | CHECK(root2->IsString()); |
| 472 | CHECK(*root_handle == root2); |
| 473 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 474 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 475 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 476 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 477 | |
| 478 | TEST(ContextSerialization) { |
| 479 | Serializer::Enable(); |
| 480 | v8::V8::Initialize(); |
| 481 | |
| 482 | v8::Persistent<v8::Context> env = v8::Context::New(); |
| 483 | ASSERT(!env.IsEmpty()); |
| 484 | env->Enter(); |
| 485 | // Make sure all builtin scripts are cached. |
| 486 | { HandleScope scope; |
| 487 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 488 | Isolate::Current()->bootstrapper()->NativesSourceLookup(i); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | // If we don't do this then we end up with a stray root pointing at the |
| 492 | // context even after we have disposed of env. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 493 | HEAP->CollectAllGarbage(true); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 494 | |
| 495 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 496 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 497 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 498 | |
| 499 | env->Exit(); |
| 500 | |
| 501 | Object* raw_context = *(v8::Utils::OpenHandle(*env)); |
| 502 | |
| 503 | env.Dispose(); |
| 504 | |
| 505 | FileByteSink startup_sink(startup_name.start()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 506 | startup_name.Dispose(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 507 | StartupSerializer startup_serializer(&startup_sink); |
| 508 | startup_serializer.SerializeStrongReferences(); |
| 509 | |
| 510 | FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 511 | PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 512 | p_ser.Serialize(&raw_context); |
| 513 | startup_serializer.SerializeWeakReferences(); |
| 514 | partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 515 | p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 516 | p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 517 | p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 518 | p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 519 | p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 520 | p_ser.CurrentAllocationAddress(LO_SPACE)); |
| 521 | } |
| 522 | |
| 523 | |
| 524 | DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
| 525 | if (!Snapshot::IsEnabled()) { |
| 526 | int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 527 | Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 528 | OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 529 | |
| 530 | CHECK(Snapshot::Initialize(startup_name.start())); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 531 | startup_name.Dispose(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 532 | |
| 533 | const char* file_name = FLAG_testing_serialization_file; |
| 534 | ReserveSpaceForPartialSnapshot(file_name); |
| 535 | |
| 536 | int snapshot_size = 0; |
| 537 | byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 538 | |
| 539 | Object* root; |
| 540 | { |
| 541 | SnapshotByteSource source(snapshot, snapshot_size); |
| 542 | Deserializer deserializer(&source); |
| 543 | deserializer.DeserializePartial(&root); |
| 544 | CHECK(root->IsContext()); |
| 545 | } |
| 546 | v8::HandleScope handle_scope; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 547 | Handle<Object> root_handle(root); |
| 548 | |
| 549 | ReserveSpaceForPartialSnapshot(file_name); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 550 | |
| 551 | Object* root2; |
| 552 | { |
| 553 | SnapshotByteSource source(snapshot, snapshot_size); |
| 554 | Deserializer deserializer(&source); |
| 555 | deserializer.DeserializePartial(&root2); |
| 556 | CHECK(root2->IsContext()); |
| 557 | CHECK(*root_handle != root2); |
| 558 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 559 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | |
| 563 | TEST(LinearAllocation) { |
| 564 | v8::V8::Initialize(); |
| 565 | int new_space_max = 512 * KB; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 566 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 567 | for (int size = 1000; size < 5 * MB; size += size >> 1) { |
| 568 | int new_space_size = (size < new_space_max) ? size : new_space_max; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 569 | HEAP->ReserveSpace( |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 570 | new_space_size, |
| 571 | size, // Old pointer space. |
| 572 | size, // Old data space. |
| 573 | size, // Code space. |
| 574 | size, // Map space. |
| 575 | size, // Cell space. |
| 576 | size); // Large object space. |
| 577 | LinearAllocationScope linear_allocation_scope; |
| 578 | const int kSmallFixedArrayLength = 4; |
| 579 | const int kSmallFixedArraySize = |
| 580 | FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize; |
| 581 | const int kSmallStringLength = 16; |
| 582 | const int kSmallStringSize = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 583 | (SeqAsciiString::kHeaderSize + kSmallStringLength + |
| 584 | kObjectAlignmentMask) & ~kObjectAlignmentMask; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 585 | const int kMapSize = Map::kSize; |
| 586 | |
| 587 | Object* new_last = NULL; |
| 588 | for (int i = 0; |
| 589 | i + kSmallFixedArraySize <= new_space_size; |
| 590 | i += kSmallFixedArraySize) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 591 | Object* obj = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 592 | HEAP->AllocateFixedArray(kSmallFixedArrayLength)->ToObjectChecked(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 593 | if (new_last != NULL) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 594 | CHECK(reinterpret_cast<char*>(obj) == |
| 595 | reinterpret_cast<char*>(new_last) + kSmallFixedArraySize); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 596 | } |
| 597 | new_last = obj; |
| 598 | } |
| 599 | |
| 600 | Object* pointer_last = NULL; |
| 601 | for (int i = 0; |
| 602 | i + kSmallFixedArraySize <= size; |
| 603 | i += kSmallFixedArraySize) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 604 | Object* obj = HEAP->AllocateFixedArray(kSmallFixedArrayLength, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 605 | TENURED)->ToObjectChecked(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 606 | int old_page_fullness = i % Page::kPageSize; |
| 607 | int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize; |
| 608 | if (page_fullness < old_page_fullness || |
| 609 | page_fullness > Page::kObjectAreaSize) { |
| 610 | i = RoundUp(i, Page::kPageSize); |
| 611 | pointer_last = NULL; |
| 612 | } |
| 613 | if (pointer_last != NULL) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 614 | CHECK(reinterpret_cast<char*>(obj) == |
| 615 | reinterpret_cast<char*>(pointer_last) + kSmallFixedArraySize); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 616 | } |
| 617 | pointer_last = obj; |
| 618 | } |
| 619 | |
| 620 | Object* data_last = NULL; |
| 621 | for (int i = 0; i + kSmallStringSize <= size; i += kSmallStringSize) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 622 | Object* obj = HEAP->AllocateRawAsciiString(kSmallStringLength, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 623 | TENURED)->ToObjectChecked(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 624 | int old_page_fullness = i % Page::kPageSize; |
| 625 | int page_fullness = (i + kSmallStringSize) % Page::kPageSize; |
| 626 | if (page_fullness < old_page_fullness || |
| 627 | page_fullness > Page::kObjectAreaSize) { |
| 628 | i = RoundUp(i, Page::kPageSize); |
| 629 | data_last = NULL; |
| 630 | } |
| 631 | if (data_last != NULL) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 632 | CHECK(reinterpret_cast<char*>(obj) == |
| 633 | reinterpret_cast<char*>(data_last) + kSmallStringSize); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 634 | } |
| 635 | data_last = obj; |
| 636 | } |
| 637 | |
| 638 | Object* map_last = NULL; |
| 639 | for (int i = 0; i + kMapSize <= size; i += kMapSize) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 640 | Object* obj = HEAP->AllocateMap(JS_OBJECT_TYPE, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 641 | 42 * kPointerSize)->ToObjectChecked(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 642 | int old_page_fullness = i % Page::kPageSize; |
| 643 | int page_fullness = (i + kMapSize) % Page::kPageSize; |
| 644 | if (page_fullness < old_page_fullness || |
| 645 | page_fullness > Page::kObjectAreaSize) { |
| 646 | i = RoundUp(i, Page::kPageSize); |
| 647 | map_last = NULL; |
| 648 | } |
| 649 | if (map_last != NULL) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 650 | CHECK(reinterpret_cast<char*>(obj) == |
| 651 | reinterpret_cast<char*>(map_last) + kMapSize); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 652 | } |
| 653 | map_last = obj; |
| 654 | } |
| 655 | |
| 656 | if (size > Page::kObjectAreaSize) { |
| 657 | // Support for reserving space in large object space is not there yet, |
| 658 | // but using an always-allocate scope is fine for now. |
| 659 | AlwaysAllocateScope always; |
| 660 | int large_object_array_length = |
| 661 | (size - FixedArray::kHeaderSize) / kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 662 | Object* obj = HEAP->AllocateFixedArray(large_object_array_length, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 663 | TENURED)->ToObjectChecked(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 664 | CHECK(!obj->IsFailure()); |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 670 | TEST(TestThatAlwaysSucceeds) { |
| 671 | } |
| 672 | |
| 673 | |
| 674 | TEST(TestThatAlwaysFails) { |
| 675 | bool ArtificialFailure = false; |
| 676 | CHECK(ArtificialFailure); |
| 677 | } |
| 678 | |
| 679 | |
| 680 | DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 681 | bool ArtificialFailure2 = false; |
| 682 | CHECK(ArtificialFailure2); |
| 683 | } |