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

Unified Diff: src/objects.cc

Issue 197283017: Refactor GetCodeCopyFromTemplate to get a single point where objects are replaced in code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« src/ic.cc ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 92e4dc4c8c9c98f03a6267e2f393dda5c4312803..c5a9a7c10cd429cdd4898ab901a23f9b0ba9fb43 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10501,20 +10501,22 @@ Map* Code::FindFirstMap() {
}
-void Code::ReplaceNthObject(int n,
- Map* match_map,
- Object* replace_with) {
+void Code::FindAndReplace(const FindAndReplacePattern& pattern) {
ASSERT(is_inline_cache_stub() || is_handler());
DisallowHeapAllocation no_allocation;
int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
+ STATIC_ASSERT(FindAndReplacePattern::kMaxCount < 32);
+ unsigned remaining_set = (1u << pattern.count_) - 1;
for (RelocIterator it(this, mask); !it.done(); it.next()) {
RelocInfo* info = it.rinfo();
Object* object = info->target_object();
if (object->IsHeapObject()) {
- if (HeapObject::cast(object)->map() == match_map) {
- if (--n == 0) {
- info->set_target_object(replace_with);
- return;
+ Map* map = HeapObject::cast(object)->map();
+ for (int i = 0; i < pattern.count_; i++) {
+ if (((remaining_set >> i) & 1) && map == *pattern.find_[i]) {
+ info->set_target_object(*pattern.replace_[i]);
+ remaining_set ^= 1u << i;
+ if (!remaining_set) return;
}
}
Toon Verwaest 2014/03/17 09:40:14 Why don't we just introduce an invariant that the
ulan 2014/03/17 13:43:31 Good idea, turned that into O(m) and added comment
}
@@ -10550,11 +10552,6 @@ void Code::FindAllTypes(TypeHandleList* types) {
}
-void Code::ReplaceFirstMap(Map* replace_with) {
- ReplaceNthObject(1, GetHeap()->meta_map(), replace_with);
-}
-
-
Code* Code::FindFirstHandler() {
ASSERT(is_inline_cache_stub());
DisallowHeapAllocation no_allocation;
@@ -10600,21 +10597,6 @@ Name* Code::FindFirstName() {
}
-void Code::ReplaceNthCell(int n, Cell* replace_with) {
- ASSERT(is_inline_cache_stub());
- DisallowHeapAllocation no_allocation;
- int mask = RelocInfo::ModeMask(RelocInfo::CELL);
- for (RelocIterator it(this, mask); !it.done(); it.next()) {
- RelocInfo* info = it.rinfo();
- if (--n == 0) {
- info->set_target_cell(replace_with);
- return;
- }
- }
- UNREACHABLE();
-}
-
-
void Code::ClearInlineCaches() {
ClearInlineCaches(NULL);
}
« src/ic.cc ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698