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/type-info.cc

Issue 137403009: Adding a type vector to replace type cells. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Seperate file for feedback slot allocation. Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 29 matching lines...) Expand all
40 40
41 namespace v8 { 41 namespace v8 {
42 namespace internal { 42 namespace internal {
43 43
44 44
45 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, 45 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code,
46 Handle<Context> native_context, 46 Handle<Context> native_context,
47 Zone* zone) 47 Zone* zone)
48 : native_context_(native_context), 48 : native_context_(native_context),
49 zone_(zone) { 49 zone_(zone) {
50 Object* raw_info = code->type_feedback_info();
51 if (raw_info->IsTypeFeedbackInfo()) {
52 feedback_vector_ = Handle<FixedArray>(TypeFeedbackInfo::cast(raw_info)->
53 feedback_vector());
54 }
55
50 BuildDictionary(code); 56 BuildDictionary(code);
51 ASSERT(dictionary_->IsDictionary()); 57 ASSERT(dictionary_->IsDictionary());
52 } 58 }
53 59
54 60
55 static uint32_t IdToKey(TypeFeedbackId ast_id) { 61 static uint32_t IdToKey(TypeFeedbackId ast_id) {
56 return static_cast<uint32_t>(ast_id.ToInt()); 62 return static_cast<uint32_t>(ast_id.ToInt());
57 } 63 }
58 64
59 65
60 Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) { 66 Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) {
61 int entry = dictionary_->FindEntry(IdToKey(ast_id)); 67 int entry = dictionary_->FindEntry(IdToKey(ast_id));
62 if (entry != UnseededNumberDictionary::kNotFound) { 68 if (entry != UnseededNumberDictionary::kNotFound) {
63 Object* value = dictionary_->ValueAt(entry); 69 Object* value = dictionary_->ValueAt(entry);
64 if (value->IsCell()) { 70 if (value->IsCell()) {
65 Cell* cell = Cell::cast(value); 71 Cell* cell = Cell::cast(value);
66 return Handle<Object>(cell->value(), isolate()); 72 return Handle<Object>(cell->value(), isolate());
67 } else { 73 } else {
68 return Handle<Object>(value, isolate()); 74 return Handle<Object>(value, isolate());
69 } 75 }
70 } 76 }
71 return Handle<Object>::cast(isolate()->factory()->undefined_value()); 77 return Handle<Object>::cast(isolate()->factory()->undefined_value());
72 } 78 }
73 79
74 80
81 Handle<Object> TypeFeedbackOracle::GetInfo(int slot) {
82 ASSERT(slot >= 0 && slot < feedback_vector_->length());
83 Object* obj = feedback_vector_->get(slot);
84 if (obj->IsSmi() ||
85 obj->IsAllocationSite() ||
86 (obj->IsJSFunction() &&
87 !CanRetainOtherContext(JSFunction::cast(obj), *native_context_))) {
danno 2014/01/28 08:27:17 nit: weird indentation
mvstanton 2014/01/30 15:13:41 Addressed, but have another look.
88 return Handle<Object>(obj, isolate());
89 }
90 return Handle<Object>::cast(isolate()->factory()->undefined_value());
91 }
92
93
75 bool TypeFeedbackOracle::LoadIsUninitialized(TypeFeedbackId id) { 94 bool TypeFeedbackOracle::LoadIsUninitialized(TypeFeedbackId id) {
76 Handle<Object> maybe_code = GetInfo(id); 95 Handle<Object> maybe_code = GetInfo(id);
77 if (maybe_code->IsCode()) { 96 if (maybe_code->IsCode()) {
78 Handle<Code> code = Handle<Code>::cast(maybe_code); 97 Handle<Code> code = Handle<Code>::cast(maybe_code);
79 return code->is_inline_cache_stub() && code->ic_state() == UNINITIALIZED; 98 return code->is_inline_cache_stub() && code->ic_state() == UNINITIALIZED;
80 } 99 }
81 return false; 100 return false;
82 } 101 }
83 102
84 103
(...skipping 29 matching lines...) Expand all
114 Handle<Object> maybe_code = GetInfo(ast_id); 133 Handle<Object> maybe_code = GetInfo(ast_id);
115 if (maybe_code->IsCode()) { 134 if (maybe_code->IsCode()) {
116 Handle<Code> code = Handle<Code>::cast(maybe_code); 135 Handle<Code> code = Handle<Code>::cast(maybe_code);
117 return code->is_keyed_store_stub() && 136 return code->is_keyed_store_stub() &&
118 code->ic_state() == POLYMORPHIC; 137 code->ic_state() == POLYMORPHIC;
119 } 138 }
120 return false; 139 return false;
121 } 140 }
122 141
123 142
143 bool TypeFeedbackOracle::CallIsMonomorphic(int slot) {
144 Handle<Object> value = GetInfo(slot);
145 return value->IsAllocationSite() || value->IsJSFunction();
146 }
147
148
124 bool TypeFeedbackOracle::CallIsMonomorphic(TypeFeedbackId id) { 149 bool TypeFeedbackOracle::CallIsMonomorphic(TypeFeedbackId id) {
125 Handle<Object> value = GetInfo(id); 150 Handle<Object> value = GetInfo(id);
126 return value->IsAllocationSite() || value->IsJSFunction() || value->IsSmi() || 151 return value->IsSmi() ||
127 (value->IsCode() && Handle<Code>::cast(value)->ic_state() == MONOMORPHIC); 152 (value->IsCode() && Handle<Code>::cast(value)->ic_state() == MONOMORPHIC);
128 } 153 }
129 154
130 155
131 bool TypeFeedbackOracle::KeyedArrayCallIsHoley(TypeFeedbackId id) { 156 bool TypeFeedbackOracle::KeyedArrayCallIsHoley(TypeFeedbackId id) {
132 Handle<Object> value = GetInfo(id); 157 Handle<Object> value = GetInfo(id);
133 Handle<Code> code = Handle<Code>::cast(value); 158 Handle<Code> code = Handle<Code>::cast(value);
134 return KeyedArrayCallStub::IsHoley(code); 159 return KeyedArrayCallStub::IsHoley(code);
135 } 160 }
136 161
137 162
138 bool TypeFeedbackOracle::CallNewIsMonomorphic(TypeFeedbackId id) { 163 bool TypeFeedbackOracle::CallNewIsMonomorphic(int slot) {
139 Handle<Object> info = GetInfo(id); 164 Handle<Object> info = GetInfo(slot);
140 return info->IsAllocationSite() || info->IsJSFunction(); 165 return info->IsAllocationSite() || info->IsJSFunction();
141 } 166 }
142 167
143 168
144 byte TypeFeedbackOracle::ForInType(TypeFeedbackId id) { 169 byte TypeFeedbackOracle::ForInType(int feedback_vector_slot) {
145 Handle<Object> value = GetInfo(id); 170 Handle<Object> value = GetInfo(feedback_vector_slot);
146 return value->IsSmi() && 171 return value->IsSmi() &&
147 Smi::cast(*value)->value() == TypeFeedbackCells::kForInFastCaseMarker 172 Smi::cast(*value)->value() == TypeFeedbackInfo::kForInFastCaseMarker
148 ? ForInStatement::FAST_FOR_IN : ForInStatement::SLOW_FOR_IN; 173 ? ForInStatement::FAST_FOR_IN : ForInStatement::SLOW_FOR_IN;
149 } 174 }
150 175
151 176
152 KeyedAccessStoreMode TypeFeedbackOracle::GetStoreMode( 177 KeyedAccessStoreMode TypeFeedbackOracle::GetStoreMode(
153 TypeFeedbackId ast_id) { 178 TypeFeedbackId ast_id) {
154 Handle<Object> maybe_code = GetInfo(ast_id); 179 Handle<Object> maybe_code = GetInfo(ast_id);
155 if (maybe_code->IsCode()) { 180 if (maybe_code->IsCode()) {
156 Handle<Code> code = Handle<Code>::cast(maybe_code); 181 Handle<Code> code = Handle<Code>::cast(maybe_code);
157 if (code->kind() == Code::KEYED_STORE_IC) { 182 if (code->kind() == Code::KEYED_STORE_IC) {
(...skipping 16 matching lines...) Expand all
174 199
175 CheckType TypeFeedbackOracle::GetCallCheckType(TypeFeedbackId id) { 200 CheckType TypeFeedbackOracle::GetCallCheckType(TypeFeedbackId id) {
176 Handle<Object> value = GetInfo(id); 201 Handle<Object> value = GetInfo(id);
177 if (!value->IsSmi()) return RECEIVER_MAP_CHECK; 202 if (!value->IsSmi()) return RECEIVER_MAP_CHECK;
178 CheckType check = static_cast<CheckType>(Smi::cast(*value)->value()); 203 CheckType check = static_cast<CheckType>(Smi::cast(*value)->value());
179 ASSERT(check != RECEIVER_MAP_CHECK); 204 ASSERT(check != RECEIVER_MAP_CHECK);
180 return check; 205 return check;
181 } 206 }
182 207
183 208
184 Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(TypeFeedbackId id) { 209 Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(int slot) {
185 Handle<Object> info = GetInfo(id); 210 Handle<Object> info = GetInfo(slot);
186 if (info->IsAllocationSite()) { 211 if (info->IsAllocationSite()) {
187 return Handle<JSFunction>(isolate()->global_context()->array_function()); 212 return Handle<JSFunction>(isolate()->global_context()->array_function());
188 } else { 213 } else {
189 return Handle<JSFunction>::cast(info); 214 return Handle<JSFunction>::cast(info);
190 } 215 }
191 } 216 }
192 217
193 218
194 Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(TypeFeedbackId id) { 219 Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(int slot) {
195 Handle<Object> info = GetInfo(id); 220 Handle<Object> info = GetInfo(slot);
196 if (info->IsAllocationSite()) { 221 if (info->IsAllocationSite()) {
197 return Handle<JSFunction>(isolate()->global_context()->array_function()); 222 return Handle<JSFunction>(isolate()->global_context()->array_function());
198 } else { 223 } else {
199 return Handle<JSFunction>::cast(info); 224 return Handle<JSFunction>::cast(info);
200 } 225 }
201 } 226 }
202 227
203 228
204 Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite( 229 Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite(int slot) {
205 TypeFeedbackId id) { 230 Handle<Object> info = GetInfo(slot);
206 Handle<Object> info = GetInfo(id);
207 if (info->IsAllocationSite()) { 231 if (info->IsAllocationSite()) {
208 return Handle<AllocationSite>::cast(info); 232 return Handle<AllocationSite>::cast(info);
209 } 233 }
210 return Handle<AllocationSite>::null(); 234 return Handle<AllocationSite>::null();
211 } 235 }
212 236
213 237
214 bool TypeFeedbackOracle::LoadIsBuiltin( 238 bool TypeFeedbackOracle::LoadIsBuiltin(
215 TypeFeedbackId id, Builtins::Name builtin) { 239 TypeFeedbackId id, Builtins::Name builtin) {
216 return *GetInfo(id) == isolate()->builtins()->builtin(builtin); 240 return *GetInfo(id) == isolate()->builtins()->builtin(builtin);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // themselves are not GC-safe, so we first get all infos, then we create the 473 // themselves are not GC-safe, so we first get all infos, then we create the
450 // dictionary (possibly triggering GC), and finally we relocate the collected 474 // dictionary (possibly triggering GC), and finally we relocate the collected
451 // infos before we process them. 475 // infos before we process them.
452 void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) { 476 void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) {
453 DisallowHeapAllocation no_allocation; 477 DisallowHeapAllocation no_allocation;
454 ZoneList<RelocInfo> infos(16, zone()); 478 ZoneList<RelocInfo> infos(16, zone());
455 HandleScope scope(isolate()); 479 HandleScope scope(isolate());
456 GetRelocInfos(code, &infos); 480 GetRelocInfos(code, &infos);
457 CreateDictionary(code, &infos); 481 CreateDictionary(code, &infos);
458 ProcessRelocInfos(&infos); 482 ProcessRelocInfos(&infos);
459 ProcessTypeFeedbackCells(code);
460 // Allocate handle in the parent scope. 483 // Allocate handle in the parent scope.
461 dictionary_ = scope.CloseAndEscape(dictionary_); 484 dictionary_ = scope.CloseAndEscape(dictionary_);
462 } 485 }
463 486
464 487
465 void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code, 488 void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code,
466 ZoneList<RelocInfo>* infos) { 489 ZoneList<RelocInfo>* infos) {
467 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); 490 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID);
468 for (RelocIterator it(*code, mask); !it.done(); it.next()) { 491 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
469 infos->Add(*it.rinfo(), zone()); 492 infos->Add(*it.rinfo(), zone());
470 } 493 }
471 } 494 }
472 495
473 496
474 void TypeFeedbackOracle::CreateDictionary(Handle<Code> code, 497 void TypeFeedbackOracle::CreateDictionary(Handle<Code> code,
475 ZoneList<RelocInfo>* infos) { 498 ZoneList<RelocInfo>* infos) {
476 AllowHeapAllocation allocation_allowed; 499 AllowHeapAllocation allocation_allowed;
477 int cell_count = code->type_feedback_info()->IsTypeFeedbackInfo()
478 ? TypeFeedbackInfo::cast(code->type_feedback_info())->
479 type_feedback_cells()->CellCount()
480 : 0;
481 int length = infos->length() + cell_count;
482 byte* old_start = code->instruction_start(); 500 byte* old_start = code->instruction_start();
483 dictionary_ = isolate()->factory()->NewUnseededNumberDictionary(length); 501 dictionary_ =
502 isolate()->factory()->NewUnseededNumberDictionary(infos->length());
484 byte* new_start = code->instruction_start(); 503 byte* new_start = code->instruction_start();
485 RelocateRelocInfos(infos, old_start, new_start); 504 RelocateRelocInfos(infos, old_start, new_start);
486 } 505 }
487 506
488 507
489 void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos, 508 void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos,
490 byte* old_start, 509 byte* old_start,
491 byte* new_start) { 510 byte* new_start) {
492 for (int i = 0; i < infos->length(); i++) { 511 for (int i = 0; i < infos->length(); i++) {
493 RelocInfo* info = &(*infos)[i]; 512 RelocInfo* info = &(*infos)[i];
(...skipping 28 matching lines...) Expand all
522 SetInfo(ast_id, target); 541 SetInfo(ast_id, target);
523 break; 542 break;
524 543
525 default: 544 default:
526 break; 545 break;
527 } 546 }
528 } 547 }
529 } 548 }
530 549
531 550
532 void TypeFeedbackOracle::ProcessTypeFeedbackCells(Handle<Code> code) {
533 Object* raw_info = code->type_feedback_info();
534 if (!raw_info->IsTypeFeedbackInfo()) return;
535 Handle<TypeFeedbackCells> cache(
536 TypeFeedbackInfo::cast(raw_info)->type_feedback_cells());
537 for (int i = 0; i < cache->CellCount(); i++) {
538 TypeFeedbackId ast_id = cache->AstId(i);
539 Cell* cell = cache->GetCell(i);
540 Object* value = cell->value();
541 if (value->IsSmi() ||
542 value->IsAllocationSite() ||
543 (value->IsJSFunction() &&
544 !CanRetainOtherContext(JSFunction::cast(value),
545 *native_context_))) {
546 SetInfo(ast_id, cell);
547 }
548 }
549 }
550
551
552 void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) { 551 void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) {
553 ASSERT(dictionary_->FindEntry(IdToKey(ast_id)) == 552 ASSERT(dictionary_->FindEntry(IdToKey(ast_id)) ==
554 UnseededNumberDictionary::kNotFound); 553 UnseededNumberDictionary::kNotFound);
555 MaybeObject* maybe_result = dictionary_->AtNumberPut(IdToKey(ast_id), target); 554 MaybeObject* maybe_result = dictionary_->AtNumberPut(IdToKey(ast_id), target);
556 USE(maybe_result); 555 USE(maybe_result);
557 #ifdef DEBUG 556 #ifdef DEBUG
558 Object* result = NULL; 557 Object* result = NULL;
559 // Dictionary has been allocated with sufficient size for all elements. 558 // Dictionary has been allocated with sufficient size for all elements.
560 ASSERT(maybe_result->ToObject(&result)); 559 ASSERT(maybe_result->ToObject(&result));
561 ASSERT(*dictionary_ == result); 560 ASSERT(*dictionary_ == result);
562 #endif 561 #endif
563 } 562 }
564 563
565 564
566 } } // namespace v8::internal 565 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698