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 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2372 FixedArray* cache = code_cache(); | 2372 FixedArray* cache = code_cache(); |
2373 | 2373 |
2374 // When updating the code cache we disregard the type encoded in the | 2374 // When updating the code cache we disregard the type encoded in the |
2375 // flags. This allows call constant stubs to overwrite call field | 2375 // flags. This allows call constant stubs to overwrite call field |
2376 // stubs, etc. | 2376 // stubs, etc. |
2377 Code::Flags flags = Code::RemoveTypeFromFlags(code->flags()); | 2377 Code::Flags flags = Code::RemoveTypeFromFlags(code->flags()); |
2378 | 2378 |
2379 // First check whether we can update existing code cache without | 2379 // First check whether we can update existing code cache without |
2380 // extending it. | 2380 // extending it. |
2381 int length = cache->length(); | 2381 int length = cache->length(); |
2382 int deleted_index = -1; | |
2382 for (int i = 0; i < length; i += 2) { | 2383 for (int i = 0; i < length; i += 2) { |
2383 Object* key = cache->get(i); | 2384 Object* key = cache->get(i); |
2385 if (key->IsNull()) { | |
2386 if (deleted_index < 0) deleted_index = i; | |
2387 continue; | |
2388 } | |
2384 if (key->IsUndefined()) { | 2389 if (key->IsUndefined()) { |
2390 if (deleted_index > 0) i = deleted_index; | |
Kasper Lund
2008/09/18 10:56:22
What if deleted_index is 0? Shouldn't you use that
| |
2385 cache->set(i + 0, name); | 2391 cache->set(i + 0, name); |
2386 cache->set(i + 1, code); | 2392 cache->set(i + 1, code); |
2387 return this; | 2393 return this; |
2388 } | 2394 } |
2389 if (name->Equals(String::cast(key))) { | 2395 if (name->Equals(String::cast(key))) { |
2390 Code::Flags found = Code::cast(cache->get(i + 1))->flags(); | 2396 Code::Flags found = Code::cast(cache->get(i + 1))->flags(); |
2391 if (Code::RemoveTypeFromFlags(found) == flags) { | 2397 if (Code::RemoveTypeFromFlags(found) == flags) { |
2392 cache->set(i + 1, code); | 2398 cache->set(i + 1, code); |
2393 return this; | 2399 return this; |
2394 } | 2400 } |
2395 } | 2401 } |
2396 } | 2402 } |
2397 | 2403 |
2404 // Reached the end of the code cache. If there were deleted | |
2405 // elements, reuse the space for the first of them. | |
2406 if (deleted_index > 0) { | |
Kasper Lund
2008/09/18 10:56:22
How about reusing if deleted_index is 0? Isn't tha
| |
2407 cache->set(deleted_index + 0, name); | |
2408 cache->set(deleted_index + 1, code); | |
2409 return this; | |
2410 } | |
2411 | |
2398 // Extend the code cache with some new entries (at least one). | 2412 // Extend the code cache with some new entries (at least one). |
2399 int new_length = length + ((length >> 1) & ~1) + 2; | 2413 int new_length = length + ((length >> 1) & ~1) + 2; |
2400 ASSERT((new_length & 1) == 0); // must be a multiple of two | 2414 ASSERT((new_length & 1) == 0); // must be a multiple of two |
2401 Object* result = cache->CopySize(new_length); | 2415 Object* result = cache->CopySize(new_length); |
2402 if (result->IsFailure()) return result; | 2416 if (result->IsFailure()) return result; |
2403 | 2417 |
2404 // Add the (name, code) pair to the new cache. | 2418 // Add the (name, code) pair to the new cache. |
2405 cache = FixedArray::cast(result); | 2419 cache = FixedArray::cast(result); |
2406 cache->set(length + 0, name); | 2420 cache->set(length + 0, name); |
2407 cache->set(length + 1, code); | 2421 cache->set(length + 1, code); |
2408 set_code_cache(cache); | 2422 set_code_cache(cache); |
2409 return this; | 2423 return this; |
2410 } | 2424 } |
2411 | 2425 |
2412 | 2426 |
2413 Object* Map::FindInCodeCache(String* name, Code::Flags flags) { | 2427 Object* Map::FindInCodeCache(String* name, Code::Flags flags) { |
2414 FixedArray* cache = code_cache(); | 2428 FixedArray* cache = code_cache(); |
2415 int length = cache->length(); | 2429 int length = cache->length(); |
2416 for (int i = 0; i < length; i += 2) { | 2430 for (int i = 0; i < length; i += 2) { |
2417 Object* key = cache->get(i); | 2431 Object* key = cache->get(i); |
2432 if (key->IsNull()) { | |
Kasper Lund
2008/09/18 10:56:22
Maybe add a comment here that explains that we're
| |
2433 continue; | |
2434 } | |
2418 if (key->IsUndefined()) { | 2435 if (key->IsUndefined()) { |
2419 return key; | 2436 return key; |
2420 } | 2437 } |
2421 if (name->Equals(String::cast(key))) { | 2438 if (name->Equals(String::cast(key))) { |
2422 Code* code = Code::cast(cache->get(i + 1)); | 2439 Code* code = Code::cast(cache->get(i + 1)); |
2423 if (code->flags() == flags) return code; | 2440 if (code->flags() == flags) return code; |
2424 } | 2441 } |
2425 } | 2442 } |
2426 return Heap::undefined_value(); | 2443 return Heap::undefined_value(); |
2427 } | 2444 } |
2428 | 2445 |
2429 | 2446 |
2430 int Map::IndexInCodeCache(Code* code) { | 2447 int Map::IndexInCodeCache(Code* code) { |
2431 FixedArray* array = code_cache(); | 2448 FixedArray* array = code_cache(); |
2432 int len = array->length(); | 2449 int len = array->length(); |
2433 for (int i = 0; i < len; i += 2) { | 2450 for (int i = 0; i < len; i += 2) { |
2434 if (array->get(i + 1) == code) return i + 1; | 2451 if (array->get(i + 1) == code) return i + 1; |
2435 } | 2452 } |
2436 return -1; | 2453 return -1; |
2437 } | 2454 } |
2438 | 2455 |
2439 | 2456 |
2440 void Map::RemoveFromCodeCache(int index) { | 2457 void Map::RemoveFromCodeCache(int index) { |
2441 FixedArray* array = code_cache(); | 2458 FixedArray* array = code_cache(); |
2442 ASSERT(array->length() >= index && array->get(index)->IsCode()); | 2459 ASSERT(array->length() >= index && array->get(index)->IsCode()); |
2443 array->set_undefined(index - 1); // key | 2460 array->set_null(index - 1); // key |
Kasper Lund
2008/09/18 10:56:22
Add comment that explains that deleted entries are
| |
2444 array->set_undefined(index); // code | 2461 array->set_null(index); // code |
2445 } | 2462 } |
2446 | 2463 |
2447 | 2464 |
2448 void FixedArray::FixedArrayIterateBody(ObjectVisitor* v) { | 2465 void FixedArray::FixedArrayIterateBody(ObjectVisitor* v) { |
2449 IteratePointers(v, kHeaderSize, kHeaderSize + length() * kPointerSize); | 2466 IteratePointers(v, kHeaderSize, kHeaderSize + length() * kPointerSize); |
2450 } | 2467 } |
2451 | 2468 |
2452 | 2469 |
2453 static bool HasKey(FixedArray* array, Object* key) { | 2470 static bool HasKey(FixedArray* array, Object* key) { |
2454 int len0 = array->length(); | 2471 int len0 = array->length(); |
(...skipping 3833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6288 // No break point. | 6305 // No break point. |
6289 if (break_point_objects()->IsUndefined()) return 0; | 6306 if (break_point_objects()->IsUndefined()) return 0; |
6290 // Single beak point. | 6307 // Single beak point. |
6291 if (!break_point_objects()->IsFixedArray()) return 1; | 6308 if (!break_point_objects()->IsFixedArray()) return 1; |
6292 // Multiple break points. | 6309 // Multiple break points. |
6293 return FixedArray::cast(break_point_objects())->length(); | 6310 return FixedArray::cast(break_point_objects())->length(); |
6294 } | 6311 } |
6295 | 6312 |
6296 | 6313 |
6297 } } // namespace v8::internal | 6314 } } // namespace v8::internal |
OLD | NEW |