Skip to content

Commit 0b65f03

Browse files
committed
Reimplement JSC::CachePayload without FileSystem::unmapViewOfFile and FileSystem::MappedFileData::leakHandle
https://bugs.webkit.org/show_bug.cgi?id=227014 Reviewed by Yusuke Suzuki. r247542 (Bug 199759) added FileSystem::unmapViewOfFile and FileSystem::MappedFileData::leakHandle for JSC::CachePayload to get the mapped address and to free the address. However, Bug 227011 is going to add a file mapping handle to FileSystem::MappedFileData for Windows port to create a SharedMemory from a MappedFileData. Destruction of MappedFileData should be done only by MappedFileData dtor. * runtime/CachePayload.cpp: (JSC::CachePayload::makeMappedPayload): (JSC::CachePayload::makeMallocPayload): (JSC::CachePayload::makeEmptyPayload): (JSC::CachePayload::CachePayload): (JSC::CachePayload::data const): (JSC::CachePayload::size const): (JSC::CachePayload::~CachePayload): Deleted. (JSC::CachePayload::operator=): Deleted. (JSC::CachePayload::freeData): Deleted. * runtime/CachePayload.h: Use Variant for data. (JSC::CachePayload::data const): Deleted. (JSC::CachePayload::size const): Deleted. (JSC::CachePayload::CachePayload): Deleted. Canonical link: https://commits.webkit.org/238933@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 2b1487f commit 0b65f03

3 files changed

Lines changed: 62 additions & 36 deletions

File tree

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
2021-06-17 Fujii Hironori <Hironori.Fujii@sony.com>
2+
3+
Reimplement JSC::CachePayload without FileSystem::unmapViewOfFile and FileSystem::MappedFileData::leakHandle
4+
https://bugs.webkit.org/show_bug.cgi?id=227014
5+
6+
Reviewed by Yusuke Suzuki.
7+
8+
r247542 (Bug 199759) added FileSystem::unmapViewOfFile and
9+
FileSystem::MappedFileData::leakHandle for JSC::CachePayload to
10+
get the mapped address and to free the address.
11+
12+
However, Bug 227011 is going to add a file mapping handle to
13+
FileSystem::MappedFileData for Windows port to create a
14+
SharedMemory from a MappedFileData. Destruction of MappedFileData
15+
should be done only by MappedFileData dtor.
16+
17+
* runtime/CachePayload.cpp:
18+
(JSC::CachePayload::makeMappedPayload):
19+
(JSC::CachePayload::makeMallocPayload):
20+
(JSC::CachePayload::makeEmptyPayload):
21+
(JSC::CachePayload::CachePayload):
22+
(JSC::CachePayload::data const):
23+
(JSC::CachePayload::size const):
24+
(JSC::CachePayload::~CachePayload): Deleted.
25+
(JSC::CachePayload::operator=): Deleted.
26+
(JSC::CachePayload::freeData): Deleted.
27+
* runtime/CachePayload.h: Use Variant for data.
28+
(JSC::CachePayload::data const): Deleted.
29+
(JSC::CachePayload::size const): Deleted.
30+
(JSC::CachePayload::CachePayload): Deleted.
31+
132
2021-06-17 Yijia Huang <yijia_huang@apple.com>
233

334
Add a new pattern to instruction selector to utilize UBFX supported by ARM64

‎Source/JavaScriptCore/runtime/CachePayload.cpp‎

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,52 @@ namespace JSC {
3030

3131
CachePayload CachePayload::makeMappedPayload(FileSystem::MappedFileData&& data)
3232
{
33-
return CachePayload(true, data.leakHandle(), data.size());
33+
return CachePayload(WTFMove(data));
3434
}
3535

3636
CachePayload CachePayload::makeMallocPayload(MallocPtr<uint8_t, VMMalloc>&& data, size_t size)
3737
{
38-
return CachePayload(false, data.leakPtr(), size);
38+
return CachePayload(std::pair { WTFMove(data), size });
3939
}
4040

4141
CachePayload CachePayload::makeEmptyPayload()
4242
{
43-
return CachePayload(true, nullptr, 0);
43+
return CachePayload(std::pair { nullptr, 0 });
4444
}
4545

4646
CachePayload::CachePayload(CachePayload&& other)
4747
{
48-
m_mapped = other.m_mapped;
49-
m_size = other.m_size;
50-
m_data = other.m_data;
51-
other.m_mapped = false;
52-
other.m_data = nullptr;
53-
other.m_size = 0;
48+
m_data = WTFMove(other.m_data);
49+
other.m_data = std::pair { nullptr, 0 };
5450
}
5551

56-
CachePayload::~CachePayload()
52+
CachePayload::CachePayload(Variant<FileSystem::MappedFileData, std::pair<MallocPtr<uint8_t, VMMalloc>, size_t>>&& data)
53+
: m_data(WTFMove(data))
5754
{
58-
freeData();
5955
}
6056

61-
CachePayload& CachePayload::operator=(CachePayload&& other)
57+
CachePayload::~CachePayload() = default;
58+
59+
const uint8_t* CachePayload::data() const
6260
{
63-
ASSERT(&other != this);
64-
freeData();
65-
return *new (this) CachePayload(WTFMove(other));
61+
return WTF::switchOn(m_data,
62+
[](const FileSystem::MappedFileData& data) {
63+
return static_cast<const uint8_t*>(data.data());
64+
},
65+
[](const std::pair<MallocPtr<uint8_t, VMMalloc>, size_t>& data) {
66+
return data.first.get();
67+
});
6668
}
6769

68-
void CachePayload::freeData()
70+
size_t CachePayload::size() const
6971
{
70-
if (!m_data)
71-
return;
72-
if (m_mapped) {
73-
FileSystem::unmapViewOfFile(m_data, m_size);
74-
} else
75-
fastFree(m_data);
72+
return WTF::switchOn(m_data,
73+
[](const FileSystem::MappedFileData& data) {
74+
return data.size();
75+
},
76+
[](const std::pair<MallocPtr<uint8_t, VMMalloc>, size_t>& data) {
77+
return data.second;
78+
});
7679
}
7780

7881
} // namespace JSC

‎Source/JavaScriptCore/runtime/CachePayload.h‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "VM.h"
2929
#include <wtf/FileSystem.h>
3030
#include <wtf/MallocPtr.h>
31+
#include <wtf/Variant.h>
3132

3233
namespace JSC {
3334

@@ -41,22 +42,13 @@ class CachePayload {
4142
JS_EXPORT_PRIVATE ~CachePayload();
4243
JS_EXPORT_PRIVATE CachePayload& operator=(CachePayload&& other);
4344

44-
const uint8_t* data() const { return m_data; }
45-
size_t size() const { return m_size; }
45+
JS_EXPORT_PRIVATE const uint8_t* data() const;
46+
JS_EXPORT_PRIVATE size_t size() const;
4647

4748
private:
48-
CachePayload(bool mapped, void* data, size_t size)
49-
: m_mapped(mapped)
50-
, m_size(size)
51-
, m_data(static_cast<uint8_t*>(data))
52-
{
53-
}
54-
55-
void freeData();
56-
57-
bool m_mapped;
58-
size_t m_size;
59-
uint8_t* m_data;
49+
CachePayload(Variant<FileSystem::MappedFileData, std::pair<MallocPtr<uint8_t, VMMalloc>, size_t>>&&);
50+
51+
Variant<FileSystem::MappedFileData, std::pair<MallocPtr<uint8_t, VMMalloc>, size_t>> m_data;
6052
};
6153

6254
} // namespace JSC

0 commit comments

Comments
 (0)