Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@fd7889c423] [MERGE #4018 @obastemur] fi…
Browse files Browse the repository at this point in the history
…x modFunctionIndex is missing on copy

Merge pull request #4018 from obastemur:modf_copy

OS14289876 credit goes to @jianchun
  • Loading branch information
chakrabot committed Nov 4, 2017
1 parent fb7e3da commit 06ba99b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 15 additions & 3 deletions deps/chakrashim/core/lib/Common/DataStructures/BaseDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ namespace JsUtil
}
}

BaseDictionary(const BaseDictionary &other) : alloc(other.alloc)
BaseDictionary(const BaseDictionary &other) :
alloc(other.alloc)
{
if(other.Count() == 0)
{
Expand All @@ -153,6 +154,7 @@ namespace JsUtil
entries = nullptr;
count = 0;
freeCount = 0;
modFunctionIndex = UNKNOWN_MOD_INDEX;

#if PROFILE_DICTIONARY
stats = nullptr;
Expand Down Expand Up @@ -182,6 +184,7 @@ namespace JsUtil
count = other.count;
freeList = other.freeList;
freeCount = other.freeCount;
modFunctionIndex = other.modFunctionIndex;

CopyArray(buckets, bucketCount, other.buckets, bucketCount);
CopyArray<EntryType, Field(ValueType, TAllocator), TAllocator>(
Expand Down Expand Up @@ -298,6 +301,7 @@ namespace JsUtil
this->entries = nullptr;
this->count = 0;
this->freeCount = 0;
this->modFunctionIndex = UNKNOWN_MOD_INDEX;
}

void Reset()
Expand All @@ -307,6 +311,7 @@ namespace JsUtil
DeleteBuckets(buckets, bucketCount);
buckets = nullptr;
bucketCount = 0;
this->modFunctionIndex = UNKNOWN_MOD_INDEX;
}
else
{
Expand All @@ -317,6 +322,7 @@ namespace JsUtil
DeleteEntries(entries, size);
entries = nullptr;
freeCount = count = size = 0;
this->modFunctionIndex = UNKNOWN_MOD_INDEX;
}
else
{
Expand Down Expand Up @@ -714,6 +720,7 @@ namespace JsUtil
count = other->count;
freeList = other->freeList;
freeCount = other->freeCount;
modFunctionIndex = other->modFunctionIndex;

CopyArray(buckets, bucketCount, other->buckets, bucketCount);
CopyArray<EntryType, Field(ValueType, TAllocator), TAllocator>(
Expand Down Expand Up @@ -875,7 +882,8 @@ namespace JsUtil
{
// minimum capacity is 4
int initSize = max(capacity, 4);
uint initBucketCount = SizePolicy::GetBucketSize(initSize, &modFunctionIndex);
int modIndex = UNKNOWN_MOD_INDEX;
uint initBucketCount = SizePolicy::GetBucketSize(initSize, &modIndex);
AssertMsg(initBucketCount > 0, "Size returned by policy should be greater than 0");

int* newBuckets = nullptr;
Expand All @@ -887,6 +895,7 @@ namespace JsUtil
this->entries = newEntries;
this->bucketCount = initBucketCount;
this->size = initSize;
this->modFunctionIndex = modIndex;
Assert(this->freeCount == 0);
#if PROFILE_DICTIONARY
stats = DictionaryStats::Create(typeid(this).name(), size);
Expand Down Expand Up @@ -1015,7 +1024,8 @@ namespace JsUtil
AutoDoResize autoDoResize(*this);

int newSize = SizePolicy::GetNextSize(count);
uint newBucketCount = SizePolicy::GetBucketSize(newSize, &modFunctionIndex);
int modIndex = UNKNOWN_MOD_INDEX;
uint newBucketCount = SizePolicy::GetBucketSize(newSize, &modIndex);

__analysis_assume(newSize > count);
int* newBuckets = nullptr;
Expand All @@ -1031,6 +1041,7 @@ namespace JsUtil

this->entries = newEntries;
this->size = newSize;
this->modFunctionIndex = modIndex;
return;
}

Expand All @@ -1041,6 +1052,7 @@ namespace JsUtil
// When TAllocator is of type Recycler, it is possible that the Allocate above causes a collection, which
// in turn can cause entries in the dictionary to be removed - i.e. the dictionary contains weak references
// that remove themselves when no longer valid. This means the free list might not be empty anymore.
this->modFunctionIndex = modIndex;
for (int i = 0; i < count; i++)
{
__analysis_assume(i < newSize);
Expand Down
8 changes: 6 additions & 2 deletions deps/chakrashim/core/lib/Common/DataStructures/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ namespace JsUtil

void Resize()
{
int newSize = PrimePolicy::GetSize(count * 2, &modFunctionIndex);
int modIndex = UNKNOWN_MOD_INDEX;
int newSize = PrimePolicy::GetSize(count * 2, &modIndex);

if (newSize <= count)
{
Expand All @@ -358,6 +359,7 @@ namespace JsUtil
EntryType* newEntries = RecyclerNewArray(recycler, EntryType, newSize);
CopyArray<EntryType, Field(const RecyclerWeakReference<TKey>*)>(newEntries, newSize, entries, count);
AnalysisAssert(count < newSize);
modFunctionIndex = modIndex;
for (int i = 0; i < count; i++)
{
uint bucket = PrimePolicy::GetBucket(newEntries[i].hash, newSize, modFunctionIndex);
Expand Down Expand Up @@ -437,7 +439,8 @@ namespace JsUtil

void Initialize(int capacity)
{
int size = PrimePolicy::GetSize(capacity, &modFunctionIndex);
int modIndex = UNKNOWN_MOD_INDEX;
int size = PrimePolicy::GetSize(capacity, &modIndex);

int* buckets = RecyclerNewArrayLeaf(recycler, int, size);
EntryType * entries = RecyclerNewArray(recycler, EntryType, size);
Expand All @@ -451,6 +454,7 @@ namespace JsUtil
for (int i = 0; i < size; i++) buckets[i] = -1;
this->entries = entries;
this->freeList = -1;
this->modFunctionIndex = modIndex;
}
}

Expand Down

0 comments on commit 06ba99b

Please sign in to comment.