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

Side by Side Diff: src/serialize.cc

Issue 2864032: [Isolates] Statics 7: ExternalReference*/Simulator/dtoa... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: rebase Created 10 years, 5 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
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 static int dummy_counter = 0; 60 static int dummy_counter = 0;
61 return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter; 61 return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter;
62 } 62 }
63 63
64 64
65 // ExternalReferenceTable is a helper class that defines the relationship 65 // ExternalReferenceTable is a helper class that defines the relationship
66 // between external references and their encodings. It is used to build 66 // between external references and their encodings. It is used to build
67 // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder. 67 // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
68 class ExternalReferenceTable { 68 class ExternalReferenceTable {
69 public: 69 public:
70 static ExternalReferenceTable* instance() { 70 static ExternalReferenceTable* instance(Isolate* isolate) {
71 if (!instance_) instance_ = new ExternalReferenceTable(); 71 ExternalReferenceTable* external_reference_table =
72 return instance_; 72 isolate->external_reference_table();
73 if (external_reference_table == NULL) {
74 external_reference_table = new ExternalReferenceTable(isolate);
75 isolate->set_external_reference_table(external_reference_table);
76 }
77 return external_reference_table;
73 } 78 }
74 79
75 int size() const { return refs_.length(); } 80 int size() const { return refs_.length(); }
76 81
77 Address address(int i) { return refs_[i].address; } 82 Address address(int i) { return refs_[i].address; }
78 83
79 uint32_t code(int i) { return refs_[i].code; } 84 uint32_t code(int i) { return refs_[i].code; }
80 85
81 const char* name(int i) { return refs_[i].name; } 86 const char* name(int i) { return refs_[i].name; }
82 87
83 int max_id(int code) { return max_id_[code]; } 88 int max_id(int code) { return max_id_[code]; }
84 89
85 private: 90 private:
86 static ExternalReferenceTable* instance_; 91 explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) {
87 92 PopulateTable(isolate);
88 ExternalReferenceTable() : refs_(64) { PopulateTable(); } 93 }
89 ~ExternalReferenceTable() { } 94 ~ExternalReferenceTable() { }
90 95
91 struct ExternalReferenceEntry { 96 struct ExternalReferenceEntry {
92 Address address; 97 Address address;
93 uint32_t code; 98 uint32_t code;
94 const char* name; 99 const char* name;
95 }; 100 };
96 101
97 void PopulateTable(); 102 void PopulateTable(Isolate* isolate);
98 103
99 // For a few types of references, we can get their address from their id. 104 // For a few types of references, we can get their address from their id.
100 void AddFromId(TypeCode type, uint16_t id, const char* name); 105 void AddFromId(TypeCode type, uint16_t id, const char* name);
101 106
102 // For other types of references, the caller will figure out the address. 107 // For other types of references, the caller will figure out the address.
103 void Add(Address address, TypeCode type, uint16_t id, const char* name); 108 void Add(Address address, TypeCode type, uint16_t id, const char* name);
104 109
105 List<ExternalReferenceEntry> refs_; 110 List<ExternalReferenceEntry> refs_;
106 int max_id_[kTypeCodeCount]; 111 int max_id_[kTypeCodeCount];
107 }; 112 };
108 113
109 114
110 ExternalReferenceTable* ExternalReferenceTable::instance_ = NULL;
111
112
113 void ExternalReferenceTable::AddFromId(TypeCode type, 115 void ExternalReferenceTable::AddFromId(TypeCode type,
114 uint16_t id, 116 uint16_t id,
115 const char* name) { 117 const char* name) {
116 Address address; 118 Address address;
117 switch (type) { 119 switch (type) {
118 case C_BUILTIN: { 120 case C_BUILTIN: {
119 ExternalReference ref(static_cast<Builtins::CFunctionId>(id)); 121 ExternalReference ref(static_cast<Builtins::CFunctionId>(id));
120 address = ref.address(); 122 address = ref.address();
121 break; 123 break;
122 } 124 }
(...skipping 28 matching lines...) Expand all
151 ExternalReferenceEntry entry; 153 ExternalReferenceEntry entry;
152 entry.address = address; 154 entry.address = address;
153 entry.code = EncodeExternal(type, id); 155 entry.code = EncodeExternal(type, id);
154 entry.name = name; 156 entry.name = name;
155 ASSERT_NE(0, entry.code); 157 ASSERT_NE(0, entry.code);
156 refs_.Add(entry); 158 refs_.Add(entry);
157 if (id > max_id_[type]) max_id_[type] = id; 159 if (id > max_id_[type]) max_id_[type] = id;
158 } 160 }
159 161
160 162
161 void ExternalReferenceTable::PopulateTable() { 163 void ExternalReferenceTable::PopulateTable(Isolate* isolate) {
162 Isolate* isolate = Isolate::Current();
163
164 for (int type_code = 0; type_code < kTypeCodeCount; type_code++) { 164 for (int type_code = 0; type_code < kTypeCodeCount; type_code++) {
165 max_id_[type_code] = 0; 165 max_id_[type_code] = 0;
166 } 166 }
167 167
168 // The following populates all of the different type of external references 168 // The following populates all of the different type of external references
169 // into the ExternalReferenceTable. 169 // into the ExternalReferenceTable.
170 // 170 //
171 // NOTE: This function was originally 100k of code. It has since been 171 // NOTE: This function was originally 100k of code. It has since been
172 // rewritten to be mostly table driven, as the callback macro style tends to 172 // rewritten to be mostly table driven, as the callback macro style tends to
173 // very easily cause code bloat. Please be careful in the future when adding 173 // very easily cause code bloat. Please be careful in the future when adding
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 28, 462 28,
463 "KeyedLookupCache::field_offsets()"); 463 "KeyedLookupCache::field_offsets()");
464 Add(ExternalReference::transcendental_cache_array_address().address(), 464 Add(ExternalReference::transcendental_cache_array_address().address(),
465 UNCLASSIFIED, 465 UNCLASSIFIED,
466 29, 466 29,
467 "TranscendentalCache::caches()"); 467 "TranscendentalCache::caches()");
468 } 468 }
469 469
470 470
471 ExternalReferenceEncoder::ExternalReferenceEncoder() 471 ExternalReferenceEncoder::ExternalReferenceEncoder()
472 : encodings_(Match) { 472 : encodings_(Match),
473 isolate_(Isolate::Current()) {
473 ExternalReferenceTable* external_references = 474 ExternalReferenceTable* external_references =
474 ExternalReferenceTable::instance(); 475 ExternalReferenceTable::instance(isolate_);
475 for (int i = 0; i < external_references->size(); ++i) { 476 for (int i = 0; i < external_references->size(); ++i) {
476 Put(external_references->address(i), i); 477 Put(external_references->address(i), i);
477 } 478 }
478 } 479 }
479 480
480 481
481 uint32_t ExternalReferenceEncoder::Encode(Address key) const { 482 uint32_t ExternalReferenceEncoder::Encode(Address key) const {
482 int index = IndexOf(key); 483 int index = IndexOf(key);
483 return index >=0 ? ExternalReferenceTable::instance()->code(index) : 0; 484 return index >= 0 ?
485 ExternalReferenceTable::instance(isolate_)->code(index) : 0;
484 } 486 }
485 487
486 488
487 const char* ExternalReferenceEncoder::NameOfAddress(Address key) const { 489 const char* ExternalReferenceEncoder::NameOfAddress(Address key) const {
488 int index = IndexOf(key); 490 int index = IndexOf(key);
489 return index >=0 ? ExternalReferenceTable::instance()->name(index) : NULL; 491 return index >= 0 ?
492 ExternalReferenceTable::instance(isolate_)->name(index) : NULL;
490 } 493 }
491 494
492 495
493 int ExternalReferenceEncoder::IndexOf(Address key) const { 496 int ExternalReferenceEncoder::IndexOf(Address key) const {
494 if (key == NULL) return -1; 497 if (key == NULL) return -1;
495 HashMap::Entry* entry = 498 HashMap::Entry* entry =
496 const_cast<HashMap &>(encodings_).Lookup(key, Hash(key), false); 499 const_cast<HashMap&>(encodings_).Lookup(key, Hash(key), false);
497 return entry == NULL 500 return entry == NULL
498 ? -1 501 ? -1
499 : static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 502 : static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
500 } 503 }
501 504
502 505
503 void ExternalReferenceEncoder::Put(Address key, int index) { 506 void ExternalReferenceEncoder::Put(Address key, int index) {
504 HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true); 507 HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true);
505 entry->value = reinterpret_cast<void*>(index); 508 entry->value = reinterpret_cast<void*>(index);
506 } 509 }
507 510
508 511
509 ExternalReferenceDecoder::ExternalReferenceDecoder() 512 ExternalReferenceDecoder::ExternalReferenceDecoder()
510 : encodings_(NewArray<Address*>(kTypeCodeCount)) { 513 : encodings_(NewArray<Address*>(kTypeCodeCount)),
514 isolate_(Isolate::Current()) {
511 ExternalReferenceTable* external_references = 515 ExternalReferenceTable* external_references =
512 ExternalReferenceTable::instance(); 516 ExternalReferenceTable::instance(isolate_);
513 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { 517 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
514 int max = external_references->max_id(type) + 1; 518 int max = external_references->max_id(type) + 1;
515 encodings_[type] = NewArray<Address>(max + 1); 519 encodings_[type] = NewArray<Address>(max + 1);
516 } 520 }
517 for (int i = 0; i < external_references->size(); ++i) { 521 for (int i = 0; i < external_references->size(); ++i) {
518 Put(external_references->code(i), external_references->address(i)); 522 Put(external_references->code(i), external_references->address(i));
519 } 523 }
520 } 524 }
521 525
522 526
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize); 1467 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize);
1464 } 1468 }
1465 } 1469 }
1466 int allocation_address = fullness_[space]; 1470 int allocation_address = fullness_[space];
1467 fullness_[space] = allocation_address + size; 1471 fullness_[space] = allocation_address + size;
1468 return allocation_address; 1472 return allocation_address;
1469 } 1473 }
1470 1474
1471 1475
1472 } } // namespace v8::internal 1476 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698