Bug 1877642 - Disable browser_fullscreen-tab-close-race.js on apple_silicon !debug...
[gecko.git] / js / src / gc / Memory.h
blobfece46171d5f2f6041d6aba981b34f748a2c2df5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef gc_Memory_h
8 #define gc_Memory_h
10 #include <stddef.h>
12 namespace js {
13 namespace gc {
15 // Sanity check that our compiled configuration matches the currently
16 // running instance and initialize any runtime data needed for allocation.
17 void InitMemorySubsystem();
19 // The page size as reported by the operating system.
20 size_t SystemPageSize();
22 // The number of bits that may be set in a valid address, as
23 // reported by the operating system or measured at startup.
24 size_t SystemAddressBits();
26 // The number of bytes of virtual memory that may be allocated or mapped, as
27 // reported by the operating system on certain platforms. If no limit was able
28 // to be determined, then it will be size_t(-1).
29 size_t VirtualMemoryLimit();
31 // The scattershot allocator is used on platforms that have a large address
32 // range. On these platforms we allocate at random addresses.
33 bool UsingScattershotAllocator();
35 // Allocate or deallocate pages from the system with the given alignment.
36 // Pages will be read/write-able.
37 void* MapAlignedPages(size_t length, size_t alignment);
38 void UnmapPages(void* region, size_t length);
40 // We can only decommit unused pages if the page size is less than or equal to
41 // the hardcoded Arena size for the running process.
42 bool DecommitEnabled();
44 // Tell the OS that the given pages are not in use, so they should not be
45 // written to a paging file. This may be a no-op on some platforms.
46 bool MarkPagesUnusedSoft(void* region, size_t length);
48 // Tell the OS that the given pages are not in use and it can decommit them
49 // immediately. This may defer to MarkPagesUnusedSoft and must be paired with
50 // MarkPagesInUse to use the pages again.
51 bool MarkPagesUnusedHard(void* region, size_t length);
53 // Undo |MarkPagesUnusedSoft|: tell the OS that the given pages are of interest
54 // and should be paged in and out normally. This may be a no-op on some
55 // platforms. May make pages read/write-able.
56 void MarkPagesInUseSoft(void* region, size_t length);
58 // Undo |MarkPagesUnusedHard|: tell the OS that the given pages are of interest
59 // and should be paged in and out normally. This may be a no-op on some
60 // platforms. Callers must check the result, false could mean that the pages
61 // are not available. May make pages read/write.
62 [[nodiscard]] bool MarkPagesInUseHard(void* region, size_t length);
64 // Returns #(hard faults) + #(soft faults)
65 size_t GetPageFaultCount();
67 // Allocate memory mapped content.
68 // The offset must be aligned according to alignment requirement.
69 void* AllocateMappedContent(int fd, size_t offset, size_t length,
70 size_t alignment);
72 // Deallocate memory mapped content.
73 void DeallocateMappedContent(void* region, size_t length);
75 void* TestMapAlignedPagesLastDitch(size_t length, size_t alignment);
77 void ProtectPages(void* region, size_t length);
78 void MakePagesReadOnly(void* region, size_t length);
79 void UnprotectPages(void* region, size_t length);
81 } // namespace gc
82 } // namespace js
84 #endif /* gc_Memory_h */