Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/objects.cc

Issue 8518001: Make eval compilation cache calling scope sensitive. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10273 matching lines...) Expand 10 before | Expand all | Expand 10 after
10284 String* string_; 10284 String* string_;
10285 uint32_t hash_; 10285 uint32_t hash_;
10286 }; 10286 };
10287 10287
10288 10288
10289 // StringSharedKeys are used as keys in the eval cache. 10289 // StringSharedKeys are used as keys in the eval cache.
10290 class StringSharedKey : public HashTableKey { 10290 class StringSharedKey : public HashTableKey {
10291 public: 10291 public:
10292 StringSharedKey(String* source, 10292 StringSharedKey(String* source,
10293 SharedFunctionInfo* shared, 10293 SharedFunctionInfo* shared,
10294 StrictModeFlag strict_mode) 10294 StrictModeFlag strict_mode,
10295 int scope_position)
10295 : source_(source), 10296 : source_(source),
10296 shared_(shared), 10297 shared_(shared),
10297 strict_mode_(strict_mode) { } 10298 strict_mode_(strict_mode),
10299 scope_position_(scope_position) { }
10298 10300
10299 bool IsMatch(Object* other) { 10301 bool IsMatch(Object* other) {
10300 if (!other->IsFixedArray()) return false; 10302 if (!other->IsFixedArray()) return false;
10301 FixedArray* pair = FixedArray::cast(other); 10303 FixedArray* pair = FixedArray::cast(other);
Jakob Kummerow 2011/11/10 11:53:23 Please rename this. If it has 4 elements, it's not
Steven 2011/11/14 08:57:21 Done.
10302 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); 10304 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
10303 if (shared != shared_) return false; 10305 if (shared != shared_) return false;
10304 int strict_unchecked = Smi::cast(pair->get(2))->value(); 10306 int strict_unchecked = Smi::cast(pair->get(2))->value();
10305 ASSERT(strict_unchecked == kStrictMode || 10307 ASSERT(strict_unchecked == kStrictMode ||
10306 strict_unchecked == kNonStrictMode); 10308 strict_unchecked == kNonStrictMode);
10307 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 10309 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
10308 if (strict_mode != strict_mode_) return false; 10310 if (strict_mode != strict_mode_) return false;
10311 int scope_position = Smi::cast(pair->get(3))->value();
10312 if (scope_position != scope_position_) return false;
10309 String* source = String::cast(pair->get(1)); 10313 String* source = String::cast(pair->get(1));
10310 return source->Equals(source_); 10314 return source->Equals(source_);
10311 } 10315 }
10312 10316
10313 static uint32_t StringSharedHashHelper(String* source, 10317 static uint32_t StringSharedHashHelper(String* source,
10314 SharedFunctionInfo* shared, 10318 SharedFunctionInfo* shared,
10315 StrictModeFlag strict_mode) { 10319 StrictModeFlag strict_mode,
10320 int scope_position) {
10316 uint32_t hash = source->Hash(); 10321 uint32_t hash = source->Hash();
10317 if (shared->HasSourceCode()) { 10322 if (shared->HasSourceCode()) {
10318 // Instead of using the SharedFunctionInfo pointer in the hash 10323 // Instead of using the SharedFunctionInfo pointer in the hash
10319 // code computation, we use a combination of the hash of the 10324 // code computation, we use a combination of the hash of the
10320 // script source code and the start and end positions. We do 10325 // script source code and the start position of the calling scope.
10321 // this to ensure that the cache entries can survive garbage 10326 // We do this to ensure that the cache entries can survive garbage
10322 // collection. 10327 // collection.
10323 Script* script = Script::cast(shared->script()); 10328 Script* script = Script::cast(shared->script());
10324 hash ^= String::cast(script->source())->Hash(); 10329 hash ^= String::cast(script->source())->Hash();
10325 if (strict_mode == kStrictMode) hash ^= 0x8000; 10330 if (strict_mode == kStrictMode) hash ^= 0x8000;
10326 hash += shared->start_position(); 10331 hash += scope_position;
10327 } 10332 }
10328 return hash; 10333 return hash;
10329 } 10334 }
10330 10335
10331 uint32_t Hash() { 10336 uint32_t Hash() {
10332 return StringSharedHashHelper(source_, shared_, strict_mode_); 10337 return StringSharedHashHelper(
10338 source_, shared_, strict_mode_, scope_position_);
10333 } 10339 }
10334 10340
10335 uint32_t HashForObject(Object* obj) { 10341 uint32_t HashForObject(Object* obj) {
10336 FixedArray* pair = FixedArray::cast(obj); 10342 FixedArray* pair = FixedArray::cast(obj);
Jakob Kummerow 2011/11/10 11:53:23 Same here
Steven 2011/11/14 08:57:21 Done.
10337 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); 10343 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
10338 String* source = String::cast(pair->get(1)); 10344 String* source = String::cast(pair->get(1));
10339 int strict_unchecked = Smi::cast(pair->get(2))->value(); 10345 int strict_unchecked = Smi::cast(pair->get(2))->value();
10340 ASSERT(strict_unchecked == kStrictMode || 10346 ASSERT(strict_unchecked == kStrictMode ||
10341 strict_unchecked == kNonStrictMode); 10347 strict_unchecked == kNonStrictMode);
10342 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 10348 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
10343 return StringSharedHashHelper(source, shared, strict_mode); 10349 int scope_position = Smi::cast(pair->get(3))->value();
10350 return StringSharedHashHelper(source, shared, strict_mode, scope_position);
10344 } 10351 }
10345 10352
10346 MUST_USE_RESULT MaybeObject* AsObject() { 10353 MUST_USE_RESULT MaybeObject* AsObject() {
10347 Object* obj; 10354 Object* obj;
10348 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(3); 10355 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(4);
10349 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 10356 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
10350 } 10357 }
10351 FixedArray* pair = FixedArray::cast(obj); 10358 FixedArray* pair = FixedArray::cast(obj);
Jakob Kummerow 2011/11/10 11:53:23 And here.
Steven 2011/11/14 08:57:21 Done.
10352 pair->set(0, shared_); 10359 pair->set(0, shared_);
10353 pair->set(1, source_); 10360 pair->set(1, source_);
10354 pair->set(2, Smi::FromInt(strict_mode_)); 10361 pair->set(2, Smi::FromInt(strict_mode_));
10362 pair->set(3, Smi::FromInt(scope_position_));
10355 return pair; 10363 return pair;
10356 } 10364 }
10357 10365
10358 private: 10366 private:
10359 String* source_; 10367 String* source_;
10360 SharedFunctionInfo* shared_; 10368 SharedFunctionInfo* shared_;
10361 StrictModeFlag strict_mode_; 10369 StrictModeFlag strict_mode_;
10370 int scope_position_;
10362 }; 10371 };
10363 10372
10364 10373
10365 // RegExpKey carries the source and flags of a regular expression as key. 10374 // RegExpKey carries the source and flags of a regular expression as key.
10366 class RegExpKey : public HashTableKey { 10375 class RegExpKey : public HashTableKey {
10367 public: 10376 public:
10368 RegExpKey(String* string, JSRegExp::Flags flags) 10377 RegExpKey(String* string, JSRegExp::Flags flags)
10369 : string_(string), 10378 : string_(string),
10370 flags_(Smi::FromInt(flags.value())) { } 10379 flags_(Smi::FromInt(flags.value())) { }
10371 10380
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
11506 Object* CompilationCacheTable::Lookup(String* src) { 11515 Object* CompilationCacheTable::Lookup(String* src) {
11507 StringKey key(src); 11516 StringKey key(src);
11508 int entry = FindEntry(&key); 11517 int entry = FindEntry(&key);
11509 if (entry == kNotFound) return GetHeap()->undefined_value(); 11518 if (entry == kNotFound) return GetHeap()->undefined_value();
11510 return get(EntryToIndex(entry) + 1); 11519 return get(EntryToIndex(entry) + 1);
11511 } 11520 }
11512 11521
11513 11522
11514 Object* CompilationCacheTable::LookupEval(String* src, 11523 Object* CompilationCacheTable::LookupEval(String* src,
11515 Context* context, 11524 Context* context,
11516 StrictModeFlag strict_mode) { 11525 StrictModeFlag strict_mode,
11517 StringSharedKey key(src, context->closure()->shared(), strict_mode); 11526 int scope_position) {
11527 StringSharedKey key(src,
11528 context->closure()->shared(),
11529 strict_mode,
11530 scope_position);
11518 int entry = FindEntry(&key); 11531 int entry = FindEntry(&key);
11519 if (entry == kNotFound) return GetHeap()->undefined_value(); 11532 if (entry == kNotFound) return GetHeap()->undefined_value();
11520 return get(EntryToIndex(entry) + 1); 11533 return get(EntryToIndex(entry) + 1);
11521 } 11534 }
11522 11535
11523 11536
11524 Object* CompilationCacheTable::LookupRegExp(String* src, 11537 Object* CompilationCacheTable::LookupRegExp(String* src,
11525 JSRegExp::Flags flags) { 11538 JSRegExp::Flags flags) {
11526 RegExpKey key(src, flags); 11539 RegExpKey key(src, flags);
11527 int entry = FindEntry(&key); 11540 int entry = FindEntry(&key);
(...skipping 14 matching lines...) Expand all
11542 int entry = cache->FindInsertionEntry(key.Hash()); 11555 int entry = cache->FindInsertionEntry(key.Hash());
11543 cache->set(EntryToIndex(entry), src); 11556 cache->set(EntryToIndex(entry), src);
11544 cache->set(EntryToIndex(entry) + 1, value); 11557 cache->set(EntryToIndex(entry) + 1, value);
11545 cache->ElementAdded(); 11558 cache->ElementAdded();
11546 return cache; 11559 return cache;
11547 } 11560 }
11548 11561
11549 11562
11550 MaybeObject* CompilationCacheTable::PutEval(String* src, 11563 MaybeObject* CompilationCacheTable::PutEval(String* src,
11551 Context* context, 11564 Context* context,
11552 SharedFunctionInfo* value) { 11565 SharedFunctionInfo* value,
11566 int scope_position) {
11553 StringSharedKey key(src, 11567 StringSharedKey key(src,
11554 context->closure()->shared(), 11568 context->closure()->shared(),
11555 value->strict_mode_flag()); 11569 value->strict_mode_flag(),
11570 scope_position);
11556 Object* obj; 11571 Object* obj;
11557 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); 11572 { MaybeObject* maybe_obj = EnsureCapacity(1, &key);
11558 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 11573 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
11559 } 11574 }
11560 11575
11561 CompilationCacheTable* cache = 11576 CompilationCacheTable* cache =
11562 reinterpret_cast<CompilationCacheTable*>(obj); 11577 reinterpret_cast<CompilationCacheTable*>(obj);
11563 int entry = cache->FindInsertionEntry(key.Hash()); 11578 int entry = cache->FindInsertionEntry(key.Hash());
11564 11579
11565 Object* k; 11580 Object* k;
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
12515 if (break_point_objects()->IsUndefined()) return 0; 12530 if (break_point_objects()->IsUndefined()) return 0;
12516 // Single break point. 12531 // Single break point.
12517 if (!break_point_objects()->IsFixedArray()) return 1; 12532 if (!break_point_objects()->IsFixedArray()) return 1;
12518 // Multiple break points. 12533 // Multiple break points.
12519 return FixedArray::cast(break_point_objects())->length(); 12534 return FixedArray::cast(break_point_objects())->length();
12520 } 12535 }
12521 #endif // ENABLE_DEBUGGER_SUPPORT 12536 #endif // ENABLE_DEBUGGER_SUPPORT
12522 12537
12523 12538
12524 } } // namespace v8::internal 12539 } } // namespace v8::internal
OLDNEW
« src/compilation-cache.cc ('K') | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698