OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 | 56 |
57 static int* GetInternalPointer(StatsCounter* counter) { | 57 static int* GetInternalPointer(StatsCounter* counter) { |
58 // All counters refer to dummy_counter, if deserializing happens without | 58 // All counters refer to dummy_counter, if deserializing happens without |
59 // setting up counters. | 59 // setting up counters. |
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* ExternalReferenceTable::instance(Isolate* isolate) { |
66 // between external references and their encodings. It is used to build | 66 ExternalReferenceTable* external_reference_table = |
67 // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder. | 67 isolate->external_reference_table(); |
68 class ExternalReferenceTable { | 68 if (external_reference_table == NULL) { |
69 public: | 69 external_reference_table = new ExternalReferenceTable(isolate); |
70 static ExternalReferenceTable* instance(Isolate* isolate) { | 70 isolate->set_external_reference_table(external_reference_table); |
71 ExternalReferenceTable* external_reference_table = | |
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; | |
78 } | 71 } |
79 | 72 return external_reference_table; |
80 int size() const { return refs_.length(); } | 73 } |
81 | |
82 Address address(int i) { return refs_[i].address; } | |
83 | |
84 uint32_t code(int i) { return refs_[i].code; } | |
85 | |
86 const char* name(int i) { return refs_[i].name; } | |
87 | |
88 int max_id(int code) { return max_id_[code]; } | |
89 | |
90 private: | |
91 explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) { | |
92 PopulateTable(isolate); | |
93 } | |
94 ~ExternalReferenceTable() { } | |
95 | |
96 struct ExternalReferenceEntry { | |
97 Address address; | |
98 uint32_t code; | |
99 const char* name; | |
100 }; | |
101 | |
102 void PopulateTable(Isolate* isolate); | |
103 | |
104 // For a few types of references, we can get their address from their id. | |
105 void AddFromId(TypeCode type, | |
106 uint16_t id, | |
107 const char* name, | |
108 Isolate* isolate); | |
109 | |
110 // For other types of references, the caller will figure out the address. | |
111 void Add(Address address, TypeCode type, uint16_t id, const char* name); | |
112 | |
113 List<ExternalReferenceEntry> refs_; | |
114 int max_id_[kTypeCodeCount]; | |
115 }; | |
116 | 74 |
117 | 75 |
118 void ExternalReferenceTable::AddFromId(TypeCode type, | 76 void ExternalReferenceTable::AddFromId(TypeCode type, |
119 uint16_t id, | 77 uint16_t id, |
120 const char* name, | 78 const char* name, |
121 Isolate* isolate) { | 79 Isolate* isolate) { |
122 Address address; | 80 Address address; |
123 switch (type) { | 81 switch (type) { |
124 case C_BUILTIN: { | 82 case C_BUILTIN: { |
125 ExternalReference ref(static_cast<Builtins::CFunctionId>(id), isolate); | 83 ExternalReference ref(static_cast<Builtins::CFunctionId>(id), isolate); |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize); | 1523 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize); |
1566 } | 1524 } |
1567 } | 1525 } |
1568 int allocation_address = fullness_[space]; | 1526 int allocation_address = fullness_[space]; |
1569 fullness_[space] = allocation_address + size; | 1527 fullness_[space] = allocation_address + size; |
1570 return allocation_address; | 1528 return allocation_address; |
1571 } | 1529 } |
1572 | 1530 |
1573 | 1531 |
1574 } } // namespace v8::internal | 1532 } } // namespace v8::internal |
OLD | NEW |