| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return p; | 197 return p; |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 static inline Object** ReadSymbol(Object** p, Handle<String>* s) { | 201 static inline Object** ReadSymbol(Object** p, Handle<String>* s) { |
| 202 *s = Handle<String>(reinterpret_cast<String*>(*p++)); | 202 *s = Handle<String>(reinterpret_cast<String*>(*p++)); |
| 203 return p; | 203 return p; |
| 204 } | 204 } |
| 205 | 205 |
| 206 | 206 |
| 207 static inline Object** ReadSentinel(Object** p) { | |
| 208 ASSERT(*p == NULL); | |
| 209 return p + 1; | |
| 210 } | |
| 211 | |
| 212 | |
| 213 template <class Allocator> | 207 template <class Allocator> |
| 214 static Object** ReadList(Object** p, List<Handle<String>, Allocator >* list) { | 208 static Object** ReadList(Object** p, List<Handle<String>, Allocator >* list) { |
| 215 ASSERT(list->is_empty()); | 209 ASSERT(list->is_empty()); |
| 216 int n; | 210 int n; |
| 217 p = ReadInt(p, &n); | 211 p = ReadInt(p, &n); |
| 218 while (n-- > 0) { | 212 while (n-- > 0) { |
| 219 Handle<String> s; | 213 Handle<String> s; |
| 220 p = ReadSymbol(p, &s); | 214 p = ReadSymbol(p, &s); |
| 221 list->Add(s); | 215 list->Add(s); |
| 222 } | 216 } |
| 223 return ReadSentinel(p); | 217 return p; |
| 224 } | 218 } |
| 225 | 219 |
| 226 | 220 |
| 227 template <class Allocator> | 221 template <class Allocator> |
| 228 static Object** ReadList(Object** p, | 222 static Object** ReadList(Object** p, |
| 229 List<Handle<String>, Allocator>* list, | 223 List<Handle<String>, Allocator>* list, |
| 230 List<Variable::Mode, Allocator>* modes) { | 224 List<Variable::Mode, Allocator>* modes) { |
| 231 ASSERT(list->is_empty()); | 225 ASSERT(list->is_empty()); |
| 232 int n; | 226 int n; |
| 233 p = ReadInt(p, &n); | 227 p = ReadInt(p, &n); |
| 234 while (n-- > 0) { | 228 while (n-- > 0) { |
| 235 Handle<String> s; | 229 Handle<String> s; |
| 236 int m; | 230 int m; |
| 237 p = ReadSymbol(p, &s); | 231 p = ReadSymbol(p, &s); |
| 238 p = ReadInt(p, &m); | 232 p = ReadInt(p, &m); |
| 239 list->Add(s); | 233 list->Add(s); |
| 240 modes->Add(static_cast<Variable::Mode>(m)); | 234 modes->Add(static_cast<Variable::Mode>(m)); |
| 241 } | 235 } |
| 242 return ReadSentinel(p); | 236 return p; |
| 243 } | 237 } |
| 244 | 238 |
| 245 | 239 |
| 246 template<class Allocator> | 240 template<class Allocator> |
| 247 Handle<Object> ScopeInfo<Allocator>::CreateHeapObject(Scope* scope) { | 241 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) |
| 248 ScopeInfo<ZoneListAllocationPolicy> sinfo(scope); | |
| 249 return sinfo.Serialize(); | |
| 250 } | |
| 251 | |
| 252 | |
| 253 template<class Allocator> | |
| 254 Object* ScopeInfo<Allocator>::EmptyHeapObject() { | |
| 255 return Heap::empty_fixed_array(); | |
| 256 } | |
| 257 | |
| 258 | |
| 259 inline bool IsNotEmpty(Object* data) { | |
| 260 return FixedArray::cast(data)->length() != 0; | |
| 261 } | |
| 262 | |
| 263 | |
| 264 inline Object** GetDataStart(Object* data) { | |
| 265 return FixedArray::cast(data)->data_start(); | |
| 266 } | |
| 267 | |
| 268 | |
| 269 template<class Allocator> | |
| 270 ScopeInfo<Allocator>::ScopeInfo(Object* data) | |
| 271 : function_name_(Factory::empty_symbol()), | 242 : function_name_(Factory::empty_symbol()), |
| 272 parameters_(4), | 243 parameters_(4), |
| 273 stack_slots_(8), | 244 stack_slots_(8), |
| 274 context_slots_(8), | 245 context_slots_(8), |
| 275 context_modes_(8) { | 246 context_modes_(8) { |
| 276 if (IsNotEmpty(data)) { | 247 if (data->length() > 0) { |
| 277 Object** p0 = GetDataStart(data); | 248 Object** p0 = data->data_start(); |
| 278 Object** p = p0; | 249 Object** p = p0; |
| 279 p = ReadSymbol(p, &function_name_); | 250 p = ReadSymbol(p, &function_name_); |
| 280 p = ReadBool(p, &calls_eval_); | 251 p = ReadBool(p, &calls_eval_); |
| 281 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 252 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
| 282 p = ReadList<Allocator>(p, ¶meters_); | 253 p = ReadList<Allocator>(p, ¶meters_); |
| 283 p = ReadList<Allocator>(p, &stack_slots_); | 254 p = ReadList<Allocator>(p, &stack_slots_); |
| 284 ASSERT((p - p0) == FixedArray::cast(data)->length()); | 255 ASSERT((p - p0) == FixedArray::cast(data)->length()); |
| 285 } | 256 } |
| 286 } | 257 } |
| 287 | 258 |
| 288 | 259 |
| 289 static inline Object** WriteInt(Object** p, int x) { | 260 static inline Object** WriteInt(Object** p, int x) { |
| 290 *p++ = Smi::FromInt(x); | 261 *p++ = Smi::FromInt(x); |
| 291 return p; | 262 return p; |
| 292 } | 263 } |
| 293 | 264 |
| 294 | 265 |
| 295 static inline Object** WriteBool(Object** p, bool b) { | 266 static inline Object** WriteBool(Object** p, bool b) { |
| 296 *p++ = Smi::FromInt(b ? 1 : 0); | 267 *p++ = Smi::FromInt(b ? 1 : 0); |
| 297 return p; | 268 return p; |
| 298 } | 269 } |
| 299 | 270 |
| 300 | 271 |
| 301 static inline Object** WriteSymbol(Object** p, Handle<String> s) { | 272 static inline Object** WriteSymbol(Object** p, Handle<String> s) { |
| 302 *p++ = *s; | 273 *p++ = *s; |
| 303 return p; | 274 return p; |
| 304 } | 275 } |
| 305 | 276 |
| 306 | 277 |
| 307 static inline Object** WriteSentinel(Object** p) { | |
| 308 *p++ = NULL; | |
| 309 return p; | |
| 310 } | |
| 311 | |
| 312 | |
| 313 template <class Allocator> | 278 template <class Allocator> |
| 314 static Object** WriteList(Object** p, List<Handle<String>, Allocator >* list) { | 279 static Object** WriteList(Object** p, List<Handle<String>, Allocator >* list) { |
| 315 const int n = list->length(); | 280 const int n = list->length(); |
| 316 p = WriteInt(p, n); | 281 p = WriteInt(p, n); |
| 317 for (int i = 0; i < n; i++) { | 282 for (int i = 0; i < n; i++) { |
| 318 p = WriteSymbol(p, list->at(i)); | 283 p = WriteSymbol(p, list->at(i)); |
| 319 } | 284 } |
| 320 return WriteSentinel(p); | 285 return p; |
| 321 } | 286 } |
| 322 | 287 |
| 323 | 288 |
| 324 template <class Allocator> | 289 template <class Allocator> |
| 325 static Object** WriteList(Object** p, | 290 static Object** WriteList(Object** p, |
| 326 List<Handle<String>, Allocator>* list, | 291 List<Handle<String>, Allocator>* list, |
| 327 List<Variable::Mode, Allocator>* modes) { | 292 List<Variable::Mode, Allocator>* modes) { |
| 328 const int n = list->length(); | 293 const int n = list->length(); |
| 329 p = WriteInt(p, n); | 294 p = WriteInt(p, n); |
| 330 for (int i = 0; i < n; i++) { | 295 for (int i = 0; i < n; i++) { |
| 331 p = WriteSymbol(p, list->at(i)); | 296 p = WriteSymbol(p, list->at(i)); |
| 332 p = WriteInt(p, modes->at(i)); | 297 p = WriteInt(p, modes->at(i)); |
| 333 } | 298 } |
| 334 return WriteSentinel(p); | 299 return p; |
| 335 } | 300 } |
| 336 | 301 |
| 337 | 302 |
| 338 template<class Allocator> | 303 template<class Allocator> |
| 339 Handle<Object> ScopeInfo<Allocator>::Serialize() { | 304 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { |
| 340 // function name, calls eval, length & sentinel for 3 tables: | 305 // function name, calls eval, length for 3 tables: |
| 341 const int extra_slots = 1 + 1 + 2 * 3; | 306 const int extra_slots = 1 + 1 + 3; |
| 342 int length = extra_slots + | 307 int length = extra_slots + |
| 343 context_slots_.length() * 2 + | 308 context_slots_.length() * 2 + |
| 344 parameters_.length() + | 309 parameters_.length() + |
| 345 stack_slots_.length(); | 310 stack_slots_.length(); |
| 346 | 311 |
| 347 Handle<Object> data(Factory::NewFixedArray(length, TENURED)); | 312 Handle<SerializedScopeInfo> data( |
| 313 SerializedScopeInfo::cast(*Factory::NewFixedArray(length, TENURED))); |
| 348 AssertNoAllocation nogc; | 314 AssertNoAllocation nogc; |
| 349 | 315 |
| 350 Object** p0 = GetDataStart(*data); | 316 Object** p0 = data->data_start(); |
| 351 Object** p = p0; | 317 Object** p = p0; |
| 352 p = WriteSymbol(p, function_name_); | 318 p = WriteSymbol(p, function_name_); |
| 353 p = WriteBool(p, calls_eval_); | 319 p = WriteBool(p, calls_eval_); |
| 354 p = WriteList(p, &context_slots_, &context_modes_); | 320 p = WriteList(p, &context_slots_, &context_modes_); |
| 355 p = WriteList(p, ¶meters_); | 321 p = WriteList(p, ¶meters_); |
| 356 p = WriteList(p, &stack_slots_); | 322 p = WriteList(p, &stack_slots_); |
| 357 ASSERT((p - p0) == length); | 323 ASSERT((p - p0) == length); |
| 358 | 324 |
| 359 return data; | 325 return data; |
| 360 } | 326 } |
| 361 | 327 |
| 362 | 328 |
| 363 static Object** ContextEntriesAddr(Object* data) { | |
| 364 ASSERT(IsNotEmpty(data)); | |
| 365 // +2 for function name and calls eval: | |
| 366 return GetDataStart(data) + 2; | |
| 367 } | |
| 368 | |
| 369 | |
| 370 static Object** ParameterEntriesAddr(Object* data) { | |
| 371 ASSERT(IsNotEmpty(data)); | |
| 372 Object** p = ContextEntriesAddr(data); | |
| 373 int n; // number of context slots; | |
| 374 p = ReadInt(p, &n); | |
| 375 return p + n*2 + 1; // *2 for pairs, +1 for sentinel | |
| 376 } | |
| 377 | |
| 378 | |
| 379 static Object** StackSlotEntriesAddr(Object* data) { | |
| 380 ASSERT(IsNotEmpty(data)); | |
| 381 Object** p = ParameterEntriesAddr(data); | |
| 382 int n; // number of parameter slots; | |
| 383 p = ReadInt(p, &n); | |
| 384 return p + n + 1; // +1 for sentinel | |
| 385 } | |
| 386 | |
| 387 | |
| 388 template<class Allocator> | 329 template<class Allocator> |
| 389 bool ScopeInfo<Allocator>::CallsEval(Object* data) { | 330 Handle<String> ScopeInfo<Allocator>::LocalName(int i) const { |
| 390 if (IsNotEmpty(data)) { | 331 // A local variable can be allocated either on the stack or in the context. |
| 391 // +1 for function name: | 332 // For variables allocated in the context they are always preceded by |
| 392 Object** p = GetDataStart(data) + 1; | 333 // Context::MIN_CONTEXT_SLOTS of fixed allocated slots in the context. |
| 334 if (i < number_of_stack_slots()) { |
| 335 return stack_slot_name(i); |
| 336 } else { |
| 337 return context_slot_name(i - number_of_stack_slots() + |
| 338 Context::MIN_CONTEXT_SLOTS); |
| 339 } |
| 340 } |
| 341 |
| 342 |
| 343 template<class Allocator> |
| 344 int ScopeInfo<Allocator>::NumberOfLocals() const { |
| 345 int number_of_locals = number_of_stack_slots(); |
| 346 if (number_of_context_slots() > 0) { |
| 347 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS); |
| 348 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS; |
| 349 } |
| 350 return number_of_locals; |
| 351 } |
| 352 |
| 353 |
| 354 Handle<SerializedScopeInfo> SerializedScopeInfo::Create(Scope* scope) { |
| 355 ScopeInfo<ZoneListAllocationPolicy> sinfo(scope); |
| 356 return sinfo.Serialize(); |
| 357 } |
| 358 |
| 359 |
| 360 SerializedScopeInfo* SerializedScopeInfo::Empty() { |
| 361 return reinterpret_cast<SerializedScopeInfo*>(Heap::empty_fixed_array()); |
| 362 } |
| 363 |
| 364 |
| 365 Object** SerializedScopeInfo::ContextEntriesAddr() { |
| 366 ASSERT(length() > 0); |
| 367 return data_start() + 2; // +2 for function name and calls eval. |
| 368 } |
| 369 |
| 370 |
| 371 Object** SerializedScopeInfo::ParameterEntriesAddr() { |
| 372 ASSERT(length() > 0); |
| 373 Object** p = ContextEntriesAddr(); |
| 374 int number_of_context_slots; |
| 375 p = ReadInt(p, &number_of_context_slots); |
| 376 return p + number_of_context_slots*2; // *2 for pairs |
| 377 } |
| 378 |
| 379 |
| 380 Object** SerializedScopeInfo::StackSlotEntriesAddr() { |
| 381 ASSERT(length() > 0); |
| 382 Object** p = ParameterEntriesAddr(); |
| 383 int number_of_parameter_slots; |
| 384 p = ReadInt(p, &number_of_parameter_slots); |
| 385 return p + number_of_parameter_slots; |
| 386 } |
| 387 |
| 388 |
| 389 bool SerializedScopeInfo::CallsEval() { |
| 390 if (length() > 0) { |
| 391 Object** p = data_start() + 1; // +1 for function name. |
| 393 bool calls_eval; | 392 bool calls_eval; |
| 394 p = ReadBool(p, &calls_eval); | 393 p = ReadBool(p, &calls_eval); |
| 395 return calls_eval; | 394 return calls_eval; |
| 396 } | 395 } |
| 397 return true; | 396 return true; |
| 398 } | 397 } |
| 399 | 398 |
| 400 | 399 |
| 401 template<class Allocator> | 400 int SerializedScopeInfo::NumberOfStackSlots() { |
| 402 int ScopeInfo<Allocator>::NumberOfStackSlots(Object* data) { | 401 if (length() > 0) { |
| 403 if (IsNotEmpty(data)) { | 402 Object** p = StackSlotEntriesAddr(); |
| 404 Object** p = StackSlotEntriesAddr(data); | 403 int number_of_stack_slots; |
| 405 int n; // number of stack slots; | 404 ReadInt(p, &number_of_stack_slots); |
| 406 ReadInt(p, &n); | 405 return number_of_stack_slots; |
| 407 return n; | |
| 408 } | 406 } |
| 409 return 0; | 407 return 0; |
| 410 } | 408 } |
| 411 | 409 |
| 412 | 410 |
| 413 template<class Allocator> | 411 int SerializedScopeInfo::NumberOfContextSlots() { |
| 414 int ScopeInfo<Allocator>::NumberOfContextSlots(Object* data) { | 412 if (length() > 0) { |
| 415 if (IsNotEmpty(data)) { | 413 Object** p = ContextEntriesAddr(); |
| 416 Object** p = ContextEntriesAddr(data); | 414 int number_of_context_slots; |
| 417 int n; // number of context slots; | 415 ReadInt(p, &number_of_context_slots); |
| 418 ReadInt(p, &n); | 416 return number_of_context_slots + Context::MIN_CONTEXT_SLOTS; |
| 419 return n + Context::MIN_CONTEXT_SLOTS; | |
| 420 } | 417 } |
| 421 return 0; | 418 return 0; |
| 422 } | 419 } |
| 423 | 420 |
| 424 | 421 |
| 425 template<class Allocator> | 422 bool SerializedScopeInfo::HasHeapAllocatedLocals() { |
| 426 bool ScopeInfo<Allocator>::HasHeapAllocatedLocals(Object* data) { | 423 if (length() > 0) { |
| 427 if (IsNotEmpty(data)) { | 424 Object** p = ContextEntriesAddr(); |
| 428 Object** p = ContextEntriesAddr(data); | 425 int number_of_context_slots; |
| 429 int n; // number of context slots; | 426 ReadInt(p, &number_of_context_slots); |
| 430 ReadInt(p, &n); | 427 return number_of_context_slots > 0; |
| 431 return n > 0; | |
| 432 } | 428 } |
| 433 return false; | 429 return false; |
| 434 } | 430 } |
| 435 | 431 |
| 436 | 432 |
| 437 template<class Allocator> | 433 int SerializedScopeInfo::StackSlotIndex(String* name) { |
| 438 int ScopeInfo<Allocator>::StackSlotIndex(Object* data, String* name) { | |
| 439 ASSERT(name->IsSymbol()); | 434 ASSERT(name->IsSymbol()); |
| 440 if (IsNotEmpty(data)) { | 435 if (length() > 0) { |
| 441 // Loop below depends on the NULL sentinel after the stack slot names. | 436 // Slots start after length entry. |
| 442 ASSERT(NumberOfStackSlots(data) > 0 || | 437 Object** p0 = StackSlotEntriesAddr(); |
| 443 *(StackSlotEntriesAddr(data) + 1) == NULL); | 438 int number_of_stack_slots; |
| 444 // slots start after length entry | 439 p0 = ReadInt(p0, &number_of_stack_slots); |
| 445 Object** p0 = StackSlotEntriesAddr(data) + 1; | |
| 446 Object** p = p0; | 440 Object** p = p0; |
| 447 while (*p != NULL) { | 441 Object** end = p0 + number_of_stack_slots; |
| 442 while (p != end) { |
| 448 if (*p == name) return static_cast<int>(p - p0); | 443 if (*p == name) return static_cast<int>(p - p0); |
| 449 p++; | 444 p++; |
| 450 } | 445 } |
| 451 } | 446 } |
| 452 return -1; | 447 return -1; |
| 453 } | 448 } |
| 454 | 449 |
| 455 | 450 int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { |
| 456 template<class Allocator> | |
| 457 int ScopeInfo<Allocator>::ContextSlotIndex(Object* data, | |
| 458 String* name, | |
| 459 Variable::Mode* mode) { | |
| 460 ASSERT(name->IsSymbol()); | 451 ASSERT(name->IsSymbol()); |
| 461 int result = ContextSlotCache::Lookup(data, name, mode); | 452 int result = ContextSlotCache::Lookup(this, name, mode); |
| 462 if (result != ContextSlotCache::kNotFound) return result; | 453 if (result != ContextSlotCache::kNotFound) return result; |
| 463 if (IsNotEmpty(data)) { | 454 if (length() > 0) { |
| 464 // Loop below depends on the NULL sentinel after the context slot names. | 455 // Slots start after length entry. |
| 465 ASSERT(NumberOfContextSlots(data) >= Context::MIN_CONTEXT_SLOTS || | 456 Object** p0 = ContextEntriesAddr(); |
| 466 *(ContextEntriesAddr(data) + 1) == NULL); | 457 int number_of_context_slots; |
| 467 | 458 p0 = ReadInt(p0, &number_of_context_slots); |
| 468 // slots start after length entry | |
| 469 Object** p0 = ContextEntriesAddr(data) + 1; | |
| 470 Object** p = p0; | 459 Object** p = p0; |
| 471 // contexts may have no variable slots (in the presence of eval()). | 460 Object** end = p0 + number_of_context_slots * 2; |
| 472 while (*p != NULL) { | 461 while (p != end) { |
| 473 if (*p == name) { | 462 if (*p == name) { |
| 474 ASSERT(((p - p0) & 1) == 0); | 463 ASSERT(((p - p0) & 1) == 0); |
| 475 int v; | 464 int v; |
| 476 ReadInt(p + 1, &v); | 465 ReadInt(p + 1, &v); |
| 477 Variable::Mode mode_value = static_cast<Variable::Mode>(v); | 466 Variable::Mode mode_value = static_cast<Variable::Mode>(v); |
| 478 if (mode != NULL) *mode = mode_value; | 467 if (mode != NULL) *mode = mode_value; |
| 479 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; | 468 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; |
| 480 ContextSlotCache::Update(data, name, mode_value, result); | 469 ContextSlotCache::Update(this, name, mode_value, result); |
| 481 return result; | 470 return result; |
| 482 } | 471 } |
| 483 p += 2; | 472 p += 2; |
| 484 } | 473 } |
| 485 } | 474 } |
| 486 ContextSlotCache::Update(data, name, Variable::INTERNAL, -1); | 475 ContextSlotCache::Update(this, name, Variable::INTERNAL, -1); |
| 487 return -1; | 476 return -1; |
| 488 } | 477 } |
| 489 | 478 |
| 490 | 479 |
| 491 template<class Allocator> | 480 int SerializedScopeInfo::ParameterIndex(String* name) { |
| 492 int ScopeInfo<Allocator>::ParameterIndex(Object* data, String* name) { | |
| 493 ASSERT(name->IsSymbol()); | 481 ASSERT(name->IsSymbol()); |
| 494 if (IsNotEmpty(data)) { | 482 if (length() > 0) { |
| 495 // We must read parameters from the end since for | 483 // We must read parameters from the end since for |
| 496 // multiply declared parameters the value of the | 484 // multiply declared parameters the value of the |
| 497 // last declaration of that parameter is used | 485 // last declaration of that parameter is used |
| 498 // inside a function (and thus we need to look | 486 // inside a function (and thus we need to look |
| 499 // at the last index). Was bug# 1110337. | 487 // at the last index). Was bug# 1110337. |
| 500 // | 488 // |
| 501 // Eventually, we should only register such parameters | 489 // Eventually, we should only register such parameters |
| 502 // once, with corresponding index. This requires a new | 490 // once, with corresponding index. This requires a new |
| 503 // implementation of the ScopeInfo code. See also other | 491 // implementation of the ScopeInfo code. See also other |
| 504 // comments in this file regarding this. | 492 // comments in this file regarding this. |
| 505 Object** p = ParameterEntriesAddr(data); | 493 Object** p = ParameterEntriesAddr(); |
| 506 int n; // number of parameters | 494 int number_of_parameter_slots; |
| 507 Object** p0 = ReadInt(p, &n); | 495 Object** p0 = ReadInt(p, &number_of_parameter_slots); |
| 508 p = p0 + n; | 496 p = p0 + number_of_parameter_slots; |
| 509 while (p > p0) { | 497 while (p > p0) { |
| 510 p--; | 498 p--; |
| 511 if (*p == name) return static_cast<int>(p - p0); | 499 if (*p == name) return static_cast<int>(p - p0); |
| 512 } | 500 } |
| 513 } | 501 } |
| 514 return -1; | 502 return -1; |
| 515 } | 503 } |
| 516 | 504 |
| 517 | 505 |
| 518 template<class Allocator> | 506 int SerializedScopeInfo::FunctionContextSlotIndex(String* name) { |
| 519 int ScopeInfo<Allocator>::FunctionContextSlotIndex(Object* data, String* name) { | |
| 520 ASSERT(name->IsSymbol()); | 507 ASSERT(name->IsSymbol()); |
| 521 if (IsNotEmpty(data)) { | 508 if (length() > 0) { |
| 522 Object** p = GetDataStart(data); | 509 Object** p = data_start(); |
| 523 if (*p == name) { | 510 if (*p == name) { |
| 524 p = ContextEntriesAddr(data); | 511 p = ContextEntriesAddr(); |
| 525 int n; // number of context slots | 512 int number_of_context_slots; |
| 526 ReadInt(p, &n); | 513 ReadInt(p, &number_of_context_slots); |
| 527 ASSERT(n != 0); | 514 ASSERT(number_of_context_slots != 0); |
| 528 // The function context slot is the last entry. | 515 // The function context slot is the last entry. |
| 529 return n + Context::MIN_CONTEXT_SLOTS - 1; | 516 return number_of_context_slots + Context::MIN_CONTEXT_SLOTS - 1; |
| 530 } | 517 } |
| 531 } | 518 } |
| 532 return -1; | 519 return -1; |
| 533 } | 520 } |
| 534 | 521 |
| 535 | 522 |
| 536 template<class Allocator> | |
| 537 Handle<String> ScopeInfo<Allocator>::LocalName(int i) const { | |
| 538 // A local variable can be allocated either on the stack or in the context. | |
| 539 // For variables allocated in the context they are always preceded by the | |
| 540 // number Context::MIN_CONTEXT_SLOTS number of fixed allocated slots in the | |
| 541 // context. | |
| 542 if (i < number_of_stack_slots()) { | |
| 543 return stack_slot_name(i); | |
| 544 } else { | |
| 545 return context_slot_name(i - number_of_stack_slots() + | |
| 546 Context::MIN_CONTEXT_SLOTS); | |
| 547 } | |
| 548 } | |
| 549 | |
| 550 | |
| 551 template<class Allocator> | |
| 552 int ScopeInfo<Allocator>::NumberOfLocals() const { | |
| 553 int number_of_locals = number_of_stack_slots(); | |
| 554 if (number_of_context_slots() > 0) { | |
| 555 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS); | |
| 556 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS; | |
| 557 } | |
| 558 return number_of_locals; | |
| 559 } | |
| 560 | |
| 561 | |
| 562 int ContextSlotCache::Hash(Object* data, String* name) { | 523 int ContextSlotCache::Hash(Object* data, String* name) { |
| 563 // Uses only lower 32 bits if pointers are larger. | 524 // Uses only lower 32 bits if pointers are larger. |
| 564 uintptr_t addr_hash = | 525 uintptr_t addr_hash = |
| 565 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(data)) >> 2; | 526 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(data)) >> 2; |
| 566 return static_cast<int>((addr_hash ^ name->Hash()) % kLength); | 527 return static_cast<int>((addr_hash ^ name->Hash()) % kLength); |
| 567 } | 528 } |
| 568 | 529 |
| 569 | 530 |
| 570 int ContextSlotCache::Lookup(Object* data, | 531 int ContextSlotCache::Lookup(Object* data, |
| 571 String* name, | 532 String* name, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 } | 628 } |
| 668 #endif // DEBUG | 629 #endif // DEBUG |
| 669 | 630 |
| 670 | 631 |
| 671 // Make sure the classes get instantiated by the template system. | 632 // Make sure the classes get instantiated by the template system. |
| 672 template class ScopeInfo<FreeStoreAllocationPolicy>; | 633 template class ScopeInfo<FreeStoreAllocationPolicy>; |
| 673 template class ScopeInfo<PreallocatedStorage>; | 634 template class ScopeInfo<PreallocatedStorage>; |
| 674 template class ScopeInfo<ZoneListAllocationPolicy>; | 635 template class ScopeInfo<ZoneListAllocationPolicy>; |
| 675 | 636 |
| 676 } } // namespace v8::internal | 637 } } // namespace v8::internal |
| OLD | NEW |