blob: c34840ace761cc60fdd1bb70705aadbda0328756 [file] [log] [blame]
Leon Clarkee46be812010-01-19 14:06:41 +00001// Copyright 2007-2010 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// 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 Clarkee46be812010-01-19 14:06:41 +000040#include "spaces.h"
41#include "objects.h"
Leon Clarked91b9f72010-01-27 17:25:45 +000042#include "natives.h"
43#include "bootstrapper.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000044
45using namespace v8::internal;
46
47static const unsigned kCounters = 256;
48static int local_counters[kCounters];
49static const char* local_counter_names[kCounters];
50
51
52static 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.
63static 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
84template <class T>
85static Address AddressOf(T id) {
86 return ExternalReference(id).address();
87}
88
89
90template <class T>
91static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) {
92 return encoder.Encode(AddressOf(id));
93}
94
95
96static int make_code(TypeCode type, int id) {
97 return static_cast<uint32_t>(type) << kReferenceTypeShift | id;
98}
99
100
101static int register_code(int reg) {
102 return Debug::k_register_address << kDebugIdShift | reg;
103}
104
105
106TEST(ExternalReferenceEncoder) {
107 StatsTable::SetCounterFunction(counter_function);
108 Heap::Setup(false);
109 ExternalReferenceEncoder encoder;
110 CHECK_EQ(make_code(BUILTIN, Builtins::ArrayCode),
111 Encode(encoder, Builtins::ArrayCode));
112 CHECK_EQ(make_code(RUNTIME_FUNCTION, Runtime::kAbort),
113 Encode(encoder, Runtime::kAbort));
114 CHECK_EQ(make_code(IC_UTILITY, IC::kLoadCallbackProperty),
115 Encode(encoder, IC_Utility(IC::kLoadCallbackProperty)));
116 CHECK_EQ(make_code(DEBUG_ADDRESS, register_code(3)),
117 Encode(encoder, Debug_Address(Debug::k_register_address, 3)));
118 ExternalReference keyed_load_function_prototype =
119 ExternalReference(&Counters::keyed_load_function_prototype);
120 CHECK_EQ(make_code(STATS_COUNTER, Counters::k_keyed_load_function_prototype),
121 encoder.Encode(keyed_load_function_prototype.address()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 ExternalReference the_hole_value_location =
123 ExternalReference::the_hole_value_location();
124 CHECK_EQ(make_code(UNCLASSIFIED, 2),
125 encoder.Encode(the_hole_value_location.address()));
Steve Blockd0582a62009-12-15 09:54:21 +0000126 ExternalReference stack_limit_address =
127 ExternalReference::address_of_stack_limit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000128 CHECK_EQ(make_code(UNCLASSIFIED, 4),
Steve Blockd0582a62009-12-15 09:54:21 +0000129 encoder.Encode(stack_limit_address.address()));
130 ExternalReference real_stack_limit_address =
131 ExternalReference::address_of_real_stack_limit();
132 CHECK_EQ(make_code(UNCLASSIFIED, 5),
133 encoder.Encode(real_stack_limit_address.address()));
134 CHECK_EQ(make_code(UNCLASSIFIED, 11),
Steve Blocka7e24c12009-10-30 11:49:00 +0000135 encoder.Encode(ExternalReference::debug_break().address()));
Steve Blockd0582a62009-12-15 09:54:21 +0000136 CHECK_EQ(make_code(UNCLASSIFIED, 7),
Steve Blocka7e24c12009-10-30 11:49:00 +0000137 encoder.Encode(ExternalReference::new_space_start().address()));
138 CHECK_EQ(make_code(UNCLASSIFIED, 3),
139 encoder.Encode(ExternalReference::roots_address().address()));
140}
141
142
143TEST(ExternalReferenceDecoder) {
144 StatsTable::SetCounterFunction(counter_function);
145 Heap::Setup(false);
146 ExternalReferenceDecoder decoder;
147 CHECK_EQ(AddressOf(Builtins::ArrayCode),
148 decoder.Decode(make_code(BUILTIN, Builtins::ArrayCode)));
149 CHECK_EQ(AddressOf(Runtime::kAbort),
150 decoder.Decode(make_code(RUNTIME_FUNCTION, Runtime::kAbort)));
151 CHECK_EQ(AddressOf(IC_Utility(IC::kLoadCallbackProperty)),
152 decoder.Decode(make_code(IC_UTILITY, IC::kLoadCallbackProperty)));
153 CHECK_EQ(AddressOf(Debug_Address(Debug::k_register_address, 3)),
154 decoder.Decode(make_code(DEBUG_ADDRESS, register_code(3))));
155 ExternalReference keyed_load_function =
156 ExternalReference(&Counters::keyed_load_function_prototype);
157 CHECK_EQ(keyed_load_function.address(),
158 decoder.Decode(
159 make_code(STATS_COUNTER,
160 Counters::k_keyed_load_function_prototype)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000161 CHECK_EQ(ExternalReference::the_hole_value_location().address(),
162 decoder.Decode(make_code(UNCLASSIFIED, 2)));
Steve Blockd0582a62009-12-15 09:54:21 +0000163 CHECK_EQ(ExternalReference::address_of_stack_limit().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 decoder.Decode(make_code(UNCLASSIFIED, 4)));
Steve Blockd0582a62009-12-15 09:54:21 +0000165 CHECK_EQ(ExternalReference::address_of_real_stack_limit().address(),
166 decoder.Decode(make_code(UNCLASSIFIED, 5)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 CHECK_EQ(ExternalReference::debug_break().address(),
Steve Blockd0582a62009-12-15 09:54:21 +0000168 decoder.Decode(make_code(UNCLASSIFIED, 11)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000169 CHECK_EQ(ExternalReference::new_space_start().address(),
Steve Blockd0582a62009-12-15 09:54:21 +0000170 decoder.Decode(make_code(UNCLASSIFIED, 7)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000171}
172
173
Leon Clarked91b9f72010-01-27 17:25:45 +0000174class FileByteSink : public SnapshotByteSink {
175 public:
176 explicit FileByteSink(const char* snapshot_file) {
177 fp_ = OS::FOpen(snapshot_file, "wb");
178 file_name_ = snapshot_file;
179 if (fp_ == NULL) {
180 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
181 exit(1);
182 }
183 }
184 virtual ~FileByteSink() {
185 if (fp_ != NULL) {
186 fclose(fp_);
187 }
188 }
189 virtual void Put(int byte, const char* description) {
190 if (fp_ != NULL) {
191 fputc(byte, fp_);
192 }
193 }
194 virtual int Position() {
195 return ftell(fp_);
196 }
197 void WriteSpaceUsed(
198 int new_space_used,
199 int pointer_space_used,
200 int data_space_used,
201 int code_space_used,
202 int map_space_used,
203 int cell_space_used,
204 int large_space_used);
205
206 private:
207 FILE* fp_;
208 const char* file_name_;
209};
210
211
212void FileByteSink::WriteSpaceUsed(
213 int new_space_used,
214 int pointer_space_used,
215 int data_space_used,
216 int code_space_used,
217 int map_space_used,
218 int cell_space_used,
219 int large_space_used) {
220 int file_name_length = StrLength(file_name_) + 10;
221 Vector<char> name = Vector<char>::New(file_name_length + 1);
222 OS::SNPrintF(name, "%s.size", file_name_);
223 FILE* fp = OS::FOpen(name.start(), "w");
224 fprintf(fp, "new %d\n", new_space_used);
225 fprintf(fp, "pointer %d\n", pointer_space_used);
226 fprintf(fp, "data %d\n", data_space_used);
227 fprintf(fp, "code %d\n", code_space_used);
228 fprintf(fp, "map %d\n", map_space_used);
229 fprintf(fp, "cell %d\n", cell_space_used);
230 fprintf(fp, "large %d\n", large_space_used);
231 fclose(fp);
232}
233
234
235static bool WriteToFile(const char* snapshot_file) {
236 FileByteSink file(snapshot_file);
237 StartupSerializer ser(&file);
238 ser.Serialize();
239 return true;
240}
241
242
Steve Blocka7e24c12009-10-30 11:49:00 +0000243static void Serialize() {
Steve Blockd0582a62009-12-15 09:54:21 +0000244 // We have to create one context. One reason for this is so that the builtins
245 // can be loaded from v8natives.js and their addresses can be processed. This
246 // will clear the pending fixups array, which would otherwise contain GC roots
247 // that would confuse the serialization/deserialization process.
248 v8::Persistent<v8::Context> env = v8::Context::New();
249 env.Dispose();
Leon Clarked91b9f72010-01-27 17:25:45 +0000250 WriteToFile(FLAG_testing_serialization_file);
Steve Blocka7e24c12009-10-30 11:49:00 +0000251}
252
253
Steve Blockd0582a62009-12-15 09:54:21 +0000254// Test that the whole heap can be serialized.
Steve Blocka7e24c12009-10-30 11:49:00 +0000255TEST(Serialize) {
Steve Blockd0582a62009-12-15 09:54:21 +0000256 Serializer::Enable();
257 v8::V8::Initialize();
Steve Blocka7e24c12009-10-30 11:49:00 +0000258 Serialize();
259}
260
261
Steve Blockd0582a62009-12-15 09:54:21 +0000262// Test that heap serialization is non-destructive.
263TEST(SerializeTwice) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000264 Serializer::Enable();
Steve Blockd0582a62009-12-15 09:54:21 +0000265 v8::V8::Initialize();
266 Serialize();
267 Serialize();
Steve Blocka7e24c12009-10-30 11:49:00 +0000268}
269
Steve Blockd0582a62009-12-15 09:54:21 +0000270
Steve Blocka7e24c12009-10-30 11:49:00 +0000271//----------------------------------------------------------------------------
272// Tests that the heap can be deserialized.
273
274static void Deserialize() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file));
276}
277
278
279static void SanityCheck() {
280 v8::HandleScope scope;
281#ifdef DEBUG
282 Heap::Verify();
283#endif
284 CHECK(Top::global()->IsJSObject());
285 CHECK(Top::global_context()->IsContext());
286 CHECK(Top::special_function_table()->IsFixedArray());
287 CHECK(Heap::symbol_table()->IsSymbolTable());
288 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure());
289}
290
291
292DEPENDENT_TEST(Deserialize, Serialize) {
293 v8::HandleScope scope;
294
295 Deserialize();
296
Steve Blockd0582a62009-12-15 09:54:21 +0000297 v8::Persistent<v8::Context> env = v8::Context::New();
298 env->Enter();
299
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 SanityCheck();
301}
302
Steve Blockd0582a62009-12-15 09:54:21 +0000303
304DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000305 v8::HandleScope scope;
306
307 Deserialize();
308
Steve Blockd0582a62009-12-15 09:54:21 +0000309 v8::Persistent<v8::Context> env = v8::Context::New();
310 env->Enter();
311
312 SanityCheck();
313}
314
315
316DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
317 v8::HandleScope scope;
318
319 Deserialize();
320
321 v8::Persistent<v8::Context> env = v8::Context::New();
322 env->Enter();
323
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 const char* c_source = "\"1234\".length";
325 v8::Local<v8::String> source = v8::String::New(c_source);
326 v8::Local<v8::Script> script = v8::Script::Compile(source);
327 CHECK_EQ(4, script->Run()->Int32Value());
328}
329
330
Steve Blockd0582a62009-12-15 09:54:21 +0000331DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
332 SerializeTwice) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000333 v8::HandleScope scope;
334
335 Deserialize();
336
Steve Blockd0582a62009-12-15 09:54:21 +0000337 v8::Persistent<v8::Context> env = v8::Context::New();
338 env->Enter();
339
340 const char* c_source = "\"1234\".length";
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 v8::Local<v8::String> source = v8::String::New(c_source);
342 v8::Local<v8::Script> script = v8::Script::Compile(source);
Steve Blockd0582a62009-12-15 09:54:21 +0000343 CHECK_EQ(4, script->Run()->Int32Value());
Steve Blocka7e24c12009-10-30 11:49:00 +0000344}
345
346
Leon Clarkee46be812010-01-19 14:06:41 +0000347TEST(PartialSerialization) {
348 Serializer::Enable();
349 v8::V8::Initialize();
Leon Clarked91b9f72010-01-27 17:25:45 +0000350
Leon Clarkee46be812010-01-19 14:06:41 +0000351 v8::Persistent<v8::Context> env = v8::Context::New();
Leon Clarked91b9f72010-01-27 17:25:45 +0000352 ASSERT(!env.IsEmpty());
Leon Clarkee46be812010-01-19 14:06:41 +0000353 env->Enter();
Leon Clarked91b9f72010-01-27 17:25:45 +0000354 // Make sure all builtin scripts are cached.
355 { HandleScope scope;
356 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
357 Bootstrapper::NativesSourceLookup(i);
358 }
359 }
360 Heap::CollectAllGarbage(true);
361 Heap::CollectAllGarbage(true);
Leon Clarkee46be812010-01-19 14:06:41 +0000362
Leon Clarked91b9f72010-01-27 17:25:45 +0000363 Object* raw_foo;
364 {
365 v8::HandleScope handle_scope;
366 v8::Local<v8::String> foo = v8::String::New("foo");
367 ASSERT(!foo.IsEmpty());
368 raw_foo = *(v8::Utils::OpenHandle(*foo));
369 }
Leon Clarkee46be812010-01-19 14:06:41 +0000370
Leon Clarked91b9f72010-01-27 17:25:45 +0000371 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
372 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
373 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
374
375 env->Exit();
376 env.Dispose();
377
378 FileByteSink startup_sink(startup_name.start());
379 StartupSerializer startup_serializer(&startup_sink);
380 startup_serializer.SerializeStrongReferences();
381
382 FileByteSink partial_sink(FLAG_testing_serialization_file);
383 PartialSerializer p_ser(&startup_serializer, &partial_sink);
384 p_ser.Serialize(&raw_foo);
385 startup_serializer.SerializeWeakReferences();
386 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE),
387 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
388 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
389 p_ser.CurrentAllocationAddress(CODE_SPACE),
390 p_ser.CurrentAllocationAddress(MAP_SPACE),
391 p_ser.CurrentAllocationAddress(CELL_SPACE),
392 p_ser.CurrentAllocationAddress(LO_SPACE));
Leon Clarkee46be812010-01-19 14:06:41 +0000393}
394
395
396DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
Leon Clarked91b9f72010-01-27 17:25:45 +0000397 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
398 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
399 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
400
401 CHECK(Snapshot::Initialize(startup_name.start()));
402
Leon Clarkee46be812010-01-19 14:06:41 +0000403 const char* file_name = FLAG_testing_serialization_file;
Leon Clarkee46be812010-01-19 14:06:41 +0000404 Vector<char> name = Vector<char>::New(file_name_length + 1);
405 OS::SNPrintF(name, "%s.size", file_name);
406 FILE* fp = OS::FOpen(name.start(), "r");
407 int new_size, pointer_size, data_size, code_size, map_size, cell_size;
408 int large_size;
409#ifdef _MSC_VER
410 // Avoid warning about unsafe fscanf from MSVC.
411 // Please note that this is only fine if %c and %s are not being used.
412#define fscanf fscanf_s
413#endif
414 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
415 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
416 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
417 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
418 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
419 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
420 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size));
421#ifdef _MSC_VER
422#undef fscanf
423#endif
424 fclose(fp);
425 Heap::ReserveSpace(new_size,
426 pointer_size,
427 data_size,
428 code_size,
429 map_size,
430 cell_size,
431 large_size);
432 int snapshot_size = 0;
433 byte* snapshot = ReadBytes(file_name, &snapshot_size);
Leon Clarked91b9f72010-01-27 17:25:45 +0000434
Leon Clarkee46be812010-01-19 14:06:41 +0000435 Object* root;
Leon Clarked91b9f72010-01-27 17:25:45 +0000436 {
437 SnapshotByteSource source(snapshot, snapshot_size);
438 Deserializer deserializer(&source);
439 deserializer.DeserializePartial(&root);
440 CHECK(root->IsString());
441 }
442 v8::HandleScope handle_scope;
443 Handle<Object>root_handle(root);
444
445 Object* root2;
446 {
447 SnapshotByteSource source(snapshot, snapshot_size);
448 Deserializer deserializer(&source);
449 deserializer.DeserializePartial(&root2);
450 CHECK(root2->IsString());
451 CHECK(*root_handle == root2);
452 }
Leon Clarkee46be812010-01-19 14:06:41 +0000453}
454
455
456TEST(LinearAllocation) {
457 v8::V8::Initialize();
458 int new_space_max = 512 * KB;
459 for (int size = 1000; size < 5 * MB; size += size >> 1) {
460 int new_space_size = (size < new_space_max) ? size : new_space_max;
461 Heap::ReserveSpace(
462 new_space_size,
463 size, // Old pointer space.
464 size, // Old data space.
465 size, // Code space.
466 size, // Map space.
467 size, // Cell space.
468 size); // Large object space.
469 LinearAllocationScope linear_allocation_scope;
470 const int kSmallFixedArrayLength = 4;
471 const int kSmallFixedArraySize =
472 FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize;
473 const int kSmallStringLength = 16;
474 const int kSmallStringSize =
475 SeqAsciiString::kHeaderSize + kSmallStringLength;
476 const int kMapSize = Map::kSize;
477
478 Object* new_last = NULL;
479 for (int i = 0;
480 i + kSmallFixedArraySize <= new_space_size;
481 i += kSmallFixedArraySize) {
482 Object* obj = Heap::AllocateFixedArray(kSmallFixedArrayLength);
483 if (new_last != NULL) {
484 CHECK_EQ(reinterpret_cast<char*>(obj),
485 reinterpret_cast<char*>(new_last) + kSmallFixedArraySize);
486 }
487 new_last = obj;
488 }
489
490 Object* pointer_last = NULL;
491 for (int i = 0;
492 i + kSmallFixedArraySize <= size;
493 i += kSmallFixedArraySize) {
494 Object* obj = Heap::AllocateFixedArray(kSmallFixedArrayLength, TENURED);
495 int old_page_fullness = i % Page::kPageSize;
496 int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize;
497 if (page_fullness < old_page_fullness ||
498 page_fullness > Page::kObjectAreaSize) {
499 i = RoundUp(i, Page::kPageSize);
500 pointer_last = NULL;
501 }
502 if (pointer_last != NULL) {
503 CHECK_EQ(reinterpret_cast<char*>(obj),
504 reinterpret_cast<char*>(pointer_last) + kSmallFixedArraySize);
505 }
506 pointer_last = obj;
507 }
508
509 Object* data_last = NULL;
510 for (int i = 0; i + kSmallStringSize <= size; i += kSmallStringSize) {
511 Object* obj = Heap::AllocateRawAsciiString(kSmallStringLength, TENURED);
512 int old_page_fullness = i % Page::kPageSize;
513 int page_fullness = (i + kSmallStringSize) % Page::kPageSize;
514 if (page_fullness < old_page_fullness ||
515 page_fullness > Page::kObjectAreaSize) {
516 i = RoundUp(i, Page::kPageSize);
517 data_last = NULL;
518 }
519 if (data_last != NULL) {
520 CHECK_EQ(reinterpret_cast<char*>(obj),
521 reinterpret_cast<char*>(data_last) + kSmallStringSize);
522 }
523 data_last = obj;
524 }
525
526 Object* map_last = NULL;
527 for (int i = 0; i + kMapSize <= size; i += kMapSize) {
528 Object* obj = Heap::AllocateMap(JS_OBJECT_TYPE, 42 * kPointerSize);
529 int old_page_fullness = i % Page::kPageSize;
530 int page_fullness = (i + kMapSize) % Page::kPageSize;
531 if (page_fullness < old_page_fullness ||
532 page_fullness > Page::kObjectAreaSize) {
533 i = RoundUp(i, Page::kPageSize);
534 map_last = NULL;
535 }
536 if (map_last != NULL) {
537 CHECK_EQ(reinterpret_cast<char*>(obj),
538 reinterpret_cast<char*>(map_last) + kMapSize);
539 }
540 map_last = obj;
541 }
542
543 if (size > Page::kObjectAreaSize) {
544 // Support for reserving space in large object space is not there yet,
545 // but using an always-allocate scope is fine for now.
546 AlwaysAllocateScope always;
547 int large_object_array_length =
548 (size - FixedArray::kHeaderSize) / kPointerSize;
549 Object* obj = Heap::AllocateFixedArray(large_object_array_length,
550 TENURED);
551 CHECK(!obj->IsFailure());
552 }
553 }
554}
555
556
Steve Block3ce2e202009-11-05 08:53:23 +0000557TEST(TestThatAlwaysSucceeds) {
558}
559
560
561TEST(TestThatAlwaysFails) {
562 bool ArtificialFailure = false;
563 CHECK(ArtificialFailure);
564}
565
566
567DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
568 bool ArtificialFailure2 = false;
569 CHECK(ArtificialFailure2);
570}