10 js/src/vm/RegExpObject.h | 27 ++++++--------------------- |
10 js/src/vm/RegExpObject.h | 27 ++++++--------------------- |
11 js/src/yarr/wtfbridge.h | 2 -- |
11 js/src/yarr/wtfbridge.h | 2 -- |
12 5 files changed, 25 insertions(+), 89 deletions(-) |
12 5 files changed, 25 insertions(+), 89 deletions(-) |
13 |
13 |
14 diff --git a/js/src/Makefile.in b/js/src/Makefile.in |
14 diff --git a/js/src/Makefile.in b/js/src/Makefile.in |
15 index fc48cbd..49f0bdc 100644 |
|
16 --- a/js/src/Makefile.in |
15 --- a/js/src/Makefile.in |
17 +++ b/js/src/Makefile.in |
16 +++ b/js/src/Makefile.in |
18 @@ -416,15 +416,20 @@ CPPSRCS += checks.cc \ |
17 @@ -356,25 +356,30 @@ CPPSRCS += checks.cc \ |
|
18 # END enclude sources for V8 dtoa |
|
19 ############################################# |
|
20 |
|
21 # For architectures without YARR JIT, PCRE is faster than the YARR |
|
22 # interpreter (bug 684559). |
19 |
23 |
20 ifeq (,$(filter arm% sparc %86 x86_64,$(TARGET_CPU))) |
24 ifeq (,$(filter arm% sparc %86 x86_64,$(TARGET_CPU))) |
21 |
25 |
22 -VPATH += $(srcdir)/yarr/pcre \ |
26 -VPATH += $(srcdir)/yarr/pcre \ |
23 +VPATH += $(srcdir)/assembler \ |
27 +VPATH += $(srcdir)/assembler \ |
40 + YarrPattern.cpp \ |
44 + YarrPattern.cpp \ |
41 + YarrSyntaxChecker.cpp \ |
45 + YarrSyntaxChecker.cpp \ |
42 $(NULL) |
46 $(NULL) |
43 else |
47 else |
44 |
48 |
45 @@ -1015,10 +1020,10 @@ endif |
49 ############################################### |
|
50 # BEGIN include sources for the Nitro assembler |
|
51 # |
|
52 |
|
53 ENABLE_YARR_JIT = 1 |
|
54 @@ -916,20 +921,20 @@ endif |
|
55 |
|
56 ############################################### |
|
57 # BEGIN kludges for the Nitro assembler |
|
58 # |
|
59 |
46 # Needed to "configure" it correctly. Unfortunately these |
60 # Needed to "configure" it correctly. Unfortunately these |
47 # flags wind up being applied to all code in js/src, not just |
61 # flags wind up being applied to all code in js/src, not just |
48 # the code in js/src/assembler. |
62 # the code in js/src/assembler. |
49 -CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1 |
63 -CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1 |
50 +CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 |
64 +CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 |
51 |
65 |
52 ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_TRACEJIT)$(ENABLE_METHODJIT)) |
66 ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_METHODJIT)) |
53 -CXXFLAGS += -DENABLE_JIT=1 |
67 -CXXFLAGS += -DENABLE_JIT=1 |
54 +CXXFLAGS += -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1 |
68 +CXXFLAGS += -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1 |
55 endif |
69 endif |
56 |
70 |
57 INCLUDES += -I$(srcdir)/assembler -I$(srcdir)/yarr |
71 INCLUDES += -I$(srcdir)/assembler -I$(srcdir)/yarr |
|
72 |
|
73 ifdef ENABLE_METHODJIT |
|
74 # Build a standalone test program that exercises the assembler |
|
75 # sources a bit. |
|
76 TESTMAIN_OBJS = \ |
58 diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h |
77 diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h |
59 index 5f7817d..91108a7 100644 |
|
60 --- a/js/src/vm/RegExpObject-inl.h |
78 --- a/js/src/vm/RegExpObject-inl.h |
61 +++ b/js/src/vm/RegExpObject-inl.h |
79 +++ b/js/src/vm/RegExpObject-inl.h |
62 @@ -327,6 +327,7 @@ RegExpPrivate::create(JSContext *cx, JSString *source, RegExpFlag flags, TokenSt |
80 @@ -362,49 +362,50 @@ detail::RegExpPrivate::create(JSContext |
63 return RetType(self); |
81 return RetType(NULL); |
|
82 |
|
83 if (!cacheInsert(cx, sourceAtom, RegExpPrivateCache_ExecCapable, priv)) |
|
84 return RetType(NULL); |
|
85 |
|
86 return RetType(priv); |
64 } |
87 } |
65 |
88 |
66 +#if ENABLE_YARR_JIT |
89 +#if ENABLE_YARR_JIT |
67 /* This function should be deleted once bad Android platforms phase out. See bug 604774. */ |
90 /* This function should be deleted once bad Android platforms phase out. See bug 604774. */ |
68 inline bool |
91 inline bool |
69 RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx) |
92 detail::RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx) |
70 @@ -337,12 +338,12 @@ RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx) |
93 { |
|
94 #if defined(ANDROID) && defined(JS_METHODJIT) |
|
95 return cx->methodJitEnabled; |
|
96 #else |
71 return true; |
97 return true; |
72 #endif |
98 #endif |
73 } |
99 } |
74 +#endif |
100 +#endif |
75 |
101 |
76 inline bool |
102 inline bool |
77 RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts, |
103 detail::RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts, |
78 uintN *parenCount, RegExpFlag flags) |
104 uintN *parenCount, RegExpFlag flags) |
79 { |
105 { |
80 -#if ENABLE_YARR_JIT |
106 -#if ENABLE_YARR_JIT |
81 /* Parse the pattern. */ |
107 /* Parse the pattern. */ |
82 ErrorCode yarrError; |
108 ErrorCode yarrError; |
83 YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag), |
109 YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag), |
84 @@ -359,7 +360,7 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream * |
110 &yarrError); |
|
111 if (yarrError) { |
|
112 reportYarrError(cx, ts, yarrError); |
|
113 return false; |
|
114 } |
|
115 *parenCount = yarrPattern.m_numSubpatterns; |
|
116 |
|
117 /* |
|
118 * The YARR JIT compiler attempts to compile the parsed pattern. If |
|
119 * it cannot, it informs us via |codeBlock.isFallBack()|, in which |
85 * case we have to bytecode compile it. |
120 * case we have to bytecode compile it. |
86 */ |
121 */ |
87 |
122 |
88 -#ifdef JS_METHODJIT |
123 -#ifdef JS_METHODJIT |
89 +#if ENABLE_YARR_JIT && defined(JS_METHODJIT) |
124 +#if ENABLE_YARR_JIT && defined(JS_METHODJIT) |
90 if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) { |
125 if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) { |
91 if (!cx->compartment->ensureJaegerCompartmentExists(cx)) |
126 JSC::ExecutableAllocator *execAlloc = cx->threadData()->getOrCreateExecutableAllocator(cx); |
|
127 if (!execAlloc) { |
|
128 js_ReportOutOfMemory(cx); |
92 return false; |
129 return false; |
93 @@ -371,21 +372,11 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream * |
130 } |
94 } |
131 |
95 #endif |
132 JSGlobalData globalData(execAlloc); |
|
133 @@ -415,31 +416,21 @@ detail::RegExpPrivateCode::compile(JSCon |
|
134 #endif |
|
135 |
|
136 WTF::BumpPointerAllocator *bumpAlloc = cx->threadData()->getOrCreateBumpPointerAllocator(cx); |
|
137 if (!bumpAlloc) { |
|
138 js_ReportOutOfMemory(cx); |
|
139 return false; |
|
140 } |
96 |
141 |
97 +#if ENABLE_YARR_JIT |
142 +#if ENABLE_YARR_JIT |
98 codeBlock.setFallBack(true); |
143 codeBlock.setFallBack(true); |
99 +#endif |
144 +#endif |
100 byteCode = byteCompile(yarrPattern, cx->compartment->regExpAllocator).get(); |
145 byteCode = byteCompile(yarrPattern, bumpAlloc).get(); |
101 return true; |
146 return true; |
102 -#else /* !defined(ENABLE_YARR_JIT) */ |
147 -#else /* !defined(ENABLE_YARR_JIT) */ |
103 - int error = 0; |
148 - int error = 0; |
104 - compiled = jsRegExpCompile(pattern.chars(), pattern.length(), |
149 - compiled = jsRegExpCompile(pattern.chars(), pattern.length(), |
105 - ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase, |
150 - ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase, |
112 - return true; |
157 - return true; |
113 -#endif |
158 -#endif |
114 } |
159 } |
115 |
160 |
116 inline bool |
161 inline bool |
117 @@ -431,19 +422,12 @@ RegExpPrivateCode::execute(JSContext *cx, const jschar *chars, size_t start, siz |
162 detail::RegExpPrivate::compile(JSContext *cx, TokenStream *ts) |
|
163 { |
|
164 if (!sticky()) |
|
165 return code.compile(cx, *source, ts, &parenCount, getFlags()); |
|
166 |
|
167 @@ -471,29 +462,22 @@ detail::RegExpPrivateCode::execute(JSCon |
|
168 int result; |
|
169 #if ENABLE_YARR_JIT |
|
170 (void) cx; /* Unused. */ |
|
171 if (codeBlock.isFallBack()) |
|
172 result = JSC::Yarr::interpret(byteCode, chars, start, length, output); |
118 else |
173 else |
119 result = JSC::Yarr::execute(codeBlock, chars, start, length, output); |
174 result = JSC::Yarr::execute(codeBlock, chars, start, length, output); |
120 #else |
175 #else |
121 - result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount); |
176 - result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount); |
122 + result = JSC::Yarr::interpret(byteCode, chars, start, length, output); |
177 + result = JSC::Yarr::interpret(byteCode, chars, start, length, output); |
123 #endif |
178 #endif |
124 |
179 |
125 if (result == -1) |
180 if (result == -1) |
126 return Success_NotFound; |
181 return RegExpRunStatus_Success_NotFound; |
127 |
182 |
128 -#if !ENABLE_YARR_JIT |
183 -#if !ENABLE_YARR_JIT |
129 - if (result < 0) { |
184 - if (result < 0) { |
130 - reportPCREError(cx, result); |
185 - reportPCREError(cx, result); |
131 - return Error; |
186 - return RegExpRunStatus_Error; |
132 - } |
187 - } |
133 -#endif |
188 -#endif |
134 - |
189 - |
135 JS_ASSERT(result >= 0); |
190 JS_ASSERT(result >= 0); |
136 return Success; |
191 return RegExpRunStatus_Success; |
137 } |
192 } |
|
193 |
|
194 inline void |
|
195 detail::RegExpPrivate::incref(JSContext *cx) |
|
196 { |
|
197 ++refCount; |
138 diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp |
198 diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp |
139 index f75c6a5..7631dd5 100644 |
|
140 --- a/js/src/vm/RegExpObject.cpp |
199 --- a/js/src/vm/RegExpObject.cpp |
141 +++ b/js/src/vm/RegExpObject.cpp |
200 +++ b/js/src/vm/RegExpObject.cpp |
142 @@ -251,7 +251,6 @@ Class js::RegExpClass = { |
201 @@ -387,17 +387,16 @@ Class js::RegExpClass = { |
143 NULL /* trace */ |
202 NULL, /* checkAccess */ |
|
203 NULL, /* call */ |
|
204 NULL, /* construct */ |
|
205 js_XDRRegExpObject, |
|
206 NULL, /* hasInstance */ |
|
207 regexp_trace |
144 }; |
208 }; |
145 |
209 |
146 -#if ENABLE_YARR_JIT |
210 -#if ENABLE_YARR_JIT |
147 void |
211 void |
148 RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error) |
212 RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error) |
149 { |
213 { |
150 @@ -283,41 +282,6 @@ RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode err |
214 switch (error) { |
|
215 case JSC::Yarr::NoError: |
|
216 JS_NOT_REACHED("Called reportYarrError with value for no error"); |
|
217 return; |
|
218 #define COMPILE_EMSG(__code, __msg) \ |
|
219 @@ -419,52 +418,16 @@ RegExpPrivateCode::reportYarrError(JSCon |
|
220 COMPILE_EMSG(QuantifierTooLarge, JSMSG_BAD_QUANTIFIER); |
|
221 COMPILE_EMSG(EscapeUnterminated, JSMSG_TRAILING_SLASH); |
|
222 #undef COMPILE_EMSG |
|
223 default: |
|
224 JS_NOT_REACHED("Unknown Yarr error code"); |
151 } |
225 } |
152 } |
226 } |
153 |
227 |
154 -#else /* !ENABLE_YARR_JIT */ |
228 -#else /* !ENABLE_YARR_JIT */ |
155 - |
229 - |
159 -#define REPORT(msg_) \ |
233 -#define REPORT(msg_) \ |
160 - JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \ |
234 - JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \ |
161 - return |
235 - return |
162 - switch (error) { |
236 - switch (error) { |
163 - case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
237 - case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
164 - case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred."); |
238 - case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred."); |
165 - case 1: REPORT(JSMSG_TRAILING_SLASH); |
239 - case 1: REPORT(JSMSG_TRAILING_SLASH); |
166 - case 2: REPORT(JSMSG_TRAILING_SLASH); |
240 - case 2: REPORT(JSMSG_TRAILING_SLASH); |
167 - case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
241 - case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
168 - case 4: REPORT(JSMSG_BAD_QUANTIFIER); |
242 - case 4: REPORT(JSMSG_BAD_QUANTIFIER); |
169 - case 5: REPORT(JSMSG_BAD_QUANTIFIER); |
243 - case 5: REPORT(JSMSG_BAD_QUANTIFIER); |
170 - case 6: REPORT(JSMSG_BAD_CLASS_RANGE); |
244 - case 6: REPORT(JSMSG_BAD_CLASS_RANGE); |
171 - case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
245 - case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX); |
182 - default: |
256 - default: |
183 - JS_NOT_REACHED("Precondition violation: unknown PCRE error code."); |
257 - JS_NOT_REACHED("Precondition violation: unknown PCRE error code."); |
184 - } |
258 - } |
185 -#undef REPORT |
259 -#undef REPORT |
186 -} |
260 -} |
|
261 - |
187 -#endif /* ENABLE_YARR_JIT */ |
262 -#endif /* ENABLE_YARR_JIT */ |
188 - |
263 - |
189 bool |
264 bool |
190 js::ParseRegExpFlags(JSContext *cx, JSString *flagStr, RegExpFlag *flagsOut) |
265 js::ParseRegExpFlags(JSContext *cx, JSString *flagStr, RegExpFlag *flagsOut) |
191 { |
266 { |
|
267 size_t n = flagStr->length(); |
|
268 const jschar *s = flagStr->getChars(cx); |
|
269 if (!s) |
|
270 return false; |
|
271 |
192 diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h |
272 diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h |
193 index 1449d56..279f3c0 100644 |
|
194 --- a/js/src/vm/RegExpObject.h |
273 --- a/js/src/vm/RegExpObject.h |
195 +++ b/js/src/vm/RegExpObject.h |
274 +++ b/js/src/vm/RegExpObject.h |
196 @@ -49,8 +49,6 @@ |
275 @@ -45,18 +45,16 @@ |
|
276 #include "jsobj.h" |
|
277 |
|
278 #include "js/TemplateLib.h" |
|
279 |
197 #include "yarr/Yarr.h" |
280 #include "yarr/Yarr.h" |
198 #if ENABLE_YARR_JIT |
281 #if ENABLE_YARR_JIT |
199 #include "yarr/YarrJIT.h" |
282 #include "yarr/YarrJIT.h" |
|
283 #include "yarr/YarrSyntaxChecker.h" |
200 -#else |
284 -#else |
201 -#include "yarr/pcre/pcre.h" |
285 -#include "yarr/pcre/pcre.h" |
202 #endif |
286 #endif |
203 |
287 |
204 namespace js { |
288 namespace js { |
205 @@ -153,48 +151,39 @@ ResetRegExpObject(JSContext *cx, AlreadyIncRefed<RegExpPrivate> rep); |
289 |
|
290 enum RegExpRunStatus |
|
291 { |
|
292 RegExpRunStatus_Error, |
|
293 RegExpRunStatus_Success, |
|
294 @@ -235,50 +233,43 @@ class RegExpObjectBuilder |
|
295 |
|
296 namespace detail { |
|
297 |
|
298 static const jschar GreedyStarChars[] = {'.', '*'}; |
|
299 |
206 /* Abstracts away the gross |RegExpPrivate| backend details. */ |
300 /* Abstracts away the gross |RegExpPrivate| backend details. */ |
207 class RegExpPrivateCode |
301 class RegExpPrivateCode |
208 { |
302 { |
209 -#if ENABLE_YARR_JIT |
303 -#if ENABLE_YARR_JIT |
210 typedef JSC::Yarr::BytecodePattern BytecodePattern; |
304 typedef JSC::Yarr::BytecodePattern BytecodePattern; |
245 - if (compiled) |
339 - if (compiled) |
246 - jsRegExpFree(compiled); |
340 - jsRegExpFree(compiled); |
247 -#endif |
341 -#endif |
248 } |
342 } |
249 |
343 |
|
344 static bool checkSyntax(JSContext *cx, TokenStream *tokenStream, JSLinearString *source) { |
|
345 #if ENABLE_YARR_JIT |
|
346 ErrorCode error = JSC::Yarr::checkSyntax(*source); |
|
347 if (error == JSC::Yarr::NoError) |
|
348 return true; |
|
349 |
|
350 @@ -286,27 +277,21 @@ class RegExpPrivateCode |
|
351 return false; |
|
352 #else |
|
353 # error "Syntax checking not implemented for !ENABLE_YARR_JIT" |
|
354 #endif |
|
355 } |
|
356 |
250 #if ENABLE_YARR_JIT |
357 #if ENABLE_YARR_JIT |
251 static inline bool isJITRuntimeEnabled(JSContext *cx); |
358 static inline bool isJITRuntimeEnabled(JSContext *cx); |
252 - void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); |
359 - static void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); |
253 -#else |
360 -#else |
254 - void reportPCREError(JSContext *cx, int error); |
361 - static void reportPCREError(JSContext *cx, int error); |
255 #endif |
362 #endif |
256 + void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); |
363 + void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); |
257 |
|
258 inline bool compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts, uintN *parenCount, |
|
259 RegExpFlag flags); |
|
260 @@ -205,11 +194,7 @@ class RegExpPrivateCode |
|
261 int *output, size_t outputCount); |
|
262 |
364 |
263 static size_t getOutputSize(size_t pairCount) { |
365 static size_t getOutputSize(size_t pairCount) { |
264 -#if ENABLE_YARR_JIT |
366 -#if ENABLE_YARR_JIT |
265 return pairCount * 2; |
367 return pairCount * 2; |
266 -#else |
368 -#else |
267 - return pairCount * 3; /* Should be x2, but PCRE has... needs. */ |
369 - return pairCount * 3; /* Should be x2, but PCRE has... needs. */ |
268 -#endif |
370 -#endif |
269 } |
371 } |
270 }; |
372 |
271 |
373 inline bool compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts, uintN *parenCount, |
|
374 RegExpFlag flags); |
|
375 |
|
376 |
|
377 inline RegExpRunStatus execute(JSContext *cx, const jschar *chars, size_t length, size_t start, |
|
378 int *output, size_t outputCount); |
272 diff --git a/js/src/yarr/wtfbridge.h b/js/src/yarr/wtfbridge.h |
379 diff --git a/js/src/yarr/wtfbridge.h b/js/src/yarr/wtfbridge.h |
273 index ac41d08..fb8eb86 100644 |
|
274 --- a/js/src/yarr/wtfbridge.h |
380 --- a/js/src/yarr/wtfbridge.h |
275 +++ b/js/src/yarr/wtfbridge.h |
381 +++ b/js/src/yarr/wtfbridge.h |
276 @@ -49,9 +49,7 @@ |
382 @@ -44,19 +44,17 @@ |
|
383 * WTF compatibility layer. This file provides various type and data |
|
384 * definitions for use by Yarr. |
|
385 */ |
|
386 |
|
387 #include "jsstr.h" |
277 #include "jsprvtd.h" |
388 #include "jsprvtd.h" |
278 #include "vm/String.h" |
389 #include "vm/String.h" |
279 #include "assembler/wtf/Platform.h" |
390 #include "assembler/wtf/Platform.h" |
280 -#if ENABLE_YARR_JIT |
391 -#if ENABLE_YARR_JIT |
281 #include "assembler/jit/ExecutableAllocator.h" |
392 #include "assembler/jit/ExecutableAllocator.h" |
282 -#endif |
393 -#endif |
283 |
394 |
284 namespace JSC { namespace Yarr { |
395 namespace JSC { namespace Yarr { |
285 |
396 |
|
397 /* |
|
398 * Basic type definitions. |
|
399 */ |
|
400 |
|
401 typedef jschar UChar; |