blob: 3988b4a893e77ba5bff1bb0331a0c9ecf5f8dcfb [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
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 "v8.h"
29
30#include "accessors.h"
31#include "api.h"
32#include "execution.h"
33#include "global-handles.h"
34#include "ic-inl.h"
35#include "natives.h"
36#include "platform.h"
37#include "runtime.h"
38#include "serialize.h"
39#include "stub-cache.h"
40#include "v8threads.h"
Steve Block3ce2e202009-11-05 08:53:23 +000041#include "top.h"
Steve Blockd0582a62009-12-15 09:54:21 +000042#include "bootstrapper.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000043
44namespace v8 {
45namespace internal {
46
Steve Blocka7e24c12009-10-30 11:49:00 +000047
48// -----------------------------------------------------------------------------
49// Coding of external references.
50
51// The encoding of an external reference. The type is in the high word.
52// The id is in the low word.
53static uint32_t EncodeExternal(TypeCode type, uint16_t id) {
54 return static_cast<uint32_t>(type) << 16 | id;
55}
56
57
58static int* GetInternalPointer(StatsCounter* counter) {
59 // All counters refer to dummy_counter, if deserializing happens without
60 // setting up counters.
61 static int dummy_counter = 0;
62 return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter;
63}
64
65
66// ExternalReferenceTable is a helper class that defines the relationship
67// between external references and their encodings. It is used to build
68// hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
69class ExternalReferenceTable {
70 public:
71 static ExternalReferenceTable* instance() {
72 if (!instance_) instance_ = new ExternalReferenceTable();
73 return instance_;
74 }
75
76 int size() const { return refs_.length(); }
77
78 Address address(int i) { return refs_[i].address; }
79
80 uint32_t code(int i) { return refs_[i].code; }
81
82 const char* name(int i) { return refs_[i].name; }
83
84 int max_id(int code) { return max_id_[code]; }
85
86 private:
87 static ExternalReferenceTable* instance_;
88
89 ExternalReferenceTable() : refs_(64) { PopulateTable(); }
90 ~ExternalReferenceTable() { }
91
92 struct ExternalReferenceEntry {
93 Address address;
94 uint32_t code;
95 const char* name;
96 };
97
98 void PopulateTable();
99
100 // For a few types of references, we can get their address from their id.
101 void AddFromId(TypeCode type, uint16_t id, const char* name);
102
103 // For other types of references, the caller will figure out the address.
104 void Add(Address address, TypeCode type, uint16_t id, const char* name);
105
106 List<ExternalReferenceEntry> refs_;
107 int max_id_[kTypeCodeCount];
108};
109
110
111ExternalReferenceTable* ExternalReferenceTable::instance_ = NULL;
112
113
114void ExternalReferenceTable::AddFromId(TypeCode type,
115 uint16_t id,
116 const char* name) {
117 Address address;
118 switch (type) {
119 case C_BUILTIN: {
120 ExternalReference ref(static_cast<Builtins::CFunctionId>(id));
121 address = ref.address();
122 break;
123 }
124 case BUILTIN: {
125 ExternalReference ref(static_cast<Builtins::Name>(id));
126 address = ref.address();
127 break;
128 }
129 case RUNTIME_FUNCTION: {
130 ExternalReference ref(static_cast<Runtime::FunctionId>(id));
131 address = ref.address();
132 break;
133 }
134 case IC_UTILITY: {
135 ExternalReference ref(IC_Utility(static_cast<IC::UtilityId>(id)));
136 address = ref.address();
137 break;
138 }
139 default:
140 UNREACHABLE();
141 return;
142 }
143 Add(address, type, id, name);
144}
145
146
147void ExternalReferenceTable::Add(Address address,
148 TypeCode type,
149 uint16_t id,
150 const char* name) {
Steve Blockd0582a62009-12-15 09:54:21 +0000151 ASSERT_NE(NULL, address);
Steve Blocka7e24c12009-10-30 11:49:00 +0000152 ExternalReferenceEntry entry;
153 entry.address = address;
154 entry.code = EncodeExternal(type, id);
155 entry.name = name;
Steve Blockd0582a62009-12-15 09:54:21 +0000156 ASSERT_NE(0, entry.code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000157 refs_.Add(entry);
158 if (id > max_id_[type]) max_id_[type] = id;
159}
160
161
162void ExternalReferenceTable::PopulateTable() {
163 for (int type_code = 0; type_code < kTypeCodeCount; type_code++) {
164 max_id_[type_code] = 0;
165 }
166
167 // The following populates all of the different type of external references
168 // into the ExternalReferenceTable.
169 //
170 // NOTE: This function was originally 100k of code. It has since been
171 // rewritten to be mostly table driven, as the callback macro style tends to
172 // very easily cause code bloat. Please be careful in the future when adding
173 // new references.
174
175 struct RefTableEntry {
176 TypeCode type;
177 uint16_t id;
178 const char* name;
179 };
180
181 static const RefTableEntry ref_table[] = {
182 // Builtins
Leon Clarkee46be812010-01-19 14:06:41 +0000183#define DEF_ENTRY_C(name, ignored) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 { C_BUILTIN, \
185 Builtins::c_##name, \
186 "Builtins::" #name },
187
188 BUILTIN_LIST_C(DEF_ENTRY_C)
189#undef DEF_ENTRY_C
190
Leon Clarkee46be812010-01-19 14:06:41 +0000191#define DEF_ENTRY_C(name, ignored) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000192 { BUILTIN, \
193 Builtins::name, \
194 "Builtins::" #name },
Leon Clarkee46be812010-01-19 14:06:41 +0000195#define DEF_ENTRY_A(name, kind, state) DEF_ENTRY_C(name, ignored)
Steve Blocka7e24c12009-10-30 11:49:00 +0000196
197 BUILTIN_LIST_C(DEF_ENTRY_C)
198 BUILTIN_LIST_A(DEF_ENTRY_A)
199 BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A)
200#undef DEF_ENTRY_C
201#undef DEF_ENTRY_A
202
203 // Runtime functions
204#define RUNTIME_ENTRY(name, nargs, ressize) \
205 { RUNTIME_FUNCTION, \
206 Runtime::k##name, \
207 "Runtime::" #name },
208
209 RUNTIME_FUNCTION_LIST(RUNTIME_ENTRY)
210#undef RUNTIME_ENTRY
211
212 // IC utilities
213#define IC_ENTRY(name) \
214 { IC_UTILITY, \
215 IC::k##name, \
216 "IC::" #name },
217
218 IC_UTIL_LIST(IC_ENTRY)
219#undef IC_ENTRY
220 }; // end of ref_table[].
221
222 for (size_t i = 0; i < ARRAY_SIZE(ref_table); ++i) {
223 AddFromId(ref_table[i].type, ref_table[i].id, ref_table[i].name);
224 }
225
226#ifdef ENABLE_DEBUGGER_SUPPORT
227 // Debug addresses
228 Add(Debug_Address(Debug::k_after_break_target_address).address(),
229 DEBUG_ADDRESS,
230 Debug::k_after_break_target_address << kDebugIdShift,
231 "Debug::after_break_target_address()");
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100232 Add(Debug_Address(Debug::k_debug_break_slot_address).address(),
233 DEBUG_ADDRESS,
234 Debug::k_debug_break_slot_address << kDebugIdShift,
235 "Debug::debug_break_slot_address()");
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 Add(Debug_Address(Debug::k_debug_break_return_address).address(),
237 DEBUG_ADDRESS,
238 Debug::k_debug_break_return_address << kDebugIdShift,
239 "Debug::debug_break_return_address()");
Ben Murdochbb769b22010-08-11 14:56:33 +0100240 Add(Debug_Address(Debug::k_restarter_frame_function_pointer).address(),
241 DEBUG_ADDRESS,
242 Debug::k_restarter_frame_function_pointer << kDebugIdShift,
243 "Debug::restarter_frame_function_pointer_address()");
Steve Blocka7e24c12009-10-30 11:49:00 +0000244 const char* debug_register_format = "Debug::register_address(%i)";
Steve Blockd0582a62009-12-15 09:54:21 +0000245 int dr_format_length = StrLength(debug_register_format);
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 for (int i = 0; i < kNumJSCallerSaved; ++i) {
247 Vector<char> name = Vector<char>::New(dr_format_length + 1);
248 OS::SNPrintF(name, debug_register_format, i);
249 Add(Debug_Address(Debug::k_register_address, i).address(),
250 DEBUG_ADDRESS,
251 Debug::k_register_address << kDebugIdShift | i,
252 name.start());
253 }
254#endif
255
256 // Stat counters
257 struct StatsRefTableEntry {
258 StatsCounter* counter;
259 uint16_t id;
260 const char* name;
261 };
262
263 static const StatsRefTableEntry stats_ref_table[] = {
264#define COUNTER_ENTRY(name, caption) \
265 { &Counters::name, \
266 Counters::k_##name, \
267 "Counters::" #name },
268
269 STATS_COUNTER_LIST_1(COUNTER_ENTRY)
270 STATS_COUNTER_LIST_2(COUNTER_ENTRY)
271#undef COUNTER_ENTRY
272 }; // end of stats_ref_table[].
273
274 for (size_t i = 0; i < ARRAY_SIZE(stats_ref_table); ++i) {
275 Add(reinterpret_cast<Address>(
276 GetInternalPointer(stats_ref_table[i].counter)),
277 STATS_COUNTER,
278 stats_ref_table[i].id,
279 stats_ref_table[i].name);
280 }
281
282 // Top addresses
Steve Block3ce2e202009-11-05 08:53:23 +0000283 const char* top_address_format = "Top::%s";
284
285 const char* AddressNames[] = {
286#define C(name) #name,
287 TOP_ADDRESS_LIST(C)
288 TOP_ADDRESS_LIST_PROF(C)
289 NULL
290#undef C
291 };
292
Steve Blockd0582a62009-12-15 09:54:21 +0000293 int top_format_length = StrLength(top_address_format) - 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000294 for (uint16_t i = 0; i < Top::k_top_address_count; ++i) {
Steve Block3ce2e202009-11-05 08:53:23 +0000295 const char* address_name = AddressNames[i];
296 Vector<char> name =
Steve Blockd0582a62009-12-15 09:54:21 +0000297 Vector<char>::New(top_format_length + StrLength(address_name) + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 const char* chars = name.start();
Steve Block3ce2e202009-11-05 08:53:23 +0000299 OS::SNPrintF(name, top_address_format, address_name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 Add(Top::get_address_from_id((Top::AddressId)i), TOP_ADDRESS, i, chars);
301 }
302
303 // Extensions
304 Add(FUNCTION_ADDR(GCExtension::GC), EXTENSION, 1,
305 "GCExtension::GC");
306
307 // Accessors
308#define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
309 Add((Address)&Accessors::name, \
310 ACCESSOR, \
311 Accessors::k##name, \
312 "Accessors::" #name);
313
314 ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
315#undef ACCESSOR_DESCRIPTOR_DECLARATION
316
317 // Stub cache tables
318 Add(SCTableReference::keyReference(StubCache::kPrimary).address(),
319 STUB_CACHE_TABLE,
320 1,
321 "StubCache::primary_->key");
322 Add(SCTableReference::valueReference(StubCache::kPrimary).address(),
323 STUB_CACHE_TABLE,
324 2,
325 "StubCache::primary_->value");
326 Add(SCTableReference::keyReference(StubCache::kSecondary).address(),
327 STUB_CACHE_TABLE,
328 3,
329 "StubCache::secondary_->key");
330 Add(SCTableReference::valueReference(StubCache::kSecondary).address(),
331 STUB_CACHE_TABLE,
332 4,
333 "StubCache::secondary_->value");
334
335 // Runtime entries
336 Add(ExternalReference::perform_gc_function().address(),
337 RUNTIME_ENTRY,
338 1,
339 "Runtime::PerformGC");
Steve Block6ded16b2010-05-10 14:33:55 +0100340 Add(ExternalReference::fill_heap_number_with_random_function().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 RUNTIME_ENTRY,
342 2,
Steve Block6ded16b2010-05-10 14:33:55 +0100343 "V8::FillHeapNumberWithRandom");
344
345 Add(ExternalReference::random_uint32_function().address(),
346 RUNTIME_ENTRY,
347 3,
348 "V8::Random");
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
350 // Miscellaneous
Steve Blocka7e24c12009-10-30 11:49:00 +0000351 Add(ExternalReference::the_hole_value_location().address(),
352 UNCLASSIFIED,
353 2,
354 "Factory::the_hole_value().location()");
355 Add(ExternalReference::roots_address().address(),
356 UNCLASSIFIED,
357 3,
358 "Heap::roots_address()");
Steve Blockd0582a62009-12-15 09:54:21 +0000359 Add(ExternalReference::address_of_stack_limit().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 UNCLASSIFIED,
361 4,
362 "StackGuard::address_of_jslimit()");
Steve Blockd0582a62009-12-15 09:54:21 +0000363 Add(ExternalReference::address_of_real_stack_limit().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000364 UNCLASSIFIED,
365 5,
Steve Blockd0582a62009-12-15 09:54:21 +0000366 "StackGuard::address_of_real_jslimit()");
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100367#ifndef V8_INTERPRETED_REGEXP
Steve Blockd0582a62009-12-15 09:54:21 +0000368 Add(ExternalReference::address_of_regexp_stack_limit().address(),
369 UNCLASSIFIED,
370 6,
Steve Blocka7e24c12009-10-30 11:49:00 +0000371 "RegExpStack::limit_address()");
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100372 Add(ExternalReference::address_of_regexp_stack_memory_address().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 UNCLASSIFIED,
Steve Blockd0582a62009-12-15 09:54:21 +0000374 7,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100375 "RegExpStack::memory_address()");
376 Add(ExternalReference::address_of_regexp_stack_memory_size().address(),
377 UNCLASSIFIED,
378 8,
379 "RegExpStack::memory_size()");
380 Add(ExternalReference::address_of_static_offsets_vector().address(),
381 UNCLASSIFIED,
382 9,
383 "OffsetsVector::static_offsets_vector");
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100384#endif // V8_INTERPRETED_REGEXP
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100385 Add(ExternalReference::new_space_start().address(),
386 UNCLASSIFIED,
387 10,
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 "Heap::NewSpaceStart()");
Andrei Popescu402d9372010-02-26 13:31:12 +0000389 Add(ExternalReference::new_space_mask().address(),
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100391 11,
Andrei Popescu402d9372010-02-26 13:31:12 +0000392 "Heap::NewSpaceMask()");
393 Add(ExternalReference::heap_always_allocate_scope_depth().address(),
394 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100395 12,
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 "Heap::always_allocate_scope_depth()");
397 Add(ExternalReference::new_space_allocation_limit_address().address(),
398 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100399 13,
Steve Blocka7e24c12009-10-30 11:49:00 +0000400 "Heap::NewSpaceAllocationLimitAddress()");
401 Add(ExternalReference::new_space_allocation_top_address().address(),
402 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100403 14,
Steve Blocka7e24c12009-10-30 11:49:00 +0000404 "Heap::NewSpaceAllocationTopAddress()");
405#ifdef ENABLE_DEBUGGER_SUPPORT
406 Add(ExternalReference::debug_break().address(),
407 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100408 15,
Steve Blocka7e24c12009-10-30 11:49:00 +0000409 "Debug::Break()");
410 Add(ExternalReference::debug_step_in_fp_address().address(),
411 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100412 16,
Steve Blocka7e24c12009-10-30 11:49:00 +0000413 "Debug::step_in_fp_addr()");
414#endif
415 Add(ExternalReference::double_fp_operation(Token::ADD).address(),
416 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100417 17,
Steve Blocka7e24c12009-10-30 11:49:00 +0000418 "add_two_doubles");
419 Add(ExternalReference::double_fp_operation(Token::SUB).address(),
420 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100421 18,
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 "sub_two_doubles");
423 Add(ExternalReference::double_fp_operation(Token::MUL).address(),
424 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100425 19,
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 "mul_two_doubles");
427 Add(ExternalReference::double_fp_operation(Token::DIV).address(),
428 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100429 20,
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 "div_two_doubles");
431 Add(ExternalReference::double_fp_operation(Token::MOD).address(),
432 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100433 21,
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 "mod_two_doubles");
435 Add(ExternalReference::compare_doubles().address(),
436 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100437 22,
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 "compare_doubles");
Steve Block6ded16b2010-05-10 14:33:55 +0100439#ifndef V8_INTERPRETED_REGEXP
440 Add(ExternalReference::re_case_insensitive_compare_uc16().address(),
441 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100442 23,
Steve Blocka7e24c12009-10-30 11:49:00 +0000443 "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()");
444 Add(ExternalReference::re_check_stack_guard_state().address(),
445 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100446 24,
Steve Blocka7e24c12009-10-30 11:49:00 +0000447 "RegExpMacroAssembler*::CheckStackGuardState()");
448 Add(ExternalReference::re_grow_stack().address(),
449 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100450 25,
Steve Blocka7e24c12009-10-30 11:49:00 +0000451 "NativeRegExpMacroAssembler::GrowStack()");
Leon Clarkee46be812010-01-19 14:06:41 +0000452 Add(ExternalReference::re_word_character_map().address(),
453 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100454 26,
Leon Clarkee46be812010-01-19 14:06:41 +0000455 "NativeRegExpMacroAssembler::word_character_map");
Steve Block6ded16b2010-05-10 14:33:55 +0100456#endif // V8_INTERPRETED_REGEXP
Leon Clarkee46be812010-01-19 14:06:41 +0000457 // Keyed lookup cache.
458 Add(ExternalReference::keyed_lookup_cache_keys().address(),
459 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100460 27,
Leon Clarkee46be812010-01-19 14:06:41 +0000461 "KeyedLookupCache::keys()");
462 Add(ExternalReference::keyed_lookup_cache_field_offsets().address(),
463 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100464 28,
Leon Clarkee46be812010-01-19 14:06:41 +0000465 "KeyedLookupCache::field_offsets()");
Andrei Popescu402d9372010-02-26 13:31:12 +0000466 Add(ExternalReference::transcendental_cache_array_address().address(),
467 UNCLASSIFIED,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100468 29,
Andrei Popescu402d9372010-02-26 13:31:12 +0000469 "TranscendentalCache::caches()");
Steve Blocka7e24c12009-10-30 11:49:00 +0000470}
471
472
473ExternalReferenceEncoder::ExternalReferenceEncoder()
474 : encodings_(Match) {
475 ExternalReferenceTable* external_references =
476 ExternalReferenceTable::instance();
477 for (int i = 0; i < external_references->size(); ++i) {
478 Put(external_references->address(i), i);
479 }
480}
481
482
483uint32_t ExternalReferenceEncoder::Encode(Address key) const {
484 int index = IndexOf(key);
Ben Murdochbb769b22010-08-11 14:56:33 +0100485 ASSERT(key == NULL || index >= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000486 return index >=0 ? ExternalReferenceTable::instance()->code(index) : 0;
487}
488
489
490const char* ExternalReferenceEncoder::NameOfAddress(Address key) const {
491 int index = IndexOf(key);
492 return index >=0 ? ExternalReferenceTable::instance()->name(index) : NULL;
493}
494
495
496int ExternalReferenceEncoder::IndexOf(Address key) const {
497 if (key == NULL) return -1;
498 HashMap::Entry* entry =
499 const_cast<HashMap &>(encodings_).Lookup(key, Hash(key), false);
500 return entry == NULL
501 ? -1
502 : static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
503}
504
505
506void ExternalReferenceEncoder::Put(Address key, int index) {
507 HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true);
Steve Block6ded16b2010-05-10 14:33:55 +0100508 entry->value = reinterpret_cast<void*>(index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000509}
510
511
512ExternalReferenceDecoder::ExternalReferenceDecoder()
513 : encodings_(NewArray<Address*>(kTypeCodeCount)) {
514 ExternalReferenceTable* external_references =
515 ExternalReferenceTable::instance();
516 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
517 int max = external_references->max_id(type) + 1;
518 encodings_[type] = NewArray<Address>(max + 1);
519 }
520 for (int i = 0; i < external_references->size(); ++i) {
521 Put(external_references->code(i), external_references->address(i));
522 }
523}
524
525
526ExternalReferenceDecoder::~ExternalReferenceDecoder() {
527 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
528 DeleteArray(encodings_[type]);
529 }
530 DeleteArray(encodings_);
531}
532
533
Steve Blocka7e24c12009-10-30 11:49:00 +0000534bool Serializer::serialization_enabled_ = false;
Steve Blockd0582a62009-12-15 09:54:21 +0000535bool Serializer::too_late_to_enable_now_ = false;
Leon Clarkee46be812010-01-19 14:06:41 +0000536ExternalReferenceDecoder* Deserializer::external_reference_decoder_ = NULL;
Steve Blocka7e24c12009-10-30 11:49:00 +0000537
538
Leon Clarkee46be812010-01-19 14:06:41 +0000539Deserializer::Deserializer(SnapshotByteSource* source) : source_(source) {
Steve Blockd0582a62009-12-15 09:54:21 +0000540}
541
542
543// This routine both allocates a new object, and also keeps
544// track of where objects have been allocated so that we can
545// fix back references when deserializing.
546Address Deserializer::Allocate(int space_index, Space* space, int size) {
547 Address address;
548 if (!SpaceIsLarge(space_index)) {
549 ASSERT(!SpaceIsPaged(space_index) ||
550 size <= Page::kPageSize - Page::kObjectStartOffset);
551 Object* new_allocation;
552 if (space_index == NEW_SPACE) {
553 new_allocation = reinterpret_cast<NewSpace*>(space)->AllocateRaw(size);
554 } else {
555 new_allocation = reinterpret_cast<PagedSpace*>(space)->AllocateRaw(size);
556 }
557 HeapObject* new_object = HeapObject::cast(new_allocation);
558 ASSERT(!new_object->IsFailure());
559 address = new_object->address();
560 high_water_[space_index] = address + size;
561 } else {
562 ASSERT(SpaceIsLarge(space_index));
563 ASSERT(size > Page::kPageSize - Page::kObjectStartOffset);
564 LargeObjectSpace* lo_space = reinterpret_cast<LargeObjectSpace*>(space);
565 Object* new_allocation;
566 if (space_index == kLargeData) {
567 new_allocation = lo_space->AllocateRaw(size);
568 } else if (space_index == kLargeFixedArray) {
569 new_allocation = lo_space->AllocateRawFixedArray(size);
570 } else {
571 ASSERT_EQ(kLargeCode, space_index);
572 new_allocation = lo_space->AllocateRawCode(size);
573 }
574 ASSERT(!new_allocation->IsFailure());
575 HeapObject* new_object = HeapObject::cast(new_allocation);
576 // Record all large objects in the same space.
577 address = new_object->address();
Andrei Popescu31002712010-02-23 13:46:05 +0000578 pages_[LO_SPACE].Add(address);
Steve Blockd0582a62009-12-15 09:54:21 +0000579 }
580 last_object_address_ = address;
581 return address;
582}
583
584
585// This returns the address of an object that has been described in the
586// snapshot as being offset bytes back in a particular space.
587HeapObject* Deserializer::GetAddressFromEnd(int space) {
588 int offset = source_->GetInt();
589 ASSERT(!SpaceIsLarge(space));
590 offset <<= kObjectAlignmentBits;
591 return HeapObject::FromAddress(high_water_[space] - offset);
592}
593
594
595// This returns the address of an object that has been described in the
596// snapshot as being offset bytes into a particular space.
597HeapObject* Deserializer::GetAddressFromStart(int space) {
598 int offset = source_->GetInt();
599 if (SpaceIsLarge(space)) {
600 // Large spaces have one object per 'page'.
601 return HeapObject::FromAddress(pages_[LO_SPACE][offset]);
602 }
603 offset <<= kObjectAlignmentBits;
604 if (space == NEW_SPACE) {
605 // New space has only one space - numbered 0.
606 return HeapObject::FromAddress(pages_[space][0] + offset);
607 }
608 ASSERT(SpaceIsPaged(space));
Leon Clarkee46be812010-01-19 14:06:41 +0000609 int page_of_pointee = offset >> kPageSizeBits;
Steve Blockd0582a62009-12-15 09:54:21 +0000610 Address object_address = pages_[space][page_of_pointee] +
611 (offset & Page::kPageAlignmentMask);
612 return HeapObject::FromAddress(object_address);
613}
614
615
616void Deserializer::Deserialize() {
617 // Don't GC while deserializing - just expand the heap.
618 AlwaysAllocateScope always_allocate;
619 // Don't use the free lists while deserializing.
620 LinearAllocationScope allocate_linearly;
621 // No active threads.
622 ASSERT_EQ(NULL, ThreadState::FirstInUse());
623 // No active handles.
624 ASSERT(HandleScopeImplementer::instance()->blocks()->is_empty());
Leon Clarked91b9f72010-01-27 17:25:45 +0000625 // Make sure the entire partial snapshot cache is traversed, filling it with
626 // valid object pointers.
627 partial_snapshot_cache_length_ = kPartialSnapshotCacheCapacity;
Steve Blockd0582a62009-12-15 09:54:21 +0000628 ASSERT_EQ(NULL, external_reference_decoder_);
629 external_reference_decoder_ = new ExternalReferenceDecoder();
Leon Clarked91b9f72010-01-27 17:25:45 +0000630 Heap::IterateStrongRoots(this, VISIT_ONLY_STRONG);
631 Heap::IterateWeakRoots(this, VISIT_ALL);
Leon Clarkee46be812010-01-19 14:06:41 +0000632}
633
634
635void Deserializer::DeserializePartial(Object** root) {
636 // Don't GC while deserializing - just expand the heap.
637 AlwaysAllocateScope always_allocate;
638 // Don't use the free lists while deserializing.
639 LinearAllocationScope allocate_linearly;
640 if (external_reference_decoder_ == NULL) {
641 external_reference_decoder_ = new ExternalReferenceDecoder();
642 }
643 VisitPointer(root);
644}
645
646
Leon Clarked91b9f72010-01-27 17:25:45 +0000647Deserializer::~Deserializer() {
648 ASSERT(source_->AtEOF());
Leon Clarkee46be812010-01-19 14:06:41 +0000649 if (external_reference_decoder_ != NULL) {
650 delete external_reference_decoder_;
651 external_reference_decoder_ = NULL;
652 }
Steve Blockd0582a62009-12-15 09:54:21 +0000653}
654
655
656// This is called on the roots. It is the driver of the deserialization
657// process. It is also called on the body of each function.
658void Deserializer::VisitPointers(Object** start, Object** end) {
659 // The space must be new space. Any other space would cause ReadChunk to try
660 // to update the remembered using NULL as the address.
661 ReadChunk(start, end, NEW_SPACE, NULL);
662}
663
664
665// This routine writes the new object into the pointer provided and then
666// returns true if the new object was in young space and false otherwise.
667// The reason for this strange interface is that otherwise the object is
668// written very late, which means the ByteArray map is not set up by the
669// time we need to use it to mark the space at the end of a page free (by
670// making it into a byte array).
671void Deserializer::ReadObject(int space_number,
672 Space* space,
673 Object** write_back) {
674 int size = source_->GetInt() << kObjectAlignmentBits;
675 Address address = Allocate(space_number, space, size);
676 *write_back = HeapObject::FromAddress(address);
677 Object** current = reinterpret_cast<Object**>(address);
678 Object** limit = current + (size >> kPointerSizeLog2);
Leon Clarkee46be812010-01-19 14:06:41 +0000679 if (FLAG_log_snapshot_positions) {
680 LOG(SnapshotPositionEvent(address, source_->position()));
681 }
Steve Blockd0582a62009-12-15 09:54:21 +0000682 ReadChunk(current, limit, space_number, address);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100683
684 if (space == Heap::map_space()) {
685 ASSERT(size == Map::kSize);
686 HeapObject* obj = HeapObject::FromAddress(address);
687 Map* map = reinterpret_cast<Map*>(obj);
688 map->set_scavenger(Heap::GetScavenger(map->instance_type(),
689 map->instance_size()));
690 }
Steve Blockd0582a62009-12-15 09:54:21 +0000691}
692
693
Leon Clarkef7060e22010-06-03 12:02:55 +0100694// This macro is always used with a constant argument so it should all fold
695// away to almost nothing in the generated code. It might be nicer to do this
696// with the ternary operator but there are type issues with that.
697#define ASSIGN_DEST_SPACE(space_number) \
698 Space* dest_space; \
699 if (space_number == NEW_SPACE) { \
700 dest_space = Heap::new_space(); \
701 } else if (space_number == OLD_POINTER_SPACE) { \
702 dest_space = Heap::old_pointer_space(); \
703 } else if (space_number == OLD_DATA_SPACE) { \
704 dest_space = Heap::old_data_space(); \
705 } else if (space_number == CODE_SPACE) { \
706 dest_space = Heap::code_space(); \
707 } else if (space_number == MAP_SPACE) { \
708 dest_space = Heap::map_space(); \
709 } else if (space_number == CELL_SPACE) { \
710 dest_space = Heap::cell_space(); \
711 } else { \
712 ASSERT(space_number >= LO_SPACE); \
713 dest_space = Heap::lo_space(); \
714 }
715
716
717static const int kUnknownOffsetFromStart = -1;
Steve Blockd0582a62009-12-15 09:54:21 +0000718
719
720void Deserializer::ReadChunk(Object** current,
721 Object** limit,
Leon Clarkef7060e22010-06-03 12:02:55 +0100722 int source_space,
Steve Blockd0582a62009-12-15 09:54:21 +0000723 Address address) {
724 while (current < limit) {
725 int data = source_->Get();
726 switch (data) {
Leon Clarkef7060e22010-06-03 12:02:55 +0100727#define CASE_STATEMENT(where, how, within, space_number) \
728 case where + how + within + space_number: \
729 ASSERT((where & ~kPointedToMask) == 0); \
730 ASSERT((how & ~kHowToCodeMask) == 0); \
731 ASSERT((within & ~kWhereToPointMask) == 0); \
732 ASSERT((space_number & ~kSpaceMask) == 0);
733
734#define CASE_BODY(where, how, within, space_number_if_any, offset_from_start) \
735 { \
736 bool emit_write_barrier = false; \
737 bool current_was_incremented = false; \
738 int space_number = space_number_if_any == kAnyOldSpace ? \
739 (data & kSpaceMask) : space_number_if_any; \
740 if (where == kNewObject && how == kPlain && within == kStartOfObject) {\
741 ASSIGN_DEST_SPACE(space_number) \
742 ReadObject(space_number, dest_space, current); \
743 emit_write_barrier = \
744 (space_number == NEW_SPACE && source_space != NEW_SPACE); \
745 } else { \
746 Object* new_object = NULL; /* May not be a real Object pointer. */ \
747 if (where == kNewObject) { \
748 ASSIGN_DEST_SPACE(space_number) \
749 ReadObject(space_number, dest_space, &new_object); \
750 } else if (where == kRootArray) { \
751 int root_id = source_->GetInt(); \
752 new_object = Heap::roots_address()[root_id]; \
753 } else if (where == kPartialSnapshotCache) { \
754 int cache_index = source_->GetInt(); \
755 new_object = partial_snapshot_cache_[cache_index]; \
756 } else if (where == kExternalReference) { \
757 int reference_id = source_->GetInt(); \
758 Address address = \
759 external_reference_decoder_->Decode(reference_id); \
760 new_object = reinterpret_cast<Object*>(address); \
761 } else if (where == kBackref) { \
762 emit_write_barrier = \
763 (space_number == NEW_SPACE && source_space != NEW_SPACE); \
764 new_object = GetAddressFromEnd(data & kSpaceMask); \
765 } else { \
766 ASSERT(where == kFromStart); \
767 if (offset_from_start == kUnknownOffsetFromStart) { \
768 emit_write_barrier = \
769 (space_number == NEW_SPACE && source_space != NEW_SPACE); \
770 new_object = GetAddressFromStart(data & kSpaceMask); \
771 } else { \
772 Address object_address = pages_[space_number][0] + \
773 (offset_from_start << kObjectAlignmentBits); \
774 new_object = HeapObject::FromAddress(object_address); \
775 } \
776 } \
777 if (within == kFirstInstruction) { \
778 Code* new_code_object = reinterpret_cast<Code*>(new_object); \
779 new_object = reinterpret_cast<Object*>( \
780 new_code_object->instruction_start()); \
781 } \
782 if (how == kFromCode) { \
783 Address location_of_branch_data = \
784 reinterpret_cast<Address>(current); \
785 Assembler::set_target_at(location_of_branch_data, \
786 reinterpret_cast<Address>(new_object)); \
787 if (within == kFirstInstruction) { \
788 location_of_branch_data += Assembler::kCallTargetSize; \
789 current = reinterpret_cast<Object**>(location_of_branch_data); \
790 current_was_incremented = true; \
791 } \
792 } else { \
793 *current = new_object; \
794 } \
795 } \
796 if (emit_write_barrier) { \
797 Heap::RecordWrite(address, static_cast<int>( \
798 reinterpret_cast<Address>(current) - address)); \
799 } \
800 if (!current_was_incremented) { \
801 current++; /* Increment current if it wasn't done above. */ \
802 } \
803 break; \
804 } \
805
806// This generates a case and a body for each space. The large object spaces are
807// very rare in snapshots so they are grouped in one body.
808#define ONE_PER_SPACE(where, how, within) \
809 CASE_STATEMENT(where, how, within, NEW_SPACE) \
810 CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
811 CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
812 CASE_BODY(where, how, within, OLD_DATA_SPACE, kUnknownOffsetFromStart) \
813 CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
814 CASE_BODY(where, how, within, OLD_POINTER_SPACE, kUnknownOffsetFromStart) \
815 CASE_STATEMENT(where, how, within, CODE_SPACE) \
816 CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \
817 CASE_STATEMENT(where, how, within, CELL_SPACE) \
818 CASE_BODY(where, how, within, CELL_SPACE, kUnknownOffsetFromStart) \
819 CASE_STATEMENT(where, how, within, MAP_SPACE) \
820 CASE_BODY(where, how, within, MAP_SPACE, kUnknownOffsetFromStart) \
821 CASE_STATEMENT(where, how, within, kLargeData) \
822 CASE_STATEMENT(where, how, within, kLargeCode) \
823 CASE_STATEMENT(where, how, within, kLargeFixedArray) \
824 CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
825
826// This generates a case and a body for the new space (which has to do extra
827// write barrier handling) and handles the other spaces with 8 fall-through
828// cases and one body.
829#define ALL_SPACES(where, how, within) \
830 CASE_STATEMENT(where, how, within, NEW_SPACE) \
831 CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
832 CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
833 CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
834 CASE_STATEMENT(where, how, within, CODE_SPACE) \
835 CASE_STATEMENT(where, how, within, CELL_SPACE) \
836 CASE_STATEMENT(where, how, within, MAP_SPACE) \
837 CASE_STATEMENT(where, how, within, kLargeData) \
838 CASE_STATEMENT(where, how, within, kLargeCode) \
839 CASE_STATEMENT(where, how, within, kLargeFixedArray) \
840 CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
841
842#define EMIT_COMMON_REFERENCE_PATTERNS(pseudo_space_number, \
843 space_number, \
844 offset_from_start) \
845 CASE_STATEMENT(kFromStart, kPlain, kStartOfObject, pseudo_space_number) \
846 CASE_BODY(kFromStart, kPlain, kStartOfObject, space_number, offset_from_start)
847
848 // We generate 15 cases and bodies that process special tags that combine
849 // the raw data tag and the length into one byte.
Steve Blockd0582a62009-12-15 09:54:21 +0000850#define RAW_CASE(index, size) \
Leon Clarkef7060e22010-06-03 12:02:55 +0100851 case kRawData + index: { \
Steve Blockd0582a62009-12-15 09:54:21 +0000852 byte* raw_data_out = reinterpret_cast<byte*>(current); \
853 source_->CopyRaw(raw_data_out, size); \
854 current = reinterpret_cast<Object**>(raw_data_out + size); \
855 break; \
856 }
857 COMMON_RAW_LENGTHS(RAW_CASE)
858#undef RAW_CASE
Leon Clarkef7060e22010-06-03 12:02:55 +0100859
860 // Deserialize a chunk of raw data that doesn't have one of the popular
861 // lengths.
862 case kRawData: {
Steve Blockd0582a62009-12-15 09:54:21 +0000863 int size = source_->GetInt();
864 byte* raw_data_out = reinterpret_cast<byte*>(current);
865 source_->CopyRaw(raw_data_out, size);
866 current = reinterpret_cast<Object**>(raw_data_out + size);
867 break;
868 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100869
870 // Deserialize a new object and write a pointer to it to the current
871 // object.
872 ONE_PER_SPACE(kNewObject, kPlain, kStartOfObject)
873 // Deserialize a new code object and write a pointer to its first
874 // instruction to the current code object.
875 ONE_PER_SPACE(kNewObject, kFromCode, kFirstInstruction)
876 // Find a recently deserialized object using its offset from the current
877 // allocation point and write a pointer to it to the current object.
878 ALL_SPACES(kBackref, kPlain, kStartOfObject)
879 // Find a recently deserialized code object using its offset from the
880 // current allocation point and write a pointer to its first instruction
881 // to the current code object.
882 ALL_SPACES(kBackref, kFromCode, kFirstInstruction)
883 // Find an already deserialized object using its offset from the start
884 // and write a pointer to it to the current object.
885 ALL_SPACES(kFromStart, kPlain, kStartOfObject)
886 // Find an already deserialized code object using its offset from the
887 // start and write a pointer to its first instruction to the current code
888 // object.
889 ALL_SPACES(kFromStart, kFromCode, kFirstInstruction)
890 // Find an already deserialized object at one of the predetermined popular
891 // offsets from the start and write a pointer to it in the current object.
892 COMMON_REFERENCE_PATTERNS(EMIT_COMMON_REFERENCE_PATTERNS)
893 // Find an object in the roots array and write a pointer to it to the
894 // current object.
895 CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0)
896 CASE_BODY(kRootArray, kPlain, kStartOfObject, 0, kUnknownOffsetFromStart)
897 // Find an object in the partial snapshots cache and write a pointer to it
898 // to the current object.
899 CASE_STATEMENT(kPartialSnapshotCache, kPlain, kStartOfObject, 0)
900 CASE_BODY(kPartialSnapshotCache,
901 kPlain,
902 kStartOfObject,
903 0,
904 kUnknownOffsetFromStart)
905 // Find an external reference and write a pointer to it to the current
906 // object.
907 CASE_STATEMENT(kExternalReference, kPlain, kStartOfObject, 0)
908 CASE_BODY(kExternalReference,
909 kPlain,
910 kStartOfObject,
911 0,
912 kUnknownOffsetFromStart)
913 // Find an external reference and write a pointer to it in the current
914 // code object.
915 CASE_STATEMENT(kExternalReference, kFromCode, kStartOfObject, 0)
916 CASE_BODY(kExternalReference,
917 kFromCode,
918 kStartOfObject,
919 0,
920 kUnknownOffsetFromStart)
921
922#undef CASE_STATEMENT
923#undef CASE_BODY
924#undef ONE_PER_SPACE
925#undef ALL_SPACES
926#undef EMIT_COMMON_REFERENCE_PATTERNS
927#undef ASSIGN_DEST_SPACE
928
929 case kNewPage: {
Steve Blockd0582a62009-12-15 09:54:21 +0000930 int space = source_->Get();
931 pages_[space].Add(last_object_address_);
Steve Block6ded16b2010-05-10 14:33:55 +0100932 if (space == CODE_SPACE) {
933 CPU::FlushICache(last_object_address_, Page::kPageSize);
934 }
Steve Blockd0582a62009-12-15 09:54:21 +0000935 break;
936 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100937
938 case kNativesStringResource: {
Steve Blockd0582a62009-12-15 09:54:21 +0000939 int index = source_->Get();
940 Vector<const char> source_vector = Natives::GetScriptSource(index);
941 NativesExternalStringResource* resource =
942 new NativesExternalStringResource(source_vector.start());
943 *current++ = reinterpret_cast<Object*>(resource);
944 break;
945 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100946
947 case kSynchronize: {
Leon Clarked91b9f72010-01-27 17:25:45 +0000948 // If we get here then that indicates that you have a mismatch between
949 // the number of GC roots when serializing and deserializing.
950 UNREACHABLE();
951 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100952
Steve Blockd0582a62009-12-15 09:54:21 +0000953 default:
954 UNREACHABLE();
955 }
956 }
957 ASSERT_EQ(current, limit);
958}
959
960
961void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
962 const int max_shift = ((kPointerSize * kBitsPerByte) / 7) * 7;
963 for (int shift = max_shift; shift > 0; shift -= 7) {
964 if (integer >= static_cast<uintptr_t>(1u) << shift) {
Andrei Popescu402d9372010-02-26 13:31:12 +0000965 Put((static_cast<int>((integer >> shift)) & 0x7f) | 0x80, "IntPart");
Steve Blockd0582a62009-12-15 09:54:21 +0000966 }
967 }
Andrei Popescu402d9372010-02-26 13:31:12 +0000968 PutSection(static_cast<int>(integer & 0x7f), "IntLastPart");
Steve Blockd0582a62009-12-15 09:54:21 +0000969}
970
Steve Blocka7e24c12009-10-30 11:49:00 +0000971#ifdef DEBUG
Steve Blockd0582a62009-12-15 09:54:21 +0000972
973void Deserializer::Synchronize(const char* tag) {
974 int data = source_->Get();
975 // If this assert fails then that indicates that you have a mismatch between
976 // the number of GC roots when serializing and deserializing.
Leon Clarkef7060e22010-06-03 12:02:55 +0100977 ASSERT_EQ(kSynchronize, data);
Steve Blockd0582a62009-12-15 09:54:21 +0000978 do {
979 int character = source_->Get();
980 if (character == 0) break;
981 if (FLAG_debug_serialization) {
982 PrintF("%c", character);
983 }
984 } while (true);
985 if (FLAG_debug_serialization) {
986 PrintF("\n");
987 }
988}
989
Steve Blocka7e24c12009-10-30 11:49:00 +0000990
991void Serializer::Synchronize(const char* tag) {
Leon Clarkef7060e22010-06-03 12:02:55 +0100992 sink_->Put(kSynchronize, tag);
Steve Blockd0582a62009-12-15 09:54:21 +0000993 int character;
994 do {
995 character = *tag++;
996 sink_->PutSection(character, "TagCharacter");
997 } while (character != 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000998}
Steve Blockd0582a62009-12-15 09:54:21 +0000999
Steve Blocka7e24c12009-10-30 11:49:00 +00001000#endif
1001
Steve Blockd0582a62009-12-15 09:54:21 +00001002Serializer::Serializer(SnapshotByteSink* sink)
1003 : sink_(sink),
1004 current_root_index_(0),
Andrei Popescu31002712010-02-23 13:46:05 +00001005 external_reference_encoder_(new ExternalReferenceEncoder),
Leon Clarkee46be812010-01-19 14:06:41 +00001006 large_object_total_(0) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001007 for (int i = 0; i <= LAST_SPACE; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +00001008 fullness_[i] = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +00001009 }
1010}
1011
1012
Andrei Popescu31002712010-02-23 13:46:05 +00001013Serializer::~Serializer() {
1014 delete external_reference_encoder_;
1015}
1016
1017
Leon Clarked91b9f72010-01-27 17:25:45 +00001018void StartupSerializer::SerializeStrongReferences() {
Steve Blocka7e24c12009-10-30 11:49:00 +00001019 // No active threads.
1020 CHECK_EQ(NULL, ThreadState::FirstInUse());
1021 // No active or weak handles.
1022 CHECK(HandleScopeImplementer::instance()->blocks()->is_empty());
1023 CHECK_EQ(0, GlobalHandles::NumberOfWeakHandles());
Steve Blockd0582a62009-12-15 09:54:21 +00001024 // We don't support serializing installed extensions.
1025 for (RegisteredExtension* ext = RegisteredExtension::first_extension();
1026 ext != NULL;
1027 ext = ext->next()) {
1028 CHECK_NE(v8::INSTALLED, ext->state());
1029 }
Leon Clarked91b9f72010-01-27 17:25:45 +00001030 Heap::IterateStrongRoots(this, VISIT_ONLY_STRONG);
Steve Blocka7e24c12009-10-30 11:49:00 +00001031}
1032
1033
Leon Clarked91b9f72010-01-27 17:25:45 +00001034void PartialSerializer::Serialize(Object** object) {
Leon Clarkee46be812010-01-19 14:06:41 +00001035 this->VisitPointer(object);
Leon Clarked91b9f72010-01-27 17:25:45 +00001036
1037 // After we have done the partial serialization the partial snapshot cache
1038 // will contain some references needed to decode the partial snapshot. We
1039 // fill it up with undefineds so it has a predictable length so the
1040 // deserialization code doesn't need to know the length.
1041 for (int index = partial_snapshot_cache_length_;
1042 index < kPartialSnapshotCacheCapacity;
1043 index++) {
1044 partial_snapshot_cache_[index] = Heap::undefined_value();
1045 startup_serializer_->VisitPointer(&partial_snapshot_cache_[index]);
1046 }
1047 partial_snapshot_cache_length_ = kPartialSnapshotCacheCapacity;
Leon Clarkee46be812010-01-19 14:06:41 +00001048}
1049
1050
Steve Blocka7e24c12009-10-30 11:49:00 +00001051void Serializer::VisitPointers(Object** start, Object** end) {
Steve Blockd0582a62009-12-15 09:54:21 +00001052 for (Object** current = start; current < end; current++) {
1053 if ((*current)->IsSmi()) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001054 sink_->Put(kRawData, "RawData");
Steve Blockd0582a62009-12-15 09:54:21 +00001055 sink_->PutInt(kPointerSize, "length");
1056 for (int i = 0; i < kPointerSize; i++) {
1057 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
1058 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001059 } else {
Leon Clarkef7060e22010-06-03 12:02:55 +01001060 SerializeObject(*current, kPlain, kStartOfObject);
Steve Blocka7e24c12009-10-30 11:49:00 +00001061 }
1062 }
1063}
1064
1065
Leon Clarked91b9f72010-01-27 17:25:45 +00001066Object* SerializerDeserializer::partial_snapshot_cache_[
1067 kPartialSnapshotCacheCapacity];
1068int SerializerDeserializer::partial_snapshot_cache_length_ = 0;
1069
1070
1071// This ensures that the partial snapshot cache keeps things alive during GC and
1072// tracks their movement. When it is called during serialization of the startup
1073// snapshot the partial snapshot is empty, so nothing happens. When the partial
1074// (context) snapshot is created, this array is populated with the pointers that
1075// the partial snapshot will need. As that happens we emit serialized objects to
1076// the startup snapshot that correspond to the elements of this cache array. On
1077// deserialization we therefore need to visit the cache array. This fills it up
1078// with pointers to deserialized objects.
Steve Block6ded16b2010-05-10 14:33:55 +01001079void SerializerDeserializer::Iterate(ObjectVisitor* visitor) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001080 visitor->VisitPointers(
1081 &partial_snapshot_cache_[0],
1082 &partial_snapshot_cache_[partial_snapshot_cache_length_]);
1083}
1084
1085
1086// When deserializing we need to set the size of the snapshot cache. This means
1087// the root iteration code (above) will iterate over array elements, writing the
1088// references to deserialized objects in them.
1089void SerializerDeserializer::SetSnapshotCacheSize(int size) {
1090 partial_snapshot_cache_length_ = size;
1091}
1092
1093
1094int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
1095 for (int i = 0; i < partial_snapshot_cache_length_; i++) {
1096 Object* entry = partial_snapshot_cache_[i];
1097 if (entry == heap_object) return i;
1098 }
Andrei Popescu31002712010-02-23 13:46:05 +00001099
Leon Clarked91b9f72010-01-27 17:25:45 +00001100 // We didn't find the object in the cache. So we add it to the cache and
1101 // then visit the pointer so that it becomes part of the startup snapshot
1102 // and we can refer to it from the partial snapshot.
1103 int length = partial_snapshot_cache_length_;
1104 CHECK(length < kPartialSnapshotCacheCapacity);
1105 partial_snapshot_cache_[length] = heap_object;
1106 startup_serializer_->VisitPointer(&partial_snapshot_cache_[length]);
1107 // We don't recurse from the startup snapshot generator into the partial
1108 // snapshot generator.
1109 ASSERT(length == partial_snapshot_cache_length_);
1110 return partial_snapshot_cache_length_++;
1111}
1112
1113
1114int PartialSerializer::RootIndex(HeapObject* heap_object) {
Leon Clarkee46be812010-01-19 14:06:41 +00001115 for (int i = 0; i < Heap::kRootListLength; i++) {
1116 Object* root = Heap::roots_address()[i];
1117 if (root == heap_object) return i;
1118 }
1119 return kInvalidRootIndex;
1120}
1121
1122
Leon Clarked91b9f72010-01-27 17:25:45 +00001123// Encode the location of an already deserialized object in order to write its
1124// location into a later object. We can encode the location as an offset from
1125// the start of the deserialized objects or as an offset backwards from the
1126// current allocation pointer.
1127void Serializer::SerializeReferenceToPreviousObject(
1128 int space,
1129 int address,
Leon Clarkef7060e22010-06-03 12:02:55 +01001130 HowToCode how_to_code,
1131 WhereToPoint where_to_point) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001132 int offset = CurrentAllocationAddress(space) - address;
1133 bool from_start = true;
1134 if (SpaceIsPaged(space)) {
1135 // For paged space it is simple to encode back from current allocation if
1136 // the object is on the same page as the current allocation pointer.
1137 if ((CurrentAllocationAddress(space) >> kPageSizeBits) ==
1138 (address >> kPageSizeBits)) {
1139 from_start = false;
1140 address = offset;
1141 }
1142 } else if (space == NEW_SPACE) {
1143 // For new space it is always simple to encode back from current allocation.
1144 if (offset < address) {
1145 from_start = false;
1146 address = offset;
1147 }
1148 }
1149 // If we are actually dealing with real offsets (and not a numbering of
1150 // all objects) then we should shift out the bits that are always 0.
1151 if (!SpaceIsLarge(space)) address >>= kObjectAlignmentBits;
Leon Clarkef7060e22010-06-03 12:02:55 +01001152 if (from_start) {
1153#define COMMON_REFS_CASE(pseudo_space, actual_space, offset) \
1154 if (space == actual_space && address == offset && \
1155 how_to_code == kPlain && where_to_point == kStartOfObject) { \
1156 sink_->Put(kFromStart + how_to_code + where_to_point + \
1157 pseudo_space, "RefSer"); \
1158 } else /* NOLINT */
1159 COMMON_REFERENCE_PATTERNS(COMMON_REFS_CASE)
1160#undef COMMON_REFS_CASE
1161 { /* NOLINT */
1162 sink_->Put(kFromStart + how_to_code + where_to_point + space, "RefSer");
Leon Clarked91b9f72010-01-27 17:25:45 +00001163 sink_->PutInt(address, "address");
1164 }
1165 } else {
Leon Clarkef7060e22010-06-03 12:02:55 +01001166 sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer");
1167 sink_->PutInt(address, "address");
Leon Clarked91b9f72010-01-27 17:25:45 +00001168 }
1169}
1170
1171
1172void StartupSerializer::SerializeObject(
Leon Clarkeeab96aa2010-01-27 16:31:12 +00001173 Object* o,
Leon Clarkef7060e22010-06-03 12:02:55 +01001174 HowToCode how_to_code,
1175 WhereToPoint where_to_point) {
Leon Clarkeeab96aa2010-01-27 16:31:12 +00001176 CHECK(o->IsHeapObject());
1177 HeapObject* heap_object = HeapObject::cast(o);
Leon Clarked91b9f72010-01-27 17:25:45 +00001178
1179 if (address_mapper_.IsMapped(heap_object)) {
Leon Clarkeeab96aa2010-01-27 16:31:12 +00001180 int space = SpaceOfAlreadySerializedObject(heap_object);
Leon Clarked91b9f72010-01-27 17:25:45 +00001181 int address = address_mapper_.MappedTo(heap_object);
1182 SerializeReferenceToPreviousObject(space,
1183 address,
Leon Clarkef7060e22010-06-03 12:02:55 +01001184 how_to_code,
1185 where_to_point);
Leon Clarked91b9f72010-01-27 17:25:45 +00001186 } else {
1187 // Object has not yet been serialized. Serialize it here.
1188 ObjectSerializer object_serializer(this,
1189 heap_object,
1190 sink_,
Leon Clarkef7060e22010-06-03 12:02:55 +01001191 how_to_code,
1192 where_to_point);
Leon Clarked91b9f72010-01-27 17:25:45 +00001193 object_serializer.Serialize();
1194 }
1195}
1196
1197
1198void StartupSerializer::SerializeWeakReferences() {
1199 for (int i = partial_snapshot_cache_length_;
1200 i < kPartialSnapshotCacheCapacity;
1201 i++) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001202 sink_->Put(kRootArray + kPlain + kStartOfObject, "RootSerialization");
Leon Clarked91b9f72010-01-27 17:25:45 +00001203 sink_->PutInt(Heap::kUndefinedValueRootIndex, "root_index");
1204 }
1205 Heap::IterateWeakRoots(this, VISIT_ALL);
1206}
1207
1208
1209void PartialSerializer::SerializeObject(
1210 Object* o,
Leon Clarkef7060e22010-06-03 12:02:55 +01001211 HowToCode how_to_code,
1212 WhereToPoint where_to_point) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001213 CHECK(o->IsHeapObject());
1214 HeapObject* heap_object = HeapObject::cast(o);
1215
1216 int root_index;
1217 if ((root_index = RootIndex(heap_object)) != kInvalidRootIndex) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001218 sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
Leon Clarked91b9f72010-01-27 17:25:45 +00001219 sink_->PutInt(root_index, "root_index");
1220 return;
1221 }
1222
1223 if (ShouldBeInThePartialSnapshotCache(heap_object)) {
1224 int cache_index = PartialSnapshotCacheIndex(heap_object);
Leon Clarkef7060e22010-06-03 12:02:55 +01001225 sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point,
1226 "PartialSnapshotCache");
Leon Clarked91b9f72010-01-27 17:25:45 +00001227 sink_->PutInt(cache_index, "partial_snapshot_cache_index");
1228 return;
1229 }
1230
1231 // Pointers from the partial snapshot to the objects in the startup snapshot
1232 // should go through the root array or through the partial snapshot cache.
1233 // If this is not the case you may have to add something to the root array.
1234 ASSERT(!startup_serializer_->address_mapper()->IsMapped(heap_object));
1235 // All the symbols that the partial snapshot needs should be either in the
1236 // root table or in the partial snapshot cache.
1237 ASSERT(!heap_object->IsSymbol());
1238
1239 if (address_mapper_.IsMapped(heap_object)) {
1240 int space = SpaceOfAlreadySerializedObject(heap_object);
1241 int address = address_mapper_.MappedTo(heap_object);
1242 SerializeReferenceToPreviousObject(space,
1243 address,
Leon Clarkef7060e22010-06-03 12:02:55 +01001244 how_to_code,
1245 where_to_point);
Steve Blockd0582a62009-12-15 09:54:21 +00001246 } else {
1247 // Object has not yet been serialized. Serialize it here.
1248 ObjectSerializer serializer(this,
1249 heap_object,
1250 sink_,
Leon Clarkef7060e22010-06-03 12:02:55 +01001251 how_to_code,
1252 where_to_point);
Steve Blockd0582a62009-12-15 09:54:21 +00001253 serializer.Serialize();
1254 }
1255}
1256
1257
Steve Blockd0582a62009-12-15 09:54:21 +00001258void Serializer::ObjectSerializer::Serialize() {
1259 int space = Serializer::SpaceOfObject(object_);
1260 int size = object_->Size();
1261
Leon Clarkef7060e22010-06-03 12:02:55 +01001262 sink_->Put(kNewObject + reference_representation_ + space,
1263 "ObjectSerialization");
Steve Blockd0582a62009-12-15 09:54:21 +00001264 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words");
1265
Leon Clarkee46be812010-01-19 14:06:41 +00001266 LOG(SnapshotPositionEvent(object_->address(), sink_->Position()));
1267
Steve Blockd0582a62009-12-15 09:54:21 +00001268 // Mark this object as already serialized.
1269 bool start_new_page;
Leon Clarked91b9f72010-01-27 17:25:45 +00001270 int offset = serializer_->Allocate(space, size, &start_new_page);
1271 serializer_->address_mapper()->AddMapping(object_, offset);
Steve Blockd0582a62009-12-15 09:54:21 +00001272 if (start_new_page) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001273 sink_->Put(kNewPage, "NewPage");
Steve Blockd0582a62009-12-15 09:54:21 +00001274 sink_->PutSection(space, "NewPageSpace");
1275 }
1276
1277 // Serialize the map (first word of the object).
Leon Clarkef7060e22010-06-03 12:02:55 +01001278 serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject);
Steve Blockd0582a62009-12-15 09:54:21 +00001279
1280 // Serialize the rest of the object.
1281 CHECK_EQ(0, bytes_processed_so_far_);
1282 bytes_processed_so_far_ = kPointerSize;
1283 object_->IterateBody(object_->map()->instance_type(), size, this);
1284 OutputRawData(object_->address() + size);
1285}
1286
1287
1288void Serializer::ObjectSerializer::VisitPointers(Object** start,
1289 Object** end) {
1290 Object** current = start;
1291 while (current < end) {
1292 while (current < end && (*current)->IsSmi()) current++;
1293 if (current < end) OutputRawData(reinterpret_cast<Address>(current));
1294
1295 while (current < end && !(*current)->IsSmi()) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001296 serializer_->SerializeObject(*current, kPlain, kStartOfObject);
Steve Blockd0582a62009-12-15 09:54:21 +00001297 bytes_processed_so_far_ += kPointerSize;
1298 current++;
1299 }
1300 }
1301}
1302
1303
1304void Serializer::ObjectSerializer::VisitExternalReferences(Address* start,
1305 Address* end) {
1306 Address references_start = reinterpret_cast<Address>(start);
1307 OutputRawData(references_start);
1308
1309 for (Address* current = start; current < end; current++) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001310 sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
Steve Blockd0582a62009-12-15 09:54:21 +00001311 int reference_id = serializer_->EncodeExternalReference(*current);
1312 sink_->PutInt(reference_id, "reference id");
1313 }
1314 bytes_processed_so_far_ += static_cast<int>((end - start) * kPointerSize);
1315}
1316
1317
1318void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
1319 Address target_start = rinfo->target_address_address();
1320 OutputRawData(target_start);
1321 Address target = rinfo->target_address();
1322 uint32_t encoding = serializer_->EncodeExternalReference(target);
1323 CHECK(target == NULL ? encoding == 0 : encoding != 0);
Leon Clarkef7060e22010-06-03 12:02:55 +01001324 int representation;
1325 // Can't use a ternary operator because of gcc.
1326 if (rinfo->IsCodedSpecially()) {
1327 representation = kStartOfObject + kFromCode;
1328 } else {
1329 representation = kStartOfObject + kPlain;
1330 }
1331 sink_->Put(kExternalReference + representation, "ExternalReference");
Steve Blockd0582a62009-12-15 09:54:21 +00001332 sink_->PutInt(encoding, "reference id");
Leon Clarkef7060e22010-06-03 12:02:55 +01001333 bytes_processed_so_far_ += rinfo->target_address_size();
Steve Blockd0582a62009-12-15 09:54:21 +00001334}
1335
1336
1337void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) {
1338 CHECK(RelocInfo::IsCodeTarget(rinfo->rmode()));
1339 Address target_start = rinfo->target_address_address();
1340 OutputRawData(target_start);
1341 Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
Leon Clarkef7060e22010-06-03 12:02:55 +01001342 serializer_->SerializeObject(target, kFromCode, kFirstInstruction);
1343 bytes_processed_so_far_ += rinfo->target_address_size();
Steve Blockd0582a62009-12-15 09:54:21 +00001344}
1345
1346
1347void Serializer::ObjectSerializer::VisitExternalAsciiString(
1348 v8::String::ExternalAsciiStringResource** resource_pointer) {
1349 Address references_start = reinterpret_cast<Address>(resource_pointer);
1350 OutputRawData(references_start);
1351 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
1352 Object* source = Heap::natives_source_cache()->get(i);
1353 if (!source->IsUndefined()) {
1354 ExternalAsciiString* string = ExternalAsciiString::cast(source);
1355 typedef v8::String::ExternalAsciiStringResource Resource;
1356 Resource* resource = string->resource();
1357 if (resource == *resource_pointer) {
Leon Clarkef7060e22010-06-03 12:02:55 +01001358 sink_->Put(kNativesStringResource, "NativesStringResource");
Steve Blockd0582a62009-12-15 09:54:21 +00001359 sink_->PutSection(i, "NativesStringResourceEnd");
1360 bytes_processed_so_far_ += sizeof(resource);
1361 return;
1362 }
1363 }
1364 }
1365 // One of the strings in the natives cache should match the resource. We
1366 // can't serialize any other kinds of external strings.
1367 UNREACHABLE();
1368}
1369
1370
1371void Serializer::ObjectSerializer::OutputRawData(Address up_to) {
1372 Address object_start = object_->address();
1373 int up_to_offset = static_cast<int>(up_to - object_start);
1374 int skipped = up_to_offset - bytes_processed_so_far_;
1375 // This assert will fail if the reloc info gives us the target_address_address
1376 // locations in a non-ascending order. Luckily that doesn't happen.
1377 ASSERT(skipped >= 0);
1378 if (skipped != 0) {
1379 Address base = object_start + bytes_processed_so_far_;
1380#define RAW_CASE(index, length) \
1381 if (skipped == length) { \
Leon Clarkef7060e22010-06-03 12:02:55 +01001382 sink_->PutSection(kRawData + index, "RawDataFixed"); \
Steve Blockd0582a62009-12-15 09:54:21 +00001383 } else /* NOLINT */
1384 COMMON_RAW_LENGTHS(RAW_CASE)
1385#undef RAW_CASE
1386 { /* NOLINT */
Leon Clarkef7060e22010-06-03 12:02:55 +01001387 sink_->Put(kRawData, "RawData");
Steve Blockd0582a62009-12-15 09:54:21 +00001388 sink_->PutInt(skipped, "length");
1389 }
1390 for (int i = 0; i < skipped; i++) {
1391 unsigned int data = base[i];
1392 sink_->PutSection(data, "Byte");
1393 }
1394 bytes_processed_so_far_ += skipped;
1395 }
1396}
1397
1398
1399int Serializer::SpaceOfObject(HeapObject* object) {
1400 for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
1401 AllocationSpace s = static_cast<AllocationSpace>(i);
1402 if (Heap::InSpace(object, s)) {
1403 if (i == LO_SPACE) {
1404 if (object->IsCode()) {
1405 return kLargeCode;
1406 } else if (object->IsFixedArray()) {
1407 return kLargeFixedArray;
1408 } else {
1409 return kLargeData;
1410 }
1411 }
1412 return i;
1413 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001414 }
1415 UNREACHABLE();
Steve Blockd0582a62009-12-15 09:54:21 +00001416 return 0;
1417}
1418
1419
1420int Serializer::SpaceOfAlreadySerializedObject(HeapObject* object) {
1421 for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
1422 AllocationSpace s = static_cast<AllocationSpace>(i);
1423 if (Heap::InSpace(object, s)) {
1424 return i;
1425 }
1426 }
1427 UNREACHABLE();
1428 return 0;
1429}
1430
1431
1432int Serializer::Allocate(int space, int size, bool* new_page) {
1433 CHECK(space >= 0 && space < kNumberOfSpaces);
1434 if (SpaceIsLarge(space)) {
1435 // In large object space we merely number the objects instead of trying to
1436 // determine some sort of address.
1437 *new_page = true;
Leon Clarkee46be812010-01-19 14:06:41 +00001438 large_object_total_ += size;
Steve Blockd0582a62009-12-15 09:54:21 +00001439 return fullness_[LO_SPACE]++;
1440 }
1441 *new_page = false;
1442 if (fullness_[space] == 0) {
1443 *new_page = true;
1444 }
1445 if (SpaceIsPaged(space)) {
1446 // Paged spaces are a little special. We encode their addresses as if the
1447 // pages were all contiguous and each page were filled up in the range
1448 // 0 - Page::kObjectAreaSize. In practice the pages may not be contiguous
1449 // and allocation does not start at offset 0 in the page, but this scheme
1450 // means the deserializer can get the page number quickly by shifting the
1451 // serialized address.
1452 CHECK(IsPowerOf2(Page::kPageSize));
1453 int used_in_this_page = (fullness_[space] & (Page::kPageSize - 1));
1454 CHECK(size <= Page::kObjectAreaSize);
1455 if (used_in_this_page + size > Page::kObjectAreaSize) {
1456 *new_page = true;
1457 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize);
1458 }
1459 }
1460 int allocation_address = fullness_[space];
1461 fullness_[space] = allocation_address + size;
1462 return allocation_address;
Steve Blocka7e24c12009-10-30 11:49:00 +00001463}
1464
1465
1466} } // namespace v8::internal