| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Consider sorting them according to type as well? | 44 // Consider sorting them according to type as well? |
| 45 return x - y; | 45 return x - y; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 template<class Allocator> | 49 template<class Allocator> |
| 50 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) | 50 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) |
| 51 : function_name_(FACTORY->empty_symbol()), | 51 : function_name_(FACTORY->empty_symbol()), |
| 52 calls_eval_(scope->calls_eval()), | 52 calls_eval_(scope->calls_eval()), |
| 53 is_strict_mode_(scope->is_strict_mode()), | 53 is_strict_mode_(scope->is_strict_mode()), |
| 54 type_(scope->type()), | |
| 55 parameters_(scope->num_parameters()), | 54 parameters_(scope->num_parameters()), |
| 56 stack_slots_(scope->num_stack_slots()), | 55 stack_slots_(scope->num_stack_slots()), |
| 57 context_slots_(scope->num_heap_slots()), | 56 context_slots_(scope->num_heap_slots()), |
| 58 context_modes_(scope->num_heap_slots()) { | 57 context_modes_(scope->num_heap_slots()) { |
| 59 // Add parameters. | 58 // Add parameters. |
| 60 for (int i = 0; i < scope->num_parameters(); i++) { | 59 for (int i = 0; i < scope->num_parameters(); i++) { |
| 61 ASSERT(parameters_.length() == i); | 60 ASSERT(parameters_.length() == i); |
| 62 parameters_.Add(scope->parameter(i)->name()); | 61 parameters_.Add(scope->parameter(i)->name()); |
| 63 } | 62 } |
| 64 | 63 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 143 } |
| 145 } | 144 } |
| 146 | 145 |
| 147 | 146 |
| 148 // Encoding format in a FixedArray object: | 147 // Encoding format in a FixedArray object: |
| 149 // | 148 // |
| 150 // - function name | 149 // - function name |
| 151 // | 150 // |
| 152 // - calls eval boolean flag | 151 // - calls eval boolean flag |
| 153 // | 152 // |
| 154 // - is strict mode scope | |
| 155 // | |
| 156 // - scope type | |
| 157 // | |
| 158 // - number of variables in the context object (smi) (= function context | 153 // - number of variables in the context object (smi) (= function context |
| 159 // slot index + 1) | 154 // slot index + 1) |
| 160 // - list of pairs (name, Var mode) of context-allocated variables (starting | 155 // - list of pairs (name, Var mode) of context-allocated variables (starting |
| 161 // with context slot 0) | 156 // with context slot 0) |
| 162 // | 157 // |
| 163 // - number of parameters (smi) | 158 // - number of parameters (smi) |
| 164 // - list of parameter names (starting with parameter 0 first) | 159 // - list of parameter names (starting with parameter 0 first) |
| 165 // | 160 // |
| 166 // - number of variables on the stack (smi) | 161 // - number of variables on the stack (smi) |
| 167 // - list of names of stack-allocated variables (starting with stack slot 0) | 162 // - list of names of stack-allocated variables (starting with stack slot 0) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 // subsequent list | 174 // subsequent list |
| 180 // - the list entries don't have to be in any particular order, so all the | 175 // - the list entries don't have to be in any particular order, so all the |
| 181 // current sorting business can go away | 176 // current sorting business can go away |
| 182 // - the ScopeInfo lookup routines can be reduced to perhaps a single lookup | 177 // - the ScopeInfo lookup routines can be reduced to perhaps a single lookup |
| 183 // which returns all information at once | 178 // which returns all information at once |
| 184 // - when gathering the information from a Scope, we only need to iterate | 179 // - when gathering the information from a Scope, we only need to iterate |
| 185 // through the local variables (parameters and context info is already | 180 // through the local variables (parameters and context info is already |
| 186 // present) | 181 // present) |
| 187 | 182 |
| 188 | 183 |
| 189 template <class T> | 184 static inline Object** ReadInt(Object** p, int* x) { |
| 190 static inline Object** ReadInt(Object** p, T* x) { | 185 *x = (reinterpret_cast<Smi*>(*p++))->value(); |
| 191 *x = static_cast<T>((reinterpret_cast<Smi*>(*p++))->value()); | |
| 192 return p; | 186 return p; |
| 193 } | 187 } |
| 194 | 188 |
| 195 | 189 |
| 196 static inline Object** ReadBool(Object** p, bool* x) { | 190 static inline Object** ReadBool(Object** p, bool* x) { |
| 197 *x = (reinterpret_cast<Smi*>(*p++))->value() != 0; | 191 *x = (reinterpret_cast<Smi*>(*p++))->value() != 0; |
| 198 return p; | 192 return p; |
| 199 } | 193 } |
| 200 | 194 |
| 201 | 195 |
| 202 template <class T> | 196 static inline Object** ReadSymbol(Object** p, Handle<String>* s) { |
| 203 static inline Object** ReadObject(Object** p, Handle<T>* s) { | 197 *s = Handle<String>(reinterpret_cast<String*>(*p++)); |
| 204 *s = Handle<T>::cast(Handle<Object>(*p++)); | |
| 205 return p; | 198 return p; |
| 206 } | 199 } |
| 207 | 200 |
| 208 | 201 |
| 209 template <class Allocator, class T> | 202 template <class Allocator> |
| 210 static Object** ReadList(Object** p, List<Handle<T>, Allocator >* list) { | 203 static Object** ReadList(Object** p, List<Handle<String>, Allocator >* list) { |
| 211 ASSERT(list->is_empty()); | 204 ASSERT(list->is_empty()); |
| 212 int n; | 205 int n; |
| 213 p = ReadInt(p, &n); | 206 p = ReadInt(p, &n); |
| 214 while (n-- > 0) { | 207 while (n-- > 0) { |
| 215 Handle<T> s; | 208 Handle<String> s; |
| 216 p = ReadObject(p, &s); | 209 p = ReadSymbol(p, &s); |
| 217 list->Add(s); | 210 list->Add(s); |
| 218 } | 211 } |
| 219 return p; | 212 return p; |
| 220 } | 213 } |
| 221 | 214 |
| 222 | 215 |
| 223 template <class Allocator> | 216 template <class Allocator> |
| 224 static Object** ReadList(Object** p, | 217 static Object** ReadList(Object** p, |
| 225 List<Handle<String>, Allocator>* list, | 218 List<Handle<String>, Allocator>* list, |
| 226 List<VariableMode, Allocator>* modes) { | 219 List<VariableMode, Allocator>* modes) { |
| 227 ASSERT(list->is_empty()); | 220 ASSERT(list->is_empty()); |
| 228 int n; | 221 int n; |
| 229 p = ReadInt(p, &n); | 222 p = ReadInt(p, &n); |
| 230 while (n-- > 0) { | 223 while (n-- > 0) { |
| 231 Handle<String> s; | 224 Handle<String> s; |
| 232 int m; | 225 int m; |
| 233 p = ReadObject(p, &s); | 226 p = ReadSymbol(p, &s); |
| 234 p = ReadInt(p, &m); | 227 p = ReadInt(p, &m); |
| 235 list->Add(s); | 228 list->Add(s); |
| 236 modes->Add(static_cast<VariableMode>(m)); | 229 modes->Add(static_cast<VariableMode>(m)); |
| 237 } | 230 } |
| 238 return p; | 231 return p; |
| 239 } | 232 } |
| 240 | 233 |
| 241 | 234 |
| 242 template<class Allocator> | 235 template<class Allocator> |
| 243 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) | 236 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) |
| 244 : function_name_(FACTORY->empty_symbol()), | 237 : function_name_(FACTORY->empty_symbol()), |
| 245 parameters_(4), | 238 parameters_(4), |
| 246 stack_slots_(8), | 239 stack_slots_(8), |
| 247 context_slots_(8), | 240 context_slots_(8), |
| 248 context_modes_(8) { | 241 context_modes_(8) { |
| 249 if (data->length() > 0) { | 242 if (data->length() > 0) { |
| 250 Object** p0 = data->data_start(); | 243 Object** p0 = data->data_start(); |
| 251 Object** p = p0; | 244 Object** p = p0; |
| 252 p = ReadObject(p, &function_name_); | 245 p = ReadSymbol(p, &function_name_); |
| 253 p = ReadBool(p, &calls_eval_); | 246 p = ReadBool(p, &calls_eval_); |
| 254 p = ReadBool(p, &is_strict_mode_); | 247 p = ReadBool(p, &is_strict_mode_); |
| 255 p = ReadInt(p, &type_); | |
| 256 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 248 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
| 257 p = ReadList<Allocator>(p, ¶meters_); | 249 p = ReadList<Allocator>(p, ¶meters_); |
| 258 p = ReadList<Allocator>(p, &stack_slots_); | 250 p = ReadList<Allocator>(p, &stack_slots_); |
| 259 ASSERT((p - p0) == FixedArray::cast(data)->length()); | 251 ASSERT((p - p0) == FixedArray::cast(data)->length()); |
| 260 } | 252 } |
| 261 } | 253 } |
| 262 | 254 |
| 263 | 255 |
| 264 static inline Object** WriteInt(Object** p, int x) { | 256 static inline Object** WriteInt(Object** p, int x) { |
| 265 *p++ = Smi::FromInt(x); | 257 *p++ = Smi::FromInt(x); |
| 266 return p; | 258 return p; |
| 267 } | 259 } |
| 268 | 260 |
| 269 | 261 |
| 270 static inline Object** WriteBool(Object** p, bool b) { | 262 static inline Object** WriteBool(Object** p, bool b) { |
| 271 *p++ = Smi::FromInt(b ? 1 : 0); | 263 *p++ = Smi::FromInt(b ? 1 : 0); |
| 272 return p; | 264 return p; |
| 273 } | 265 } |
| 274 | 266 |
| 275 | 267 |
| 276 template <class T> | 268 static inline Object** WriteSymbol(Object** p, Handle<String> s) { |
| 277 static inline Object** WriteObject(Object** p, Handle<T> s) { | |
| 278 *p++ = *s; | 269 *p++ = *s; |
| 279 return p; | 270 return p; |
| 280 } | 271 } |
| 281 | 272 |
| 282 | 273 |
| 283 template <class Allocator, class T> | 274 template <class Allocator> |
| 284 static Object** WriteList(Object** p, List<Handle<T>, Allocator >* list) { | 275 static Object** WriteList(Object** p, List<Handle<String>, Allocator >* list) { |
| 285 const int n = list->length(); | 276 const int n = list->length(); |
| 286 p = WriteInt(p, n); | 277 p = WriteInt(p, n); |
| 287 for (int i = 0; i < n; i++) { | 278 for (int i = 0; i < n; i++) { |
| 288 p = WriteObject(p, list->at(i)); | 279 p = WriteSymbol(p, list->at(i)); |
| 289 } | 280 } |
| 290 return p; | 281 return p; |
| 291 } | 282 } |
| 292 | 283 |
| 293 | 284 |
| 294 template <class Allocator> | 285 template <class Allocator> |
| 295 static Object** WriteList(Object** p, | 286 static Object** WriteList(Object** p, |
| 296 List<Handle<String>, Allocator>* list, | 287 List<Handle<String>, Allocator>* list, |
| 297 List<VariableMode, Allocator>* modes) { | 288 List<VariableMode, Allocator>* modes) { |
| 298 const int n = list->length(); | 289 const int n = list->length(); |
| 299 p = WriteInt(p, n); | 290 p = WriteInt(p, n); |
| 300 for (int i = 0; i < n; i++) { | 291 for (int i = 0; i < n; i++) { |
| 301 p = WriteObject(p, list->at(i)); | 292 p = WriteSymbol(p, list->at(i)); |
| 302 p = WriteInt(p, modes->at(i)); | 293 p = WriteInt(p, modes->at(i)); |
| 303 } | 294 } |
| 304 return p; | 295 return p; |
| 305 } | 296 } |
| 306 | 297 |
| 307 | 298 |
| 308 template<class Allocator> | 299 template<class Allocator> |
| 309 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { | 300 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { |
| 310 // function name, calls eval, is_strict_mode, scope type, | 301 // function name, calls eval, is_strict_mode, length for 3 tables: |
| 311 // length for 3 tables: | 302 const int extra_slots = 1 + 1 + 1 + 3; |
| 312 const int extra_slots = 1 + 1 + 1 + 1 + 3; | |
| 313 int length = extra_slots + | 303 int length = extra_slots + |
| 314 context_slots_.length() * 2 + | 304 context_slots_.length() * 2 + |
| 315 parameters_.length() + | 305 parameters_.length() + |
| 316 stack_slots_.length(); | 306 stack_slots_.length(); |
| 317 | 307 |
| 318 Handle<SerializedScopeInfo> data( | 308 Handle<SerializedScopeInfo> data( |
| 319 SerializedScopeInfo::cast(*FACTORY->NewSerializedScopeInfo(length))); | 309 SerializedScopeInfo::cast(*FACTORY->NewSerializedScopeInfo(length))); |
| 320 AssertNoAllocation nogc; | 310 AssertNoAllocation nogc; |
| 321 | 311 |
| 322 Object** p0 = data->data_start(); | 312 Object** p0 = data->data_start(); |
| 323 Object** p = p0; | 313 Object** p = p0; |
| 324 p = WriteObject(p, function_name_); | 314 p = WriteSymbol(p, function_name_); |
| 325 p = WriteBool(p, calls_eval_); | 315 p = WriteBool(p, calls_eval_); |
| 326 p = WriteBool(p, is_strict_mode_); | 316 p = WriteBool(p, is_strict_mode_); |
| 327 p = WriteInt(p, type_); | |
| 328 p = WriteList(p, &context_slots_, &context_modes_); | 317 p = WriteList(p, &context_slots_, &context_modes_); |
| 329 p = WriteList(p, ¶meters_); | 318 p = WriteList(p, ¶meters_); |
| 330 p = WriteList(p, &stack_slots_); | 319 p = WriteList(p, &stack_slots_); |
| 331 ASSERT((p - p0) == length); | 320 ASSERT((p - p0) == length); |
| 332 | 321 |
| 333 return data; | 322 return data; |
| 334 } | 323 } |
| 335 | 324 |
| 336 | 325 |
| 337 template<class Allocator> | 326 template<class Allocator> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 365 } | 354 } |
| 366 | 355 |
| 367 | 356 |
| 368 SerializedScopeInfo* SerializedScopeInfo::Empty() { | 357 SerializedScopeInfo* SerializedScopeInfo::Empty() { |
| 369 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); | 358 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); |
| 370 } | 359 } |
| 371 | 360 |
| 372 | 361 |
| 373 Object** SerializedScopeInfo::ContextEntriesAddr() { | 362 Object** SerializedScopeInfo::ContextEntriesAddr() { |
| 374 ASSERT(length() > 0); | 363 ASSERT(length() > 0); |
| 375 // +4 for function name, calls eval, strict mode, scope type. | 364 // +3 for function name, calls eval, strict mode. |
| 376 return data_start() + 4; | 365 return data_start() + 3; |
| 377 } | 366 } |
| 378 | 367 |
| 379 | 368 |
| 380 Object** SerializedScopeInfo::ParameterEntriesAddr() { | 369 Object** SerializedScopeInfo::ParameterEntriesAddr() { |
| 381 ASSERT(length() > 0); | 370 ASSERT(length() > 0); |
| 382 Object** p = ContextEntriesAddr(); | 371 Object** p = ContextEntriesAddr(); |
| 383 int number_of_context_slots; | 372 int number_of_context_slots; |
| 384 p = ReadInt(p, &number_of_context_slots); | 373 p = ReadInt(p, &number_of_context_slots); |
| 385 return p + number_of_context_slots*2; // *2 for pairs | 374 return p + number_of_context_slots*2; // *2 for pairs |
| 386 } | 375 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 410 if (length() > 0) { | 399 if (length() > 0) { |
| 411 Object** p = data_start() + 2; // +2 for function name, calls eval. | 400 Object** p = data_start() + 2; // +2 for function name, calls eval. |
| 412 bool strict_mode; | 401 bool strict_mode; |
| 413 p = ReadBool(p, &strict_mode); | 402 p = ReadBool(p, &strict_mode); |
| 414 return strict_mode; | 403 return strict_mode; |
| 415 } | 404 } |
| 416 return false; | 405 return false; |
| 417 } | 406 } |
| 418 | 407 |
| 419 | 408 |
| 420 ScopeType SerializedScopeInfo::Type() { | |
| 421 ASSERT(length() > 0); | |
| 422 // +3 for function name, calls eval, strict mode. | |
| 423 Object** p = data_start() + 3; | |
| 424 ScopeType type; | |
| 425 p = ReadInt(p, &type); | |
| 426 return type; | |
| 427 } | |
| 428 | |
| 429 | |
| 430 int SerializedScopeInfo::NumberOfStackSlots() { | 409 int SerializedScopeInfo::NumberOfStackSlots() { |
| 431 if (length() > 0) { | 410 if (length() > 0) { |
| 432 Object** p = StackSlotEntriesAddr(); | 411 Object** p = StackSlotEntriesAddr(); |
| 433 int number_of_stack_slots; | 412 int number_of_stack_slots; |
| 434 ReadInt(p, &number_of_stack_slots); | 413 ReadInt(p, &number_of_stack_slots); |
| 435 return number_of_stack_slots; | 414 return number_of_stack_slots; |
| 436 } | 415 } |
| 437 return 0; | 416 return 0; |
| 438 } | 417 } |
| 439 | 418 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 453 if (length() > 0) { | 432 if (length() > 0) { |
| 454 Object** p = ContextEntriesAddr(); | 433 Object** p = ContextEntriesAddr(); |
| 455 int number_of_context_slots; | 434 int number_of_context_slots; |
| 456 ReadInt(p, &number_of_context_slots); | 435 ReadInt(p, &number_of_context_slots); |
| 457 return number_of_context_slots > 0; | 436 return number_of_context_slots > 0; |
| 458 } | 437 } |
| 459 return false; | 438 return false; |
| 460 } | 439 } |
| 461 | 440 |
| 462 | 441 |
| 463 bool SerializedScopeInfo::HasContext() { | |
| 464 return HasHeapAllocatedLocals() || | |
| 465 Type() == WITH_SCOPE; | |
| 466 } | |
| 467 | |
| 468 | |
| 469 int SerializedScopeInfo::StackSlotIndex(String* name) { | 442 int SerializedScopeInfo::StackSlotIndex(String* name) { |
| 470 ASSERT(name->IsSymbol()); | 443 ASSERT(name->IsSymbol()); |
| 471 if (length() > 0) { | 444 if (length() > 0) { |
| 472 // Slots start after length entry. | 445 // Slots start after length entry. |
| 473 Object** p0 = StackSlotEntriesAddr(); | 446 Object** p0 = StackSlotEntriesAddr(); |
| 474 int number_of_stack_slots; | 447 int number_of_stack_slots; |
| 475 p0 = ReadInt(p0, &number_of_stack_slots); | 448 p0 = ReadInt(p0, &number_of_stack_slots); |
| 476 Object** p = p0; | 449 Object** p = p0; |
| 477 Object** end = p0 + number_of_stack_slots; | 450 Object** end = p0 + number_of_stack_slots; |
| 478 while (p != end) { | 451 while (p != end) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 632 } |
| 660 #endif // DEBUG | 633 #endif // DEBUG |
| 661 | 634 |
| 662 | 635 |
| 663 // Make sure the classes get instantiated by the template system. | 636 // Make sure the classes get instantiated by the template system. |
| 664 template class ScopeInfo<FreeStoreAllocationPolicy>; | 637 template class ScopeInfo<FreeStoreAllocationPolicy>; |
| 665 template class ScopeInfo<PreallocatedStorage>; | 638 template class ScopeInfo<PreallocatedStorage>; |
| 666 template class ScopeInfo<ZoneListAllocationPolicy>; | 639 template class ScopeInfo<ZoneListAllocationPolicy>; |
| 667 | 640 |
| 668 } } // namespace v8::internal | 641 } } // namespace v8::internal |
| OLD | NEW |