OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Keep separate tables for the different entry kinds. | 47 // Keep separate tables for the different entry kinds. |
48 static Object* tables[NUMBER_OF_TABLE_ENTRIES] = { 0, }; | 48 static Object* tables[NUMBER_OF_TABLE_ENTRIES] = { 0, }; |
49 | 49 |
50 | 50 |
51 static Handle<CompilationCacheTable> AllocateTable(int size) { | 51 static Handle<CompilationCacheTable> AllocateTable(int size) { |
52 CALL_HEAP_FUNCTION(CompilationCacheTable::Allocate(size), | 52 CALL_HEAP_FUNCTION(CompilationCacheTable::Allocate(size), |
53 CompilationCacheTable); | 53 CompilationCacheTable); |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 static Handle<CompilationCacheTable> GetTable(CompilationCache::Entry entry) { | 57 static Handle<CompilationCacheTable> GetTable(int index) { |
| 58 ASSERT(index >= 0 && index < NUMBER_OF_TABLE_ENTRIES); |
58 Handle<CompilationCacheTable> result; | 59 Handle<CompilationCacheTable> result; |
59 if (tables[entry]->IsUndefined()) { | 60 if (tables[index]->IsUndefined()) { |
60 static const int kInitialCacheSize = 64; | 61 static const int kInitialCacheSize = 64; |
61 result = AllocateTable(kInitialCacheSize); | 62 result = AllocateTable(kInitialCacheSize); |
62 tables[entry] = *result; | 63 tables[index] = *result; |
63 } else { | 64 } else { |
64 CompilationCacheTable* table = CompilationCacheTable::cast(tables[entry]); | 65 CompilationCacheTable* table = CompilationCacheTable::cast(tables[index]); |
65 result = Handle<CompilationCacheTable>(table); | 66 result = Handle<CompilationCacheTable>(table); |
66 } | 67 } |
67 return result; | 68 return result; |
68 } | 69 } |
69 | 70 |
70 | 71 |
71 static Handle<JSFunction> Lookup(Handle<String> source, | 72 static Handle<JSFunction> Lookup(Handle<String> source, |
72 Handle<Context> context, | 73 Handle<Context> context, |
73 CompilationCache::Entry entry) { | 74 CompilationCache::Entry entry) { |
74 // Make sure not to leak the table into the surrounding handle | 75 // Make sure not to leak the table into the surrounding handle |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 131 |
131 | 132 |
132 // TODO(245): Need to allow identical code from different contexts to | 133 // TODO(245): Need to allow identical code from different contexts to |
133 // be cached in the same script generation. Currently the first use | 134 // be cached in the same script generation. Currently the first use |
134 // will be cached, but subsequent code from different source / line | 135 // will be cached, but subsequent code from different source / line |
135 // won't. | 136 // won't. |
136 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, | 137 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, |
137 Handle<Object> name, | 138 Handle<Object> name, |
138 int line_offset, | 139 int line_offset, |
139 int column_offset) { | 140 int column_offset) { |
| 141 // Use an int for the generation index, so value range propagation |
| 142 // in gcc 4.3+ won't assume it can only go up to LAST_ENTRY when in |
| 143 // fact it can go up to SCRIPT + NUMBER_OF_SCRIPT_GENERATIONS. |
| 144 int generation = SCRIPT; |
140 Object* result = NULL; | 145 Object* result = NULL; |
141 Entry generation = SCRIPT; // First generation. | |
142 | 146 |
143 // Probe the script generation tables. Make sure not to leak handles | 147 // Probe the script generation tables. Make sure not to leak handles |
144 // into the caller's handle scope. | 148 // into the caller's handle scope. |
145 { HandleScope scope; | 149 { HandleScope scope; |
146 while (generation < SCRIPT + NUMBER_OF_SCRIPT_GENERATIONS) { | 150 while (generation < SCRIPT + NUMBER_OF_SCRIPT_GENERATIONS) { |
147 Handle<CompilationCacheTable> table = GetTable(generation); | 151 Handle<CompilationCacheTable> table = GetTable(generation); |
148 Handle<Object> probe(table->Lookup(*source)); | 152 Handle<Object> probe(table->Lookup(*source)); |
149 if (probe->IsJSFunction()) { | 153 if (probe->IsJSFunction()) { |
150 Handle<JSFunction> boilerplate = Handle<JSFunction>::cast(probe); | 154 Handle<JSFunction> boilerplate = Handle<JSFunction>::cast(probe); |
151 // Break when we've found a suitable boilerplate function that | 155 // Break when we've found a suitable boilerplate function that |
152 // matches the origin. | 156 // matches the origin. |
153 if (HasOrigin(boilerplate, name, line_offset, column_offset)) { | 157 if (HasOrigin(boilerplate, name, line_offset, column_offset)) { |
154 result = *boilerplate; | 158 result = *boilerplate; |
155 break; | 159 break; |
156 } | 160 } |
157 } | 161 } |
158 // Go to the next generation. | 162 // Go to the next generation. |
159 generation = static_cast<Entry>(generation + 1); | 163 generation++; |
160 } | 164 } |
161 } | 165 } |
162 | 166 |
163 // Once outside the menacles of the handle scope, we need to recheck | 167 // Once outside the menacles of the handle scope, we need to recheck |
164 // to see if we actually found a cached script. If so, we return a | 168 // to see if we actually found a cached script. If so, we return a |
165 // handle created in the caller's handle scope. | 169 // handle created in the caller's handle scope. |
166 if (result != NULL) { | 170 if (result != NULL) { |
167 Handle<JSFunction> boilerplate(JSFunction::cast(result)); | 171 Handle<JSFunction> boilerplate(JSFunction::cast(result)); |
168 ASSERT(HasOrigin(boilerplate, name, line_offset, column_offset)); | 172 ASSERT(HasOrigin(boilerplate, name, line_offset, column_offset)); |
169 // If the script was found in a later generation, we promote it to | 173 // If the script was found in a later generation, we promote it to |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 for (int i = NUMBER_OF_TABLE_ENTRIES - 1; i > SCRIPT; i--) { | 255 for (int i = NUMBER_OF_TABLE_ENTRIES - 1; i > SCRIPT; i--) { |
252 tables[i] = tables[i - 1]; | 256 tables[i] = tables[i - 1]; |
253 } | 257 } |
254 for (int j = 0; j <= LAST_ENTRY; j++) { | 258 for (int j = 0; j <= LAST_ENTRY; j++) { |
255 tables[j] = Heap::undefined_value(); | 259 tables[j] = Heap::undefined_value(); |
256 } | 260 } |
257 } | 261 } |
258 | 262 |
259 | 263 |
260 } } // namespace v8::internal | 264 } } // namespace v8::internal |
OLD | NEW |