-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathJITTimeConstructorCache.cpp
147 lines (127 loc) · 4.37 KB
/
JITTimeConstructorCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
CompileAssert(sizeof(JITTimeConstructorCache) == sizeof(JITTimeConstructorCacheIDL));
JITTimeConstructorCache::JITTimeConstructorCache(const Js::JavascriptFunction* constructor, Js::ConstructorCache* runtimeCache)
{
Assert(constructor != nullptr);
Assert(runtimeCache != nullptr);
m_data.runtimeCacheAddr = runtimeCache;
m_data.runtimeCacheGuardAddr = const_cast<void*>(runtimeCache->GetAddressOfGuardValue());
m_data.slotCount = runtimeCache->content.slotCount;
m_data.inlineSlotCount = runtimeCache->content.inlineSlotCount;
m_data.skipNewScObject = runtimeCache->content.skipDefaultNewObject;
m_data.ctorHasNoExplicitReturnValue = runtimeCache->content.ctorHasNoExplicitReturnValue;
m_data.typeIsFinal = runtimeCache->content.typeIsFinal;
m_data.isUsed = false;
m_data.guardedPropOps = 0;
if (runtimeCache->IsNormal())
{
JITType::BuildFromJsType(reinterpret_cast<Js::DynamicType*>(runtimeCache->GetValue()), (JITType*)&m_data.type);
}
}
JITTimeConstructorCache::JITTimeConstructorCache(const JITTimeConstructorCache* other)
{
Assert(other != nullptr);
Assert(other->GetRuntimeCacheAddr() != 0);
m_data.runtimeCacheAddr = reinterpret_cast<void*>(other->GetRuntimeCacheAddr());
m_data.runtimeCacheGuardAddr = reinterpret_cast<void*>(other->GetRuntimeCacheGuardAddr());
m_data.type = *(TypeIDL*)PointerValue(other->GetType().t);
m_data.slotCount = other->GetSlotCount();
m_data.inlineSlotCount = other->GetInlineSlotCount();
m_data.skipNewScObject = other->SkipNewScObject();
m_data.ctorHasNoExplicitReturnValue = other->CtorHasNoExplicitReturnValue();
m_data.typeIsFinal = other->IsTypeFinal();
m_data.isUsed = false;
m_data.guardedPropOps = 0; // REVIEW: OOP JIT should we copy these when cloning?
}
JITTimeConstructorCache*
JITTimeConstructorCache::Clone(JitArenaAllocator* allocator) const
{
JITTimeConstructorCache* clone = Anew(allocator, JITTimeConstructorCache, this);
return clone;
}
BVSparse<JitArenaAllocator>*
JITTimeConstructorCache::GetGuardedPropOps() const
{
return (BVSparse<JitArenaAllocator>*)(m_data.guardedPropOps & ~(intptr_t)1);
}
void
JITTimeConstructorCache::EnsureGuardedPropOps(JitArenaAllocator* allocator)
{
if (GetGuardedPropOps() == nullptr)
{
m_data.guardedPropOps = (intptr_t)Anew(allocator, BVSparse<JitArenaAllocator>, allocator);
m_data.guardedPropOps |= 1; // tag it to prevent false positive after the arena address reuse in recycler
}
}
void
JITTimeConstructorCache::SetGuardedPropOp(uint propOpId)
{
Assert(GetGuardedPropOps() != nullptr);
GetGuardedPropOps()->Set(propOpId);
}
void
JITTimeConstructorCache::AddGuardedPropOps(const BVSparse<JitArenaAllocator>* propOps)
{
Assert(GetGuardedPropOps() != nullptr);
GetGuardedPropOps()->Or(propOps);
}
intptr_t
JITTimeConstructorCache::GetRuntimeCacheAddr() const
{
return reinterpret_cast<intptr_t>(PointerValue(m_data.runtimeCacheAddr));
}
intptr_t
JITTimeConstructorCache::GetRuntimeCacheGuardAddr() const
{
return reinterpret_cast<intptr_t>(PointerValue(m_data.runtimeCacheGuardAddr));
}
JITTypeHolder
JITTimeConstructorCache::GetType() const
{
return JITTypeHolder((JITType*)&m_data.type);
}
int
JITTimeConstructorCache::GetSlotCount() const
{
return m_data.slotCount;
}
int16
JITTimeConstructorCache::GetInlineSlotCount() const
{
return m_data.inlineSlotCount;
}
bool
JITTimeConstructorCache::SkipNewScObject() const
{
return m_data.skipNewScObject != FALSE;
}
bool
JITTimeConstructorCache::CtorHasNoExplicitReturnValue() const
{
return m_data.ctorHasNoExplicitReturnValue != FALSE;
}
bool
JITTimeConstructorCache::IsTypeFinal() const
{
return m_data.typeIsFinal != FALSE;
}
bool
JITTimeConstructorCache::IsUsed() const
{
return m_data.isUsed != FALSE;
}
// TODO: OOP JIT, does this need to flow back?
void
JITTimeConstructorCache::SetUsed(bool val)
{
m_data.isUsed = val;
}
JITTimeConstructorCacheIDL *
JITTimeConstructorCache::GetData()
{
return &m_data;
}