@@ -73,40 +73,10 @@ namespace Js
7373 return value;
7474 }
7575
76- int32 GetSigned (CountT typeEnum) const
77- {
78- #if DBG
79- if (!bgThreadCallStarted && ThreadContext::GetContextForCurrentThread () == nullptr )
80- {
81- bgThreadCallStarted = true ;
82- }
83- #endif
84-
85- uint8 type = static_cast <uint8>(typeEnum);
86- uint8 localFieldSize = fieldSize;
87- int32 value = 0 ;
88- if (localFieldSize == 1 )
89- {
90- value = this ->fields ->i8Fields [type];
91- }
92- else if (localFieldSize == 2 )
93- {
94- value = this ->fields ->i16Fields [type];
95- }
96- else if (localFieldSize == 4 )
97- {
98- value = this ->fields ->i32Fields [type];
99- }
100- else
101- {
102- Assert (localFieldSize == 0 && this ->isCleaningUp && this ->fields == nullptr ); // OOM when initial allocation failed
103- }
104- return value;
105- }
106-
10776 uint32 Set (CountT typeEnum, uint32 val, T* host)
10877 {
109- Assert (bgThreadCallStarted == false || isCleaningUp == true );
78+ Assert (bgThreadCallStarted == false || isCleaningUp == true
79+ || host->GetScriptContext ()->GetThreadContext ()->GetEtwRundownCriticalSection ()->IsLockedByAnyThread ());
11080
11181 uint8 type = static_cast <uint8>(typeEnum);
11282 if (fieldSize == 1 )
@@ -144,46 +114,6 @@ namespace Js
144114 return val;
145115 }
146116
147- int32 SetSigned (CountT typeEnum, int32 val, T* host)
148- {
149- Assert (bgThreadCallStarted == false || isCleaningUp == true );
150-
151- uint8 type = static_cast <uint8>(typeEnum);
152- if (fieldSize == 1 )
153- {
154- if (val <= INT8_MAX && val >= INT8_MIN)
155- {
156- return this ->fields ->i8Fields [type] = static_cast <uint8>(val);
157- }
158- else
159- {
160- (val <= INT16_MAX && val >= INT16_MIN)? AllocCounters<uint16>(host): AllocCounters<uint32>(host);
161- return host->counters .SetSigned (typeEnum, val, host);
162- }
163- }
164-
165- if (fieldSize == 2 )
166- {
167- if (val <= INT16_MAX && val >= INT16_MIN)
168- {
169- return this ->fields ->i16Fields [type] = static_cast <uint16>(val);
170- }
171- else
172- {
173- AllocCounters<uint32>(host);
174- return host->counters .SetSigned (typeEnum, val, host);
175- }
176- }
177-
178- if (fieldSize == 4 )
179- {
180- return this ->fields ->i32Fields [type] = val;
181- }
182-
183- Assert (fieldSize == 0 && this ->isCleaningUp && this ->fields == nullptr && val == 0 ); // OOM when allocating the counters structure
184- return val;
185- }
186-
187117 uint32 Increase (CountT typeEnum, T* host)
188118 {
189119 Assert (bgThreadCallStarted == false );
@@ -225,7 +155,6 @@ namespace Js
225155 Assert (ThreadContext::GetContextForCurrentThread () || ThreadContext::GetCriticalSection ()->IsLocked ());
226156 Assert (host->GetRecycler () != nullptr );
227157
228- const uint8 signedStart = static_cast <uint8>(CountT::SignedFieldsStart);
229158 const uint8 max = static_cast <uint8>(CountT::Max);
230159 typedef CompactCounters<T, CountT> CounterT;
231160 CounterT::Fields* fieldsArray = (CounterT::Fields*)RecyclerNewArrayLeafZ (host->GetRecycler (), FieldT, sizeof (FieldT)*max);
@@ -235,45 +164,42 @@ namespace Js
235164 {
236165 if (sizeof (FieldT) == 2 )
237166 {
238- for (; i < signedStart; i++)
239- {
240- fieldsArray->u16Fields [i] = oldFieldsArray->u8Fields [i];
241- }
242167 for (; i < max; i++)
243168 {
244- fieldsArray->i16Fields [i] = oldFieldsArray->i8Fields [i];
169+ fieldsArray->u16Fields [i] = oldFieldsArray->u8Fields [i];
245170 }
246171 }
247172 else if (sizeof (FieldT) == 4 )
248173 {
249- for (; i < signedStart; i++)
250- {
251- fieldsArray->u32Fields [i] = oldFieldsArray->u8Fields [i];
252- }
253174 for (; i < max; i++)
254175 {
255- fieldsArray->i32Fields [i] = oldFieldsArray->i8Fields [i];
176+ fieldsArray->u32Fields [i] = oldFieldsArray->u8Fields [i];
256177 }
257178 }
258179 }
259180 else if (this ->fieldSize == 2 )
260181 {
261- for (; i < signedStart; i++)
262- {
263- fieldsArray->u32Fields [i] = oldFieldsArray->u16Fields [i];
264- }
265182 for (; i < max; i++)
266183 {
267- fieldsArray->i32Fields [i] = oldFieldsArray->i16Fields [i];
184+ fieldsArray->u32Fields [i] = oldFieldsArray->u16Fields [i];
268185 }
269186 }
270187 else
271188 {
272189 Assert (this ->fieldSize ==0 );
273190 }
274191
275- this ->fieldSize = sizeof (FieldT);
276- this ->fields = fieldsArray;
192+ if (this ->fieldSize == 0 )
193+ {
194+ this ->fieldSize = sizeof (FieldT);
195+ this ->fields = fieldsArray;
196+ }
197+ else
198+ {
199+ AutoCriticalSection autoCS (host->GetScriptContext ()->GetThreadContext ()->GetEtwRundownCriticalSection ());
200+ this ->fieldSize = sizeof (FieldT);
201+ this ->fields = fieldsArray;
202+ }
277203 }
278204
279205 };
0 commit comments