示例#1
0
文件: Heap.cs 项目: rafatahmed/Dynamo
        /// <summary>
        /// Allocate a string, the string will be put in string table.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private StackValue AllocateStringInternal(string str, bool isConstant)
        {
            int index;
            if (!stringTable.TryGetPointer(str, out index))
            {
                index = AllocateInternal(new StackValue[] {}, PrimitiveType.kTypeString);
                stringTable.AddString(index, str);
            }

            if (isConstant)
                fixedHeapElements.Add(index);

            var svString = StackValue.BuildString(index);
            DSString dsstring = ToHeapObject<DSString>(svString);
            dsstring.SetPointer(svString);
            return svString;
        }
示例#2
0
        /// <summary>
        /// Allocate a string, the string will be put in string table.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private StackValue AllocateStringInternal(string str, bool isConstant)
        {
            int index;

            if (stringTable.TryGetPointer(str, out index))
            {
                // Any existing heap elements, marked as white, that are in the sweepSet and that are referenced during the sweep cycle will be marked as Black.
                // This will ensure that no reachable data is mistakenly cleaned up.
                bool isDuringGCCriticalAsyncCycle = gcState != GCState.Pause;// Between the time the GC takes a snapshot of the stack and heap untill GC cycle is over.
                bool isValidHeapIndex             = index >= 0 && index < heapElements.Count;
                if (isDuringGCCriticalAsyncCycle && isValidHeapIndex)
                {
                    var he = heapElements[index];
                    Validity.Assert(he != null, "Heap element found at index {0} cannot be null", index);

                    // If heap element is marked as white then it is either not processed by Propagate step yet or processed and found as garbage.
                    // If the sweepSet does not contain the heap element's index then there is no need to mark it black (since cleanup will not even be tried)
                    if (he.Mark == GCMark.White && sweepSet.Contains(index))
                    {
                        // Set the heap element's Mark as Black so that it will not get cleaned up.
                        // No need to do a recursive mark on the it since it is just a string and thus cannot have references to other heap elements.
                        he.Mark = GCMark.Black;
                    }
                }
            }
            else
            {
                index = AllocateInternal(new StackValue[] {}, PrimitiveType.String);
                stringTable.AddString(index, str);
            }

            if (isConstant)
            {
                fixedHeapElements.Add(index);
            }

            var      svString = StackValue.BuildString(index);
            DSString dsstring = ToHeapObject <DSString>(svString);

            dsstring.SetPointer(svString);
            return(svString);
        }