public void AllocValueTypeAndCopy(StackObject *ptr, StackObject *src) { var dst = ILIntepreter.ResolveReference(src); var type = intepreter.AppDomain.GetType(dst->Value); int size, managedCount; type.GetValueTypeSize(out size, out managedCount); if (allocator == null) { allocator = new StackObjectAllocator(AllocBlock); } StackObjectAllocation alloc; if (allocator.AllocExisting(ptr, size, managedCount, out alloc)) { if (dst != alloc.Address) { dst = alloc.Address; ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; int managedIdx = alloc.ManagedIndex; InitializeValueTypeObject(type, dst, true, ref managedIdx); intepreter.CopyStackValueType(src, ptr, managedStack); FreeValueTypeObject(src); } else { ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; } } else { int start = int.MaxValue; int end = int.MinValue; StackObject *endAddr; CountValueTypeManaged(src, ref start, ref end, &endAddr); if (endAddr == valueTypePtr) { valueTypePtr = dst; } allocator.RegisterAllocation(ptr, dst, size, start, managedCount); ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; } }
public void AllocValueType(StackObject *ptr, IType type, bool register = false) { if (type.IsValueType) { StackObject *dst; int size, managedCount; type.GetValueTypeSize(out size, out managedCount); int managedIdx = -1; if (register) { if (allocator == null) { allocator = new StackObjectAllocator(AllocBlock); } var allocation = allocator.Alloc(ptr, size, managedCount); dst = allocation.Address; managedIdx = allocation.ManagedIndex; } else { dst = valueTypePtr; managedIdx = managedStack.Count; valueTypePtr = ILIntepreter.Minus(valueTypePtr, size); if (valueTypePtr <= StackBase) { throw new StackOverflowException(); } } ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; InitializeValueTypeObject(type, dst, register, ref managedIdx); } else { throw new ArgumentException(type.FullName + " is not a value type.", "type"); } }