Bug 717540 - Remove MFBT dependency on JS_Assert, add MOZ_Assert, and use it for WTF assertions. r=waldo,r=khuey

This commit is contained in:
Mike Hommey 2012-02-13 15:48:23 +01:00
parent 400207258e
commit b5d2448f11
21 changed files with 178 additions and 82 deletions

View File

@ -256,7 +256,9 @@ endif
endif # WINNT && !GNU_CC
ifndef MOZ_GLUE_PROGRAM_LDFLAGS
ifdef MOZ_GLUE_PROGRAM_LDFLAGS
DEFINES += -DMOZ_GLUE_IN_PROGRAM
else
MOZ_GLUE_PROGRAM_LDFLAGS=$(MOZ_GLUE_LDFLAGS)
endif

View File

@ -9127,12 +9127,12 @@ ac_configure_args="$ac_configure_args --prefix=$dist"
ac_configure_args="$ac_configure_args --with-sync-build-files=$_topsrcdir"
if test "$MOZ_MEMORY"; then
ac_configure_args="$ac_configure_args --enable-jemalloc"
if test -n "$MOZ_GLUE_LDFLAGS"; then
export MOZ_GLUE_LDFLAGS
fi
if test -n "$MOZ_GLUE_PROGRAM_LDFLAGS"; then
export MOZ_GLUE_PROGRAM_LDFLAGS
fi
fi
if test -n "$MOZ_GLUE_LDFLAGS"; then
export MOZ_GLUE_LDFLAGS
fi
if test -n "$MOZ_GLUE_PROGRAM_LDFLAGS"; then
export MOZ_GLUE_PROGRAM_LDFLAGS
fi
export MOZ_APP_NAME
AC_OUTPUT_SUBDIRS(js/src)

View File

@ -367,8 +367,7 @@ VPATH += $(srcdir)/assembler \
$(srcdir)/yarr \
$(NONE)
CPPSRCS += Assertions.cpp \
ExecutableAllocator.cpp \
CPPSRCS += ExecutableAllocator.cpp \
ARMAssembler.cpp \
MacroAssemblerARM.cpp \
MacroAssemblerX86Common.cpp \
@ -490,6 +489,13 @@ endif
include $(topsrcdir)/config/config.mk
ifeq (,$(MOZ_GLUE_PROGRAM_LDFLAGS))
# When building standalone, we need to include mfbt sources, and to declare
# "exported" mfbt symbols on its behalf when we use its headers.
include $(srcdir)/../../mfbt/sources.mk
DEFINES += -DIMPL_MFBT
endif
EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
ifndef BUILD_OPT
@ -669,11 +675,6 @@ distclean::
DEFINES += -DEXPORT_JS_API
# mfbt is always packed with us, so if we're building a shared object,
# we need to declare "exported" mfbt symbols on its behalf when we use
# its headers.
DEFINES += -DIMPL_MFBT
INCLUDES += -I$(srcdir)
ifdef JS_THREADSAFE

View File

@ -91,9 +91,11 @@ public:
DoubleLessThanOrUnordered = X86Assembler::ConditionB,
DoubleLessThanOrEqualOrUnordered = X86Assembler::ConditionBE
};
COMPILE_ASSERT(
!((X86Assembler::ConditionE | X86Assembler::ConditionNE | X86Assembler::ConditionA | X86Assembler::ConditionAE | X86Assembler::ConditionB | X86Assembler::ConditionBE) & DoubleConditionBits),
DoubleConditionBits_should_not_interfere_with_X86Assembler_Condition_codes);
static void staticAsserts() {
COMPILE_ASSERT(
!((X86Assembler::ConditionE | X86Assembler::ConditionNE | X86Assembler::ConditionA | X86Assembler::ConditionAE | X86Assembler::ConditionB | X86Assembler::ConditionBE) & DoubleConditionBits),
DoubleConditionBits_should_not_interfere_with_X86Assembler_Condition_codes);
}
static const RegisterID stackPointerRegister = X86Registers::esp;

View File

@ -26,6 +26,18 @@
#ifndef WTF_Assertions_h
#define WTF_Assertions_h
#include "Platform.h"
#include "mozilla/Assertions.h"
#define ASSERT(assertion) MOZ_ASSERT(assertion)
#define ASSERT_UNUSED(variable, assertion) ASSERT(assertion)
#define ASSERT_NOT_REACHED() MOZ_NOT_REACHED("")
#define CRASH() MOZ_Crash()
#define COMPILE_ASSERT(exp, name) MOZ_STATIC_ASSERT(exp, #name)
#endif
#if 0
/*
no namespaces because this file has to be includable from C and Objective-C

View File

@ -256,7 +256,9 @@ endif
endif # WINNT && !GNU_CC
ifndef MOZ_GLUE_PROGRAM_LDFLAGS
ifdef MOZ_GLUE_PROGRAM_LDFLAGS
DEFINES += -DMOZ_GLUE_IN_PROGRAM
else
MOZ_GLUE_PROGRAM_LDFLAGS=$(MOZ_GLUE_LDFLAGS)
endif

View File

@ -105,6 +105,9 @@ CSRCS = \
# $(NULL)
DEFINES += -DEXPORT_JS_API
# Building against js_static requires that we declare mfbt sybols "exported"
# on its behalf.
DEFINES += -DIMPL_MFBT
LIBS = $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS)

View File

@ -6601,7 +6601,7 @@ JS_AbortIfWrongThread(JSRuntime *rt)
{
#ifdef JS_THREADSAFE
if (!rt->onOwnerThread())
JS_Assert("rt->onOwnerThread()", __FILE__, __LINE__);
MOZ_Assert("rt->onOwnerThread()", __FILE__, __LINE__);
#endif
}

View File

@ -70,6 +70,8 @@
/************************************************************************/
#define JS_Assert MOZ_Assert
#ifdef __cplusplus
namespace JS {

View File

@ -349,7 +349,7 @@ types::TypeFailure(JSContext *cx, const char *fmt, ...)
cx->compartment->types.print(cx, true);
/* Always active, even in release builds */
JS_Assert(msgbuf, __FILE__, __LINE__);
MOZ_Assert(msgbuf, __FILE__, __LINE__);
*((volatile int *)NULL) = 0; /* Should never be reached */
}

View File

@ -69,35 +69,6 @@ JS_PUBLIC_DATA(uint32_t) OOM_counter = 0;
*/
JS_STATIC_ASSERT(sizeof(void *) == sizeof(void (*)()));
static JS_NEVER_INLINE void
CrashInJS()
{
/*
* We write 123 here so that the machine code for this function is
* unique. Otherwise the linker, trying to be smart, might use the
* same code for CrashInJS and for some other function. That
* messes up the signature in minidumps.
*/
#if defined(WIN32)
/*
* We used to call DebugBreak() on Windows, but amazingly, it causes
* the MSVS 2010 debugger not to be able to recover a call stack.
*/
*((volatile int *) NULL) = 123;
exit(3);
#elif defined(__APPLE__)
/*
* On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
* trapped.
*/
*((volatile int *) NULL) = 123; /* To continue from here in GDB: "return" then "continue". */
raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */
#else
raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
#endif
}
/*
* |JS_Assert| historically took |JSIntn ln| as its last argument. We've
* boiled |JSIntn ln| down to simply |int ln| so that mfbt may declare the
@ -106,14 +77,6 @@ CrashInJS()
*/
JS_STATIC_ASSERT((tl::IsSameType<JSIntn, int>::result));
JS_PUBLIC_API(void)
JS_Assert(const char *s, const char *file, int ln)
{
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
fflush(stderr);
CrashInJS();
}
#ifdef JS_BASIC_STATS
#include <math.h>

View File

@ -331,9 +331,9 @@ inline __attribute__ ((unused)) void MUST_FLOW_THROUGH(const char *label) {}
#ifdef JS_CRASH_DIAGNOSTICS
# define JS_POISON(p, val, size) memset((p), (val), (size))
# define JS_OPT_ASSERT(expr) \
((expr) ? (void)0 : JS_Assert(#expr, __FILE__, __LINE__))
((expr) ? (void)0 : MOZ_Assert(#expr, __FILE__, __LINE__))
# define JS_OPT_ASSERT_IF(cond, expr) \
((!(cond) || (expr)) ? (void)0 : JS_Assert(#expr, __FILE__, __LINE__))
((!(cond) || (expr)) ? (void)0 : MOZ_Assert(#expr, __FILE__, __LINE__))
#else
# define JS_POISON(p, val, size) ((void) 0)
# define JS_OPT_ASSERT(expr) ((void) 0)

View File

@ -53,6 +53,9 @@ CPPSRCS = \
$(NULL)
DEFINES += -DEXPORT_JS_API
# Building against js_static requires that we declare mfbt sybols "exported"
# on its behalf.
DEFINES += -DIMPL_MFBT
LIBS = $(NSPR_LIBS) $(EDITLINE_LIBS) $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX)
ifdef MOZ_NATIVE_FFI

View File

@ -1008,7 +1008,7 @@ CrashIfInvalidSlot(StackFrame *fp, Value *vp)
if (vp < fp->slots() || vp >= fp->slots() + fp->script()->nslots) {
JS_ASSERT(false && "About to dereference invalid slot");
*(int *)0xbad = 0; // show up nicely in crash-stats
JS_Assert("About to dereference invalid slot", __FILE__, __LINE__);
MOZ_Assert("About to dereference invalid slot", __FILE__, __LINE__);
}
}

91
mfbt/Assertions.cpp Normal file
View File

@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=99 ft=cpp:
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Hommey <mh@glandium.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Attributes.h"
#include "mozilla/Types.h"
#include <cstdio>
#include <cstdlib>
#ifndef WIN32
#include <signal.h>
#endif
/* Implementations of runtime and static assertion macros for C and C++. */
extern "C" {
MOZ_EXPORT_API(void)
MOZ_Crash()
{
/*
* We write 123 here so that the machine code for this function is
* unique. Otherwise the linker, trying to be smart, might use the
* same code for MOZ_Crash and for some other function. That
* messes up the signature in minidumps.
*/
#if defined(WIN32)
/*
* We used to call DebugBreak() on Windows, but amazingly, it causes
* the MSVS 2010 debugger not to be able to recover a call stack.
*/
*((volatile int *) NULL) = 123;
exit(3);
#elif defined(__APPLE__)
/*
* On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
* trapped.
*/
*((volatile int *) NULL) = 123; /* To continue from here in GDB: "return" then "continue". */
raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */
#else
raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
#endif
}
MOZ_EXPORT_API(void)
MOZ_Assert(const char* s, const char* file, int ln)
{
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
fflush(stderr);
MOZ_Crash();
}
}

View File

@ -126,26 +126,15 @@
#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason)
/*
* XXX: we're cheating here in order to avoid creating object files
* for mfbt /just/ to provide a function like FatalError() to be used
* by MOZ_ASSERT(). (It'll happen eventually, but for just ASSERT()
* it isn't worth the pain.) JS_Assert(), although unfortunately
* named, is part of SpiderMonkey's stable, external API, so this
* isn't quite as bad as it seems.
*
* Once mfbt needs object files, this unholy union with JS_Assert()
* will be broken.
*
* JS_Assert is present even in release builds, for the benefit of applications
* that build DEBUG and link against a non-DEBUG SpiderMonkey library.
*/
#ifdef __cplusplus
extern "C" {
#endif
extern MFBT_API(void)
JS_Assert(const char* s, const char* file, int ln);
MOZ_Crash(void);
extern MFBT_API(void)
MOZ_Assert(const char* s, const char* file, int ln);
#ifdef __cplusplus
} /* extern "C" */
@ -186,10 +175,10 @@ JS_Assert(const char* s, const char* file, int ln);
#ifdef DEBUG
/* First the single-argument form. */
# define MOZ_ASSERT_HELPER1(expr) \
((expr) ? ((void)0) : JS_Assert(#expr, __FILE__, __LINE__))
((expr) ? ((void)0) : MOZ_Assert(#expr, __FILE__, __LINE__))
/* Now the two-argument form. */
# define MOZ_ASSERT_HELPER2(expr, explain) \
((expr) ? ((void)0) : JS_Assert(#expr " (" explain ")", __FILE__, __LINE__))
((expr) ? ((void)0) : MOZ_Assert(#expr " (" explain ")", __FILE__, __LINE__))
/* And now, helper macrology up the wazoo. */
/* Count the number of arguments passed to MOZ_ASSERT. */
# define MOZ_COUNT_ASSERT_ARGS(...) \
@ -239,7 +228,7 @@ JS_Assert(const char* s, const char* file, int ln);
* }
*/
#ifdef DEBUG
# define MOZ_NOT_REACHED(reason) JS_Assert(reason, __FILE__, __LINE__)
# define MOZ_NOT_REACHED(reason) MOZ_Assert(reason, __FILE__, __LINE__)
#else
# define MOZ_NOT_REACHED(reason) ((void)0)
#endif

View File

@ -100,7 +100,7 @@ namespace detail {
* For more details, and examples of using these macros, see
* https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
*/
class MFBT_API(GuardObjectNotifier)
class MOZ_EXPORT_API(GuardObjectNotifier)
{
private:
bool* statementDone;
@ -117,7 +117,7 @@ class MFBT_API(GuardObjectNotifier)
}
};
class MFBT_API(GuardObjectNotificationReceiver)
class MOZ_EXPORT_API(GuardObjectNotificationReceiver)
{
private:
bool statementDone;

View File

@ -42,6 +42,11 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = mozglue
LIBRARY_NAME = mfbt
FORCE_STATIC_LIB = 1
STL_FLAGS =
DIRS =
# exported_headers.mk defines the headers exported by mfbt. It is included by
@ -49,4 +54,11 @@ DIRS =
# work to install mfbt's exported headers itself.
include $(srcdir)/exported_headers.mk
# sources.mk defines the source files built for mfbt. It is included by mfbt
# itself and by the JS engine, which, when built standalone, must do the work
# to build mfbt sources itself.
include $(srcdir)/sources.mk
DEFINES += -DIMPL_MFBT
include $(topsrcdir)/config/rules.mk

View File

@ -129,8 +129,17 @@
# define MFBT_API(type) MOZ_EXPORT_API(type)
# define MFBT_DATA(type) MOZ_EXPORT_DATA(type)
#else
# define MFBT_API(type) MOZ_IMPORT_API(type)
# define MFBT_DATA(type) MOZ_IMPORT_DATA(type)
/*
* When mozglue is linked in the program, we need the MFBT API symbols
* to be weak.
*/
# if defined(MOZ_GLUE_IN_PROGRAM)
# define MFBT_API(type) __attribute__((weak)) MOZ_IMPORT_API(type)
# define MFBT_DATA(type) __attribute__((weak)) MOZ_IMPORT_DATA(type)
# else
# define MFBT_API(type) MOZ_IMPORT_API(type)
# define MFBT_DATA(type) MOZ_IMPORT_DATA(type)
# endif
#endif
/*

3
mfbt/sources.mk Normal file
View File

@ -0,0 +1,3 @@
CPPSRCS += \
Assertions.cpp \
$(NULL)

View File

@ -93,6 +93,8 @@ ifdef MOZ_LINKER
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,linker,../linker)
endif
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
ifeq (Android, $(OS_TARGET))
WRAP_LDFLAGS =
endif