Files
roytam1 2b8d14ce6d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1253137 - Baldr: update section header structure to match BinaryEncoding.md, part 2 (r=sunfish) (dbf52e6bb6)
- Bug 1253137 - Baldr: fix unknown-section handling (r=sunfish) (5f2ca84f1f)
- Bug 1253137 - Baldr: make all the section-ids match and remove c-string labels not in BinaryEncoding.md (r=sunfish) (87fbb4e5aa)
- Bug 1253137 - Baldr: move module generator constants back to WasmBinary.h (r=bustage) (b3a02a01d6)
- Bug 1246116: Wire BrTable in wasm and add a bunch of tests; r=sunfish (7b7002830e)
- Bug 1253115 - BaldrMonkey: Implement initial load/store offset support. r=luke (10944fb68b)
- Bug 1246116 - Baldr: remove two timeout tests until there is a good way to make them not fail on platforms without wasm (arm64) (r=red) (558235d951)
- Bug 1253142 - Remove the long-deprecated nsIMemory.isLowMemory function. r=froydnj. (b29cc3bbee)
- Bug 1253137 - Baldr: remove expected type from WasmIonCompile.cpp (r=sunfish) (36a0ee01fb)
- Bug 1253137 - Baldr: switch to bottom-up validation in Wasm.cpp (r=sunfish) (ee6cbfb6c2)
- Bug 1253137 - Baldr: switch from expression-count to function body byte size (r=sunfish) (16f85fd09e)
- Bug 1253137 - Baldr: move local definitions into the body (r=sunfish) (3cc8dc6f17)
- Bug 1253137 - Baldr: change wasmEvalText/Wasm.instantiateModule to return/take a typed array view instead of buffer (r=sunfish) (93288775ff)
- Bug 1253137 - Baldr: move ValType/ExprType into WasmBinary.h and tidy up WasmBinary.h (r=sunfish) (97e87b51c6)
- Bug 1246116 - Baldr: make the wasm br_table limit match asm.js (r=bbouvier) (a911172c39)
- Bug 1253115 - Ion: include asm.js load/store offset in GVN (r=sunfish) (6fe71cee89)
- Bug 1253884 - Baldr: fix parsing of (f32.const -0) (r=sunfish) (796e4e4e43)
- Bug 1253137 - Baldr: switch local array to local entry array (r=sunfish) (ca93aeb54b)
- Bug 1254984 - Experimental text representation of WebAssembly binary code (r=luke) (555507230b)
- Bug 1253137 - Baldr: pass around Bytes instead of Bytecode/UniqueBytecode (r=sunfish) (098db250ae)
- Bug 1253137 - Baldr: use length+bytes instead of c-strings (r=sunfish) (7aba9bc27c)
- Bug 1253137 - Baldr: switch {i32, i64}.const to SLEB128 (r=sunfish) (75b4235c40)
- Bug 1243488 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in uriloader/exthandler/; r=bz (086e0d94ac)
- Bug 1253137 - BalderMonkey: Define encodings for eqz, rotl, and rotr r=luke (df0751ca5e)
- Bug 1253137 - Baldr: add nop placeholder for branch values (r=sunfish) (ee4b8da1ce)
- Bug 1253137 - Baldr: put exports object onto .exports field of instance object (r=sunfish) (2d280c1bfa)
- Bug 1253137 - Baldr: add explicit function body count (r=sunfish) (6205d9cea2)
- Bug 1253137 - Baldr: update encoding of br_table branch targets (r=sunfish) (84e5ed54c0)
- Bug 1253137 - Baldr: update encoding of memory access immediates (r=sunfish) (e98f220129)
- Bug 1253137 - Baldr: switch from LEB128 to prefix-based scheme to match BinaryEncoding.md (r=sunfish) (0a909bfda8)
- Bug 1254893 - Keep a list of wasm::Modules per compartment. (r=terrence) (ebc9b55096)
- Bug 1254893 - Fire onNewScript for new wasm modules. (r=jimb) (f9cd6a4dac)
- Bug 1247126: Remove Debugger's tenure promotion log. r=fitzgen (10dd84a712)
- Bug 1239813: Ensure compartments don't get GC'd while Debugger.prototype.findScripts' ScriptQuery is holding them in its HashSet. r=sfink (7278791e79)
- Bug 1239813 - Add some asserts to IterateScripts to help us track down bug 1240231. r=sfink (fd49df43e8)
- Bug 1221378: Root Debuggers in js::Debugger::slowPathOnLogAllocationSite, in case logging causes a GC. r=fitzgen (f9a4dc94d9)
- Bug 1248162 - Clear pending exceptions when ignoring OOMs in Debugger::slowPathOnNewGlobalObject; r=jimb (4f54e5ecc2)
- Bug 1246215 - Console prevents let re-declaration even when first wasan error; r=jryans,shu (6b36a886c2)
- Bug 1246215 - Guard against passing non-atoms and non-property names to LookupProperty; r=evilpie (129cbe6144)
- Bug 1250190: Make DebuggeeWouldRun checks not assume we always unlock before re-locking. r=fitzgen (d0c740a1f5)
- Bug 1245877 - Expose error message names via the debugger object; r=jorendorff (1406d70c4d)
- Bug 1250520 - Handle reporting DebuggeeWouldRun when the script has no filename. (r=fitzgen) (47402fe973)
- Bug 1252453: make Debugger::slowPathOnLogAllocationSite apply a read barrier to Debugger objects. r=terrence (b46b7fe8a2)
- Bug 1254893 - Prep Debugger.Script for a tagged union referent. (r=jimb) (d6231c1aed)
- Bug 1254893 - Prep Debugger.Source for a tagged union referent. (r=jimb) (3209106a0f)
- Bug 1254893 - Synthesize Debugger.Scripts for wasm modules and find them via findScripts. (r=jimb) (225488fb00)
- Bug 1254893 - Display placeholder text for synthesized Debugger.Sources. (r=jimb) (f2099a40fd)
- Bug 1254453 - Support using Variant inside GC wrappers. (r=terrence) (0454cc6491)
- Bug 1254893 - Add a .format property on Debugger.Script. (r=jimb) (05a71ca78c)
- Bug 1254893 - Support wasm for most of the Debugger.Source properties. (r=jimb) (941075c666)
- Bug 1254893 - Append "> wasm" to URLs of wasm Debugger.Sources to hack around blacklisting in devtools. (r=jimb) (0a78f4294c)
- Bug 1254893 - Followup: read barrier wasm modules exposed via Debugger.findScript. (r=luke) (e329952674)
- Bug 1254893 - Update Debugger.Source docs. (r=jimb) (4a19e39364)
- Bug 1254893 - Update Debugger.Script docs. (r=jimb) (97186b2dfa)
- Bug 1254893 - Synthesize Debugger.Sources for wasm modules. (r=jimb) (ee9522479a)
- Bug 1254893 - Followup: fix awkward wording in Debugger.Source docs. DONTBUILD. (r=me) (b8734c7ac8)
- Bug 1254893 - Tests for perfunctory functionality of wasm Debugger.Scripts and Debugger.Sources. (r=jimb) (37308f45c4)
- Bug 1254893 - Connect wasm::BinaryToText with Debugger.Source (r=shu) (5c7918d178)
- Bug 1254893 - Change 'Experimental' to 'Temporary' in string and DONTBUILD (r=me) (78b018aea0)
- Bug 1243267 - Guard against reentrancy into the dispatch of a scroll event. r=mats (2da2136351)
- Bug 1254105 - Avoid passing magic values to the error reporter machinery in the ShortestPaths testing function; r=jimb (a8dcdf997d)
- Bug 1252912 - Ensure that we wrap the results of the shortestPaths JS shell testing function. r=jimb (8a19ebf0a3)
- Bug 1252432 part 4 - Implement wasm {f32,f64}.convert_{u,s}/i64 on x64. r=sunfish (1d3ad096b8)
- Bug 1256633 - Reject wasm i64 ops on platforms that don't support them yet. r=bbouvier (e0452420f2)
- Bug 1255772: Implement wasm::Unreachable; r=sunfish (67b40b287a)
- Bug 1254836 - Baldr: handle over-recursion in validator (r=bbouvier) (0b35cbccdf)
- Bug 1256480: Allow passing Float32 arguments to FFI on the stack; r=luke (c1bc3e06a7)
- Bug 1256956 - Silence some GCC warnings. r=luke. (eaeeddccd9)
- Bug 1245112 - Part 12: Move MacroAssembler::branchPtrWithPatch into generic macro assembler. r=nbp (6e99b92e92)
- Bug 1245112 - Part 13: Move MacroAssembler::branchPtrInNurseryRange into generic macro assembler. r=jonco (a09ecb3d7b)
- Bug 1245112 - Part 14: Move MacroAssembler::branchValueIsNurseryObject into generic macro assembler. r=jonco (f91b64eff4)
- Bug 1245112 - Part 15: Move MacroAssembler::branchAdd32 into generic macro assembler. r=lth (3179998ae2)
- Bug 1245112 - Part 16: Move MacroAssembler::branchSub32 into generic macro assembler. r=lth (0cdb5bbf74)
- Bug 1245112 - Part 17: Move MacroAssembler::decBranchPtr into generic macro assembler. r=nbp (5f9f615121)
- Bug 1245112 - Part 18: Move MacroAssembler::branchTestInt32 into generic macro assembler. r=jandem (d19625e026)
- Bug 1245112 - Part 19: Move MacroAssembler::branchTestInt32Truthy into generic macro assembler. r=jandem (18580b219d)
- Bug 1245112 - Part 18 followup: More refactor branchTestInt32. r=nbp (0cba5f769b)
- Bug 1245112 - Part 20: Move MacroAssembler::branchTestDouble into generic macro assembler. r=nbp (36e18c1990)
- Bug 1245112 - Part 21: Move MacroAssembler::branchTestDoubleTruthy into generic macro assembler. r=nbp (706fece6a2)
- Bug 1245112 - Part 22: Move MacroAssembler::branchTestNumber into generic macro assembler. r=bhackett (53a04401bc)
- Bug 1245112 - Part 23: Move MacroAssembler::branchTestBoolean into generic macro assembler. r=sstangl (80fd098bfc)
- Bug 1245112 - Part 24: Move MacroAssembler::branchTestBooleanTruthy into generic macro assembler. r=sstangl (b6c9773d6b)
- Bug 1245112 - Part 25: Move MacroAssembler::branchTestUndefined into generic macro assembler. r=sstangl (a0e87e7c07)
- Bug 1245112 - Part 26: Move MacroAssembler::branchTestString into generic macro assembler. r=sstangl (cb74d2a341)
- Bug 1245112 - Part 27: Move MacroAssembler::branchTestStringTruthy into generic macro assembler. r=sstangl (3f0846f961)
- Bug 1245112 - Part 28: Move MacroAssembler::branchTestSymbol into generic macro assembler. r=jorendorff (20bcf1f5f0)
- Bug 1245112 - Part 29: Move MacroAssembler::branchTestNull into generic macro assembler. r=sstangl (49795964c7)
- Bug 1245112 - Part 30: Move MacroAssembler::branchTestObject into generic macro assembler. r=sstangl (48536c8883)
- Bug 1245112 - Part 31: Move MacroAssembler::branchTestGCThing into generic macro assembler. r=jandem (d3cbbb7446)
- Bug 1245112 - Part 32: Move MacroAssembler::branchTestPrimitive into generic macro assembler. r=jandem (9a89167842)
- Bug 1245112 - Part 33: Move MacroAssembler::branchTestMagic into generic macro assembler. r=jandem (65a1847bc1)
- Bug 1245112 - Part 34: Move MacroAssembler::branchTestMagicValue into generic macro assembler. r=jandem (4772aa0d5c)
- Bug 1245112 - Part 35: Move MacroAssembler::branchTestValue into generic macro assembler. r=jandem (c8e417a332)
- Bug 1245112 - Part 36: Move MacroAssembler::branchPtrImpl into generic macro assembler. r=nbp (844d3c0b07)
- Bug 1248289 - Part 0: Change OrderedHashTable::Range::ht member from a reference to a pointer to use offsetof. r=sfink (4eae1c9dd6)
- Bug 1254808 - IonMonkey: Factor MacroAssembler::popReturnAddress on ARM. r=nbp (2cee710668)
- Bug 1252326: Flush the assembly buffer at the end of codegen for plateforms which need it; r=luke (2195910785)
- Bug 1255956: Check for OOM after flushing constant pools; r=luke (d5190f17f0)
- Bug 1249961 - Rename MacroAssembler::branchEqualTypeIfNeeded to MacroAssembler::maybeBranchTestType. r=nbp (8dc9347991)
- Bug 1249960 - Rename Int32Key to RegisterOrInt32Constant, branchKey to branch32, storeKey to store32, bumpKey to inc32 and dec32. r=nbp (f29d6f63a1)
- Bug 1248289 - Part 1: Inline _GetNextMapEntryForIterator intrinsic. r=jandem (ed1ef17167)
- Bug 1253877 - Baldr: print missing text labels in resolving phase (r=mbx) (aca747eaed)
- Bug 1255691: Implement Select; r=sunfish (5dfc79e866)
- Bug 1244414 - Create iframe element from script to avoid racing with the load event; r=bz (ba1ba93693)
- Bug 1241784 - Part 3: Test. r=birtles (f87f4aff69)
- Bug 1241784 - Part 1: Add a helper function for Element.animate(). r=birtles (8dfbda09e9)
- Bug 1241784 - Part 2: Implement CSSPseudoElement.animate(). r=birtles (e52ae76368)
- Bug 1241784 - Part 4: Remove removeElement from testcommon.js. r=birtles (a78d60ae3c)
- Bug 1238694 - Limit the number of asm.js/wasm code allocations to avoid running into Linux kernel limits. r=luke (2f27e29df6)
- Bug 1258320 - Fix jump target in CodeGenerator::visitGetNextMapEntryForIterator. r=jandem (35a52f67c6)
- Bug 1254376 - Add a read barrier to the global's debugger vector r=jimb (31712fa31d)
- Bug 1245860 - Remove Debugger.onIonCompilation Hook. r=shu (8584bd0547)
- Bug 1254092 - TraceIncomingCCWs should work at the JSCompartment level of granularity. r=jimb (f1fc5ea7fb)
- Bug 1257045 - Give Debugger wrappers of wasm code their own CCW key kinds. (r=jimb) (ff4817d32e)
- Bug 1255954 - Odin: move asserts so they only run on successful validation (r=bbouvier) (4d58c80c0b)
- Bug 837192 - Stop trying to inject "use strict"; into Function.prototype.toString() output. r=Waldo. (e58bac6110)
- Bug 1256291: Fix unified build under js/; r=Ms2ger (8ce81ec08f)
- Bug 1258346: Check for success in calls to append() in WasmBinaryToText: r=jorendorff (5e106e29bd)
- Bug 1107143 - Don't build event regions unless we're painting to the window. r=tnikkel (7880bda251)
- Bug 1252374 - Increase the chunk size of the displayListArena. r=roc. (ce9543e592)
2024-02-15 11:15:07 +08:00

221 lines
4.9 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMemoryImpl.h"
#include "nsThreadUtils.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsISimpleEnumerator.h"
#include "nsCOMPtr.h"
#include "mozilla/Services.h"
#ifdef ANDROID
#include <stdio.h>
// Minimum memory threshold for a device to be considered
// a low memory platform. This value has be in sync with
// Java's equivalent threshold, defined in
// mobile/android/base/util/HardwareUtils.java
#define LOW_MEMORY_THRESHOLD_KB (384 * 1024)
#endif
static nsMemoryImpl sGlobalMemory;
NS_IMPL_QUERY_INTERFACE(nsMemoryImpl, nsIMemory)
NS_IMETHODIMP_(void*)
nsMemoryImpl::Alloc(size_t aSize)
{
return NS_Alloc(aSize);
}
NS_IMETHODIMP_(void*)
nsMemoryImpl::Realloc(void* aPtr, size_t aSize)
{
return NS_Realloc(aPtr, aSize);
}
NS_IMETHODIMP_(void)
nsMemoryImpl::Free(void* aPtr)
{
NS_Free(aPtr);
}
NS_IMETHODIMP
nsMemoryImpl::HeapMinimize(bool aImmediate)
{
return FlushMemory(MOZ_UTF16("heap-minimize"), aImmediate);
}
NS_IMETHODIMP
nsMemoryImpl::IsLowMemoryPlatform(bool* aResult)
{
#ifdef ANDROID
static int sLowMemory = -1; // initialize to unknown, lazily evaluate to 0 or 1
if (sLowMemory == -1) {
sLowMemory = 0; // assume "not low memory" in case file operations fail
*aResult = false;
// check if MemTotal from /proc/meminfo is less than LOW_MEMORY_THRESHOLD_KB
FILE* fd = fopen("/proc/meminfo", "r");
if (!fd) {
return NS_OK;
}
uint64_t mem = 0;
int rv = fscanf(fd, "MemTotal: %llu kB", &mem);
if (fclose(fd)) {
return NS_OK;
}
if (rv != 1) {
return NS_OK;
}
sLowMemory = (mem < LOW_MEMORY_THRESHOLD_KB) ? 1 : 0;
}
*aResult = (sLowMemory == 1);
#else
*aResult = false;
#endif
return NS_OK;
}
/*static*/ nsresult
nsMemoryImpl::Create(nsISupports* aOuter, const nsIID& aIID, void** aResult)
{
if (NS_WARN_IF(aOuter)) {
return NS_ERROR_NO_AGGREGATION;
}
return sGlobalMemory.QueryInterface(aIID, aResult);
}
nsresult
nsMemoryImpl::FlushMemory(const char16_t* aReason, bool aImmediate)
{
nsresult rv = NS_OK;
if (aImmediate) {
// They've asked us to run the flusher *immediately*. We've
// got to be on the UI main thread for us to be able to do
// that...are we?
if (!NS_IsMainThread()) {
NS_ERROR("can't synchronously flush memory: not on UI thread");
return NS_ERROR_FAILURE;
}
}
bool lastVal = sIsFlushing.exchange(true);
if (lastVal) {
return NS_OK;
}
PRIntervalTime now = PR_IntervalNow();
// Run the flushers immediately if we can; otherwise, proxy to the
// UI thread an run 'em asynchronously.
if (aImmediate) {
rv = RunFlushers(aReason);
} else {
// Don't broadcast more than once every 1000ms to avoid being noisy
if (PR_IntervalToMicroseconds(now - sLastFlushTime) > 1000) {
sFlushEvent.mReason = aReason;
rv = NS_DispatchToMainThread(&sFlushEvent);
}
}
sLastFlushTime = now;
return rv;
}
nsresult
nsMemoryImpl::RunFlushers(const char16_t* aReason)
{
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
// Instead of:
// os->NotifyObservers(this, "memory-pressure", aReason);
// we are going to do this manually to see who/what is
// deallocating.
nsCOMPtr<nsISimpleEnumerator> e;
os->EnumerateObservers("memory-pressure", getter_AddRefs(e));
if (e) {
nsCOMPtr<nsIObserver> observer;
bool loop = true;
while (NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop) {
nsCOMPtr<nsISupports> supports;
e->GetNext(getter_AddRefs(supports));
if (!supports) {
continue;
}
observer = do_QueryInterface(supports);
observer->Observe(observer, "memory-pressure", aReason);
}
}
}
sIsFlushing = false;
return NS_OK;
}
// XXX need NS_IMPL_STATIC_ADDREF/RELEASE
NS_IMETHODIMP_(MozExternalRefCountType)
nsMemoryImpl::FlushEvent::AddRef()
{
return 2;
}
NS_IMETHODIMP_(MozExternalRefCountType)
nsMemoryImpl::FlushEvent::Release()
{
return 1;
}
NS_IMPL_QUERY_INTERFACE(nsMemoryImpl::FlushEvent, nsIRunnable)
NS_IMETHODIMP
nsMemoryImpl::FlushEvent::Run()
{
sGlobalMemory.RunFlushers(mReason);
return NS_OK;
}
mozilla::Atomic<bool>
nsMemoryImpl::sIsFlushing;
PRIntervalTime
nsMemoryImpl::sLastFlushTime = 0;
nsMemoryImpl::FlushEvent
nsMemoryImpl::sFlushEvent;
XPCOM_API(void*)
NS_Alloc(size_t aSize)
{
return moz_xmalloc(aSize);
}
XPCOM_API(void*)
NS_Realloc(void* aPtr, size_t aSize)
{
return moz_xrealloc(aPtr, aSize);
}
XPCOM_API(void)
NS_Free(void* aPtr)
{
moz_free(aPtr);
}
nsresult
NS_GetMemoryManager(nsIMemory** aResult)
{
return sGlobalMemory.QueryInterface(NS_GET_IID(nsIMemory), (void**)aResult);
}