378
|
1 |
From: Mike Hommey <mh@glandium.org>
|
|
2 |
Date: Sat, 24 Dec 2011 09:56:58 +0100
|
|
3 |
Subject: Bug 691898 - Use YARR interpreter instead of PCRE on platforms where
|
|
4 |
YARR JIT is not supported
|
|
5 |
|
|
6 |
---
|
|
7 |
js/src/Makefile.in | 21 +++++++++++++--------
|
|
8 |
js/src/vm/RegExpObject-inl.h | 28 ++++++----------------------
|
|
9 |
js/src/vm/RegExpObject.cpp | 36 ------------------------------------
|
|
10 |
js/src/vm/RegExpObject.h | 27 ++++++---------------------
|
|
11 |
js/src/yarr/wtfbridge.h | 2 --
|
|
12 |
5 files changed, 25 insertions(+), 89 deletions(-)
|
|
13 |
|
|
14 |
diff --git a/js/src/Makefile.in b/js/src/Makefile.in
|
|
15 |
index fc48cbd..49f0bdc 100644
|
|
16 |
--- a/js/src/Makefile.in
|
|
17 |
+++ b/js/src/Makefile.in
|
|
18 |
@@ -416,15 +416,20 @@ CPPSRCS += checks.cc \
|
|
19 |
|
|
20 |
ifeq (,$(filter arm% sparc %86 x86_64,$(TARGET_CPU)))
|
|
21 |
|
|
22 |
-VPATH += $(srcdir)/yarr/pcre \
|
|
23 |
+VPATH += $(srcdir)/assembler \
|
|
24 |
+ $(srcdir)/assembler/wtf \
|
|
25 |
+ $(srcdir)/yarr \
|
|
26 |
$(NULL)
|
|
27 |
|
|
28 |
CPPSRCS += \
|
|
29 |
- pcre_compile.cpp \
|
|
30 |
- pcre_exec.cpp \
|
|
31 |
- pcre_tables.cpp \
|
|
32 |
- pcre_xclass.cpp \
|
|
33 |
- pcre_ucp_searchfuncs.cpp \
|
|
34 |
+ Assertions.cpp \
|
|
35 |
+ OSAllocatorOS2.cpp \
|
|
36 |
+ OSAllocatorPosix.cpp \
|
|
37 |
+ OSAllocatorWin.cpp \
|
|
38 |
+ PageBlock.cpp \
|
|
39 |
+ YarrInterpreter.cpp \
|
|
40 |
+ YarrPattern.cpp \
|
|
41 |
+ YarrSyntaxChecker.cpp \
|
|
42 |
$(NULL)
|
|
43 |
else
|
|
44 |
|
|
45 |
@@ -1015,10 +1020,10 @@ endif
|
|
46 |
# Needed to "configure" it correctly. Unfortunately these
|
|
47 |
# flags wind up being applied to all code in js/src, not just
|
|
48 |
# the code in js/src/assembler.
|
|
49 |
-CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1
|
|
50 |
+CXXFLAGS += -DUSE_SYSTEM_MALLOC=1
|
|
51 |
|
|
52 |
ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_TRACEJIT)$(ENABLE_METHODJIT))
|
|
53 |
-CXXFLAGS += -DENABLE_JIT=1
|
|
54 |
+CXXFLAGS += -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1
|
|
55 |
endif
|
|
56 |
|
|
57 |
INCLUDES += -I$(srcdir)/assembler -I$(srcdir)/yarr
|
|
58 |
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
|
|
61 |
+++ b/js/src/vm/RegExpObject-inl.h
|
|
62 |
@@ -327,6 +327,7 @@ RegExpPrivate::create(JSContext *cx, JSString *source, RegExpFlag flags, TokenSt
|
|
63 |
return RetType(self);
|
|
64 |
}
|
|
65 |
|
|
66 |
+#if ENABLE_YARR_JIT
|
|
67 |
/* This function should be deleted once bad Android platforms phase out. See bug 604774. */
|
|
68 |
inline bool
|
|
69 |
RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx)
|
|
70 |
@@ -337,12 +338,12 @@ RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx)
|
|
71 |
return true;
|
|
72 |
#endif
|
|
73 |
}
|
|
74 |
+#endif
|
|
75 |
|
|
76 |
inline bool
|
|
77 |
RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts,
|
|
78 |
uintN *parenCount, RegExpFlag flags)
|
|
79 |
{
|
|
80 |
-#if ENABLE_YARR_JIT
|
|
81 |
/* Parse the pattern. */
|
|
82 |
ErrorCode yarrError;
|
|
83 |
YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag),
|
|
84 |
@@ -359,7 +360,7 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *
|
|
85 |
* case we have to bytecode compile it.
|
|
86 |
*/
|
|
87 |
|
|
88 |
-#ifdef JS_METHODJIT
|
|
89 |
+#if ENABLE_YARR_JIT && defined(JS_METHODJIT)
|
|
90 |
if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) {
|
|
91 |
if (!cx->compartment->ensureJaegerCompartmentExists(cx))
|
|
92 |
return false;
|
|
93 |
@@ -371,21 +372,11 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *
|
|
94 |
}
|
|
95 |
#endif
|
|
96 |
|
|
97 |
+#if ENABLE_YARR_JIT
|
|
98 |
codeBlock.setFallBack(true);
|
|
99 |
+#endif
|
|
100 |
byteCode = byteCompile(yarrPattern, cx->compartment->regExpAllocator).get();
|
|
101 |
return true;
|
|
102 |
-#else /* !defined(ENABLE_YARR_JIT) */
|
|
103 |
- int error = 0;
|
|
104 |
- compiled = jsRegExpCompile(pattern.chars(), pattern.length(),
|
|
105 |
- ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase,
|
|
106 |
- multiline() ? JSRegExpMultiline : JSRegExpSingleLine,
|
|
107 |
- parenCount, &error);
|
|
108 |
- if (error) {
|
|
109 |
- reportPCREError(cx, error);
|
|
110 |
- return false;
|
|
111 |
- }
|
|
112 |
- return true;
|
|
113 |
-#endif
|
|
114 |
}
|
|
115 |
|
|
116 |
inline bool
|
|
117 |
@@ -431,19 +422,12 @@ RegExpPrivateCode::execute(JSContext *cx, const jschar *chars, size_t start, siz
|
|
118 |
else
|
|
119 |
result = JSC::Yarr::execute(codeBlock, chars, start, length, output);
|
|
120 |
#else
|
|
121 |
- result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount);
|
|
122 |
+ result = JSC::Yarr::interpret(byteCode, chars, start, length, output);
|
|
123 |
#endif
|
|
124 |
|
|
125 |
if (result == -1)
|
|
126 |
return Success_NotFound;
|
|
127 |
|
|
128 |
-#if !ENABLE_YARR_JIT
|
|
129 |
- if (result < 0) {
|
|
130 |
- reportPCREError(cx, result);
|
|
131 |
- return Error;
|
|
132 |
- }
|
|
133 |
-#endif
|
|
134 |
-
|
|
135 |
JS_ASSERT(result >= 0);
|
|
136 |
return Success;
|
|
137 |
}
|
|
138 |
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
|
|
141 |
+++ b/js/src/vm/RegExpObject.cpp
|
|
142 |
@@ -251,7 +251,6 @@ Class js::RegExpClass = {
|
|
143 |
NULL /* trace */
|
|
144 |
};
|
|
145 |
|
|
146 |
-#if ENABLE_YARR_JIT
|
|
147 |
void
|
|
148 |
RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error)
|
|
149 |
{
|
|
150 |
@@ -283,41 +282,6 @@ RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode err
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
-#else /* !ENABLE_YARR_JIT */
|
|
155 |
-
|
|
156 |
-void
|
|
157 |
-RegExpPrivateCode::reportPCREError(JSContext *cx, int error)
|
|
158 |
-{
|
|
159 |
-#define REPORT(msg_) \
|
|
160 |
- JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \
|
|
161 |
- return
|
|
162 |
- switch (error) {
|
|
163 |
- case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
164 |
- case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred.");
|
|
165 |
- case 1: REPORT(JSMSG_TRAILING_SLASH);
|
|
166 |
- case 2: REPORT(JSMSG_TRAILING_SLASH);
|
|
167 |
- case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
168 |
- case 4: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
169 |
- case 5: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
170 |
- case 6: REPORT(JSMSG_BAD_CLASS_RANGE);
|
|
171 |
- case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
172 |
- case 8: REPORT(JSMSG_BAD_CLASS_RANGE);
|
|
173 |
- case 9: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
174 |
- case 10: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
|
|
175 |
- case 11: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
176 |
- case 12: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
|
|
177 |
- case 13: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
178 |
- case 14: REPORT(JSMSG_MISSING_PAREN);
|
|
179 |
- case 15: REPORT(JSMSG_BAD_BACKREF);
|
|
180 |
- case 16: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
181 |
- case 17: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
182 |
- default:
|
|
183 |
- JS_NOT_REACHED("Precondition violation: unknown PCRE error code.");
|
|
184 |
- }
|
|
185 |
-#undef REPORT
|
|
186 |
-}
|
|
187 |
-#endif /* ENABLE_YARR_JIT */
|
|
188 |
-
|
|
189 |
bool
|
|
190 |
js::ParseRegExpFlags(JSContext *cx, JSString *flagStr, RegExpFlag *flagsOut)
|
|
191 |
{
|
|
192 |
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
|
|
195 |
+++ b/js/src/vm/RegExpObject.h
|
|
196 |
@@ -49,8 +49,6 @@
|
|
197 |
#include "yarr/Yarr.h"
|
|
198 |
#if ENABLE_YARR_JIT
|
|
199 |
#include "yarr/YarrJIT.h"
|
|
200 |
-#else
|
|
201 |
-#include "yarr/pcre/pcre.h"
|
|
202 |
#endif
|
|
203 |
|
|
204 |
namespace js {
|
|
205 |
@@ -153,48 +151,39 @@ ResetRegExpObject(JSContext *cx, AlreadyIncRefed<RegExpPrivate> rep);
|
|
206 |
/* Abstracts away the gross |RegExpPrivate| backend details. */
|
|
207 |
class RegExpPrivateCode
|
|
208 |
{
|
|
209 |
-#if ENABLE_YARR_JIT
|
|
210 |
typedef JSC::Yarr::BytecodePattern BytecodePattern;
|
|
211 |
typedef JSC::Yarr::ErrorCode ErrorCode;
|
|
212 |
+ typedef JSC::Yarr::YarrPattern YarrPattern;
|
|
213 |
+#if ENABLE_YARR_JIT
|
|
214 |
typedef JSC::Yarr::JSGlobalData JSGlobalData;
|
|
215 |
typedef JSC::Yarr::YarrCodeBlock YarrCodeBlock;
|
|
216 |
- typedef JSC::Yarr::YarrPattern YarrPattern;
|
|
217 |
|
|
218 |
/* Note: Native code is valid only if |codeBlock.isFallBack() == false|. */
|
|
219 |
YarrCodeBlock codeBlock;
|
|
220 |
- BytecodePattern *byteCode;
|
|
221 |
-#else
|
|
222 |
- JSRegExp *compiled;
|
|
223 |
#endif
|
|
224 |
+ BytecodePattern *byteCode;
|
|
225 |
|
|
226 |
public:
|
|
227 |
RegExpPrivateCode()
|
|
228 |
:
|
|
229 |
#if ENABLE_YARR_JIT
|
|
230 |
codeBlock(),
|
|
231 |
- byteCode(NULL)
|
|
232 |
-#else
|
|
233 |
- compiled(NULL)
|
|
234 |
#endif
|
|
235 |
+ byteCode(NULL)
|
|
236 |
{ }
|
|
237 |
|
|
238 |
~RegExpPrivateCode() {
|
|
239 |
#if ENABLE_YARR_JIT
|
|
240 |
codeBlock.release();
|
|
241 |
+#endif
|
|
242 |
if (byteCode)
|
|
243 |
Foreground::delete_<BytecodePattern>(byteCode);
|
|
244 |
-#else
|
|
245 |
- if (compiled)
|
|
246 |
- jsRegExpFree(compiled);
|
|
247 |
-#endif
|
|
248 |
}
|
|
249 |
|
|
250 |
#if ENABLE_YARR_JIT
|
|
251 |
static inline bool isJITRuntimeEnabled(JSContext *cx);
|
|
252 |
- void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error);
|
|
253 |
-#else
|
|
254 |
- void reportPCREError(JSContext *cx, int error);
|
|
255 |
#endif
|
|
256 |
+ 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 |
|
|
263 |
static size_t getOutputSize(size_t pairCount) {
|
|
264 |
-#if ENABLE_YARR_JIT
|
|
265 |
return pairCount * 2;
|
|
266 |
-#else
|
|
267 |
- return pairCount * 3; /* Should be x2, but PCRE has... needs. */
|
|
268 |
-#endif
|
|
269 |
}
|
|
270 |
};
|
|
271 |
|
|
272 |
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
|
|
275 |
+++ b/js/src/yarr/wtfbridge.h
|
|
276 |
@@ -49,9 +49,7 @@
|
|
277 |
#include "jsprvtd.h"
|
|
278 |
#include "vm/String.h"
|
|
279 |
#include "assembler/wtf/Platform.h"
|
|
280 |
-#if ENABLE_YARR_JIT
|
|
281 |
#include "assembler/jit/ExecutableAllocator.h"
|
|
282 |
-#endif
|
|
283 |
|
|
284 |
namespace JSC { namespace Yarr {
|
|
285 |
|