Commit 0bb532d2 authored by Xi Ruoyao's avatar Xi Ruoyao
Browse files

Bug 1841040 - Remove over-alignment from GCMarker and Nursery,...

Bug 1841040 - Remove over-alignment from GCMarker and Nursery, r=spidermonkey-reviewers,jonco a=RyanVM

js_new<T> cannot guarantee the alignment if T is over-aligned, and this
issue is not trivial to fix (blocked by Bug 1842582).

Add a static assert to detect the attempt using js_new<T> for
over-aligned T, and remove the problematic alignas() attributes as a
short-term fix.

Differential Revision: https://phabricator.services.mozilla.com/D182546
parent 5805d10d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -478,6 +478,9 @@ static inline void js_free(void* p) {
#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)              \
  template <class T, typename... Args>                                      \
  QUALIFIERS T* MOZ_HEAP_ALLOCATOR NEWNAME(Args&&... args) {                \
    static_assert(                                                          \
        alignof(T) <= alignof(max_align_t),                                 \
        "over-aligned type is not supported by JS_DECLARE_NEW_METHODS");    \
    void* memory = ALLOCATOR(sizeof(T));                                    \
    return MOZ_LIKELY(memory) ? new (memory) T(std::forward<Args>(args)...) \
                              : nullptr;                                    \
@@ -494,6 +497,9 @@ static inline void js_free(void* p) {
#define JS_DECLARE_NEW_ARENA_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)           \
  template <class T, typename... Args>                                         \
  QUALIFIERS T* MOZ_HEAP_ALLOCATOR NEWNAME(arena_id_t arena, Args&&... args) { \
    static_assert(                                                             \
        alignof(T) <= alignof(max_align_t),                                    \
        "over-aligned type is not supported by JS_DECLARE_NEW_ARENA_METHODS"); \
    void* memory = ALLOCATOR(arena, sizeof(T));                                \
    return MOZ_LIKELY(memory) ? new (memory) T(std::forward<Args>(args)...)    \
                              : nullptr;                                       \
+1 −1
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ enum ShouldReportMarkTime : bool {

} /* namespace gc */

class alignas(TypicalCacheLineSize) GCMarker {
class GCMarker {
  enum MarkingState : uint8_t {
    // Have not yet started marking.
    NotActive,
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class GCSchedulingTunables;
class TenuringTracer;
}  // namespace gc

class alignas(TypicalCacheLineSize) Nursery {
class Nursery {
 public:
  explicit Nursery(gc::GCRuntime* gc);
  ~Nursery();