Description: Fix build failure on platforms where YARR JIT is not supported From: https://bug691898.bugzilla.mozilla.org/attachment.cgi?id=596771 Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=691898 # HG changeset patch # Parent 9fb9c1cfc1df49ba616e0cce1586d708b0f3c0c8 # User Landry Breuil Use YARR interpreter instead of PCRE on platforms where YARR JIT is not supported Index: mozilla/js/src/Makefile.in =================================================================== --- mozilla.orig/js/src/Makefile.in 2012-02-23 02:06:55.000000000 +0000 +++ mozilla/js/src/Makefile.in 2012-02-23 13:25:21.157807364 +0000 @@ -340,15 +340,20 @@ ifeq (,$(filter arm% sparc %86 x86_64 mips%,$(TARGET_CPU))) -VPATH += $(srcdir)/yarr/pcre \ +VPATH += $(srcdir)/assembler \ + $(srcdir)/assembler/wtf \ + $(srcdir)/yarr \ $(NULL) CPPSRCS += \ - pcre_compile.cpp \ - pcre_exec.cpp \ - pcre_tables.cpp \ - pcre_xclass.cpp \ - pcre_ucp_searchfuncs.cpp \ + Assertions.cpp \ + OSAllocatorOS2.cpp \ + OSAllocatorPosix.cpp \ + OSAllocatorWin.cpp \ + PageBlock.cpp \ + YarrInterpreter.cpp \ + YarrPattern.cpp \ + YarrSyntaxChecker.cpp \ $(NULL) else @@ -883,10 +888,10 @@ # Needed to "configure" it correctly. Unfortunately these # flags wind up being applied to all code in js/src, not just # the code in js/src/assembler. -CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1 +CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_METHODJIT)) -CXXFLAGS += -DENABLE_JIT=1 +CXXFLAGS += -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1 endif INCLUDES += -I$(srcdir)/assembler -I$(srcdir)/yarr Index: mozilla/js/src/jsapi.cpp =================================================================== --- mozilla.orig/js/src/jsapi.cpp 2012-02-23 02:07:17.000000000 +0000 +++ mozilla/js/src/jsapi.cpp 2012-02-23 13:26:06.801806553 +0000 @@ -701,7 +701,9 @@ ownerThread_(NULL), #endif tempLifoAlloc(TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE), +#if ENABLE_ASSEMBLER execAlloc_(NULL), +#endif bumpAlloc_(NULL), nativeStackBase(0), nativeStackQuota(0), @@ -793,8 +795,12 @@ #ifdef DEBUG noGCOrAllocationCheck(0), #endif +#if ENABLE_ASSEMBLER inOOMReport(0), jitHardening(false) +#else + inOOMReport(0) +#endif { /* Initialize infallibly first, so we can goto bad and JS_DestroyRuntime. */ JS_INIT_CLIST(&contextList); @@ -856,7 +862,9 @@ { JS_ASSERT(onOwnerThread()); +#if ENABLE_ASSEMBLER delete_(execAlloc_); +#endif delete_(bumpAlloc_); #ifdef DEBUG @@ -1318,7 +1326,9 @@ JS_PUBLIC_API(void) JS_SetJitHardening(JSRuntime *rt, JSBool enabled) { +#if ENABLE_ASSEMBLER rt->setJitHardening(!!enabled); +#endif } JS_PUBLIC_API(const char *) Index: mozilla/js/src/jscntxt.cpp =================================================================== --- mozilla.orig/js/src/jscntxt.cpp 2012-02-23 02:07:17.000000000 +0000 +++ mozilla/js/src/jscntxt.cpp 2012-02-23 13:25:21.161807364 +0000 @@ -105,9 +105,11 @@ if (regexpCode) { size_t method = 0, regexp = 0, unused = 0; +#if ENABLE_ASSEMBLER if (execAlloc_) execAlloc_->sizeOfCode(&method, ®exp, &unused); JS_ASSERT(method == 0); /* this execAlloc is only used for regexp code */ +#endif *regexpCode = regexp + unused; } @@ -125,6 +127,7 @@ JS_ATOMIC_SET(&interrupt, 1); } +#if ENABLE_ASSEMBLER void JSRuntime::setJitHardening(bool enabled) { @@ -146,6 +149,7 @@ js_ReportOutOfMemory(cx); return execAlloc_; } +#endif WTF::BumpPointerAllocator * JSRuntime::createBumpPointerAllocator(JSContext *cx) Index: mozilla/js/src/jscntxt.h =================================================================== --- mozilla.orig/js/src/jscntxt.h 2012-02-23 02:07:17.000000000 +0000 +++ mozilla/js/src/jscntxt.h 2012-02-23 13:25:21.161807364 +0000 @@ -224,16 +224,22 @@ * Both of these allocators are used for regular expression code which is shared at the * thread-data level. */ +#if ENABLE_ASSEMBLER JSC::ExecutableAllocator *execAlloc_; +#endif WTF::BumpPointerAllocator *bumpAlloc_; +#if ENABLE_ASSEMBLER JSC::ExecutableAllocator *createExecutableAllocator(JSContext *cx); +#endif WTF::BumpPointerAllocator *createBumpPointerAllocator(JSContext *cx); public: +#if ENABLE_ASSEMBLER JSC::ExecutableAllocator *getExecutableAllocator(JSContext *cx) { return execAlloc_ ? execAlloc_ : createExecutableAllocator(cx); } +#endif WTF::BumpPointerAllocator *getBumpPointerAllocator(JSContext *cx) { return bumpAlloc_ ? bumpAlloc_ : createBumpPointerAllocator(cx); } @@ -588,7 +594,9 @@ */ int32_t inOOMReport; +#if ENABLE_ASSEMBLER bool jitHardening; +#endif JSRuntime(); ~JSRuntime(); @@ -683,10 +691,12 @@ JS_FRIEND_API(void) triggerOperationCallback(); +#if ENABLE_ASSEMBLER void setJitHardening(bool enabled); bool getJitHardening() const { return jitHardening; } +#endif void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *normal, size_t *temporary, size_t *regexpCode, size_t *stackCommitted); Index: mozilla/js/src/jsprvtd.h =================================================================== --- mozilla.orig/js/src/jsprvtd.h 2012-02-23 02:07:18.000000000 +0000 +++ mozilla/js/src/jsprvtd.h 2012-02-23 13:25:21.161807364 +0000 @@ -317,12 +317,13 @@ } /* namespace js */ +#if ENABLE_ASSEMBLER namespace JSC { class ExecutableAllocator; } /* namespace JSC */ - +#endif namespace WTF { class BumpPointerAllocator; Index: mozilla/js/src/vm/RegExpObject-inl.h =================================================================== --- mozilla.orig/js/src/vm/RegExpObject-inl.h 2012-02-23 02:07:40.000000000 +0000 +++ mozilla/js/src/vm/RegExpObject-inl.h 2012-02-23 13:25:21.161807364 +0000 @@ -136,6 +136,7 @@ setSlot(STICKY_FLAG_SLOT, BooleanValue(enabled)); } +#if ENABLE_YARR_JIT /* This function should be deleted once bad Android platforms phase out. See bug 604774. */ inline bool detail::RegExpCode::isJITRuntimeEnabled(JSContext *cx) @@ -146,6 +147,7 @@ return true; #endif } +#endif inline RegExpShared * RegExpToShared(JSContext *cx, JSObject &obj) Index: mozilla/js/src/vm/RegExpObject.cpp =================================================================== --- mozilla.orig/js/src/vm/RegExpObject.cpp 2012-02-23 02:07:40.000000000 +0000 +++ mozilla/js/src/vm/RegExpObject.cpp 2012-02-23 13:25:21.161807364 +0000 @@ -170,7 +170,6 @@ /* detail::RegExpCode */ -#if ENABLE_YARR_JIT void RegExpCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error) { @@ -202,46 +201,9 @@ } } -#else /* !ENABLE_YARR_JIT */ - -void -RegExpCode::reportPCREError(JSContext *cx, int error) -{ -#define REPORT(msg_) \ - JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \ - return - switch (error) { - case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred."); - case 1: REPORT(JSMSG_TRAILING_SLASH); - case 2: REPORT(JSMSG_TRAILING_SLASH); - case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 4: REPORT(JSMSG_BAD_QUANTIFIER); - case 5: REPORT(JSMSG_BAD_QUANTIFIER); - case 6: REPORT(JSMSG_BAD_CLASS_RANGE); - case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 8: REPORT(JSMSG_BAD_CLASS_RANGE); - case 9: REPORT(JSMSG_BAD_QUANTIFIER); - case 10: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN); - case 11: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 12: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN); - case 13: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 14: REPORT(JSMSG_MISSING_PAREN); - case 15: REPORT(JSMSG_BAD_BACKREF); - case 16: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - case 17: REPORT(JSMSG_REGEXP_TOO_COMPLEX); - default: - JS_NOT_REACHED("Precondition violation: unknown PCRE error code."); - } -#undef REPORT -} - -#endif /* ENABLE_YARR_JIT */ - bool RegExpCode::compile(JSContext *cx, JSLinearString &pattern, uintN *parenCount, RegExpFlag flags) { -#if ENABLE_YARR_JIT /* Parse the pattern. */ ErrorCode yarrError; YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag), @@ -258,7 +220,7 @@ * case we have to bytecode compile it. */ -#ifdef JS_METHODJIT +#if ENABLE_YARR_JIT && defined(JS_METHODJIT) if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) { JSC::ExecutableAllocator *execAlloc = cx->runtime->getExecutableAllocator(cx); if (!execAlloc) { @@ -279,21 +241,11 @@ return false; } +#if ENABLE_YARR_JIT codeBlock.setFallBack(true); +#endif byteCode = byteCompile(yarrPattern, bumpAlloc).get(); return true; -#else /* !defined(ENABLE_YARR_JIT) */ - int error = 0; - compiled = jsRegExpCompile(pattern.chars(), pattern.length(), - ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase, - multiline() ? JSRegExpMultiline : JSRegExpSingleLine, - parenCount, &error); - if (error) { - reportPCREError(cx, error); - return false; - } - return true; -#endif } RegExpRunStatus @@ -308,19 +260,12 @@ else result = JSC::Yarr::execute(codeBlock, chars, start, length, output); #else - result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount); + result = JSC::Yarr::interpret(byteCode, chars, start, length, output); #endif if (result == -1) return RegExpRunStatus_Success_NotFound; -#if !ENABLE_YARR_JIT - if (result < 0) { - reportPCREError(cx, result); - return RegExpRunStatus_Error; - } -#endif - JS_ASSERT(result >= 0); return RegExpRunStatus_Success; } Index: mozilla/js/src/vm/RegExpObject.h =================================================================== --- mozilla.orig/js/src/vm/RegExpObject.h 2012-02-23 02:07:40.000000000 +0000 +++ mozilla/js/src/vm/RegExpObject.h 2012-02-23 13:25:21.161807364 +0000 @@ -52,8 +52,6 @@ #if ENABLE_YARR_JIT #include "yarr/YarrJIT.h" #include "yarr/YarrSyntaxChecker.h" -#else -#include "yarr/pcre/pcre.h" #endif /* @@ -223,40 +221,33 @@ class RegExpCode { -#if ENABLE_YARR_JIT typedef JSC::Yarr::BytecodePattern BytecodePattern; typedef JSC::Yarr::ErrorCode ErrorCode; + typedef JSC::Yarr::YarrPattern YarrPattern; +#if ENABLE_YARR_JIT typedef JSC::Yarr::JSGlobalData JSGlobalData; typedef JSC::Yarr::YarrCodeBlock YarrCodeBlock; - typedef JSC::Yarr::YarrPattern YarrPattern; /* Note: Native code is valid only if |codeBlock.isFallBack() == false|. */ YarrCodeBlock codeBlock; - BytecodePattern *byteCode; -#else - JSRegExp *compiled; #endif + BytecodePattern *byteCode; public: RegExpCode() : #if ENABLE_YARR_JIT codeBlock(), - byteCode(NULL) -#else - compiled(NULL) #endif + byteCode(NULL) { } ~RegExpCode() { #if ENABLE_YARR_JIT codeBlock.release(); +#endif if (byteCode) Foreground::delete_(byteCode); -#else - if (compiled) - jsRegExpFree(compiled); -#endif } static bool checkSyntax(JSContext *cx, TokenStream *tokenStream, JSLinearString *source) { @@ -268,23 +259,17 @@ reportYarrError(cx, tokenStream, error); return false; #else -# error "Syntax checking not implemented for !ENABLE_YARR_JIT" + return true; /* XXX! */ #endif } #if ENABLE_YARR_JIT static inline bool isJITRuntimeEnabled(JSContext *cx); - static void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); -#else - static void reportPCREError(JSContext *cx, int error); #endif + static void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error); static size_t getOutputSize(size_t pairCount) { -#if ENABLE_YARR_JIT return pairCount * 2; -#else - return pairCount * 3; /* Should be x2, but PCRE has... needs. */ -#endif } bool compile(JSContext *cx, JSLinearString &pattern, uintN *parenCount, RegExpFlag flags); Index: mozilla/js/src/yarr/wtfbridge.h =================================================================== --- mozilla.orig/js/src/yarr/wtfbridge.h 2012-02-23 02:07:42.000000000 +0000 +++ mozilla/js/src/yarr/wtfbridge.h 2012-02-23 13:25:21.161807364 +0000 @@ -49,9 +49,7 @@ #include "jsprvtd.h" #include "vm/String.h" #include "assembler/wtf/Platform.h" -#if ENABLE_YARR_JIT #include "assembler/jit/ExecutableAllocator.h" -#endif namespace JSC { namespace Yarr {