| 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 5035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5046 // Regular expressions | 5046 // Regular expressions |
| 5047 // The regular expression holds a single reference to a FixedArray in | 5047 // The regular expression holds a single reference to a FixedArray in |
| 5048 // the kDataOffset field. | 5048 // the kDataOffset field. |
| 5049 // The FixedArray contains the following data: | 5049 // The FixedArray contains the following data: |
| 5050 // - tag : type of regexp implementation (not compiled yet, atom or irregexp) | 5050 // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 5051 // - reference to the original source string | 5051 // - reference to the original source string |
| 5052 // - reference to the original flag string | 5052 // - reference to the original flag string |
| 5053 // If it is an atom regexp | 5053 // If it is an atom regexp |
| 5054 // - a reference to a literal string to search for | 5054 // - a reference to a literal string to search for |
| 5055 // If it is an irregexp regexp: | 5055 // If it is an irregexp regexp: |
| 5056 // - a reference to code for ASCII inputs (bytecode or compiled). | 5056 // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 5057 // - a reference to code for UC16 inputs (bytecode or compiled). | 5057 // used for tracking the last usage (used for code flushing). |
| 5058 // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 5059 // used for tracking the last usage (used for code flushing).. |
| 5058 // - max number of registers used by irregexp implementations. | 5060 // - max number of registers used by irregexp implementations. |
| 5059 // - number of capture registers (output values) of the regexp. | 5061 // - number of capture registers (output values) of the regexp. |
| 5060 class JSRegExp: public JSObject { | 5062 class JSRegExp: public JSObject { |
| 5061 public: | 5063 public: |
| 5062 // Meaning of Type: | 5064 // Meaning of Type: |
| 5063 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. | 5065 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 5064 // ATOM: A simple string to match against using an indexOf operation. | 5066 // ATOM: A simple string to match against using an indexOf operation. |
| 5065 // IRREGEXP: Compiled with Irregexp. | 5067 // IRREGEXP: Compiled with Irregexp. |
| 5066 // IRREGEXP_NATIVE: Compiled to native code with Irregexp. | 5068 // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 5067 enum Type { NOT_COMPILED, ATOM, IRREGEXP }; | 5069 enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5080 | 5082 |
| 5081 DECL_ACCESSORS(data, Object) | 5083 DECL_ACCESSORS(data, Object) |
| 5082 | 5084 |
| 5083 inline Type TypeTag(); | 5085 inline Type TypeTag(); |
| 5084 inline int CaptureCount(); | 5086 inline int CaptureCount(); |
| 5085 inline Flags GetFlags(); | 5087 inline Flags GetFlags(); |
| 5086 inline String* Pattern(); | 5088 inline String* Pattern(); |
| 5087 inline Object* DataAt(int index); | 5089 inline Object* DataAt(int index); |
| 5088 // Set implementation data after the object has been prepared. | 5090 // Set implementation data after the object has been prepared. |
| 5089 inline void SetDataAt(int index, Object* value); | 5091 inline void SetDataAt(int index, Object* value); |
| 5092 |
| 5093 // Used during GC when flushing code or setting age. |
| 5094 inline Object* DataAtUnchecked(int index); |
| 5095 inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 5096 inline Type TypeTagUnchecked(); |
| 5097 |
| 5090 static int code_index(bool is_ascii) { | 5098 static int code_index(bool is_ascii) { |
| 5091 if (is_ascii) { | 5099 if (is_ascii) { |
| 5092 return kIrregexpASCIICodeIndex; | 5100 return kIrregexpASCIICodeIndex; |
| 5093 } else { | 5101 } else { |
| 5094 return kIrregexpUC16CodeIndex; | 5102 return kIrregexpUC16CodeIndex; |
| 5095 } | 5103 } |
| 5096 } | 5104 } |
| 5097 | 5105 |
| 5106 static int saved_code_index(bool is_ascii) { |
| 5107 if (is_ascii) { |
| 5108 return kIrregexpASCIICodeSavedIndex; |
| 5109 } else { |
| 5110 return kIrregexpUC16CodeSavedIndex; |
| 5111 } |
| 5112 } |
| 5113 |
| 5098 static inline JSRegExp* cast(Object* obj); | 5114 static inline JSRegExp* cast(Object* obj); |
| 5099 | 5115 |
| 5100 // Dispatched behavior. | 5116 // Dispatched behavior. |
| 5101 #ifdef DEBUG | 5117 #ifdef DEBUG |
| 5102 void JSRegExpVerify(); | 5118 void JSRegExpVerify(); |
| 5103 #endif | 5119 #endif |
| 5104 | 5120 |
| 5105 static const int kDataOffset = JSObject::kHeaderSize; | 5121 static const int kDataOffset = JSObject::kHeaderSize; |
| 5106 static const int kSize = kDataOffset + kPointerSize; | 5122 static const int kSize = kDataOffset + kPointerSize; |
| 5107 | 5123 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5118 static const int kAtomDataSize = kAtomPatternIndex + 1; | 5134 static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 5119 | 5135 |
| 5120 // Irregexp compiled code or bytecode for ASCII. If compilation | 5136 // Irregexp compiled code or bytecode for ASCII. If compilation |
| 5121 // fails, this fields hold an exception object that should be | 5137 // fails, this fields hold an exception object that should be |
| 5122 // thrown if the regexp is used again. | 5138 // thrown if the regexp is used again. |
| 5123 static const int kIrregexpASCIICodeIndex = kDataIndex; | 5139 static const int kIrregexpASCIICodeIndex = kDataIndex; |
| 5124 // Irregexp compiled code or bytecode for UC16. If compilation | 5140 // Irregexp compiled code or bytecode for UC16. If compilation |
| 5125 // fails, this fields hold an exception object that should be | 5141 // fails, this fields hold an exception object that should be |
| 5126 // thrown if the regexp is used again. | 5142 // thrown if the regexp is used again. |
| 5127 static const int kIrregexpUC16CodeIndex = kDataIndex + 1; | 5143 static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
| 5144 |
| 5145 // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 5146 // is a potential candidate for flushing. |
| 5147 static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 5148 // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 5149 // a potential candidate for flushing. |
| 5150 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 5151 |
| 5128 // Maximal number of registers used by either ASCII or UC16. | 5152 // Maximal number of registers used by either ASCII or UC16. |
| 5129 // Only used to check that there is enough stack space | 5153 // Only used to check that there is enough stack space |
| 5130 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2; | 5154 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
| 5131 // Number of captures in the compiled regexp. | 5155 // Number of captures in the compiled regexp. |
| 5132 static const int kIrregexpCaptureCountIndex = kDataIndex + 3; | 5156 static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
| 5133 | 5157 |
| 5134 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; | 5158 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
| 5135 | 5159 |
| 5136 // Offsets directly into the data fixed array. | 5160 // Offsets directly into the data fixed array. |
| 5137 static const int kDataTagOffset = | 5161 static const int kDataTagOffset = |
| 5138 FixedArray::kHeaderSize + kTagIndex * kPointerSize; | 5162 FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 5139 static const int kDataAsciiCodeOffset = | 5163 static const int kDataAsciiCodeOffset = |
| 5140 FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; | 5164 FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
| 5141 static const int kDataUC16CodeOffset = | 5165 static const int kDataUC16CodeOffset = |
| 5142 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; | 5166 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
| 5143 static const int kIrregexpCaptureCountOffset = | 5167 static const int kIrregexpCaptureCountOffset = |
| 5144 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; | 5168 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
| 5145 | 5169 |
| 5146 // In-object fields. | 5170 // In-object fields. |
| 5147 static const int kSourceFieldIndex = 0; | 5171 static const int kSourceFieldIndex = 0; |
| 5148 static const int kGlobalFieldIndex = 1; | 5172 static const int kGlobalFieldIndex = 1; |
| 5149 static const int kIgnoreCaseFieldIndex = 2; | 5173 static const int kIgnoreCaseFieldIndex = 2; |
| 5150 static const int kMultilineFieldIndex = 3; | 5174 static const int kMultilineFieldIndex = 3; |
| 5151 static const int kLastIndexFieldIndex = 4; | 5175 static const int kLastIndexFieldIndex = 4; |
| 5152 static const int kInObjectFieldCount = 5; | 5176 static const int kInObjectFieldCount = 5; |
| 5177 |
| 5178 // The uninitialized value for a regexp code object. |
| 5179 static const int kUninitializedValue = -1; |
| 5180 |
| 5181 // The compilation error value for the regexp code object. The real error |
| 5182 // object is in the saved code field. |
| 5183 static const int kCompilationErrorValue = -2; |
| 5184 |
| 5185 // When we store the sweep generation at which we moved the code from the |
| 5186 // code index to the saved code index we mask it of to be in the [0:255] |
| 5187 // range. |
| 5188 static const int kCodeAgeMask = 0xff; |
| 5153 }; | 5189 }; |
| 5154 | 5190 |
| 5155 | 5191 |
| 5156 class CompilationCacheShape { | 5192 class CompilationCacheShape { |
| 5157 public: | 5193 public: |
| 5158 static inline bool IsMatch(HashTableKey* key, Object* value) { | 5194 static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5159 return key->IsMatch(value); | 5195 return key->IsMatch(value); |
| 5160 } | 5196 } |
| 5161 | 5197 |
| 5162 static inline uint32_t Hash(HashTableKey* key) { | 5198 static inline uint32_t Hash(HashTableKey* key) { |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6829 } else { | 6865 } else { |
| 6830 value &= ~(1 << bit_position); | 6866 value &= ~(1 << bit_position); |
| 6831 } | 6867 } |
| 6832 return value; | 6868 return value; |
| 6833 } | 6869 } |
| 6834 }; | 6870 }; |
| 6835 | 6871 |
| 6836 } } // namespace v8::internal | 6872 } } // namespace v8::internal |
| 6837 | 6873 |
| 6838 #endif // V8_OBJECTS_H_ | 6874 #endif // V8_OBJECTS_H_ |
| OLD | NEW |