From:  Andrew Sutherland <asutherland@asutherland.org>
Date:  29 Sep 2017 11:27:34 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.tech.js-engine.internals
Subject:  

Re: C++ coding style rule for keeping class fields together

NNTP-Posting-Host:  63.245.214.181

On Thu, Sep 28, 2017, at 08:51 PM, Nicholas Nethercote wrote:
> I sometimes want to know the memory layout of a class/struct. Having all
> the fields together makes that a *lot* easier.

Note that gdb's ptype command can help with this using "/m" which avoids
printing methods.  (And of course one can use gdb's python magic to do
even cooler things if you want to see where there's wasted space, etc.)

So, like:
$ gdb OBJDIR/dist/bin/libxul.so
(gdb) ptype/m JSContext
type = struct JSContext : public JS::RootingContext, public
js::MallocProvider {
  private:
    js::UnprotectedData runtime_;
    js::WriteOnceData kind_;
    js::WriteOnceData threadNative_;
    js::ThreadLocalData helperThread_;
    js::ThreadLocalData options_;
    js::ThreadLocalData arenas_;
  protected:
    js::ThreadLocalData enterCompartmentDepth_;
  private:
    static JS::Error reportedError;
    static JS::OOM reportedOOM;
    js::ThreadLocalData yieldCallback_;
  public:
    js::ThreadLocalData jitActivation;
    js::ThreadLocalData regexpStack;
    js::ThreadLocalData activation_;
    js::Activation * volatile profilingActivation_;
  private:
    js::ThreadLocalData interpreterStack_;
  public:
    const uintptr_t nativeStackBase;
    js::ThreadLocalData nativeStackQuota[3];
    js::ThreadLocalData entryMonitor;
    js::ThreadLocalData noExecuteDebuggerTop;
    bool handlingSegFault;
    js::ThreadLocalData activityCallback;
    js::ThreadLocalData activityCallbackArg;
    js::ThreadLocalData requestDepth;
  private:
    js::ThreadLocalData autoFlushICache_;
  public:
    js::ThreadLocalData dtoaState;
    js::ThreadLocalData heapState;
    js::ThreadLocalData suppressGC;
    js::ThreadLocalData enableAccessValidation;
    js::ThreadLocalData inUnsafeRegion;
    js::ThreadLocalData generationalDisabled;
    js::ThreadLocalData compactingDisabledCount;
    js::ThreadLocalData keepAtoms;
  private:
    js::ThreadLocalData frontendCollectionPool_;
    mozilla::Atomic
    suppressProfilerSampling;
    js::UnprotectedData geckoProfiler_;
  public:
    static const size_t TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE;
  private:
    js::ThreadLocalData tempLifoAlloc_;
  public:
    js::ThreadLocalData debuggerMutations;
    js::ThreadLocalData propertyRemovals;
    js::ThreadLocalData ionPcScriptCache;
  private:
    js::ThreadLocalData throwing;
    js::ThreadLocalData unwrappedException_;
    js::ThreadLocalData overRecursed_;
    js::ThreadLocalData propagatingForcedReturn_;
    js::ThreadLocalData liveVolatileJitFrameIter_;
  public:
    js::ThreadLocalData reportGranularity;
    js::ThreadLocalData resolvingList;
    js::ThreadLocalData generatingError;
  private:
    js::ThreadLocalData cycleDetectorVector_;
  public:
    js::UnprotectedData data;
    js::ThreadLocalData outstandingRequests;
    js::ThreadLocalData jitIsBroken;
  private:
    js::ThreadLocalData asyncStackForNewActivations_;
  public:
    js::ThreadLocalData asyncCauseForNewActivations;
    js::ThreadLocalData asyncCallIsExplicit;
  private:
    js::ThreadLocalData interruptCallbacks_;
  public:
    js::ThreadLocalData interruptCallbackDisabled;
    mozilla::Atomic
    interrupt_;
    mozilla::Atomic
    interruptRegExpJit_;
  private:
    mozilla::Atomic
    handlingJitInterrupt_;
  public:
    js::FutexThread fx;
    js::ThreadLocalData osrTempData_;
    js::ThreadLocalData ionReturnOverride_;
    mozilla::Atomic
    jitStackLimit;
    js::ThreadLocalData jitStackLimitNoInterrupt;
    js::ThreadLocalData getIncumbentGlobalCallback;
    js::ThreadLocalData enqueuePromiseJobCallback;
    js::ThreadLocalData enqueuePromiseJobCallbackData;
    js::ThreadLocalData jobQueue;
    js::ThreadLocalData drainingJobQueue;
    js::ThreadLocalData stopDrainingJobQueue;
    js::ThreadLocalData promiseRejectionTrackerCallback;
    js::ThreadLocalData promiseRejectionTrackerCallbackData;

    typedef js::Vector InterruptCallbackVector;
}

Andrew