Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 // scripts and evals. The boilerplates are looked up using the source | 35 // scripts and evals. The boilerplates are looked up using the source |
| 36 // string as the key. | 36 // string as the key. |
| 37 class CompilationCache { | 37 class CompilationCache { |
| 38 public: | 38 public: |
| 39 // The same source code string has different compiled code for | 39 // The same source code string has different compiled code for |
| 40 // scripts and evals. Internally, we use separate caches to avoid | 40 // scripts and evals. Internally, we use separate caches to avoid |
| 41 // getting the wrong kind of entry when looking up. | 41 // getting the wrong kind of entry when looking up. |
| 42 enum Entry { | 42 enum Entry { |
| 43 SCRIPT, | 43 SCRIPT, |
| 44 EVAL_GLOBAL, | 44 EVAL_GLOBAL, |
| 45 EVAL_CONTEXTUAL | 45 EVAL_CONTEXTUAL, |
| 46 REGEXP, | |
| 47 _LAST_ENTRY | |
|
Kasper Lund
2008/10/24 06:42:50
I would change _LAST_ENTRY to LAST_ENTRY and let i
| |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 // Finds the script function boilerplate for a source | 50 // Finds the script function boilerplate for a source |
| 49 // string. Returns an empty handle if the cache doesn't contain a | 51 // string. Returns an empty handle if the cache doesn't contain a |
| 50 // script for the given source string with the right origin. | 52 // script for the given source string with the right origin. |
| 51 static Handle<JSFunction> LookupScript(Handle<String> source, | 53 static Handle<JSFunction> LookupScript(Handle<String> source, |
| 52 Handle<Object> name, | 54 Handle<Object> name, |
| 53 int line_offset, | 55 int line_offset, |
| 54 int column_offset); | 56 int column_offset); |
| 55 | 57 |
| 56 // Finds the function boilerplate for a source string for | 58 // Finds the function boilerplate for a source string for |
| 57 // eval. Returns an empty handle if the cache doesn't contain a | 59 // eval. Returns an empty handle if the cache doesn't contain a |
| 58 // script for the given source string. | 60 // script for the given source string. |
| 59 static Handle<JSFunction> LookupEval(Handle<String> source, | 61 static Handle<JSFunction> LookupEval(Handle<String> source, |
| 60 Entry entry); | 62 Entry entry); |
| 61 | 63 |
| 64 static Handle<Object> LookupRegExp(Handle<String> source, | |
|
Kasper Lund
2008/10/24 06:42:50
Maybe you should explain return value in case of a
| |
| 65 int flags); | |
| 66 | |
| 67 static void PutRegExp(Handle<String> source, | |
|
Kasper Lund
2008/10/24 06:42:50
Maybe you should rename the Associate method to Pu
| |
| 68 int flags, | |
| 69 Handle<FixedArray> data); | |
| 70 | |
| 62 // Associate the (source, kind) pair to the boilerplate. This may | 71 // Associate the (source, kind) pair to the boilerplate. This may |
| 63 // overwrite an existing mapping. | 72 // overwrite an existing mapping. |
| 64 static void Associate(Handle<String> source, | 73 static void Associate(Handle<String> source, |
| 65 Entry entry, | 74 Entry entry, |
| 66 Handle<JSFunction> boilerplate); | 75 Handle<JSFunction> boilerplate); |
| 67 | 76 |
| 68 // Clear the cache - also used to initialize the cache at startup. | 77 // Clear the cache - also used to initialize the cache at startup. |
| 69 static void Clear(); | 78 static void Clear(); |
| 70 | 79 |
| 71 // GC support. | 80 // GC support. |
| 72 static void Iterate(ObjectVisitor* v); | 81 static void Iterate(ObjectVisitor* v); |
| 73 | 82 |
| 74 // Notify the cache that a mark-sweep garbage collection is about to | 83 // Notify the cache that a mark-sweep garbage collection is about to |
| 75 // take place. This is used to retire entries from the cache to | 84 // take place. This is used to retire entries from the cache to |
| 76 // avoid keeping them alive too long without using them. For now, we | 85 // avoid keeping them alive too long without using them. For now, we |
| 77 // just clear the cache but we should consider are more | 86 // just clear the cache but we should consider are more |
| 78 // sophisticated LRU scheme. | 87 // sophisticated LRU scheme. |
| 79 static void MarkCompactPrologue() { Clear(); } | 88 static void MarkCompactPrologue() { Clear(); } |
| 80 }; | 89 }; |
| 81 | 90 |
| 82 | 91 |
| 83 } } // namespace v8::internal | 92 } } // namespace v8::internal |
| 84 | 93 |
| 85 #endif // V8_COMPILATION_CACHE_H_ | 94 #endif // V8_COMPILATION_CACHE_H_ |
| OLD | NEW |